Permalink
Browse files

support this.file api

  • Loading branch information...
1 parent 395c7fa commit 71aaab7edcd45b59f0a3d903eaea1efba72aff9b @tkellen tkellen committed Nov 13, 2012
Showing with 59 additions and 147 deletions.
  1. +1 −73 CONTRIBUTING.md
  2. +1 −1 Gruntfile.js
  3. +19 −29 README.md
  4. +38 −44 tasks/less.js
View
@@ -1,73 +1 @@
-[Grunt homepage](http://gruntjs.com/) | [Documentation table of contents](https://github.com/gruntjs/grunt/blob/devel/docs/toc.md)
-
-# Contributing to grunt
-
-There are a number of grunt projects.
-
-* [grunt](https://github.com/gruntjs/grunt) - the main grunt project
-* [gruntjs.com](https://github.com/gruntjs/gruntjs.com) - the gruntjs.com website
-* [grunt-contrib collection](https://github.com/gruntjs/grunt-contrib) - a collection of all grunt "contrib" plugins
-
-In addition, each individual grunt-contrib plugin is a separate repository listed on the [gruntjs org homepage](https://github.com/gruntjs).
-
-## Filing issues
-If something isn't working like you think it should, please read the documentation first. If you'd like to chat with someone, [pop into IRC](#discussing-grunt) and ask your question there.
-
-The best way to ensure an issue gets addressed is to file it in the appropriate issues tracker.
-
-**If there's an issue with a specific grunt-contrib plugin:**
-Please file an issue on that plugin's issues tracker.
-
-**If you'd like to contribute a new plugin:**
-Please file an issue on the [grunt-contrib collection issues tracker](https://github.com/gruntjs/grunt-contrib/issues). We don't accept all plugins, but we'll certainly consider yours.
-
-**If there's an issue with the [website](http://gruntjs.com/):**
-Please file an issue on the [gruntjs.com website issues tracker](https://github.com/gruntjs/gruntjs.com/issues).
-
-**If there's an issue that isn't specific to any of the above:**
-Please file an issue on the [grunt issues tracker](https://github.com/gruntjs/grunt/issues).
-
-### Simplify the issue
-Try to [reduce your code](http://www.webkit.org/quality/reduction.html) to the bare minimum required to reproduce the issue. This makes it much easier (and much faster) to isolate and fix the issue.
-
-### Explain the issue
-If we can't reproduce the issue, we can't fix it. Please list the exact steps required to reproduce the issue. Include versions of your OS, Node.js, grunt, etc. Include relevant logs or sample code.
-
-## Discussing grunt
-Join the [freenode](http://freenode.net/) IRC #grunt channel. We've got a bot and everything.
-
-_No private messages, please._
-
-## Modifying grunt
-First, ensure that you have the latest [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed.
-
-1. Fork and clone the repo.
-1. Check out the correct branch. Currently, grunt development happens in the `devel` branch.
-1. Run `npm install` to install all grunt dependencies.
-1. Run `npm link` to put the dev version of grunt in the system path (this is only needed for developing grunt, not for plugins or the website).
-1. Run `grunt` to grunt grunt.
-
-Assuming that you don't see any red, you're ready to go. Just be sure to run `grunt` after making any changes, to ensure that nothing breaks.
-
-### Submitting pull requests
-
-1. Create a new branch, please don't work in your `master` or `devel` branch directly.
-1. Add failing tests for the change you want to make. Run `grunt` to see the tests fail.
-1. Fix stuff.
-1. Run `grunt` to see if the tests pass. Repeat steps 2-4 until done.
-1. Update the documentation to reflect any changes.
-1. Push to your fork and submit a pull request.
-
-### Syntax
-
-* Two space indents. Don't use tabs anywhere. Use `\t` if you need a tab character in a string.
-* No trailing whitespace, except in markdown files where a linebreak must be forced.
-* Don't go overboard with the whitespace.
-* No more than [one assignment](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) per `var` statement.
-* Delimit strings with single-quotes `'`, not double-quotes `"`.
-* Prefer `if` and `else` to ["clever"](http://programmers.stackexchange.com/a/25281) uses of `? :` conditional or `||`, `&&` logical operators.
-* Comments are great. Just put them _before_ the line of code, _not_ at the _end_ of the line.
-* **When in doubt, follow the conventions you see used in the source already.**
-
-### Reverting back to the "official" grunt
-If you've used `npm link` to put a dev version of grunt in the system path and, for some reason, need to revert back to the current official grunt release, just reinstall grunt globally with `npm install -g grunt`
+Please see the [Contributing to grunt](http://gruntjs.com/contributing) guide for information on contributing to this project.
View
@@ -96,4 +96,4 @@ module.exports = function(grunt) {
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test', 'build-contrib']);
-};
+};
View
@@ -2,31 +2,20 @@
> Compile LESS files to CSS.
-_Note that this plugin has not yet been released, and only works with the latest bleeding-edge, in-development version of grunt. See the [When will I be able to use in-development feature 'X'?](https://github.com/gruntjs/grunt/blob/devel/docs/faq.md#when-will-i-be-able-to-use-in-development-feature-x) FAQ entry for more information._
## Getting Started
-_If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide._
+If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide, as it explains how to create a [gruntfile][Getting Started] as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
-From the same directory as your project's [Gruntfile][Getting Started] and [package.json][], install this plugin with the following command:
-
-```bash
+```shell
npm install grunt-contrib-less --save-dev
```
-Once that's done, add this line to your project's Gruntfile:
-
-```js
-grunt.loadNpmTasks('grunt-contrib-less');
-```
-
-If the plugin has been installed correctly, running `grunt --help` at the command line should list the newly-installed plugin's task or tasks. In addition, the plugin should be listed in package.json as a `devDependency`, which ensures that it will be installed whenever the `npm install` command is run.
-
[grunt]: http://gruntjs.com/
[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
-[package.json]: https://npmjs.org/doc/json.html
-## The less task
+## Less task
+_Run this task with the `grunt less` command._
### Overview
@@ -46,37 +35,37 @@ grunt.initConfig({
```
### Options
-## options.paths
+#### options.paths
Type: `String|Array`
Default: Directory of input file.
Specifies directories to scan for @import directives when parsing. Default value is the directory of the source, which is probably what you want.
-## options.compress
+#### options.compress
Type: `Boolean`
Default: False
Compress output by removing some whitespaces.
-## options.yuicompress
+#### options.yuicompress
Type: `Boolean`
Default: False
Compress output using cssmin.js
-## options.optimization
+#### options.optimization
Type: `Integer`
Default: null
Set the parser's optimization level. The lower the number, the less nodes it will create in the tree. This could matter for debugging, or if you want to access the individual nodes in the tree.
-## options.strictImports
+#### options.strictImports
Type: `Boolean`
Default: False
Force evaluation of imports.
-## options.dumpLineNumbers
+#### options.dumpLineNumbers
Type: `String`
Default: false
@@ -109,13 +98,14 @@ less: {
## Release History
- * 2012-10-17 - v0.3.2 - Add support for dumpLineNumbers.
- * 2012-10-11 - v0.3.1 - Rename grunt-contrib-lib dep to grunt-lib-contrib.
- * 2012-09-23 - v0.3.0 - Global options depreciated Revert normalize linefeeds.
- * 2012-09-15 - v0.2.2 - Support all less options Normalize linefeeds Default path to dirname of src file.
- * 2012-09-09 - v0.2.0 - Refactored from grunt-contrib into individual repo.
+ * 2012-10-17   v0.3.2   Add support for dumpLineNumbers.
+ * 2012-10-11   v0.3.1   Rename grunt-contrib-lib dep to grunt-lib-contrib.
+ * 2012-09-23   v0.3.0   Global options depreciated Revert normalize linefeeds.
+ * 2012-09-15   v0.2.2   Support all less options Normalize linefeeds Default path to dirname of src file.
+ * 2012-09-09   v0.2.0   Refactored from grunt-contrib into individual repo.
+
+---
---
-Task submitted by <a href="http://goingslowly.com/">Tyler Kellen</a>.
+Task submitted by [Tyler Kellen](http://goingslowly.com/)
-*Generated on Thu Oct 18 2012 18:59:49.*
+*This file was generated on Tue Nov 13 2012 16:14:04.*
View
@@ -20,7 +20,6 @@ module.exports = function(grunt) {
};
grunt.registerMultiTask('less', 'Compile LESS files to CSS', function() {
- var basePath, newFileDest, srcFiles;
var done = this.async();
var options = this.options({
@@ -29,52 +28,46 @@ module.exports = function(grunt) {
});
grunt.verbose.writeflags(options, 'Options');
- grunt.util.async.forEachSeries(this.files, function(file, next) {
- file.dest = path.normalize(file.dest);
- srcFiles = grunt.file.expandFiles(file.src);
+ // get files
+ var files = grunt.file.expandFiles(this.file.src);
+ var destFile = this.file.dest;
- if (srcFiles.length === 0) {
- grunt.fail.warn('Unable to compile; no valid source files were found.');
- }
-
- if (helpers.isIndividualDest(file.dest)) {
- basePath = helpers.findBasePath(srcFiles, options.basePath);
-
- grunt.util.async.forEachSeries(srcFiles, function(srcFile, nextFile) {
- newFileDest = helpers.buildIndividualDest(file.dest, srcFile, basePath, options.flatten);
-
- compileLess(srcFile, options, function(css, err) {
- if(!err) {
- grunt.file.write(newFileDest, css || '');
- grunt.log.writeln('File ' + newFileDest.cyan + ' created.');
-
- nextFile(null);
- } else {
- done();
- }
- });
- }, function(err) {
- next();
+ if (files.length === 0) {
+ grunt.fail.warn('Unable to compile; no valid source files were found.');
+ done();
+ }
+
+ // hack by chris to support compiling individual files
+ if (helpers.isIndividualDest(destFile)) {
+ var basePath = helpers.findBasePath(files, options.basePath);
+ grunt.util.async.forEachSeries(files, function(file, next) {
+ var newFileDest = helpers.buildIndividualDest(destFile, file, basePath, options.flatten);
+ compileLess(file, options, function(css, err) {
+ if(!err) {
+ grunt.file.write(newFileDest, css || '');
+ grunt.log.writeln('File ' + newFileDest.cyan + ' created.');
+ next(null);
+ } else {
+ done(false);
+ }
});
- } else {
- grunt.util.async.concatSeries(srcFiles, function(srcFile, nextConcat) {
- compileLess(srcFile, options, function(css, err) {
- if(!err) {
- nextConcat(null, css);
- } else {
- done();
- }
- });
- }, function(err, css) {
- grunt.file.write(file.dest, css.join('\n') || '');
- grunt.log.writeln('File ' + file.dest.cyan + ' created.');
-
- next();
+ });
+ } else {
+ // normal execution
+ grunt.util.async.concatSeries(files, function(file, next) {
+ compileLess(file, options, function(css, err) {
+ if(!err) {
+ next(null, css);
+ } else {
+ done(false);
+ }
});
- }
- }, function() {
- done();
- });
+ }, function(err, css) {
+ grunt.file.write(destFile, css.join('\n') || '');
+ grunt.log.writeln('File ' + destFile.cyan + ' created.');
+ done();
+ });
+ }
});
var formatLessError = function(e) {
@@ -101,6 +94,7 @@ module.exports = function(grunt) {
parser.parse(srcCode, function(parse_err, tree) {
if (parse_err) {
lessError(parse_err);
+ callback('',true);
}
try {

0 comments on commit 71aaab7

Please sign in to comment.