Skip to content

Commit

Permalink
Adding file_template helper. Closes gruntjs#97.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy committed Apr 6, 2012
1 parent 06cafe3 commit 834bfc2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tasks/misc.js
Expand Up @@ -52,6 +52,12 @@ module.exports = function(grunt) {
return grunt.helper('strip_banner', src, this.directive ? this.flags : opts);
});

// Process a file as a template.
grunt.registerHelper('file_template', function(filepath) {
var src = grunt.file.read(filepath);
return grunt.template.process(src);
});

// Generate banner from template.
grunt.registerHelper('banner', function(prop) {
if (!prop) { prop = 'meta.banner'; }
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/template.txt
@@ -0,0 +1 @@
Version: <%= grunt.version %>, today: <%= grunt.template.today("yyyy-mm-dd") %>.
8 changes: 8 additions & 0 deletions test/tasks/misc_test.js
Expand Up @@ -60,6 +60,14 @@ exports['file_strip_banner'] = function(test) {
test.done();
};

exports['file_template'] = function(test) {
test.expect(2);
var expected = 'Version: ' + grunt.version + ', today: ' + grunt.template.today('yyyy-mm-dd') + '.';
test.equal(grunt.helper('file_template', 'test/fixtures/template.txt'), expected, 'It should return the parsed template.');
test.equal(grunt.task.directive('<file_template:test/fixtures/template.txt>'), expected, 'It should return the parsed template.');
test.done();
};

exports['banner'] = function(test) {
test.expect(5);
grunt.config('test_config', {a: 'aaaaa', b: 'bbbbb', c: [1, 2, 3], d: [{a: 1}, {a: 2}, {a: 3}]});
Expand Down

0 comments on commit 834bfc2

Please sign in to comment.