UNPKG

grunt-browserify-jst

Version:

JST templates compiler to use with grunt-browserify

67 lines (49 loc) 2.21 kB
grunt-browserify-jst ==================== > Grunt plugin for JST templates compillation. > Precompiles [Underscore](https://www.npmjs.com/package/underscore) templates to JST file to use with [grunt-browserify](https://www.npmjs.com/package/grunt-browserify). ## Getting Started If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: ```shell npm install grunt-browserify-jst --save-dev ``` Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: ```js grunt.loadNpmTasks('grunt-browserify-jst'); ``` ## browserify-jst task _Run this task with the `grunt browserify-jst` command._ Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide. _This plugin uses [the Underscore library](https://www.npmjs.com/package/underscore) to generate JavaScript template functions. Some developers generate template functions dynamically during development. If you are doing so, please be aware that the functions generated by this plugin may differ from those created at run-time. ### Options #### processName Type: `function` Default: `null` This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. The example below stores all templates on the default namespace in capital letters. ```js options: { processName: function(filepath) { return filepath.toUpperCase(); } } ``` ### Sample configuration ```js 'browserify-jst': { compile: { options: { processName: function(filepath) { return filepath.toUpperCase(); } }, src : 'path/**/*.html', dest : 'jst.js' } } ``` ### Usage in the code ```js var jst = require('./jst'); template = jst['MY-TEMPLATE']; var markup = template({/* template parameters */}); ```