Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add handlebarsHelpers #49

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Readme.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ So the way generated image is accessed from generated API at the moment has to b
[spritesheet-templates](https://github.com/twolfson/spritesheet-templates). Default behaviour is to
use filename (without dirname and extension)
- `cssImageRef` - path by which generated image will be referenced in API. If target.image is interpolated, cssImageRef should be interpolated the same way too.
- `handlebarsHelpers` - object. Container for helpers to register to handlebars for our template
- Each key-value pair is the name of a handlebars helper corresponding to its function
- For example, `{half: function (num) { return num/2; }` will add a handlebars helper that halves numbers
- `spritesmithOptions` - optional. Options for [spritesmith](https://github.com/Ensighten/spritesmith)
- `retina` - optional, when specified, uses retina capabilities of [spritesheet-templates](https://github.com/twolfson/spritesheet-templates). Can be either suffix string (like '@2x') or object consisting of three fields:
- `classifier` - `Function` that allows to say which source is for retina spritesheet and which is not. Will be called with full path to source file, and should return an object of this format -
Expand Down
8 changes: 7 additions & 1 deletion lib/processOptions.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = function (rawOptions) {
return path.parse(path.relative(mergedOptions.src.cwd, fileName)).name;
},
cssImageRef: rawOptions.target.image,
customTemplates: {}
customTemplates: {},
handlebarsHelpers: {}
},
spritesmithOptions: {},
spritesheetTemplatesOptions: {}
Expand All @@ -45,6 +46,11 @@ module.exports = function (rawOptions) {
}
});

var handlebarsHelpers = mergedOptions.apiOptions.handlebarsHelpers;
Object.keys(handlebarsHelpers).forEach(function registerHelper(helperKey) {
templater.registerHandlebarsHelper(helperKey, handlebarsHelpers[helperKey]);
});

processRetinaOptions(mergedOptions);

return mergedOptions;
Expand Down