Dry
This commit is contained in:
parent
507aa8af93
commit
a5ccb9f0e8
|
@ -1,29 +1,42 @@
|
||||||
const externalHandlebars = require("./external")
|
const { date, duration } = require("./date")
|
||||||
const helperList = require("@budibase/handlebars-helpers")
|
|
||||||
|
|
||||||
let helpers = undefined
|
// https://github.com/evanw/esbuild/issues/56
|
||||||
|
const externalCollections = {
|
||||||
|
math: require("@budibase/handlebars-helpers/lib/math"),
|
||||||
|
array: require("@budibase/handlebars-helpers/lib/array"),
|
||||||
|
number: require("@budibase/handlebars-helpers/lib/number"),
|
||||||
|
url: require("@budibase/handlebars-helpers/lib/url"),
|
||||||
|
string: require("@budibase/handlebars-helpers/lib/string"),
|
||||||
|
comparison: require("@budibase/handlebars-helpers/lib/comparison"),
|
||||||
|
object: require("@budibase/handlebars-helpers/lib/object"),
|
||||||
|
regex: require("@budibase/handlebars-helpers/lib/regex"),
|
||||||
|
uuid: require("@budibase/handlebars-helpers/lib/uuid"),
|
||||||
|
}
|
||||||
|
|
||||||
const helpersToRemoveForJs = ["sortBy"]
|
const helpersToRemoveForJs = ["sortBy"]
|
||||||
module.exports.helpersToRemoveForJs = helpersToRemoveForJs
|
module.exports.helpersToRemoveForJs = helpersToRemoveForJs
|
||||||
|
|
||||||
|
const addedHelpers = {
|
||||||
|
date: date,
|
||||||
|
duration: duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
let helpers = undefined
|
||||||
|
|
||||||
module.exports.getJsHelperList = () => {
|
module.exports.getJsHelperList = () => {
|
||||||
if (helpers) {
|
if (helpers) {
|
||||||
return helpers
|
return helpers
|
||||||
}
|
}
|
||||||
|
|
||||||
helpers = {}
|
helpers = {}
|
||||||
let constructed = []
|
for (let collection of Object.values(externalCollections)) {
|
||||||
for (let collection of externalHandlebars.externalCollections) {
|
|
||||||
constructed.push(helperList[collection]())
|
|
||||||
}
|
|
||||||
for (let collection of constructed) {
|
|
||||||
for (let [key, func] of Object.entries(collection)) {
|
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
|
// 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, {})
|
helpers[key] = (...props) => func(...props, {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let key of Object.keys(externalHandlebars.addedHelpers)) {
|
for (let key of Object.keys(addedHelpers)) {
|
||||||
helpers[key] = externalHandlebars.addedHelpers[key]
|
helpers[key] = addedHelpers[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const toRemove of helpersToRemoveForJs) {
|
for (const toRemove of helpersToRemoveForJs) {
|
||||||
|
|
|
@ -1,40 +1,3 @@
|
||||||
const { date, duration } = require("./helpers/date")
|
const { getJsHelperList } = require("./helpers/list")
|
||||||
|
|
||||||
// https://github.com/evanw/esbuild/issues/56
|
module.exports = getJsHelperList()
|
||||||
const externalCollections = {
|
|
||||||
math: require("@budibase/handlebars-helpers/lib/math"),
|
|
||||||
array: require("@budibase/handlebars-helpers/lib/array"),
|
|
||||||
number: require("@budibase/handlebars-helpers/lib/number"),
|
|
||||||
url: require("@budibase/handlebars-helpers/lib/url"),
|
|
||||||
string: require("@budibase/handlebars-helpers/lib/string"),
|
|
||||||
comparison: require("@budibase/handlebars-helpers/lib/comparison"),
|
|
||||||
object: require("@budibase/handlebars-helpers/lib/object"),
|
|
||||||
regex: require("@budibase/handlebars-helpers/lib/regex"),
|
|
||||||
uuid: require("@budibase/handlebars-helpers/lib/uuid"),
|
|
||||||
}
|
|
||||||
|
|
||||||
const addedHelpers = {
|
|
||||||
date: date,
|
|
||||||
duration: duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
let helpers = undefined
|
|
||||||
|
|
||||||
const getHelperList = () => {
|
|
||||||
if (helpers) {
|
|
||||||
return helpers
|
|
||||||
}
|
|
||||||
|
|
||||||
helpers = {}
|
|
||||||
for (let collection of Object.values(externalCollections)) {
|
|
||||||
for (let [key, func] of Object.entries(collection)) {
|
|
||||||
helpers[key] = func
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let key of Object.keys(addedHelpers)) {
|
|
||||||
helpers[key] = addedHelpers[key]
|
|
||||||
}
|
|
||||||
return helpers
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = getHelperList()
|
|
||||||
|
|
Loading…
Reference in New Issue