Skip to content

Commit

Permalink
Added '--nostamp' option to binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Pawlowicz committed Nov 30, 2012
1 parent e919372 commit 09772f3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
7 changes: 5 additions & 2 deletions bin/enhancecss
Expand Up @@ -13,7 +13,8 @@ var options = {
assetHosts: null,
pregzip: false,
noEmbed: false,
cryptedStamp: false
cryptedStamp: false,
stamp: true
};
var fromStdin = !process.env['__DIRECT__'] && process.stdin.readable;

Expand All @@ -23,6 +24,7 @@ if (argv.pregzip) options.pregzip = true;
if (argv.cryptedstamp) options.cryptedStamp = true;
if (argv.o) options.target = argv.o;
if (argv._) options.source = argv._[0];
if (argv.nostamp) options.stamp = false;

options.rootPath = argv.root || process.cwd();

Expand Down Expand Up @@ -55,7 +57,8 @@ function enhance(source, callback) {
assetHosts: options.assetHosts,
noEmbedVersion: options.noEmbed,
cryptedStamp: options.cryptedStamp,
pregzip: options.pregzip
pregzip: options.pregzip,
stamp: options.stamp
}).process(source, function(error, data) {
if (error) throw error;
callback(data);
Expand Down
9 changes: 3 additions & 6 deletions lib/enhance.js
Expand Up @@ -9,10 +9,7 @@ var isWindows = process.platform == 'win32';

var EnhanceCSS = function(options) {
this.options = options;

if (typeof(options.stamp) === 'undefined') {
this.options.stamp = true;
}
this.options.stamp = ('stamp' in options) ? options.stamp : true;
};

EnhanceCSS.prototype = {
Expand Down Expand Up @@ -77,11 +74,11 @@ EnhanceCSS.prototype = {

// Break early if file does not exist
if (!pathInfo.exists) return match;

if (self.options.stamp) {
self._addFileStamp(pathInfo);
}

return ['url(', (self.nextAssetHost() || ''), pathInfo.relative, ')'].join('');
});
}
Expand Down
16 changes: 15 additions & 1 deletion test/binary-test.js
Expand Up @@ -22,9 +22,14 @@ var checkFiles = function(fileName, options) {

// verify content
assert.include(fs.readFileSync(pathToFile()).toString('utf8'), 'a{background:url(data:image/png;base64');
if (options.noEmbed)
if (options.noEmbed) {
assert.include(fs.readFileSync(pathToFile(true)).toString('utf8'), 'a{background:url(/test/data/gradient');

if (options.stamp === false) {
assert.match(fs.readFileSync(pathToFile(true)).toString('utf8'), /gradient\.\w+\)/);
}
}

if (options.pregzip) {
zlib.gunzip(fs.readFileSync(pathToFile(false, true)), function(error, result) {
assert.include(result.toString('utf8'), 'a{background:url(data:image/png;base64');
Expand Down Expand Up @@ -93,6 +98,15 @@ vows.describe('enhance css binary').addBatch({
},
teardown: cleanup(1)
}),
'simple embed with no stamps': pipelinedContext("--noembedversion --nostamp -o /tmp/test1.css", {
'should give empty output': function(error, stdout) {
assert.isEmpty(stdout);
},
'should create valid files': function() {
checkFiles('test1', { stamp: false, noEmbed: true, pregzip: false });
},
teardown: cleanup(1)
}),
'embed with --noembedversion option': pipelinedContext("--noembedversion -o /tmp/test2.css", {
'should give empty output': function(error, stdout) {
assert.isEmpty(stdout);
Expand Down
2 changes: 1 addition & 1 deletion test/embed-test.js
Expand Up @@ -561,7 +561,7 @@ vows.describe('embedding images').addBatch({
}
}).addBatch({
'not embedded files should not get mtime timestamp if "stamp" option equals false': {
topic: runOn('div{background:url(/test/data/gradient.jpg)}', {stamp: false, noEmbedVersion: true}),
topic: runOn('div{background:url(/test/data/gradient.jpg)}', { stamp: false, noEmbedVersion: true }),
'in the "embedded" version': function(data) {
assert.equal(data.embedded.plain, data.original);
},
Expand Down

0 comments on commit 09772f3

Please sign in to comment.