Skip to content
This repository
Browse code

support this.file api

  • Loading branch information...
commit 71aaab7edcd45b59f0a3d903eaea1efba72aff9b 1 parent 395c7fa
Tyler Kellen tkellen authored

Showing 4 changed files with 59 additions and 147 deletions. Show diff stats Hide diff stats

  1. +1 73 CONTRIBUTING.md
  2. +1 1  Gruntfile.js
  3. +19 29 README.md
  4. +38 44 tasks/less.js
74 CONTRIBUTING.md
Source Rendered
... ... @@ -1,73 +1 @@
1   -[Grunt homepage](http://gruntjs.com/) | [Documentation table of contents](https://github.com/gruntjs/grunt/blob/devel/docs/toc.md)
2   -
3   -# Contributing to grunt
4   -
5   -There are a number of grunt projects.
6   -
7   -* [grunt](https://github.com/gruntjs/grunt) - the main grunt project
8   -* [gruntjs.com](https://github.com/gruntjs/gruntjs.com) - the gruntjs.com website
9   -* [grunt-contrib collection](https://github.com/gruntjs/grunt-contrib) - a collection of all grunt "contrib" plugins
10   -
11   -In addition, each individual grunt-contrib plugin is a separate repository listed on the [gruntjs org homepage](https://github.com/gruntjs).
12   -
13   -## Filing issues
14   -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.
15   -
16   -The best way to ensure an issue gets addressed is to file it in the appropriate issues tracker.
17   -
18   -**If there's an issue with a specific grunt-contrib plugin:**
19   -Please file an issue on that plugin's issues tracker.
20   -
21   -**If you'd like to contribute a new plugin:**
22   -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.
23   -
24   -**If there's an issue with the [website](http://gruntjs.com/):**
25   -Please file an issue on the [gruntjs.com website issues tracker](https://github.com/gruntjs/gruntjs.com/issues).
26   -
27   -**If there's an issue that isn't specific to any of the above:**
28   -Please file an issue on the [grunt issues tracker](https://github.com/gruntjs/grunt/issues).
29   -
30   -### Simplify the issue
31   -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.
32   -
33   -### Explain the issue
34   -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.
35   -
36   -## Discussing grunt
37   -Join the [freenode](http://freenode.net/) IRC #grunt channel. We've got a bot and everything.
38   -
39   -_No private messages, please._
40   -
41   -## Modifying grunt
42   -First, ensure that you have the latest [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed.
43   -
44   -1. Fork and clone the repo.
45   -1. Check out the correct branch. Currently, grunt development happens in the `devel` branch.
46   -1. Run `npm install` to install all grunt dependencies.
47   -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).
48   -1. Run `grunt` to grunt grunt.
49   -
50   -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.
51   -
52   -### Submitting pull requests
53   -
54   -1. Create a new branch, please don't work in your `master` or `devel` branch directly.
55   -1. Add failing tests for the change you want to make. Run `grunt` to see the tests fail.
56   -1. Fix stuff.
57   -1. Run `grunt` to see if the tests pass. Repeat steps 2-4 until done.
58   -1. Update the documentation to reflect any changes.
59   -1. Push to your fork and submit a pull request.
60   -
61   -### Syntax
62   -
63   -* Two space indents. Don't use tabs anywhere. Use `\t` if you need a tab character in a string.
64   -* No trailing whitespace, except in markdown files where a linebreak must be forced.
65   -* Don't go overboard with the whitespace.
66   -* No more than [one assignment](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) per `var` statement.
67   -* Delimit strings with single-quotes `'`, not double-quotes `"`.
68   -* Prefer `if` and `else` to ["clever"](http://programmers.stackexchange.com/a/25281) uses of `? :` conditional or `||`, `&&` logical operators.
69   -* Comments are great. Just put them _before_ the line of code, _not_ at the _end_ of the line.
70   -* **When in doubt, follow the conventions you see used in the source already.**
71   -
72   -### Reverting back to the "official" grunt
73   -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`
  1 +Please see the [Contributing to grunt](http://gruntjs.com/contributing) guide for information on contributing to this project.
2  Gruntfile.js
@@ -96,4 +96,4 @@ module.exports = function(grunt) {
96 96 // By default, lint and run all tests.
97 97 grunt.registerTask('default', ['jshint', 'test', 'build-contrib']);
98 98
99   -};
  99 +};
48 README.md
Source Rendered
@@ -2,31 +2,20 @@
2 2
3 3 > Compile LESS files to CSS.
4 4
5   -_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._
6 5
7 6 ## Getting Started
8   -_If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide._
  7 +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:
9 8
10   -From the same directory as your project's [Gruntfile][Getting Started] and [package.json][], install this plugin with the following command:
11   -
12   -```bash
  9 +```shell
13 10 npm install grunt-contrib-less --save-dev
14 11 ```
15 12
16   -Once that's done, add this line to your project's Gruntfile:
17   -
18   -```js
19   -grunt.loadNpmTasks('grunt-contrib-less');
20   -```
21   -
22   -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.
23   -
24 13 [grunt]: http://gruntjs.com/
25 14 [Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
26   -[package.json]: https://npmjs.org/doc/json.html
27 15
28 16
29   -## The less task
  17 +## Less task
  18 +_Run this task with the `grunt less` command._
30 19
31 20 ### Overview
32 21
@@ -46,37 +35,37 @@ grunt.initConfig({
46 35 ```
47 36 ### Options
48 37
49   -## options.paths
  38 +#### options.paths
50 39 Type: `String|Array`
51 40 Default: Directory of input file.
52 41
53 42 Specifies directories to scan for @import directives when parsing. Default value is the directory of the source, which is probably what you want.
54 43
55   -## options.compress
  44 +#### options.compress
56 45 Type: `Boolean`
57 46 Default: False
58 47
59 48 Compress output by removing some whitespaces.
60 49
61   -## options.yuicompress
  50 +#### options.yuicompress
62 51 Type: `Boolean`
63 52 Default: False
64 53
65 54 Compress output using cssmin.js
66 55
67   -## options.optimization
  56 +#### options.optimization
68 57 Type: `Integer`
69 58 Default: null
70 59
71 60 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.
72 61
73   -## options.strictImports
  62 +#### options.strictImports
74 63 Type: `Boolean`
75 64 Default: False
76 65
77 66 Force evaluation of imports.
78 67
79   -## options.dumpLineNumbers
  68 +#### options.dumpLineNumbers
80 69 Type: `String`
81 70 Default: false
82 71
@@ -109,13 +98,14 @@ less: {
109 98
110 99 ## Release History
111 100
112   - * 2012-10-17 - v0.3.2 - Add support for dumpLineNumbers.
113   - * 2012-10-11 - v0.3.1 - Rename grunt-contrib-lib dep to grunt-lib-contrib.
114   - * 2012-09-23 - v0.3.0 - Global options depreciated Revert normalize linefeeds.
115   - * 2012-09-15 - v0.2.2 - Support all less options Normalize linefeeds Default path to dirname of src file.
116   - * 2012-09-09 - v0.2.0 - Refactored from grunt-contrib into individual repo.
  101 + * 2012-10-17   v0.3.2   Add support for dumpLineNumbers.
  102 + * 2012-10-11   v0.3.1   Rename grunt-contrib-lib dep to grunt-lib-contrib.
  103 + * 2012-09-23   v0.3.0   Global options depreciated Revert normalize linefeeds.
  104 + * 2012-09-15   v0.2.2   Support all less options Normalize linefeeds Default path to dirname of src file.
  105 + * 2012-09-09   v0.2.0   Refactored from grunt-contrib into individual repo.
  106 +
  107 +---
117 108
118   ---
119   -Task submitted by <a href="http://goingslowly.com/">Tyler Kellen</a>.
  109 +Task submitted by [Tyler Kellen](http://goingslowly.com/)
120 110
121   -*Generated on Thu Oct 18 2012 18:59:49.*
  111 +*This file was generated on Tue Nov 13 2012 16:14:04.*
82 tasks/less.js
@@ -20,7 +20,6 @@ module.exports = function(grunt) {
20 20 };
21 21
22 22 grunt.registerMultiTask('less', 'Compile LESS files to CSS', function() {
23   - var basePath, newFileDest, srcFiles;
24 23 var done = this.async();
25 24
26 25 var options = this.options({
@@ -29,52 +28,46 @@ module.exports = function(grunt) {
29 28 });
30 29 grunt.verbose.writeflags(options, 'Options');
31 30
32   - grunt.util.async.forEachSeries(this.files, function(file, next) {
33   - file.dest = path.normalize(file.dest);
34   - srcFiles = grunt.file.expandFiles(file.src);
  31 + // get files
  32 + var files = grunt.file.expandFiles(this.file.src);
  33 + var destFile = this.file.dest;
35 34
36   - if (srcFiles.length === 0) {
37   - grunt.fail.warn('Unable to compile; no valid source files were found.');
38   - }
39   -
40   - if (helpers.isIndividualDest(file.dest)) {
41   - basePath = helpers.findBasePath(srcFiles, options.basePath);
42   -
43   - grunt.util.async.forEachSeries(srcFiles, function(srcFile, nextFile) {
44   - newFileDest = helpers.buildIndividualDest(file.dest, srcFile, basePath, options.flatten);
45   -
46   - compileLess(srcFile, options, function(css, err) {
47   - if(!err) {
48   - grunt.file.write(newFileDest, css || '');
49   - grunt.log.writeln('File ' + newFileDest.cyan + ' created.');
50   -
51   - nextFile(null);
52   - } else {
53   - done();
54   - }
55   - });
56   - }, function(err) {
57   - next();
  35 + if (files.length === 0) {
  36 + grunt.fail.warn('Unable to compile; no valid source files were found.');
  37 + done();
  38 + }
  39 +
  40 + // hack by chris to support compiling individual files
  41 + if (helpers.isIndividualDest(destFile)) {
  42 + var basePath = helpers.findBasePath(files, options.basePath);
  43 + grunt.util.async.forEachSeries(files, function(file, next) {
  44 + var newFileDest = helpers.buildIndividualDest(destFile, file, basePath, options.flatten);
  45 + compileLess(file, options, function(css, err) {
  46 + if(!err) {
  47 + grunt.file.write(newFileDest, css || '');
  48 + grunt.log.writeln('File ' + newFileDest.cyan + ' created.');
  49 + next(null);
  50 + } else {
  51 + done(false);
  52 + }
58 53 });
59   - } else {
60   - grunt.util.async.concatSeries(srcFiles, function(srcFile, nextConcat) {
61   - compileLess(srcFile, options, function(css, err) {
62   - if(!err) {
63   - nextConcat(null, css);
64   - } else {
65   - done();
66   - }
67   - });
68   - }, function(err, css) {
69   - grunt.file.write(file.dest, css.join('\n') || '');
70   - grunt.log.writeln('File ' + file.dest.cyan + ' created.');
71   -
72   - next();
  54 + });
  55 + } else {
  56 + // normal execution
  57 + grunt.util.async.concatSeries(files, function(file, next) {
  58 + compileLess(file, options, function(css, err) {
  59 + if(!err) {
  60 + next(null, css);
  61 + } else {
  62 + done(false);
  63 + }
73 64 });
74   - }
75   - }, function() {
76   - done();
77   - });
  65 + }, function(err, css) {
  66 + grunt.file.write(destFile, css.join('\n') || '');
  67 + grunt.log.writeln('File ' + destFile.cyan + ' created.');
  68 + done();
  69 + });
  70 + }
78 71 });
79 72
80 73 var formatLessError = function(e) {
@@ -101,6 +94,7 @@ module.exports = function(grunt) {
101 94 parser.parse(srcCode, function(parse_err, tree) {
102 95 if (parse_err) {
103 96 lessError(parse_err);
  97 + callback('',true);
104 98 }
105 99
106 100 try {

0 comments on commit 71aaab7

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