1
0
Fork 0
mirror of synced 2024-06-29 03:20:34 +12:00

fix use of loop item in javascript bindings

This commit is contained in:
Peter Clement 2022-06-23 16:09:35 +01:00
parent 6b7b31c7a9
commit 482be4b5b4

View file

@ -1,5 +1,10 @@
const { getTable } = require("../api/controllers/table/utils")
const { findHBSBlocks } = require("@budibase/string-templates")
const {
findHBSBlocks,
decodeJSBinding,
isJSBinding,
encodeJSBinding,
} = require("@budibase/string-templates")
/**
* When values are input to the system generally they will be of type string as this is required for template strings.
@ -77,11 +82,21 @@ exports.getError = err => {
}
exports.substituteLoopStep = (hbsString, substitute) => {
let blocks = findHBSBlocks(hbsString)
let blocks = []
let checkForJS = isJSBinding(hbsString)
if (checkForJS) {
hbsString = decodeJSBinding(hbsString)
blocks.push(hbsString)
} else {
blocks = findHBSBlocks(hbsString)
}
for (let block of blocks) {
let oldBlock = block
block = block.replace(/loop/, substitute)
hbsString = hbsString.replace(new RegExp(oldBlock, "g"), block)
if (checkForJS) {
hbsString = encodeJSBinding(block)
} else {
hbsString = block
}
}
return hbsString