Closed jhcao23 closed 5 years ago
Hey @jhcao23 thanks for the issue!
IIRC --helper
can be used multiple times, what is the issue with calling hbs --helper swag
? Does this not do what you expect?
Hey @keithamus Can --helper support the whole library? I assume this option only supports one single helper function, doesn't it?
Looking at the code for hbs-cli, it duck-types to see if there is a ".register" function and simply calls that.
Looking through the docs for Swag it expects you to call Swag.registerHelpers
. Our code could be modified to handle this case but it seems non standard?
Looking through the docs for helpers
, it seems that the module is a function that you call like so: require('handlebars-helpers')({ handlebars: handlebars })
. Again this is non-standard.
To get this working today you could write a simple wrapper helper which looks something like this:
// myhelpers.js
const swag = require('swag')
const helpers = require('handlebars-helpers')
module.exports = {
register(handlebars) {
Swag.registerHelpers(handlebars)
helpers({ handlebars })
}
}
Then simply call hbs --helpers myhelpers --data data.json template.mustache
Another option would be to raise Issues/PRs against these project and ask them to support the defacto-standard of a register(handlebars)
function.
beautiful!
Can we add one more parameter to accept third party helpers such as Swag and the popular helpers, such as
hbs --extraHelper 'swag' --data data.json template.mustache
?