hamlet.coffee
v0.7.7-pre.0
Published
Truly amazing templating!
Readme
Hamlet
Hamlet is a simple and powerful reactive templating system.
It's framework agnostic and focuses on clean declarative templating, leaving you to build your application with your favorite tools. Hamlet leverages the power of native browser APIs to keep your data model and html elements in sync.
All of this in only 3.7kb, minified and gzipped!
Getting Started
Using Node.js
Install the command line Hamlet compiler
npm install hamlet-cliCompile your templates and export them
node_modules/.bin/hamlet -d templatesAdd hamlet-runtime to your package.json
npm install --save-dev hamlet-runtimeTo use the templates in a Node.js style project built with browserify you can require them normally.
// main.js
mainTemplate = require("./templates/main");
document.body.appendChild(mainTemplate(data));Now use browserify to build the file you'll serve on your page.
browserify main.js > build.jsIn the browser
Install the command line Hamlet compiler
npm install -g hamlet-cliCompile your templates and expose them to the global browser scope.
hamlet --runtime "Hamlet" -d templates -e 'JST["$file"]'
cat templates/*.js > templates.jsDownload the Hamlet runtime script with bower.
bower install hamlet-runtimeRender them to the DOM:
document.body.appendChild(JST.main(data))Resources
Check out the wiki for developer resources.
Gotchas
If you are experiencing unexpected behavior in your templates make sure your templates have exactly one root element.
Problematic Example:
.one
.two
.three
.fourCorrect solution:
.root
.one
.two
.three
.four