Added: onError and onSuccess callback options
This commit is contained in:
parent
852727e179
commit
df32000dd2
10
README.md
10
README.md
|
@ -30,10 +30,18 @@ Options passed as a hash into `sass()` will be passed along to [`node-sass`](htt
|
||||||
|
|
||||||
## gulp-sass specific options
|
## 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.
|
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
|
#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.
|
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.
|
||||||
|
|
8
index.js
8
index.js
|
@ -31,6 +31,8 @@ module.exports = function (options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.success = function (css) {
|
opts.success = function (css) {
|
||||||
|
if (typeof opts.onSuccess === 'function') opts.onSuccess(css);
|
||||||
|
|
||||||
file.path = ext(file.path, '.css');
|
file.path = ext(file.path, '.css');
|
||||||
file.contents = new Buffer(css);
|
file.contents = new Buffer(css);
|
||||||
cb(null, file);
|
cb(null, file);
|
||||||
|
@ -41,6 +43,12 @@ module.exports = function (options) {
|
||||||
gutil.log('[gulp-sass] ' + err);
|
gutil.log('[gulp-sass] ' + err);
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof opts.onError === 'function') {
|
||||||
|
opts.onError(err);
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
|
||||||
return cb(new gutil.PluginError('gulp-sass', err));
|
return cb(new gutil.PluginError('gulp-sass', err));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
14
test/test.js
14
test/test.js
|
@ -92,4 +92,18 @@ test('emit error on sass errors', function (t) {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
stream.write(errorFile);
|
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);
|
||||||
});
|
});
|
Loading…
Reference in a new issue