Permalink
Browse files

options.template

  • Loading branch information...
1 parent 300f8bc commit cad72bee172ef2e0ebee6cd8e7ae409eaf04c09d @eprev committed Feb 22, 2013
View
@@ -25,7 +25,7 @@ module.exports = function (grunt) {
// Before generating any new files, remove any previously-created files.
clean: {
- tests: ['test/tmp', 'test/fixtures/**/*.js', 'test/fixtures/**/*.xml.js']
+ tests: ['test/tmp', 'test/fixtures/**/*.js']
},
// Configuration to be run (and then tested).
@@ -50,19 +50,26 @@ module.exports = function (grunt) {
files: [{
expand: true, // Enable dynamic expantion.
src: ['test/fixtures/qux/**/*.xml'],
- dest: 'test/tmp/dynamic', // Destination path prefix.
+ dest: 'test/tmp/dynamic', // Destination path prefix.
ext: '.js' // Dest filepaths will have this extension.
}]
},
- dynamic_expansion_with_cwd: {
+ dynamic_expansion_with_cwd_and_template: {
files: [{
expand: true, // Enable dynamic expantion.
- cwd: 'test/fixtures', // Src matches are relative to this path.
+ cwd: 'test/fixtures', // Src matches are relative to this path.
src: ['**/*.xml'], // Actual pattern(s) to match.
dest: 'test/tmp/dynamic-compiled', // Destination path prefix.
ext: '.js' // Dest filepaths will have this extension.
}],
options: {
+ template: function (data) {
+ // Make AMD module
+ return grunt.template.process(
+ 'define(<%= JSON.stringify(name) %>, function () { return <%= contents %> ; });',
+ {data: data}
+ );
+ },
compile: {
debug: false,
beautify: false
View
@@ -31,13 +31,13 @@ module.exports = function (grunt) {
this.files.forEach(function (f) {
f.src.forEach(function (src) {
- var dest, relFn, contents;
+ var dest, relSrc, contents;
if (f.orig.expand) {
dest = f.dest;
- relFn = f.orig.cwd ? relative(f.orig.cwd, src) : src;
+ relSrc = f.orig.cwd ? relative(f.orig.cwd, src) : src;
} else {
dest = f.dest ? join(f.dest, src) : src;
- relFn = src;
+ relSrc = src;
}
var se = extname(src),
de = extname(dest);
@@ -52,6 +52,13 @@ module.exports = function (grunt) {
grunt.log.error(e.stack);
}
if (contents) {
+ if (options.template) {
+ contents = options.template({
+ name: se ? relSrc.slice(0, -se.length) : relSrc,
+ src: src,
+ contents: contents
+ });
+ }
grunt.file.write(dest, contents);
grunt.log.ok();
}
Oops, something went wrong.
Oops, something went wrong.
View
@@ -59,7 +59,7 @@ exports.bem = {
});
test.done();
},
- dynamic_expansion_with_cwd: function (test) {
+ dynamic_expansion_with_cwd_and_template: function (test) {
this.templates.forEach(function (tpl) {
var actual = grunt.file.read('test/tmp/dynamic-compiled/' + tpl + '.js');
var expected = grunt.file.read('test/expected/tmp/dynamic-compiled/' + tpl + '.js');

0 comments on commit cad72be

Please sign in to comment.