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.
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);
})
})
<h1>Hello, <%= name %></h1>
<% for (var i = 0; i < 10; i++) { %>
<p> You are awesome. </p>
<% } %>
{
name: "Col. Mustard"
}
<h1>Hello, Col. Mustard</h1>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p> You are awesome. </p>
<p>
<%= h.reverse(function (){ %>
This is my reversed string.
<% }) %>
</p>
{
h: {
reverse : function (toCapture) {
// 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 = templateManager.currentView.renderer.capture(toCapture);
return buffer.split("").reverse().join("");
}
}
}
<p>
.gnirts desrever ym si sihT
</p>
<p>
<%= h.embolden(function (){ %>
This guy will be bold.
<% }) %>
</p>
{
h: {
embolden : function (printable) {
// 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
templateManager.currentView.renderer.print("<strong>");
// here we're printing that stuff inside the block by executing it
printable();
return "</strong>";
}
}
}
<p>
<strong>
This guy will be bold.
</strong>
</p>