Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Grunt task funtionality #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/tmp
node_modules
14 changes: 14 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"node": true,
"es5": true
}
49 changes: 49 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Sample Gruntfile.js for using bless in Grunt
*
* Copyright (c) 2013 Aki Alexandra Nofftz
* Licensed under the MIT license.
*/

'use strict';

module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},

// Before generating any new files, remove any previously-created files.
clean: {
test: 'tmp'
},

// Configuration to be run (and then tested).
bless: {
split: {
files: {
'tmp/above-limit.css': ['test/input/above-limit.css'],
'tmp/below-limit.css': ['test/input/below-limit.css']
}
}
},
});

// Actually load this plugin's task(s).
grunt.loadTasks('tasks');

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');

grunt.registerTask('mkdir', grunt.file.mkdir);

grunt.registerTask('default', ['jshint', 'mkdir:tmp', 'bless']);
};
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
"url" : "http://blesscss.com",
"keywords" : ["css", "parser", "bless", "less", "sass", "stylus"],
"author" : "Paul Young <[email protected]>",
"contributors" : [],
"contributors" : ["Aki Alexandra Nofftz <[email protected]>"],
"version" : "3.0.2",
"bin" : { "blessc": "./bin/blessc" },
"main" : "./lib/bless/index",
"directories" : { "test": "./test" },
"engines" : { "node": ">=0.6.0" },
"devDependencies" : { "vows": "~0.6.2" }
"devDependencies" : {
"vows" : "~0.6.2",
"grunt" : "~0.4.0",
"grunt-contrib-clean" : "latest",
"grunt-contrib-jshint" : "latest",
"grunt-contrib-nodeunit" : "latest"
}
}
63 changes: 63 additions & 0 deletions tasks/bless.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Provides bless.js as Grunt task
*
* Copyright (c) Aki Alexandra Nofftz
* Licensed under the MIT license.
*/

'use strict';

module.exports = function(grunt) {
var path = require('path'),
bless = require('../lib/bless');

grunt.registerMultiTask('bless', 'Split CSS files suiteable for IE', function() {

var options = this.options({
cacheBuster: true,
cleanup: true,
compress: false,
force: false,
imports: true
});
grunt.log.writeflags(options, 'options');

grunt.util.async.forEach(this.files, function (files, next) {
var data = '';

// read and concat files
files.src.forEach(function (file) {
data += grunt.file.read(file);
});

new (bless.Parser)({
output: files.dest,
options: options
}).parse(data, function (err, files, numSelectors) {
if (err) {
grunt.log.error(err);
throw grunt.util.error(err);
}

// print log message
var msg = 'Found ' + numSelectors + ' selector';
if (numSelectors !== 1) {
msg += 's';
}
msg += ', ';
if (files.length > 1) {
msg += 'splitting into ' + files.length + ' files.';
} else {
msg += 'not splitting.';
}
grunt.log.verbose.writeln(msg);

// write processed file(s)
files.forEach(function (file) {
grunt.file.write(file.filename, file.content);
});
});
next();
});
});
};