Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit bda8c0cace6ab20234170626d36046a21027b6a2 @tkellen tkellen committed Sep 7, 2012
Showing with 308 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +3 −0 AUTHORS
  3. +22 −0 LICENSE-MIT
  4. +61 −0 README.md
  5. +73 −0 grunt.js
  6. +42 −0 package.json
  7. +76 −0 tasks/stylus.js
  8. +1 −0 test/fixtures/include/variables.styl
  9. +4 −0 test/fixtures/stylus.styl
  10. +3 −0 test/fixtures/stylus2.styl
  11. +20 −0 test/stylus_test.js
@@ -0,0 +1,3 @@
+node_modules
+npm-debug.log
+tmp
@@ -0,0 +1,3 @@
+Eric Woroshow (http://ericw.ca)
+Chris Talkington (http://christalkington.com/)
+Jean-Sébastien Ney
@@ -0,0 +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.
@@ -0,0 +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'],
+ }
+ }
+},
+```
@@ -0,0 +1,73 @@
+/*
+ * 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');
+
+};
@@ -0,0 +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"
+ ]
+}
@@ -0,0 +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);
+ }
+ });
+ };
+};
@@ -0,0 +1 @@
+$font-name = Helvetica
@@ -0,0 +1,4 @@
+@import "variables.styl"
+body
+ font $font-name
+ font-size 10px
@@ -0,0 +1,3 @@
+@import "variables.styl"
+#header
+ font $font-name
@@ -0,0 +1,20 @@
+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 bda8c0c

Please sign in to comment.