Merge pull request #14214 from Budibase/fix/14201
Add all HBS helpers to manifest
This commit is contained in:
commit
0fb9c78551
|
@ -1,4 +1,7 @@
|
|||
import { HelperFunctionBuiltin } from "../src/helpers/constants"
|
||||
import {
|
||||
HelperFunctionBuiltin,
|
||||
EXTERNAL_FUNCTION_COLLECTIONS,
|
||||
} from "../src/helpers/constants"
|
||||
import { readFileSync, writeFileSync } from "fs"
|
||||
import { marked } from "marked"
|
||||
import { join, dirname } from "path"
|
||||
|
@ -14,21 +17,6 @@ type HelperInfo = {
|
|||
tags?: any[]
|
||||
}
|
||||
|
||||
/**
|
||||
* full list of supported helpers can be found here:
|
||||
* https://github.com/budibase/handlebars-helpers
|
||||
*/
|
||||
|
||||
const COLLECTIONS = [
|
||||
"math",
|
||||
"array",
|
||||
"number",
|
||||
"url",
|
||||
"string",
|
||||
"comparison",
|
||||
"object",
|
||||
"uuid",
|
||||
]
|
||||
const FILENAME = join(__dirname, "..", "src", "manifest.json")
|
||||
const outputJSON: any = {}
|
||||
const ADDED_HELPERS = {
|
||||
|
@ -140,7 +128,7 @@ const excludeFunctions: Record<string, string[]> = { string: ["raw"] }
|
|||
*/
|
||||
function run() {
|
||||
const foundNames: string[] = []
|
||||
for (let collection of COLLECTIONS) {
|
||||
for (let collection of EXTERNAL_FUNCTION_COLLECTIONS) {
|
||||
const collectionFile = readFileSync(
|
||||
`${dirname(
|
||||
require.resolve("@budibase/handlebars-helpers")
|
||||
|
|
|
@ -58,7 +58,7 @@ function buildList(parts: string[], value: any) {
|
|||
if (!value) {
|
||||
return parts.length > 1 ? `${build()}` : build()
|
||||
} else {
|
||||
return parts.length === 0 ? value : `${value}, ${build()}`
|
||||
return parts.length === 0 ? value : `${build()}, ${value}`
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,22 @@ export const HelperFunctionBuiltin = [
|
|||
"with",
|
||||
]
|
||||
|
||||
/**
|
||||
* full list of supported helpers can be found here:
|
||||
* https://github.com/Budibase/handlebars-helpers
|
||||
*/
|
||||
export const EXTERNAL_FUNCTION_COLLECTIONS = [
|
||||
"math",
|
||||
"array",
|
||||
"number",
|
||||
"url",
|
||||
"string",
|
||||
"comparison",
|
||||
"object",
|
||||
"regex",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
export const HelperFunctionNames = {
|
||||
OBJECT: "object",
|
||||
ALL: "all",
|
||||
|
|
|
@ -2,26 +2,12 @@
|
|||
import helpers from "@budibase/handlebars-helpers"
|
||||
|
||||
import { date, duration } from "./date"
|
||||
import { HelperFunctionBuiltin } from "./constants"
|
||||
import {
|
||||
HelperFunctionBuiltin,
|
||||
EXTERNAL_FUNCTION_COLLECTIONS,
|
||||
} from "./constants"
|
||||
import Handlebars from "handlebars"
|
||||
|
||||
/**
|
||||
* full list of supported helpers can be found here:
|
||||
* https://github.com/Budibase/handlebars-helpers
|
||||
*/
|
||||
|
||||
const EXTERNAL_FUNCTION_COLLECTIONS = [
|
||||
"math",
|
||||
"array",
|
||||
"number",
|
||||
"url",
|
||||
"string",
|
||||
"comparison",
|
||||
"object",
|
||||
"regex",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
const ADDED_HELPERS = {
|
||||
date: date,
|
||||
duration: duration,
|
||||
|
@ -40,7 +26,7 @@ export function registerAll(handlebars: typeof Handlebars) {
|
|||
let hbsHelperInfo = helpers[collection]()
|
||||
for (let entry of Object.entries(hbsHelperInfo)) {
|
||||
const name = entry[0]
|
||||
// skip built in functions and ones seen already
|
||||
// skip built-in functions and ones seen already
|
||||
if (
|
||||
HelperFunctionBuiltin.indexOf(name) !== -1 ||
|
||||
externalNames.indexOf(name) !== -1
|
||||
|
|
|
@ -1312,6 +1312,26 @@
|
|||
"requiresBlock": false
|
||||
}
|
||||
},
|
||||
"regex": {
|
||||
"toRegex": {
|
||||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{toRegex 'foo'}} -> /foo/",
|
||||
"description": "<p>Convert the given string to a regular expression.</p>\n",
|
||||
"requiresBlock": false
|
||||
},
|
||||
"test": {
|
||||
"args": [
|
||||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{test 'foobar' (toRegex 'foo')}} -> true",
|
||||
"description": "<p>Returns true if the given <code>str</code> matches the given regex. A regex can be passed on the context, or using the <a href=\"#toregex\">toRegex</a> helper as a subexpression.</p>\n",
|
||||
"requiresBlock": false
|
||||
}
|
||||
},
|
||||
"uuid": {
|
||||
"uuid": {
|
||||
"args": [],
|
||||
|
|
|
@ -93,10 +93,10 @@ describe("Test that the string processing works correctly", () => {
|
|||
|
||||
it("should handle a complex statement", () => {
|
||||
const response = convertToJS(
|
||||
"This is the average: {{ join ( avg val1 val2 val3 ) val4 }}"
|
||||
"This is the average: {{ join val1 ( avg val2 val3 val4 ) }}"
|
||||
)
|
||||
checkLines(response, [
|
||||
'const var1 = helpers.join(helpers.avg($("val1"), $("val2"), $("val3")), $("val4"));',
|
||||
'const var1 = helpers.join($("val1"), helpers.avg($("val2"), $("val3"), $("val4")));',
|
||||
"return `This is the average: ${var1}`;",
|
||||
])
|
||||
})
|
||||
|
@ -119,10 +119,10 @@ describe("Test that the string processing works correctly", () => {
|
|||
|
||||
it("should handle multiple complex statements", () => {
|
||||
const response = convertToJS(
|
||||
"average: {{ avg ( abs val1 ) val2 }} add: {{ add 1 2 }}"
|
||||
"average: {{ avg val1 ( abs val2 ) }} add: {{ add 1 2 }}"
|
||||
)
|
||||
checkLines(response, [
|
||||
'const var1 = helpers.avg(helpers.abs($("val1")), $("val2"));',
|
||||
'const var1 = helpers.avg($("val1"), helpers.abs($("val2")));',
|
||||
"const var2 = helpers.add(1, 2);",
|
||||
"return `average: ${var1} add: ${var2}`;",
|
||||
])
|
||||
|
|
Loading…
Reference in New Issue