Skip to content
Browse files

refactoring less task.

  • Loading branch information...
1 parent 50453ba commit fb2fe77c9f9f72a0ee8b1b172ad39d666aab2ea0 @jharding jharding committed Apr 4, 2012
Showing with 23 additions and 11 deletions.
  1. +23 −11 tasks/less.js
View
34 tasks/less.js
@@ -23,9 +23,6 @@ module.exports = function(grunt) {
var path = require('path');
var less = require('less');
- // Please see the grunt documentation for more information regarding task and
- // helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
-
// ==========================================================================
// TASKS
// ==========================================================================
@@ -34,17 +31,17 @@ module.exports = function(grunt) {
var src = this.file.src;
var dest = this.file.dest;
var options = this.data.options || {};
-
+
var done = this.async();
utils.async.map(src, grunt.helper('less', options), function(err, results) {
if (err) {
grunt.warn(err);
done(false);
}
-
- file.write(dest, results.join('\n\n'));
- done(true);
+
+ file.write(dest, results.join('\n'));
+ done();
});
});
@@ -58,14 +55,29 @@ module.exports = function(grunt) {
paths: [path.dirname(src)]
});
- var data = fs.readFileSync(src, 'utf8');
- parser.parse(data, function(err, tree) {
+ // read source file
+ fs.readFile(src, 'utf8', function(err, data) {
if (err) {
callback(err);
}
+
+ // send data from source file to LESS parser to get CSS
+ parser.parse(data, function(err, tree) {
+ if (err) {
+ callback(err);
+ }
+
+ try {
+ var css = tree.toCSS({
+ compress: options.compress,
+ yuicompress: options.yuicompress
+ });
+ } catch(e) {
+ callback(e);
+ }
- var css = tree.toCSS(options);
- callback(null, css);
+ callback(null, css);
+ });
});
};
});

0 comments on commit fb2fe77

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