2.0.0 • Published 11 years ago

thulium v2.0.0

Weekly downloads
26
License
-
Repository
github
Last release
11 years ago

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

<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>

A printable helper (capture style)

The template

<p>
<%= h.reverse(function (){ %>
This is my reversed string.
<% }) %>
</p>

The context

{
 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("");
    }
 }
}

The output

<p>

.gnirts desrever ym si sihT

</p>

A printable helper (custom style)

The template

<p>
<%= h.embolden(function (){ %>
This guy will be bold.
<% }) %>
</p>

The context

{
 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>";
    }
 }
}

The output

<p>
<strong>
This guy will be bold.
</strong>
</p>
2.0.0

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago