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

34 lines
950 B
JavaScript
Raw Normal View History

const externalHandlebars = require("./external")
const helperList = require("@budibase/handlebars-helpers")
let helpers = undefined
2024-01-30 16:52:25 +01:00
const helpersToRemove = ["sortBy"]
2024-01-31 10:00:41 +01:00
module.exports.getJsHelperList = () => {
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
2024-01-30 16:52:25 +01:00
for (const toRemove of helpersToRemove) {
delete helpers[toRemove]
}
Object.freeze(helpers)
return helpers
}