grunt-template-client-dot

Compiles doT templates ready for RequireJS

npm install grunt-template-client-dot
14 downloads in the last week
28 downloads in the last month

grunt-template-client

Compile any and all templates into a ready to use script include.

Getting Started

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

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

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

Example

given the following config and template

config

  templateclient: {
    dist: {
        options: {
            variable: 'window.tmpl',
            prefix: 'Hogan.compile(',
            suffix: ')'
        },
        src: ['templates/**/*.hogan'],
        dest: 'dist/tmpl.js' 
    }
  }

templates

templates/item.hogan

<li>
  <h2>{{title}}<h2>
  <p>{{text}}</p>
</li>

templates/list.hogan

<ul id="a-list">
{{#items}}
  {{>item}}
{{/items}}
</ul>

will output the following script file

dist/tmpl.js

(function compileTemplates() {
  window.tmpl=window.tmpl||{};
  tmpl.item=Hogan.compile('<li><h2>{{title}}</h2><p>{{text}}</p></li>');
  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: [] });

Todo

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

Contributing

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.

Release History

License

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

npm loves you