Giter Club home page Giter Club logo

thulium's Introduction

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>

thulium's People

Contributors

escusado avatar rbdr avatar

Watchers

René Monroy avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.