Permalink
Browse files

add feature support src leftspace and rightspace

  • Loading branch information...
1 parent 4c6e723 commit bf096fd6aff715174a32097b10e5e92ca8f356df @navyxie committed Jul 28, 2016
Showing with 37 additions and 11 deletions.
  1. +7 −0 README.md
  2. +16 −8 index.js
  3. +1 −1 package.json
  4. +1 −0 test/test.js
  5. +2 −0 test/views/forcemodify.html
  6. +8 −1 test/views/test.html
  7. +2 −1 test/views/test.jade
View
@@ -86,6 +86,13 @@ gulp.task('originTemplateContent',['returnToOrigin']);
## change log
+- 0.3.0
+
+ ```
+ feature support:
+ image src support leftspace and rightspace.
+ ```
+
- 0.2.2
```
View
@@ -29,6 +29,15 @@ var extList = ['.BMP', '.JPG', '.JPEG', '.PNG', '.GIF'];
function isInExtList (ext) {
return (_.indexOf(extList, ext) !== -1);
}
+
+function isIndexOfInArr (arr, str) {
+ for (var i = 0 ; i < arr.length ; i++) {
+ if (str.indexOf(arr[i]) !== -1) {
+ return true;
+ }
+ }
+ return false;
+}
/**
* filePath current filepath
* url staticfile(image) url
@@ -68,10 +77,8 @@ function formatUrl (filePath, url, options) {
}
//skip when url contain skip character
- for (var i = 0 ; i < skip.length ; i++) {
- if (formattedUrl.indexOf(skip[i]) !== -1) {
- return formattedUrl;
- }
+ if (isIndexOfInArr(skip, formattedUrl)) {
+ return formattedUrl;
}
// skip when static file not in extList
@@ -141,11 +148,12 @@ function formatUrl (filePath, url, options) {
* @return {[type]} [description]
*/
function customContent (fileContents, filePath, options) {
- var imgReg = /src=['"]?([^'"]*)['"]?/ig;
- var srcReg = /(src=)['"]?([^'"]*)['"]?/i;
+ var imgReg = /src([\s]+)?=([\s]+)?['"]?([^'"]*)['"]?/ig;
+ var srcReg = /(src([\s]+)?=([\s]+)?)['"]?([^'"]*)['"]?/i;
+ var skip = options.skip || [];
fileContents = fileContents.replace(imgReg, function (srcStr) {
- return srcStr.replace(srcReg, function (originStr, srcEqualStr, imageUrl) {
- if (srcEqualStr && imageUrl && isInExtList(path.extname(imageUrl).toUpperCase())) {
+ return srcStr.replace(srcReg, function (originStr, srcEqualStr, leftSpace, rightSpace, imageUrl, index) {
+ if (srcEqualStr && imageUrl && isInExtList(path.extname(imageUrl).toUpperCase()) && !isIndexOfInArr(skip, imageUrl)) {
return srcEqualStr + "'" + formatUrl(filePath, imageUrl, options) + "'";
} else {
return srcStr;
View
@@ -1,6 +1,6 @@
{
"name": "gulp-custom-css-urls",
- "version": "0.2.2",
+ "version": "0.3.0",
"description": "a gulp plugin custom image url inline in css",
"main": "index.js",
"scripts": {
View
@@ -83,6 +83,7 @@ describe('gulp-custom-css-urls', function() {
},
outputImage: true,
ext: 'html',
+ skip: ['{'],
outputImage_path: './.test_dist_img'
}))
.pipe(vfs.dest('./.test_dist_jade'))
@@ -10,5 +10,7 @@
var a = "test.png";
var q = {};
q.src=a;
+ var p = {};
+ p.src="/images{{abc}}.png";
</script>
</html>
@@ -3,7 +3,14 @@
<script type="text/javascript" src="/javasctipts/test.js"></script>
<link rel="stylesheet" type="text/css" href="/styles/example1.css">
<body>
- <div id="header"><img src="/images/example.png" /></div>
+ <div id="header"><img src = "/images/example.png" /></div>
<div id="footer"><img src="/images/example.png" /></div>
</body>
+ <script type="text/javascript">
+ var a = "test.png";
+ var q = {};
+ q.src=a;
+ var p = {};
+ p.src="/images{{abc}}.png";
+ </script>
</html>
@@ -6,4 +6,5 @@
img(src="/images/example{{test}}.png")
img(src="/images/example{test}.png")
#footer
- img(src='/images/example.png')
+ img(src='/images/example.png')
+ img(src = '/images/example.png')

0 comments on commit bf096fd

Please sign in to comment.