diff --git a/packages/string-templates/src/utilities.js b/packages/string-templates/src/utilities.js index 76edaef923..bb35e94567 100644 --- a/packages/string-templates/src/utilities.js +++ b/packages/string-templates/src/utilities.js @@ -1,6 +1,6 @@ const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g -module.exports.FIND_HBS_REGEX = /{{[^}}]*}}/g +module.exports.FIND_HBS_REGEX = /{{([^{}])+}}/g module.exports.isAlphaNumeric = char => { return char.match(ALPHA_NUMERIC_REGEX) diff --git a/packages/string-templates/test/basic.spec.js b/packages/string-templates/test/basic.spec.js index 172c94ca21..6babce8f8c 100644 --- a/packages/string-templates/test/basic.spec.js +++ b/packages/string-templates/test/basic.spec.js @@ -11,6 +11,13 @@ describe("Test that the string processing works correctly", () => { expect(output).toBe("templating is easy") }) + it("should process a literal template", async () => { + const output = await processString("derp is {{{ adjective }}}", { + adjective: "derp" + }) + expect(output).toBe("derp is derp") + }) + it("should fail gracefully when wrong type passed in", async () => { let error = null try { diff --git a/packages/string-templates/test/escapes.spec.js b/packages/string-templates/test/escapes.spec.js index eb94b1ce2e..39df8719d6 100644 --- a/packages/string-templates/test/escapes.spec.js +++ b/packages/string-templates/test/escapes.spec.js @@ -32,4 +32,20 @@ describe("Handling context properties with spaces in their name", () => { }) expect(output).toBe("testcase 1") }) +}) + +describe("attempt some complex problems", () => { + it("should be able to handle a very complex handlebars statement", async () => { + const context = { + "New Repeater": { + "Get Actors": { + "first_name": "Bob", + "last_name": "Bobert" + }, + }, + } + const hbs = "{{ New Repeater.Get Actors.first_name }} {{ New Repeater.Get Actors.last_name }}" + const output = await processString(hbs, context) + expect(output).toBe("Bob Bobert") + }) }) \ No newline at end of file diff --git a/packages/string-templates/test/renderApp.spec.js b/packages/string-templates/test/renderApp.spec.js new file mode 100644 index 0000000000..1ae08ee113 --- /dev/null +++ b/packages/string-templates/test/renderApp.spec.js @@ -0,0 +1,33 @@ +const { processString } = require("../src/index") + +describe("specific test case for whether or not full app template can still be rendered", () => { + it("should be able to render the app template", async () => { + const template = + ` + + + {{{head}}} + + + {{{body}}} + ` + const context = { + appId: "App1", + head: "App", + body: "

App things

" + } + const output = await processString(template, context) + expect(output).toBe(` + + + App + + +

App things

+ `) + }) +}) \ No newline at end of file