TEMX
Flexible ES6 Template Engine
Installation
npm install temx --save
Getting started
Once you have a template, use the tmpl method to compile the template into a function. The generated function takes a model argument, which will be used to render the template.
import tmpl each end from "temx" const template = tmpl` <p> Hello, my name is . I am from . I have kids: </p> <ul> <li> is </li> </ul>` const model = name: "Alan" hometown: "Somewhere, TX" kids: name: "Jimmy" age: "12" name: "Sally" age: "4" const result =
Output
<p>Hello, my name is Alan. I am from Somewhere, TX. I have 2 kids:</p>
<ul>
<li>Jimmy is 12</li>
<li>Sally is 4</li>
</ul>
Each block
each(array, [valueProp[, keyProp]])
tmpl` Fruits: . `
Output
Fruit
1. apple
2. orange
3. banana
each(array, options)
tmpl` Fruits: . `
each(object)
tmpl` Object Properties: = `
Output
Object Properties:
prop1 = value1
prop2 = value2
Conditional block
when(condition)
tmpl` <p></p> ` error: "Something went wrong"
unless(condition)
tmpl` <p>Successfully</p> ` error: null
when + unless
tmpl` <p></p> <p>Successfully</p> ` error: "Something went wrong"