diff --git a/parseTemplate.js b/parseTemplate.js index 8f7b15f..c5c04c7 100644 --- a/parseTemplate.js +++ b/parseTemplate.js @@ -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 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 : "" } )