Hedgehog is a node.js utility script that will watch a directory with raw hogan.js template files. It will listen for changes and compile the raw mustache templates into compiled vanilla js files.
The templates will be available in a global T namespace (this is
configurable), relative to the
filepath of the raw template file.
For instance: Let's say we create a template
and save it as ./templates/user/profile.mustache
:
<h1>{{ name }}</h1>
Now all you need to do is include the compiled templates along with the HoganTemplate (~700 bytes) lib.
<script src="HoganTemplate.js"></script>
<script src="templates/compiled/user/profile.js"></script>
<script>
var html = T['user/profile'].r({name: "Daniel"});
// html == "<h1>Daniel</h1>"
</script>
npm install hedgehog
to install it in your current working directory, or:
npm install hedgehog -g
to install it globally.
Tested on node 0.6.x
You can run the hedgehog as standalone utility or with your existing node app:
var Hedgehog = require('hedgehog');
var h = new Hedgehog();
By default hedgehog will look in a ./templates
directory.
By default hedgehog will compile templates into a ./templates/compiled
directory
You can configure hedgehog by passing an options object. For example:
new Hedgehog({
'input_path': 'path/to/raw/templates',
});
By default compiled templates will be accessible through the window.T object in the browser, you can set this to whatever you prefer.
A path relative from where the script is called, that points to your raw .mustache templates.
A path relative from where the script is called, that specifies where the the vanilla .js files should be compiled into.
Hogan.js compiles mustache templates, but you can use another file extension if you like.
For a Rails project, I'd typically use Jammit to concatenate and minify the template files on deployment.
For a Express.js project I've tried connect-assets with great success. It's an asset pipeline for node.js/connect.js inspired by Rails 3.1