Permalink
Browse files

Fix merge with multiple resolutions

  • Loading branch information...
1 parent 475b069 commit 18bb250e6946c999765b5129e9066c5ec0296ce3 @kpdecker committed Nov 19, 2012
Showing with 42 additions and 13 deletions.
  1. +13 −11 lib/url.js
  2. +29 −2 test/multiple-output.js
View
@@ -100,16 +100,25 @@ module.exports = function(options) {
return imageInfo.literal = outputPath.call(this, lookup[0], url.href, options);
} else {
// Multiple outputs here, add a placeholder that we can replace on output
- return imageInfo.literal = literalNode('stylusImages://' + imageInfo.id);
+ return imageInfo.literal = literalNode('stylusImages://' + imageInfo.id, url.href);
}
}
url.raw = true;
return url;
};
-function literalNode(href) {
- return new nodes.Literal('url("' + href + '")');
+function literalNode(href, id) {
+ var ret = new nodes.Literal('url("' + href + '")');
+ if (id !== undefined) {
+ ret.url = id;
+ ret.clone = function() {
+ var ret = nodes.Literal.prototype.clone.call(this);
+ ret.url = this.url;
+ return ret;
+ };
+ }
+ return ret;
}
function lookupPath(url, paths, options) {
@@ -213,14 +222,7 @@ function outputPath(resolution, id, options) {
}
// Encode
- var ret = literalNode('data:' + mimes[extname(resolution.href)] + ';base64,' + buf.toString('base64'));
- ret.url = id;
- ret.clone = function() {
- var ret = nodes.Literal.prototype.clone.call(this);
- ret.url = this.url;
- return ret;
- };
- return ret;
+ return literalNode('data:' + mimes[extname(resolution.href)] + ';base64,' + buf.toString('base64'), id);
}
module.exports.lookup = lookupPath;
@@ -75,7 +75,34 @@ describe('multiple ouput', function() {
done();
});
});
- it.skip('should merge files for each resolution', function(done) {
- // TODO : Setup a case where one resolution should merge the the other should not
+ it('should merge files for each resolution', function(done) {
+ runTest(
+ '.test\n'
+ + ' background-image url("images/barrowLoRez.png")\n'
+ + ' display inline-block\n'
+ + '.test\n'
+ + ' background-image url("images/barrowLoRez.png")\n',
+
+ {images: {resolutions: [0.5, 1, 2, 3]}},
+
+ function(data) {
+ function expected(density) {
+ return '.test {\n'
+ + ' display: inline-block;\n'
+ + '}\n'
+ + '.test,\n'
+ + '.test {\n'
+ + ' background-image: url("' + (density >= 2 ? lib.HI_REZ_DATA : lib.LO_REZ_DATA) + '");\n'
+ + '}\n';
+ }
+ data.should.eql({
+ '0.5': expected(0.5),
+ '1': expected(1),
+ '2': expected(2),
+ '3': expected(3)
+ });
+
+ done();
+ });
});
});

0 comments on commit 18bb250

Please sign in to comment.