2022-07-28 21:20:53 +02:00
|
|
|
const externalHandlebars = require("./external")
|
|
|
|
const helperList = require("@budibase/handlebars-helpers")
|
|
|
|
|
2023-12-19 18:46:15 +01:00
|
|
|
let helpers = undefined
|
|
|
|
|
2022-07-28 21:20:53 +02:00
|
|
|
module.exports.getHelperList = () => {
|
2023-12-19 18:46:15 +01:00
|
|
|
if (helpers) {
|
|
|
|
return helpers
|
|
|
|
}
|
|
|
|
|
|
|
|
helpers = {}
|
2022-07-28 21:20:53 +02:00
|
|
|
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)) {
|
2023-12-19 18:46:15 +01:00
|
|
|
helpers[key] = func
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let key of Object.keys(externalHandlebars.addedHelpers)) {
|
2023-12-19 18:46:15 +01:00
|
|
|
helpers[key] = externalHandlebars.addedHelpers[key]
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|
2024-01-25 17:24:47 +01:00
|
|
|
|
|
|
|
helpers = adjustJsHelpers(helpers)
|
2023-12-19 18:46:15 +01:00
|
|
|
Object.freeze(helpers)
|
|
|
|
return helpers
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|
2024-01-25 17:24:47 +01:00
|
|
|
|
2024-01-25 17:35:00 +01:00
|
|
|
// Some helpers depend on handlebars injecting some parameters. This function adjust the helpers when required
|
2024-01-25 17:24:47 +01:00
|
|
|
function adjustJsHelpers(helpers) {
|
|
|
|
const result = { ...helpers }
|
|
|
|
|
|
|
|
result.avg = function (...params) {
|
|
|
|
return helpers.avg(...params, {})
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|