-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Labels
Description
There are 2 main use-cases I see for "javascript" templates:
- Compile template files into JavaScript functions for use on the client. These templates will be namespaced and combined into a single .js file.
- Compile template files into JavaScript functions for use on the server. These templates will be run immediately, with the output being saved into .html files.
This plugin already does 1, but what about 2? In my example, I'm already using lo-dash templates in the client via requirejs plugin, but I don't want to use Jade for the app's index.html page. I also want to use lo-dash templates.
So, in my project Gruntfile, I created this "tmpl" task, but it seems a little redundant for this to be a separate thing.
grunt.registerMultiTask('tmpl', 'compile lodash templates to html files', function() {
var _ = require('lodash');
var options = this.options({
data: {},
templateSettings: null,
});
var origTemplateSettings = _.templateSettings;
this.files.forEach(function(f) {
var src = grunt.file.read(f.src[0]);
if (options.templateSettings) {
_.templateSettings = _.extend(_.templateSettings, options.templateSettings);
}
var html = _.template(src, options.data);
grunt.file.write(f.dest, html);
_.templateSettings = origTemplateSettings;
});
});
Is there a place in grunt-contrib-jst for the "2" behavior?