Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gruntjs/grunt-contrib-stylus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: backbone-boilerplate/grunt-contrib-stylus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 21, 2013

  1. broke out compile into a lib

    tbranyen committed Jan 21, 2013

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d1d7763 View commit details
  2. Copy the full SHA
    0ac3a38 View commit details
Showing with 70 additions and 45 deletions.
  1. +1 −1 package.json
  2. +64 −0 tasks/lib/stylus.js
  3. +5 −44 tasks/stylus.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
"url": "https://github.com/gruntjs/grunt-contrib-stylus/blob/master/LICENSE-MIT"
}
],
"main": "grunt.js",
"main": "./tasks/lib/stylus.js",
"engines": {
"node": ">= 0.8.0"
},
64 changes: 64 additions & 0 deletions tasks/lib/stylus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* grunt-contrib-stylus
* https://gruntjs.com/
*
* Copyright (c) 2012 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.
*/

'use strict';

// External libs.
var stylus = require('stylus');

exports.init = function(grunt) {
var exports = {};

exports.compileFile = function(srcFile, options, callback) {
options = grunt.util._.extend({filename: srcFile}, options);

exports.compile(grunt.file.read(srcFile), options, callback);
};

exports.compile = function(srcCode, options, callback) {
// Never compress output in debug mode
if (grunt.option('debug')) {
options.compress = false;
}

var s = stylus(srcCode);

grunt.util._.each(options, function(value, key) {
if (key === 'urlfunc') {
// Custom name of function for embedding images as Data URI
s.define(value, stylus.url());
} else if (key === 'use') {
value.forEach(function(func) {
if (typeof func === 'function') {
s.use(func());
}
});
} else {
s.set(key, value);
}
});

// Load Nib if available
try {
s.use(require('nib')());
} catch (e) {}

s.render(function(err, css) {
if (err) {
grunt.log.error(err);
grunt.fail.warn('Stylus failed to compile.');

callback(css, true);
} else {
callback(css, null);
}
});
};

return exports;
};
49 changes: 5 additions & 44 deletions tasks/stylus.js
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@
'use strict';

module.exports = function(grunt) {

// Internal lib.
var stylus = require('./lib/stylus').init(grunt);

grunt.registerMultiTask('stylus', 'Compile Stylus files into CSS', function() {
var done = this.async();
var path = require('path');
@@ -42,7 +46,7 @@ module.exports = function(grunt) {

var compiled = [];
grunt.util.async.concatSeries(srcFiles, function(file, next) {
compileStylus(file, options, function(css, err) {
stylus.compileFile(file, options, function(css, err) {
if (!err) {
compiled.push(css);
next(null);
@@ -62,47 +66,4 @@ module.exports = function(grunt) {
}, done);
});

var compileStylus = function(srcFile, options, callback) {
options = grunt.util._.extend({filename: srcFile}, options);

// Never compress output in debug mode
if (grunt.option('debug')) {
options.compress = false;
}

var srcCode = grunt.file.read(srcFile);
var stylus = require('stylus');
var s = stylus(srcCode);

grunt.util._.each(options, function(value, key) {
if (key === 'urlfunc') {
// Custom name of function for embedding images as Data URI
s.define(value, stylus.url());
} else if (key === 'use') {
value.forEach(function(func) {
if (typeof func === 'function') {
s.use(func());
}
});
} else {
s.set(key, value);
}
});

// Load Nib if available
try {
s.use(require('nib')());
} catch (e) {}

s.render(function(err, css) {
if (err) {
grunt.log.error(err);
grunt.fail.warn('Stylus failed to compile.');

callback(css, true);
} else {
callback(css, null);
}
});
};
};