Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Commit df32000

Browse files
committed
Added: onError and onSuccess callback options
1 parent 852727e commit df32000

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@ Options passed as a hash into `sass()` will be passed along to [`node-sass`](htt
3030

3131
## gulp-sass specific options
3232

33-
#### `errLogToConsole`
33+
#### `errLogToConsole: true`
3434

3535
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.
3636

37+
#### `onSuccess: callback`
38+
39+
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.
40+
41+
#### `onError: callback`
42+
43+
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.
44+
3745
#Imports and Partials
3846

3947
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.

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ module.exports = function (options) {
3131
}
3232

3333
opts.success = function (css) {
34+
if (typeof opts.onSuccess === 'function') opts.onSuccess(css);
35+
3436
file.path = ext(file.path, '.css');
3537
file.contents = new Buffer(css);
3638
cb(null, file);
@@ -41,6 +43,12 @@ module.exports = function (options) {
4143
gutil.log('[gulp-sass] ' + err);
4244
return cb();
4345
}
46+
47+
if (typeof opts.onError === 'function') {
48+
opts.onError(err);
49+
return cb();
50+
}
51+
4452
return cb(new gutil.PluginError('gulp-sass', err));
4553
};
4654

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,18 @@ test('emit error on sass errors', function (t) {
9292
t.end();
9393
});
9494
stream.write(errorFile);
95+
});
96+
97+
test('call custom error callback when opts.onError is given', function (t) {
98+
var stream = gsass({ onError: function (err) {
99+
t.equal(err,
100+
'source string:1: error: property "font" must be followed by a \':\'\n'
101+
);
102+
t.end();
103+
}});
104+
105+
var errorFile = createVinyl('somefile.sass',
106+
new Buffer('body { font \'Comic Sans\'; }'));
107+
108+
stream.write(errorFile);
95109
});

0 commit comments

Comments
 (0)