grunt-simple-templates
Simple compilation of JavaScript templates into objects
Getting Started
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-simple-templates --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt;
The "templates" task
Overview
In your project's Gruntfile, add a section named templates
to the data object passed into grunt.initConfig()
.
grunt
Options
options.namespace
Type: String
Default value: 'TEMPLATES'
Your templates will be in an object called window.#{NAMESPACE}
.
options.extension
Type: String
Default value: 'mustache'
Templates matching the extension options.extension
will be compiled.
Usage Examples
Default Options
In this example, the default options are used to compile Mustache templates. So if the testing.mustache
file has the content {{test}}
and the dir/testing.mustache
file had the content {{nested test}}
, the generated result would be window.TEMPLATES = {"testing":"{{test}}\n","dir/testing":"{{nested test}}\n"};
grunt
Custom Options
In this example, custom options are used to compile Handlebars templates. So if the testing.hbs
file has the content {{test}}
and the dir/testing.hbs
file had the content {{nested test}}
, the generated result in this case would be window.HANDLEBARS = {"testing":"{{test}}\n","dir/testing":"{{nested test}}\n"};
grunt
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
0.0.2
: Only match provided or default extension.
0.0.1
: Initial release.