2024-02-02 10:51:46 +01:00
|
|
|
const externalHandlebars = require("./external")
|
|
|
|
const helperList = require("@budibase/handlebars-helpers")
|
2022-07-28 21:20:53 +02:00
|
|
|
|
2024-02-02 10:51:46 +01:00
|
|
|
let helpers = undefined
|
2023-12-19 18:46:15 +01:00
|
|
|
|
2024-01-31 10:34:49 +01:00
|
|
|
const helpersToRemoveForJs = ["sortBy"]
|
|
|
|
module.exports.helpersToRemoveForJs = helpersToRemoveForJs
|
2024-01-30 16:52:25 +01:00
|
|
|
|
2024-01-31 10:00:41 +01:00
|
|
|
module.exports.getJsHelperList = () => {
|
2023-12-19 18:46:15 +01:00
|
|
|
if (helpers) {
|
|
|
|
return helpers
|
|
|
|
}
|
|
|
|
|
|
|
|
helpers = {}
|
2024-02-02 10:51:46 +01:00
|
|
|
let constructed = []
|
|
|
|
for (let collection of externalHandlebars.externalCollections) {
|
|
|
|
constructed.push(helperList[collection]())
|
|
|
|
}
|
|
|
|
for (let collection of constructed) {
|
2022-07-28 21:20:53 +02:00
|
|
|
for (let [key, func] of Object.entries(collection)) {
|
2024-01-25 19:48:34 +01:00
|
|
|
// 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, {})
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|
|
|
|
}
|
2024-02-02 10:51:46 +01:00
|
|
|
for (let key of Object.keys(externalHandlebars.addedHelpers)) {
|
|
|
|
helpers[key] = externalHandlebars.addedHelpers[key]
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|
2024-01-25 17:24:47 +01:00
|
|
|
|
2024-01-31 10:34:49 +01:00
|
|
|
for (const toRemove of helpersToRemoveForJs) {
|
2024-01-30 16:52:25 +01:00
|
|
|
delete helpers[toRemove]
|
|
|
|
}
|
2023-12-19 18:46:15 +01:00
|
|
|
Object.freeze(helpers)
|
|
|
|
return helpers
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|