Added: onError and onSuccess callback options

dev
David Manning 2014-01-25 09:46:20 -08:00
parent 852727e179
commit df32000dd2
3 changed files with 31 additions and 1 deletions

View File

@ -30,10 +30,18 @@ Options passed as a hash into `sass()` will be passed along to [`node-sass`](htt
## gulp-sass specific options
#### `errLogToConsole`
#### `errLogToConsole: true`
If you pass `errLogToConsole: true` into the options hash, sass errors will be logged to the console instead of generating a `gutil.PluginError` object. Use this option with `gulp.watch` to keep gulp from stopping every time you mess up your sass.
#### `onSuccess: callback`
Pass in your own callback to be called upon successful compilaton by node-sass. The callback has the form `callback(css)`, and is passed the compiled css as a string. Note: This *does not* prevent gulp-sass's default behavior of writing the output css file.
#### `onError: callback`
Pass in your own callback to be called upon a sass error from node-sass. The callback has the form `callback(err)`, where err is the error string generated by libsass. Note: this *does* prevent an actual `gulpPluginError` object from being created.
#Imports and Partials
gulp-sass now automatically passes along the directory of every scss file it parses as an include path for node-sass. This means that as long as you specify your includes relative to path of your scss file, everything will just work.

View File

@ -31,6 +31,8 @@ module.exports = function (options) {
}
opts.success = function (css) {
if (typeof opts.onSuccess === 'function') opts.onSuccess(css);
file.path = ext(file.path, '.css');
file.contents = new Buffer(css);
cb(null, file);
@ -41,6 +43,12 @@ module.exports = function (options) {
gutil.log('[gulp-sass] ' + err);
return cb();
}
if (typeof opts.onError === 'function') {
opts.onError(err);
return cb();
}
return cb(new gutil.PluginError('gulp-sass', err));
};

View File

@ -92,4 +92,18 @@ test('emit error on sass errors', function (t) {
t.end();
});
stream.write(errorFile);
});
test('call custom error callback when opts.onError is given', function (t) {
var stream = gsass({ onError: function (err) {
t.equal(err,
'source string:1: error: property "font" must be followed by a \':\'\n'
);
t.end();
}});
var errorFile = createVinyl('somefile.sass',
new Buffer('body { font \'Comic Sans\'; }'));
stream.write(errorFile);
});