From 797a17da4b37999ece245cb10f1724089a99a7ed Mon Sep 17 00:00:00 2001 From: Ronald Lokers Date: Sat, 2 Jun 2012 21:24:57 +0200 Subject: [PATCH] added config option - Added the option to set the sass and css folders in the grunt config file so you don't have to create a separate compass configuration file - updated the read me to reflect these changes --- README.md | 36 ++++++++++++++++++++++++++++-------- tasks/grunt-compass.js | 16 +++++++++++----- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7880df3..4281ac9 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,31 @@ This is a custom grunt.js task that executes `compass compile` for you and print 1. Place the `grunt-compass` folder in the root of your project. 2. Call `grunt.loadTasks('grunt-compass/tasks');` in your gruntfile. 3. Configure `grunt watch` to watch your scss files and call the task. -e.g.: - -````javascript -watch: { - files: ['assets/scss/partials/*.scss'], - tasks: ['compass'] -} -```` \ No newline at end of file + e.g.: + + ```javascript + watch: { + files: ['assets/scss/partials/*.scss'], + tasks: ['compass'] + } + ``` + +4. Setup the config for compass in your grunt config, or setup a compass config file: + * Option 1: Set the configuration for compass in your grunt.js file: + + ```javascript + compass: { + src: 'assets/scss/partials', + dest: 'assets/css/partials' + } + ``` + + "src" is the folder with sass/scss files. + "dest" is the file where the css files will be place. + * Option 2: Setup a compass project + ``` + compass install compass + ``` +5. Run "grunt watch" and change some SASS files :) + +**Notice:** At this moment this task doesn't work with "grunt" or "grunt compass" it only creates the folders, not the files! \ No newline at end of file diff --git a/tasks/grunt-compass.js b/tasks/grunt-compass.js index f530c24..2b95c8a 100644 --- a/tasks/grunt-compass.js +++ b/tasks/grunt-compass.js @@ -3,8 +3,15 @@ module.exports = function( grunt ) { // Create a new task. grunt.registerTask( 'compass', 'This triggers the `compass compile` command.', function() { - var exec = require('child_process').exec; - grunt.log.write( '`compass compile` was initiated.' ); + var exec = require('child_process').exec, + command = "compass compile", + src = grunt.config('compass.src'), + dest = grunt.config('compass.dest'); + + if (src !== undefined && + dest !== undefined) { + command += ' --sass-dir="' + src + '" --css-dir="' + dest + '"'; + } function puts( error, stdout, stderr ) { @@ -12,13 +19,12 @@ module.exports = function( grunt ) { grunt.log.write( stdout ); grunt.log.error( stderr ); - - if ( error !== null ) { grunt.log.error( error ); } } - exec( "compass compile", puts ); + exec( command, puts ); + grunt.log.write( '`' + command + '` was initiated.' ); }); }; \ No newline at end of file