8000 Remove forcing paths to be absolute. · D3R/gulp-css-image-hash@1e093a5 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 1e093a5

Browse files
committed
Remove forcing paths to be absolute.
Change console.log to gulp log Skip passing data urls to modifier
1 parent 44a0c81 commit 1e093a5

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var through = require('through2'),
44
async = require('async'),
55
fs = require('fs'),
66
crypto = require('crypto'),
7-
extname = require('path').extname;
7+
extname = require('path').extname,
8+
gutil = require('gulp-util');
89

910
var PLUGIN_NAME = 'gulp-css-image-hash';
1011

@@ -38,11 +39,6 @@ function cssImageHash(webPath, includeFileExtensions) {
3839
if (path[0] == '"' || path[0] == "'") {
3940
path = path.slice(1).slice(0, -1);
4041
}
41-
42-
//If the path does not start with a '/', add it
43-
if (path[0] != '/') {
44-
path = '/' + path;
45-
}
4642

4743
pairs.push([curValue, path]);
4844
});
@@ -57,6 +53,10 @@ function cssImageHash(webPath, includeFileExtensions) {
5753
return callback();
5854
}
5955
}
56+
57+
if (path.substr(0, 4) == 'data') {
58+
return callback();
59+
}
6060

6161
if (typeof(webPath) == 'function') {
6262
path = webPath(path);
@@ -83,7 +83,7 @@ function cssImageHash(webPath, includeFileExtensions) {
8383
});
8484

8585
file.on('error', function(error) {
86-
console.log(error.message);
86+
gutil.log('gulp-css-image-hash: Skipping ' + path);
8787
callback();
8888
});
8989
}, function (err) {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
"license": "MIT",
1616
"dependencies": {
1717
"async": "^0.9.0",
18+
"gulp-util": "^3.0.8",
1819
"through2": "*"
1920
},
2021
"devDependencies": {
22+
"mocha": "^3.2.0",
2123
"should": "^4.3.0"
2224
}
2325
}

test/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ describe('gulp-css-image-hash', function() {
4848
done();
4949
});
5050
});
51+
52+
it('should ignore data urls', function(done) {
53+
var fakeFile = new File({
54+
contents: new Buffer('body { background: url(data:image/gif;base64,R0lGO); }')
55+
});
56+
57+
var hasher = imagehash('test/examples/');
58+
hasher.write(fakeFile);
59+
60+
hasher.once('data', function(file) {
61+
assert(file.isBuffer());
62+
assert.equal(file.contents.toString(), 'body { background: url(data:image/gif;base64,R0lGO); }');
63+
done();
64+
});
65+
});
5166

5267
it('should update resolvable resource', function(done) {
5368
var fakeFile = new File({

0 commit comments

Comments
 (0)
0