Permalink
Browse files

Merge pull request #6 from petebacondarwin/extension-option

Extension option
  • Loading branch information...
2 parents b90ac32 + 341f486 commit 7d2c6ee1a18bfe85ecf85788b8d9d8a5fec48321 @avalade committed Jul 21, 2012
Showing with 24 additions and 12 deletions.
  1. +6 −4 tasks/coffee.js
  2. +18 −8 test/coffee_test.js
View
@@ -18,9 +18,10 @@ module.exports = function(grunt) {
grunt.registerMultiTask('coffee', 'Compile CoffeeScript files', function() {
var dest = this.file.dest,
- options = this.data.options;
+ options = this.data.options,
+ extension = this.data.extension;
grunt.file.expandFiles(this.file.src).forEach(function(filepath) {
- grunt.helper('coffee', filepath, dest, options);
+ grunt.helper('coffee', filepath, dest, options, extension);
});
if (grunt.task.current.errorCount) {
@@ -32,12 +33,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,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 7d2c6ee

Please sign in to comment.