Thulium (Tm) Templating
A proper templating engine. With specs and a syntax that isn't crazy (ie. Not Jade and not EJS).
It depends on Neon for the class system.
Usage
It's easy to use. If you want it in the browser, just require the files. If using node:
$ npm install thulium
From there, it's as easy as:
tm = new Thulium({template: "A template string"});
tm.parseSync().renderSync(context);
Of course, async methods are available:
tm.parse(function () {
tm.render(context, function (view) {
console.log(view);
})
})
Examples
A simple template
The template
<h1>Hello, <%= name %></h1>
<% for (var i = 0; i < 10; i++) { %>
<p> You are awesome. </p>
<% } %>
The context
name: "Col. Mustard"
The output
Hello, Col. Mustard You are awesome. You are awesome. You are awesome. You are awesome. You are awesome. You are awesome. You are awesome. You are awesome. You are awesome. You are awesome.
A printable helper (capture style)
The template
<p>
<%= h.reverse(function (){ %>
This is my reversed string.
<% }) %>
</p>
The context
h: { // Let's imagine for a second that templateManager is a reference // to a ... um, template manager. That has an instance of the // current view. Which is our instance of Tm var buffer = templateManagercurrentViewrenderer; return buffer; }
The output
.gnirts desrever ym si sihT
A printable helper (custom style)
The template
<p>
<%= h.embolden(function (){ %>
This guy will be bold.
<% }) %>
</p>
The context
h: { // Let's imagine for a second that templateManager is a reference // to a ... um, template manager. That has an instance of the // current view. Which is our instance of Tm templateManagercurrentViewrenderer; // here we're printing that stuff inside the block by executing it ; return "</strong>"; }
The output
This guy will be bold.