bluemold

Template engine based on jQuery template syntax

Bluemold Template Engine

Bluemold is a Javascript template engine based on jQuery Template syntax.

It is designed to run serverside (Node.js) and output HTML or any text based format.

Bluemold is the template engine used for the portfolios at http://famedriver.com

npm install bluemold
var Bluemold = require('bluemold'),
    template = "Hello ${world}. {{each words}}${$value} {{/each}}",
    data     = {world: "Earth", words:["Where", "will", "we", "go?"]};

Bluemold( template, data)
// 'Hello Earth. Where will we go? '
var data = {a:"Hello", f: function(s){ return s.toUpperCase()}}
Bluemold("${f(a)} WORLD", data)

// 'HELLO WORLD'

By default the sandbox only includes the user data and the Underscore library as _. To include additional functions or data set them with the sandbox method.

Bluemold.sandbox({http: function(){return 'an http function'}})
Bluemold("${http()}")
// 'an http function'

See the specs for more examples

Bluemold can be run via a child process. This allows timeouts to be set on rendering and avoids infinite loops or other problems.

var send = require('bluemold').send;
send(["this data is ${data}", {data:true}, "template"], 1000 /*timeout*/, function(string){....});

The supported tags are

  • {{each}}{{/each}}
  • {{if}}{{/if}}
  • {{else}}
  • {{html}}
  • ${} & {{=}}
  • {{tmpl}}

{{wrap}} is not supported.

See the jQuery Template page.

Unlike jQeury templates, HTML is not escaped but default.

Proper error messages with line numbers.

I would love contributors, fork away! But please use 2 soft space indents and write specs for any new features.

Besure to have pegjs and jasmine-node installed.

 npm install pegjs
 npm install jasmine-node

 scripts/build # regenerate the parser
 scripts/spec  # run the tests 

Please reports bugs here

Node JQTP is another jQuery Template engine for Node.