A project of The Great Code Club.
Simple template engine that can parse, compile and render to HTML.
Here's what it looks like.
html {
head {
// {...} are optional if next to tag name
title "My App"
}
body {
h1 "My App"
section {
// Text nodes in quotes
"This is cool"
// Statements
{% for(var i = 0; i < 3; i++) { %}
// Expressions (output value)
p {{ i }}
{% } %}
}
}
}
You need:
- A recent version of node.
make
. You probably have it already.
To install Node modules and compile the parser:
$ npm install
$ make
To compile a template file to HTML:
$ bin/compile samples/index.tmpl
Using the API:
var engine = require('./lib/engine'),
compiledTemplate = engine.compile('html {{ variable }}')
// compiledTemplate is a function that will return the HTML
console.log(compiledTemplate({ variable: 'woohoo!' }))
// => <html>woohoo!</html>
To run the tests:
$ make test
Or to run the tests on file change:
$ make watch
Copyright 2014 Coded Inc.
marc@codedinc.com
You are free to modify and distribute this however you want. Except for teaching purposes.