Skip to content

Commit

Permalink
refactored the code so that the less helper is a bit easier to use.
Browse files Browse the repository at this point in the history
  • Loading branch information
jharding committed Apr 8, 2012
1 parent 05eac5c commit 10039d5
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions tasks/less.js
Expand Up @@ -33,26 +33,28 @@ module.exports = function(grunt) {
var options = this.data.options || {}; var options = this.data.options || {};


if (!src) { if (!src) {
grunt.warn('no src provided'); grunt.warn('Missing src property.');
return false;
} }


if (!dest) { if (!dest) {
grunt.warn('no dest provided'); grunt.warn('Missing dest property');
return false;
} }


var srcFiles = file.expandFiles(src); var srcFiles = file.expandFiles(src);


var done = this.async(); var done = this.async();


utils.async.map(srcFiles, grunt.helper('less', options), function(err, results) { grunt.helper('less', srcFiles, options, function(err, css) {
if (err) { if (err) {
grunt.warn(err); grunt.warn(err);
done(false); done(false);


return; return;
} }

file.write(dest, results.join(utils.linefeed)); file.write(dest, css);
done(); done();
}); });
}); });
Expand All @@ -61,8 +63,8 @@ module.exports = function(grunt) {
// HELPERS // HELPERS
// ========================================================================== // ==========================================================================


grunt.registerHelper('less', function(options, callback) { grunt.registerHelper('less', function(srcFiles, options, callback) {
return function(src, callback) { var compileLESSFile = function(src, callback) {
var parser = new less.Parser({ var parser = new less.Parser({
paths: [path.dirname(src)] paths: [path.dirname(src)]
}); });
Expand All @@ -72,8 +74,9 @@ module.exports = function(grunt) {
if (err) { if (err) {
callback(err); callback(err);
} }

// send data from source file to LESS parser to get CSS // send data from source file to LESS parser to get CSS
verbose.writeln('Parsing ' + src);
parser.parse(data, function(err, tree) { parser.parse(data, function(err, tree) {
if (err) { if (err) {
callback(err); callback(err);
Expand All @@ -94,5 +97,14 @@ module.exports = function(grunt) {
}); });
}); });
}; };

utils.async.map(srcFiles, compileLESSFile, function(err, results) {
if (err) {
callback(err);
return;
}

callback(null, results.join(utils.linefeed));
});
}); });
}; };

0 comments on commit 10039d5

Please sign in to comment.