Permalink
Browse files

bring task into line with new task specs.

  • Loading branch information...
1 parent bda8c0c commit 379c8a07b5c192fdc7e16f861cdc4acda9c789eb @ctalkington ctalkington committed Sep 8, 2012
Showing with 293 additions and 291 deletions.
  1. +22 −22 LICENSE-MIT
  2. +61 −61 README.md
  3. +74 −73 grunt.js
  4. +41 −41 package.json
  5. +75 −75 tasks/stylus.js
  6. +20 −19 test/stylus_test.js
View
44 LICENSE-MIT
@@ -1,22 +1,22 @@
-Copyright (c) 2012 Eric Woroshow, contributors
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
+Copyright (c) 2012 Eric Woroshow, contributors
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
122 README.md
@@ -1,61 +1,61 @@
-# grunt-contrib-stylus
-> Compile Stylus files to CSS (part of the [grunt-contrib](/gruntjs/grunt-contrib) collection). Submitted by [Eric Woroshow](/errcw).
-
-## Getting Started
-Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-contrib-stylus`
-
-Then add this line to your project's `grunt.js` gruntfile:
-
-```javascript
-grunt.loadNpmTasks('grunt-contrib-stylus');
-```
-
-[grunt]: https://github.com/cowboy/grunt
-[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
-
-### Overview
-
-Inside your `grunt.js` file add a section named `stylus`. This section specifies the files to compile and the options passed to [stylus](http://learnboost.github.com/stylus/).
-
-This task comes preloaded with [nib](http://visionmedia.github.com/nib/).
-
-#### Parameters
-
-##### files ```object```
-
-This defines what files this task will process and should contain key:value pairs.
-
-The key (destination) should be an unique filepath (supports [grunt.template](https://github.com/cowboy/grunt/blob/master/docs/api_template.md)) and the value (source) should be a filepath or an array of filepaths (supports [minimatch](https://github.com/isaacs/minimatch)).
-
-Note: When the value contains an array of multiple filepaths, the contents are concatenated in the order passed.
-
-##### options ```object```
-
-This controls how this task (and its helpers) operate and should contain key:value pairs, see options below.
-
-#### Options
-
-##### compress ```boolean```
-
-This specifies if we should compress the compiled css.
-
-##### paths ```string|array```
-
-This specifies directories to scan for @import directives when parsing.
-
-#### Config Example
-
-``` javascript
-stylus: {
- compile: {
- options: {
- compress: true,
- paths: ['path/to/import', 'another/to/import']
- },
- files: {
- 'path/to/result.css': 'path/to/source.styl',
- 'path/to/another.css': ['path/to/sources/*.styl', 'path/to/more/*.style'],
- }
- }
-},
-```
+# grunt-contrib-stylus
+> Compile Stylus files to CSS (part of the [grunt-contrib](https://github.com/gruntjs/grunt-contrib) collection). Submitted by [Eric Woroshow](https://github.com/errcw).
+
+## Getting Started
+Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-contrib-stylus`
+
+Then add this line to your project's `grunt.js` gruntfile:
+
+```javascript
+grunt.loadNpmTasks('grunt-contrib-stylus');
+```
+
+[grunt]: https://github.com/cowboy/grunt
+[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
+
+### Overview
+
+Inside your `grunt.js` file add a section named `stylus`. This section specifies the files to compile and the options passed to [stylus](http://learnboost.github.com/stylus/).
+
+This task comes preloaded with [nib](http://visionmedia.github.com/nib/).
+
+#### Parameters
+
+##### files ```object```
+
+This defines what files this task will process and should contain key:value pairs.
+
+The key (destination) should be an unique filepath (supports [grunt.template](https://github.com/cowboy/grunt/blob/master/docs/api_template.md)) and the value (source) should be a filepath or an array of filepaths (supports [minimatch](https://github.com/isaacs/minimatch)).
+
+Note: When the value contains an array of multiple filepaths, the contents are concatenated in the order passed.
+
+##### options ```object```
+
+This controls how this task (and its helpers) operate and should contain key:value pairs, see options below.
+
+#### Options
+
+##### compress ```boolean```
+
+This specifies if we should compress the compiled css.
+
+##### paths ```string|array```
+
+This specifies directories to scan for @import directives when parsing.
+
+#### Config Example
+
+``` javascript
+stylus: {
+ compile: {
+ options: {
+ compress: true,
+ paths: ['path/to/import', 'another/to/import']
+ },
+ files: {
+ 'path/to/result.css': 'path/to/source.styl',
+ 'path/to/another.css': ['path/to/sources/*.styl', 'path/to/more/*.style'],
+ }
+ }
+},
+```
View
147 grunt.js
@@ -1,73 +1,74 @@
-/*
- * grunt-contrib-stylus
- * http://gruntjs.com/
- *
- * Copyright (c) 2012 Eric Woroshow, contributors
- * Licensed under the MIT license.
- * https://github.com/gruntjs/grunt-contrib-stylus/blob/master/LICENSE-MIT
- */
-
-module.exports = function(grunt) {
- 'use strict';
-
- // Project configuration.
- grunt.initConfig({
- // JSHint files and options.
- lint: {
- all: ['grunt.js', 'tasks/*.js', '<config:nodeunit.tasks>']
- },
- jshint: {
- options: {
- curly: true,
- eqeqeq: true,
- immed: true,
- latedef: true,
- newcap: true,
- noarg: true,
- sub: true,
- undef: true,
- boss: true,
- eqnull: true,
- node: true,
- es5: true
- }
- },
- // Before generating any new files, remove any previously-created files.
- clean: {
- test: ['tmp']
- },
- // Configuration to be run and then tested. All files will be created in
- // the local "tmp" directory.
- stylus: {
- compile: {
- files: {
- "tmp/stylus.css": ["test/fixtures/stylus.styl"],
- "tmp/stylus_b.css": ["test/fixtures/stylus.styl", "test/fixtures/stylus2.styl"]
- },
- options: {
- paths: ["test/fixtures/include"],
- compress: true
- }
- }
- },
- // Unit tests.
- nodeunit: {
- tasks: ['test/*_test.js']
- }
- });
-
- // Actually load this plugin's task(s).
- grunt.loadTasks('tasks');
-
- // The clean plugin helps in testing.
- grunt.loadNpmTasks('grunt-contrib-clean');
-
- // Whenever the "test" task is run, first clean the "tmp" dir, then run this
- // plugin's task(s), then test the result.
- grunt.renameTask('test', 'nodeunit');
- grunt.registerTask('test', 'clean stylus nodeunit');
-
- // By default, lint and run all tests.
- grunt.registerTask('default', 'lint test');
-
-};
+/*
+ * grunt-contrib-stylus
+ * http://gruntjs.com/
+ *
+ * Copyright (c) 2012 Eric Woroshow, contributors
+ * Licensed under the MIT license.
+ * https://github.com/gruntjs/grunt-contrib-stylus/blob/master/LICENSE-MIT
+ */
+
+module.exports = function(grunt) {
+ 'use strict';
+
+ // Project configuration.
+ grunt.initConfig({
+ lint: {
+ all: ['grunt.js', 'tasks/*.js', '<config:nodeunit.tasks>']
+ },
+
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ node: true,
+ es5: true
+ }
+ },
+
+ // Before generating any new files, remove any previously-created files.
+ clean: {
+ test: ['tmp']
+ },
+
+ // Configuration to be run (and then tested).
+ stylus: {
+ compile: {
+ files: {
+ 'tmp/stylus.css': ['test/fixtures/stylus.styl'],
+ 'tmp/stylus_b.css': ['test/fixtures/stylus.styl', 'test/fixtures/stylus2.styl']
+ },
+ options: {
+ paths: ['test/fixtures/include'],
+ compress: true
+ }
+ }
+ },
+
+ // Unit tests.
+ nodeunit: {
+ tasks: ['test/*_test.js']
+ }
+ });
+
+ // Actually load this plugin's task(s).
+ grunt.loadTasks('tasks');
+
+ // The clean plugin helps in testing.
+ grunt.loadNpmTasks('grunt-contrib-clean');
+
+ // Whenever the 'test' task is run, first clean the 'tmp' dir, then run this
+ // plugin's task(s), then test the result.
+ grunt.renameTask('test', 'nodeunit');
+ grunt.registerTask('test', 'clean stylus nodeunit');
+
+ // By default, lint and run all tests.
+ grunt.registerTask('default', 'lint test');
+};
View
82 package.json
@@ -1,42 +1,42 @@
-{
- "name": "grunt-contrib-stylus",
- "description": "Compile LESS files to CSS.",
- "version": "0.1.0",
- "homepage": "https://github.com/gruntjs/grunt-contrib-stylus",
- "author": {
- "name": "Eric Woroshow",
- "url": "http://ericw.ca/"
- },
- "repository": {
- "type": "git",
- "url": "git://github.com/gruntjs/grunt-contrib-stylus.git"
- },
- "bugs": {
- "url": "https://github.com/gruntjs/grunt-contrib-stylus/issues"
- },
- "licenses": [
- {
- "type": "MIT",
- "url": "https://github.com/gruntjs/grunt-contrib-stylus/blob/master/LICENSE-MIT"
- }
- ],
- "main": "grunt.js",
- "engines": {
- "node": "*"
- },
- "scripts": {
- "test": "grunt test"
- },
- "dependencies": {
- "grunt-contrib-lib": "~0.1.0",
- "stylus": "~0.29.0",
- "nib": "~0.8.1"
- },
- "devDependencies": {
- "grunt": "~0.3.15",
- "grunt-contrib-clean": "~0.1.0"
- },
- "keywords": [
- "gruntplugin"
- ]
+{
+ "name": "grunt-contrib-stylus",
+ "description": "Compile LESS files to CSS.",
+ "version": "0.2.0",
+ "homepage": "https://github.com/gruntjs/grunt-contrib-stylus",
+ "author": {
+ "name": "Eric Woroshow",
+ "url": "http://ericw.ca/"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/gruntjs/grunt-contrib-stylus.git"
+ },
+ "bugs": {
+ "url": "https://github.com/gruntjs/grunt-contrib-stylus/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/gruntjs/grunt-contrib-stylus/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "grunt.js",
+ "engines": {
+ "node": "*"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "dependencies": {
+ "stylus": "~0.29.0",
+ "nib": "~0.8.2",
+ "grunt-contrib-lib": "~0.1.0",
+ "grunt-contrib-clean": "~0.1.0"
+ },
+ "devDependencies": {
+ "grunt": "~0.3.15"
+ },
+ "keywords": [
+ "gruntplugin"
+ ]
}
View
150 tasks/stylus.js
@@ -1,76 +1,76 @@
-/*
- * grunt-contrib-stylus
- * http://gruntjs.com/
- *
- * Copyright (c) 2012 Eric Woroshow, contributors
- * Licensed under the MIT license.
- * https://github.com/gruntjs/grunt-contrib-stylus/blob/master/LICENSE-MIT
- */
-
-module.exports = function(grunt) {
- "use strict";
-
- // TODO: ditch this when grunt v0.4 is released
- grunt.util = grunt.util || grunt.utils;
-
- var _ = grunt.util._;
- var async = grunt.util.async;
- var helpers = require("grunt-contrib-lib").init(grunt);
-
- grunt.registerMultiTask("stylus", "Compile Stylus files into CSS", function() {
- var options = helpers.options(this);
-
- grunt.verbose.writeflags(options, "Options");
-
- // TODO: ditch this when grunt v0.4 is released
- this.files = this.files || helpers.normalizeMultiTaskFiles(this.data, this.target);
-
- var done = this.async();
-
- var srcFiles;
- var sourceCode;
- var helperOptions;
-
- async.forEachSeries(this.files, function(file, next) {
- srcFiles = grunt.file.expandFiles(file.src);
-
- async.concatSeries(srcFiles, function(srcFile, nextConcat) {
- helperOptions = _.extend({filename: srcFile}, options);
- sourceCode = grunt.file.read(srcFile);
-
- stylus(sourceCode, helperOptions, function(css) {
- nextConcat(null, css);
- });
- }, function(err, css) {
- grunt.file.write(file.dest, css.join("\n") || "");
- grunt.log.writeln("File '" + file.dest + "' created.");
-
- next();
- });
- }, function() {
- done();
- });
- });
-
- var stylus = function(source, options, callback) {
- var s = require("stylus")(source);
-
- // load nib if available
- try {
- s.use(require("nib")());
- } catch (e) {}
-
- _.each(options, function(value, key) {
- s.set(key, value);
- });
-
- s.render(function(err, css) {
- if (err) {
- grunt.log.error(err);
- grunt.fail.warn("Stylus failed to compile.");
- } else {
- callback(css);
- }
- });
- };
+/*
+ * grunt-contrib-stylus
+ * http://gruntjs.com/
+ *
+ * Copyright (c) 2012 Eric Woroshow, contributors
+ * Licensed under the MIT license.
+ * https://github.com/gruntjs/grunt-contrib-stylus/blob/master/LICENSE-MIT
+ */
+
+module.exports = function(grunt) {
+ 'use strict';
+
+ // TODO: ditch this when grunt v0.4 is released
+ grunt.util = grunt.util || grunt.utils;
+
+ var _ = grunt.util._;
+ var async = grunt.util.async;
+ var helpers = require('grunt-contrib-lib').init(grunt);
+
+ grunt.registerMultiTask('stylus', 'Compile Stylus files into CSS', function() {
+ var options = helpers.options(this);
+
+ grunt.verbose.writeflags(options, 'Options');
+
+ // TODO: ditch this when grunt v0.4 is released
+ this.files = this.files || helpers.normalizeMultiTaskFiles(this.data, this.target);
+
+ var done = this.async();
+
+ var srcFiles;
+ var sourceCode;
+ var helperOptions;
+
+ async.forEachSeries(this.files, function(file, next) {
+ srcFiles = grunt.file.expandFiles(file.src);
+
+ async.concatSeries(srcFiles, function(srcFile, nextConcat) {
+ helperOptions = _.extend({filename: srcFile}, options);
+ sourceCode = grunt.file.read(srcFile);
+
+ compileStylus(sourceCode, helperOptions, function(css) {
+ nextConcat(null, css);
+ });
+ }, function(err, css) {
+ grunt.file.write(file.dest, css.join('\n') || '');
+ grunt.log.writeln('File ' + file.dest + ' created.');
+
+ next();
+ });
+ }, function() {
+ done();
+ });
+ });
+
+ var compileStylus = function(source, options, callback) {
+ var s = require('stylus')(source);
+
+ // load nib if available
+ try {
+ s.use(require('nib')());
+ } catch (e) {}
+
+ _.each(options, function(value, key) {
+ s.set(key, value);
+ });
+
+ s.render(function(err, css) {
+ if (err) {
+ grunt.log.error(err);
+ grunt.fail.warn('Stylus failed to compile.');
+ } else {
+ callback(css);
+ }
+ });
+ };
};
View
39 test/stylus_test.js
@@ -1,20 +1,21 @@
-var grunt = require('grunt');
-
-exports['stylus'] = {
- main: function(test) {
- 'use strict';
-
- var expect, result;
- test.expect(2);
-
- expect = "body{font:Helvetica;font-size:10px}\n";
- result = grunt.file.read("tmp/stylus.css");
- test.equal(expect, result, "should compile stylus to css, handling includes and compression");
-
- expect = "body{font:Helvetica;font-size:10px}\n\n#header{font:Helvetica}\n";
- result = grunt.file.read("tmp/stylus_b.css");
- test.equal(expect, result, "should concat output when passed an array");
-
- test.done();
- }
+var grunt = require('grunt');
+
+exports['stylus'] = {
+ main: function(test) {
+ 'use strict';
+
+ var expect, result;
+
+ test.expect(2);
+
+ expect = 'body{font:Helvetica;font-size:10px}\n';
+ result = grunt.file.read('tmp/stylus.css');
+ test.equal(expect, result, 'should compile stylus to css, handling includes and compression');
+
+ expect = 'body{font:Helvetica;font-size:10px}\n\n#header{font:Helvetica}\n';
+ result = grunt.file.read('tmp/stylus_b.css');
+ test.equal(expect, result, 'should concat output when passed an array');
+
+ test.done();
+ }
};

0 comments on commit 379c8a0

Please sign in to comment.