From 1d7723d2f4ce8db44a30975cdb6a0c374c97b180 Mon Sep 17 00:00:00 2001 From: Aki Alexandra Nofftz Date: Wed, 27 Feb 2013 17:14:26 +0100 Subject: [PATCH] Provide Grunt task --- .gitignore | 2 ++ .jshintrc | 14 +++++++++++ Gruntfile.js | 49 +++++++++++++++++++++++++++++++++++++++ package.json | 10 ++++++-- tasks/bless.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 Gruntfile.js create mode 100644 tasks/bless.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..661efda --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/tmp +node_modules \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..e0cc7bb --- /dev/null +++ b/.jshintrc @@ -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 +} \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..b942aa2 --- /dev/null +++ b/Gruntfile.js @@ -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']); +}; \ No newline at end of file diff --git a/package.json b/package.json index a764723..80ca2b9 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,17 @@ "url" : "http://blesscss.com", "keywords" : ["css", "parser", "bless", "less", "sass", "stylus"], "author" : "Paul Young ", - "contributors" : [], + "contributors" : ["Aki Alexandra Nofftz "], "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" + } } diff --git a/tasks/bless.js b/tasks/bless.js new file mode 100644 index 0000000..cc2a621 --- /dev/null +++ b/tasks/bless.js @@ -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(); + }); + }); +};