Inject {} at the end of the helper calls

This commit is contained in:
Adria Navarro 2024-01-25 19:48:34 +01:00
parent a14ff42b14
commit db14f9afab
1 changed files with 2 additions and 12 deletions

View File

@ -15,24 +15,14 @@ module.exports.getHelperList = () => {
} }
for (let collection of constructed) { for (let collection of constructed) {
for (let [key, func] of Object.entries(collection)) { for (let [key, func] of Object.entries(collection)) {
helpers[key] = func // Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it
helpers[key] = (...props) => func(...props, {})
} }
} }
for (let key of Object.keys(externalHandlebars.addedHelpers)) { for (let key of Object.keys(externalHandlebars.addedHelpers)) {
helpers[key] = externalHandlebars.addedHelpers[key] helpers[key] = externalHandlebars.addedHelpers[key]
} }
helpers = adjustJsHelpers(helpers)
Object.freeze(helpers) Object.freeze(helpers)
return helpers return helpers
} }
// Some helpers depend on handlebars injecting some parameters. This function adjust the helpers when required
function adjustJsHelpers(helpers) {
const result = { ...helpers }
result.avg = function (...params) {
return helpers.avg(...params, {})
}
return result
}