Skip to content

Commit

Permalink
added test case for custom mustache template
Browse files Browse the repository at this point in the history
  • Loading branch information
aslansky committed Aug 17, 2014
1 parent 8711e3f commit b30aea2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .jscs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
"requireLineFeedAtFileEnd": true,
"requireRightStickedOperators": [ "!" ],
"requireLeftStickedOperators": [ "," ],
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforePostfixUnaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceBeforePostfixUnaryOperators": true,
"requireKeywordsOnNewLine": ["else", "else if"],
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true,
Expand All @@ -14,8 +16,6 @@
"disallowSpacesInsideParentheses": true,
"disallowSpaceAfterKeywords": [],
"disallowSpaceAfterObjectKeys": true,
"disallowLeftStickedOperators": [ "?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<=" ],
"disallowRightStickedOperators": [ "?", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<=" ],
"disallowImplicitTypeConversion": [],
"disallowMultipleLineBreaks": true,
"disallowSpacesInsideArrayBrackets": true,
Expand Down
5 changes: 2 additions & 3 deletions lib/templates/sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Load in local modules
var fs = require('graceful-fs');
var path = require('path');
var mustache = require('mustache');
var tmpl = {
'css': fs.readFileSync(__dirname + '/css.mustache', 'utf8'),
Expand Down Expand Up @@ -48,9 +49,7 @@ function cssTemplate (params) {
}
});
// Render and return CSS
var tmplFile = options.template
? fs.readFileSync(options.template, 'utf8')
: tmpl[options.processor];
var tmplFile = options.template ? fs.readFileSync(path.join(process.cwd(), options.template), 'utf8') : tmpl[options.processor];
var css = mustache.render(tmplFile, tmplParams);
return css;
}
Expand Down
35 changes: 34 additions & 1 deletion test/css-sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,40 @@ describe('css-sprite (lib/css-sprite.js)', function () {
done();
});
});
it('should return a object stream with a sprite and a css file (using a custom template)', function (done) {
var png, css;
vfs.src('./test/fixtures/**')
.pipe(sprite({
out: './dist/img',
name: 'sprites.png',
style: './dist/css/sprites.css',
template: './test/template/template.mustache'
}))
.pipe(through2.obj(function (file, enc, cb) {
if (file.relative.indexOf('png') > -1) {
png = file;
}
else {
css = file;
}
cb();
}))
.on('data', noop)
.on('end', function () {
png.should.be.ok;
png.path.should.equal('dist/img/sprites.png');
png.relative.should.equal('sprites.png');
css.should.be.ok;
css.path.should.equal('./dist/css/sprites.css');
css.relative.should.equal('sprites.css');
css.contents.toString('utf-8').should.containEql('.icon-camera');
css.contents.toString('utf-8').should.containEql('.icon-cart');
css.contents.toString('utf-8').should.containEql('.icon-command');
css.contents.toString('utf-8').should.containEql('.icon-font');
css.contents.toString('utf-8').should.containEql('custom: \'template\';');
done();
});
});
it('should return a object stream with retina sprite, normal sprite and css with media query', function (done) {
var png = [], css;
vfs.src('./test/fixtures/**')
Expand Down Expand Up @@ -255,7 +289,6 @@ describe('css-sprite (lib/css-sprite.js)', function () {
});
});
it('should throw error when file stream', function (done) {

vfs.src('./test/fixtures/**', {buffer: false})
.pipe(sprite({
out: './dist/img',
Expand Down
24 changes: 24 additions & 0 deletions test/template/template.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{#sprite}}
{{class}} {
background-image: url('{{{escaped_image}}}');
}

{{/sprite}}
{{#retina}}
@media (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (-webkit-min-device-pixel-ratio: 1.5), (min-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx) {
{{class}} {
background-image: url('{{{escaped_image}}}');
background-size: {{px.total_width}} {{px.total_height}};
}
}

{{/retina}}
{{#items}}
{{class}} {
custom: 'template';
background-position: {{px.offset_x}} {{px.offset_y}};
width: {{px.width}};
height: {{px.height}};
}

{{/items}}

0 comments on commit b30aea2

Please sign in to comment.