gitmyhub

tarim

JavaScript ★ 13 updated 5y ago

a template engine, using Lodash's template syntax and supporting including other templates

Tarim is a template engine that lets you write dynamic text or HTML by mixing plain content with placeholders and code. You write a template string once, then pass it data to fill in the blanks and produce final output. It's useful whenever you need to generate text programmatically—emails, HTML pages, code snippets, or any document that has a fixed structure but variable content.

The engine uses syntax borrowed from Lodash, a popular JavaScript utility library. For example, you can write hello <%= user %>! and then feed it data like { user: 'fred' } to get hello fred!. You can also embed JavaScript logic directly: loops, conditionals, and function calls all work inside the template. If you want to include another template file within your template, you can do that too with a simple <% include fileName %> command. This is handy when you have reusable chunks of template code—like a header or footer—that multiple templates need.

You might use this if you're building a web server that generates HTML pages, a script that creates emails, a CLI tool that produces config files, or any other situation where you're assembling text dynamically. For example, an e-commerce site could use it to generate order confirmation emails by inserting customer name, order number, and items into a template. A static site generator might use it to turn data and templates into web pages.

The README doesn't explain the underlying machinery, but the basic idea is that Tarim takes your template string and JavaScript data, compiles it into a function, and runs that function to produce the final output. The engine also lets you customize how delimiters work, set where included templates live on disk, and configure how the data object is named inside the template.