budibase/packages/string-templates/src/helpers/list.js

29 lines
835 B
JavaScript
Raw Normal View History

const externalHandlebars = require("./external")
const helperList = require("@budibase/handlebars-helpers")
let helpers = undefined
module.exports.getHelperList = () => {
if (helpers) {
return helpers
}
helpers = {}
let constructed = []
for (let collection of externalHandlebars.externalCollections) {
constructed.push(helperList[collection]())
}
for (let collection of constructed) {
for (let [key, func] of Object.entries(collection)) {
// 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)) {
helpers[key] = externalHandlebars.addedHelpers[key]
}
2024-01-25 17:24:47 +01:00
Object.freeze(helpers)
return helpers
}