Fixed variable name being appended by space.

This commit is contained in:
BurnyLlama 2023-08-04 20:18:58 +02:00
parent d23b5e3b8f
commit 66dae1820a

View File

@ -37,14 +37,14 @@ export default function parseTemplate(template, data) {
// Syntax: {{ variableName }}
// Does: Inserts a variable, if it exists.
.replace(
/{{\s*(.+)\s*}}/gm,
/{{\s*(\S+?)\s*}}/gm,
(match, variableName) => {
if (flattenedData[variableName] === undefined || flattenedData[variableName] === null) {
error(`Error: ${variableName} is not defined!`)
error(`Error: "${variableName}" is not defined!`)
process.exit(1)
}
log(`${variableName} = ${flattenedData[variableName]}`)
log(`"${variableName}" = ${flattenedData[variableName]}`)
return flattenedData[variableName]
}
)
@ -54,14 +54,14 @@ export default function parseTemplate(template, data) {
// {% endif %}
// Does: includes <code to include> if variableName exists and is true.
.replace(
/^{%\s*if\s*(.+)\s*%}$([\s\S]*?)^{%\s*endif\s*%}$/gm,
/^{%\s*if\s*(\S+?)\s*%}$([\s\S]*?)^{%\s*endif\s*%}$/gm,
(match, variableName, codeBlock) => {
if (flattenedData[variableName] === undefined || flattenedData[variableName] === null) {
error(`Error: ${variableName} is not defined!`)
error(`Error: "${variableName}" is not defined!`)
process.exit(1)
}
log(`${variableName} = ${flattenedData[variableName]}`)
log(`"${variableName}" = ${flattenedData[variableName]}`)
return flattenedData[variableName] ? codeBlock : ""
}
)