Permalink
Browse files

add option forceModify

  • Loading branch information...
1 parent 6396038 commit ca2dc70601da178235a0fcf35782bcfa3771ff88 @navyxie committed Jul 28, 2016
Showing with 47 additions and 3 deletions.
  1. +3 −1 .gitignore
  2. +3 −1 .npmignore
  3. +13 −0 README.md
  4. +8 −0 index.js
  5. +1 −1 package.json
  6. +10 −0 test/test.js
  7. +9 −0 test/views/forcemodify.html
View
@@ -2,4 +2,6 @@ node_modules
coverage
npm-debug.log
.DS_Store
-.test_dist_img
+.test_dist_img
+./.test_dist_img
+./.test_dist_jade
View
@@ -2,4 +2,6 @@ node_modules
coverage
npm-debug.log
.DS_Store
-.test_dist_img
+.test_dist_img
+./.test_dist_img
+./.test_dist_jade
View
@@ -65,3 +65,16 @@ gulp.task('jade',['jadeDemo'])
- npm test
- npm run cov
+
+## change log
+
+- 0.2.0
+ add option forceModify:
+ which is a function , change url and direct return result.
+- 0.1.0
+ add option ext:
+ which support css, html ,jade, default css.
+ add option skip:
+ which is a array, url will skip when contain character in skip array
+- 0.0.1
+ only support css file
View
@@ -36,6 +36,7 @@ function formatUrl (filePath, url, options) {
var cssDirname = path.dirname(filePath);
// options
var modify = options.modify; // function you can modify return url before prepend or append
+ var forceModify = options.forceModify // first call and return.
var prepend = options.prepend;
var append = options.append;
var skip = options.skip || [];
@@ -47,10 +48,17 @@ function formatUrl (filePath, url, options) {
var formattedUrl = url; // image origin filepath
var imgAbsolutePath = formattedUrl; // image absolute filepath
try {
+
//if images url is data:base64 , continue
if (formattedUrl.indexOf('data:') === 0) {
return formattedUrl;
}
+
+ //if support forceModify function , call it and return result
+ if (_.isFunction(forceModify)) {
+ return forceModify(formattedUrl, filePath);
+ }
+
// if images url is netword file , continue
if (/^(http|https|ftp|\/\/)/gi.test(formattedUrl)) {
return formattedUrl;
View
@@ -1,6 +1,6 @@
{
"name": "gulp-custom-css-urls",
- "version": "0.1.0",
+ "version": "0.2.0",
"description": "a gulp plugin custom image url inline in css",
"main": "index.js",
"scripts": {
View
@@ -87,6 +87,16 @@ describe('gulp-custom-css-urls', function() {
}))
.pipe(vfs.dest('./.test_dist_jade'))
});
+ it('html -> forceModify() should be ok if image url is relative to website root path', function () {
+ vfs.src('test/views/forcemodify.html')
+ .pipe(customCssUrls({
+ forceModify: function (imageUrl, filePath) {
+ return imageUrl.replace('https://demo.com', '');
+ },
+ ext: 'html'
+ }))
+ .pipe(vfs.dest('./.test_dist_jade'))
+ });
after(function(done){
setTimeout(function () {
execSync("rm -r " + path.join(process.cwd(), './.test_dist_img'));
@@ -0,0 +1,9 @@
+<html>
+ <head><title>test</title></head>
+ <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="https://demo.com/images/example.png" /></div>
+ <div id="footer"><img src="/images/example.png" /></div>
+ </body>
+</html>

0 comments on commit ca2dc70

Please sign in to comment.