Closed WhereJuly closed 7 years ago
cssOpts.cssSelector
is specific to the CSS template itself:
https://github.com/twolfson/spritesheet-templates/blob/10.2.1/lib/templates/css.template.js#L16-L18
Since you are using a custom template and not that template, the option won't be used.
For your scenario, we expose the cssOpts
variables as options
in templates:
https://github.com/twolfson/gulp.spritesmith/tree/6.3.0#templating
This means your template should work if we update it to:
gulpfile.js:
spritesmith({
algorithm: 'left-right',
imgName: 'sprites-' + folder + '.png',
cssName: 'sprites-' + folder + '.css',
cssTemplate: './spritesmith.tpl.mustache',
cssOpts: {
folder: folder
}
})
Template:
.sprite-{{options.folder}} {
background-image: url({{{spritesheet.image}}});
display: block;
}
{{#sprites}}
.sprite-{{options.folder}}-{{name}} {
background-position: {{px.offset_x}} {{px.offset_y}};
width: {{px.width}};
height: {{px.height}};
}
{{/sprites}}
Great! Thank you for quick answer. I knew it should be somewhere there.
The functionality is wide and spread over the different docs so that it somehow difficult to figure out the how to's for the particluar use case (or is it just me such a inexperienced?). Did not you think of making a "Usage Receipes" lik e.g. Browsersync or Gulp itself do?
I at least see 4 ones:
.jpg
sprites.I would contribute with cases description and 'how-to'. You would establish a new receipes.MD
section, edit my input & publish. What do you think?
We're aware that the current documentation is daunting. We've considered building a website for better documentation linking but we haven't had the time to invest in that.
With respect to explicit examples, we do have an examples section:
https://github.com/twolfson/gulp.spritesmith/tree/6.3.0#examples
We try not to over-do examples though as it can be hard to separate signal from noise at that point. From our perspective, examples/features should be added if there are enough recurring requests. In the ones you listed:
Understood. Thank you again.
First thanks a lot for the great product!
Sorry to bother you but I looked into the documentation, tried some options, and I did not find how to get a reference to my source folder name from within the custom Mustache template.
The ultimate goal is to be able to insert the source folder name within the CSS class selector name generated by Spritesmith.
The background is that I generate multiple different pairs of
folder.css
+folder.png
with Spritesmith. I do all the things with Gulp, like reading multiple nested source folders and make the desired output (as per below). The only thing I miss is getting the source folder name into my CSS something like .spriteprefix-folder
-spritename {CSS rules}. I usecssOpts.cssSelector
(see below) but I have no effect in my CSS output.Currently I use this custom Musache template:
via this Gulp script:
And I get the following result (excerpt):
What I want to get is:
folder
variableI suppose this should be possible with current options. I cannot just find the right one. Thank you again.