grunt-hogan-client

compiles hogan templates into ready to use includes

grunt-hogan-client

Compile Hogan Templates into ready to use script include.

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-hogan-client

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-hogan-client');

given the following config and template

  hoganclient: {
    options: {
      variable: 'window.tmpl'
    }
    src: ['templates/**/*.hogan'],
    dest: 'dist/tmpl.js' 
  }
<li>
  <h2>{{title}}<h2>
  <p>{{text}}</p>
</li>
<ul id="a-list">
{{#items}}
  {{>item}}
{{/items}}
</ul>

will output the following script file

(function compileHoganTemplates() {
  window.tmpl=window.tmpl||{};
  window.tmpl.item=Hogan.compile('<li><h2>{{title}}</h2><p>{{text}}</p></li>');
  window.tmpl.list=Hogan.compile('<ul id="a-list">{{#items}}{{>item}}{{/items}}</ul>');
}());

ready to use/include/concat etc in your app like this.

tmpl.list.render({ items: [] });

I guess there will be need to tweek the regex that cleans the template.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

(Nothing yet)

Copyright (c) 2012 Markus Ullmark
Licensed under the MIT license.