Skip to content
This repository
branch: master

nTPL => ntpl

latest commit 80b46e0c43
Fedor Indutny authored December 28, 2010
Octocat-spinner-32 benchmarks nTPL => ntpl December 28, 2010
Octocat-spinner-32 lib nTPL => ntpl December 28, 2010
Octocat-spinner-32 nTPL.native nTPL => ntpl December 28, 2010
Octocat-spinner-32 tests nTPL => ntpl December 28, 2010
Octocat-spinner-32 tpl nTPL => ntpl December 28, 2010
Octocat-spinner-32 .gitignore .node remove September 09, 2010
Octocat-spinner-32 MIT-LICENSE Added MIT-LICENSE August 11, 2010
Octocat-spinner-32 Makefile nTPL => ntpl December 28, 2010
Octocat-spinner-32 README.rdoc nTPL => ntpl December 28, 2010
Octocat-spinner-32 example.js nTPL => ntpl December 28, 2010
Octocat-spinner-32 install.sh nTPL => ntpl December 28, 2010
Octocat-spinner-32 package.json nTPL => ntpl December 28, 2010
Octocat-spinner-32 wscript nTPL => ntpl December 28, 2010
README.rdoc

ntpl project: simple, fast and powerfull templates for node.js (github.com/donnerjack13589/ntpl).

It's easy to learn - start now! Now comes with support of Express.js!

It's fast:

Mustache saids that running complex.html example gives following results: Mu - 40 secs (benchmarks/million_complex.js)

On my PC - running ntpl's: ntpl - 6 secs (benchmarks/million_complex.js)

Feel the difference?

Some features:

  • ntpl have native parser written on C++, so templates are compiled very fast.

  • ntpl have many optimizations in template rendering process.

  • ntpl uses buffers

  • ntpl is extendable (ntpl.modificators)

  • ntpl can reload template on file change (watch: true)

Installation:

npm install ntpl

Manual installation instructions:

curl github.com/donnerjack13589/ntpl/raw/master/install.sh | sh or if it dies “Permission Denied” or EACCESS error curl github.com/donnerjack13589/ntpl/raw/master/install.sh | sudo sh

Advanced installation instructions:

git clone git@github.com:donnerjack13589/ntpl.git cd ntpl make all make test

Basic examples:

var ntpl = require(“ntpl”).plugins(“ntpl.block”, “ntpl.filter”).ntpl; ntpl(“1 + 1 = {%= 1+1 %}”)(); ntpl({ template : “1 + 1 = {%= 1+1 %}” })(); ntpl(“filename.tpl”)(); // 1 + 1 = 2 ntpl({ template : “Hello {%= a %}!”, args: [“a”] })({a: 'World'}); // >> Hello World! ntpl({ template: “Hello {%each a%}{%= this %}, {%/each%}world!”, args: [“a”] })({a: ['Andy','Alex']}); // >> Hello Andy, Alex, World! ntpl({ template: “{%if godmode%}My Lord!{%else%}Who are you?{%/if%}”, args: [“godmode”] })({godmode: true}); // >> My Lord! var $ = require(“ntpl”); $.parse(“It also works!”)(); // >> It also works!

Medium examples:

ntpl(“foo {* text here won't be compiled or printed *} bar”)(); // >> foo bar ntpl(“{%each [1,2,3] %} ”{%= this %}“ {%/each%}?”)(); // >> “1” “2” “3” ntpl(“{%catch var a %}What's up, dude?{%/catch%}{%= a.substr(0,9) %}?”)(); // >> What's up? ntpl({ template: “filename.tpl”, callback: function (tpl) { console.log(tpl()); } }); // Will load “filename.tpl” in async mode

Harder examples:

ntpl({ template: “<button>{%= value%}</button>”, args: [“value”], name: “input” }); ntpl(“input”)({value:'Hello world!'}); // >> Button with text “Hello world!” ntpl({ template: “filename.tpl”, callback: function (tpl) { console.log(tpl()); }, watch: true }); // Will load “filename.tpl” in async mode // And watch for file changes (template will be refreshed) // P.S. Also available in a sync mode

Block module

var ntpl = require(“ntpl”).plugins(“ntpl.block”).ntpl; ntpl({ template: “Hello, {%block 'username'%}{%/block%}!{%= message %}”, args: [“message”], name: “block-test” }); ntpl(“{%extends 'block-test', {message: ”How do you do?“}%}{%block 'username'%}Admin{%/block%}”)(); // >> Hello, Admin!How do you do?

Set modificators

Use “set” modificator to setup options inside template

Examples:

“set.html” {%set name first template %} {%set args a1, a2, a3 %} {%set some 123 %} {%set foo.bar 1,2,3 %} {%= a1 %} {%= a2 %} {%= a3 %}

Template generated from this file will have 'first template' name and can get 'a1', 'a2', 'a3' as arguments

var tpl = ntpl(“set.html”); ntpl(“first template”)({a1:1,a2:2,a3:3}); tpl.options; // {name: “first template”, args: [“a1”, “a2”, “a3”], some: “123”, foo : { bar: [“1”,“2”,“3”] } }

More info:

You can't setup any other options now. Only 'name' and 'args' are allowed. But if you generated template with “watch=true” and then change {%set … %} in template - 'name' and 'args' will be refreshed!

Something went wrong with that request. Please try again.