Permalink
Browse files

Added option to specify the extension of the generated file.

  • Loading branch information...
1 parent 9b89279 commit 9d63a161c37415091bbb4f88630fb0157a23372b @petebacondarwin petebacondarwin committed Jul 20, 2012
Showing with 21 additions and 10 deletions.
  1. +3 −2 tasks/coffee.js
  2. +18 −8 test/coffee_test.js
View
5 tasks/coffee.js
@@ -32,12 +32,13 @@ module.exports = function(grunt) {
// HELPERS
// ==========================================================================
- grunt.registerHelper('coffee', function(src, destPath, options) {
+ grunt.registerHelper('coffee', function(src, destPath, options, extension) {
var coffee = require('coffee-script'),
js = '';
destPath = destPath ? destPath : path.dirname(src);
- var dest = path.join(destPath, path.basename(src, '.coffee') + '.js');
+ extension = extension ? extension : '.js';
+ var dest = path.join(destPath, path.basename(src, '.coffee') + extension);
options = options || {};
if( options.bare !== false ) {
View
26 test/coffee_test.js
@@ -26,10 +26,8 @@ fs.existsSync = fs.existsSync ? fs.existsSync : path.existsSync;
var src = 'test/fixtures/hello_world.coffee';
var destFolder = 'tmp/js';
-var relativeDest = function(src) {
- var out = path.resolve(path.dirname(src),path.basename(src, '.coffee') + '.js');
- return out;
-};
+var dest1 = 'test/fixtures/hello_world.js';
+var dest2 = 'test/fixtures/hello_world.coffee.js';
exports['coffee'] = {
setUp: function(done) {
@@ -43,8 +41,12 @@ exports['coffee'] = {
}
fs.rmdirSync(destFolder);
}
- if (fs.existsSync(relativeDest(src))) {
- fs.unlinkSync(relativeDest(src));
+
+ if (fs.existsSync(dest1)) {
+ fs.unlinkSync(dest1);
+ }
+ if (fs.existsSync(dest2)) {
+ fs.unlinkSync(dest2);
}
done();
},
@@ -66,10 +68,18 @@ exports['coffee'] = {
},
'helper-nodest': function(test) {
- grunt.helper('coffee', [src], null);
- test.equal(grunt.file.read(relativeDest(src)),
+ test.expect(1);
+ grunt.helper('coffee', [src]);
+ test.equal(grunt.file.read(dest1),
'\nconsole.log("Hello CoffeeScript!");\n',
'it should compile the coffee');
test.done();
+ },
+
+ 'helper-extension': function(test) {
+ test.expect(1);
+ grunt.helper('coffee', [src], null, {}, '.coffee.js');
+ test.ok(fs.existsSync(dest2));
+ test.done();
}
};

0 comments on commit 9d63a16

Please sign in to comment.