squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
592 stars 82 forks source link

Render breaks when using some custom tags #146

Closed SomaticIT closed 3 years ago

SomaticIT commented 4 years ago

Describe the bug When using some custom tags, the whole template engine breaks.

  1. Not important: ["[", "]"] breaks because it should be escaped,
  2. Important: ["\\$\\(", "\\)"] breaks because parens are interpreted by squirrelly.

To Reproduce Steps to reproduce the behavior:

  1. Configure: Sqrl.defaultConfig = ["\\$\\(", "\\)"];
  2. Create template: const template = "Data: $(test)";
  3. Call function: Sqrl.render(template, { test: "value" });
  4. Look at error :)

Expected behavior Render result should be: Data: value

Package & Environment Details

Additional context I develop a software that already use the syntax $(property) for its users. We built a very simple template engine that need to evolve. We selected your project to replace our template engine with something far more powerful.

I love your project as it's well developped, light and fast. I would be very happy to be able to run your project in my software.

Do you think it's possible?

Thanks

nebrelbug commented 4 years ago

Hi @SomaticIT! Glad to hear you like this project! Unfortunately, it's not going to be possible to use (, ), |, or => inside of the closing delimiters. I looked for a while at possibilities, but it would just be too complex.

Could you just slightly change the delimiters?

Example:

Sqrl.defaultConfig.tags = ["\\${", "}"]
// $ has to be escaped because it's a RegExp special char

const template = "Hi ${it.name}"

Sqrl.render(template, { name: "@SomaticIT" })
// "Hi @SomaticIT"