Skip to content
Browse files

Adding file_template helper. Closes #97.

  • Loading branch information...
1 parent 06cafe3 commit 834bfc2bee3fa80517df2e65972d1a7e5e666de3 @cowboy committed Apr 6, 2012
Showing with 15 additions and 0 deletions.
  1. +6 −0 tasks/misc.js
  2. +1 −0 test/fixtures/template.txt
  3. +8 −0 test/tasks/misc_test.js
View
6 tasks/misc.js
@@ -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'; }
View
1 test/fixtures/template.txt
@@ -0,0 +1 @@
+Version: <%= grunt.version %>, today: <%= grunt.template.today("yyyy-mm-dd") %>.
View
8 test/tasks/misc_test.js
@@ -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}]});

0 comments on commit 834bfc2

Please sign in to comment.
Something went wrong with that request. Please try again.