2013-09-01 01:53:11 +02:00
|
|
|
var es = require('event-stream')
|
|
|
|
, clone = require('clone')
|
|
|
|
, sass = require('node-sass')
|
2014-01-10 17:27:05 +01:00
|
|
|
, path = require('path')
|
|
|
|
, gutil = require('gulp-util')
|
|
|
|
, ext = gutil.replaceExtension
|
2013-09-01 01:53:11 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
module.exports = function (options) {
|
|
|
|
var opts = options ? clone(options) : {};
|
|
|
|
|
|
|
|
function nodeSass (file, cb) {
|
2014-01-10 17:27:05 +01:00
|
|
|
if (path.basename(file.path).indexOf('_') === 0) {
|
|
|
|
return cb();
|
|
|
|
}
|
2014-01-05 16:15:20 +01:00
|
|
|
|
|
|
|
if (file.isNull()) {
|
2014-01-10 17:27:05 +01:00
|
|
|
return cb();
|
2014-01-05 16:15:20 +01:00
|
|
|
}
|
|
|
|
|
2013-12-14 17:47:44 +01:00
|
|
|
opts.data = file.contents.toString();
|
2013-09-01 06:54:25 +02:00
|
|
|
|
2013-09-01 04:00:14 +02:00
|
|
|
opts.success = function (css) {
|
2013-12-14 17:47:44 +01:00
|
|
|
file.path = ext(file.path, '.css');
|
|
|
|
file.shortened = file.shortened && ext(file.shortened, '.css');
|
|
|
|
file.contents = new Buffer(css);
|
|
|
|
cb(null, file);
|
2013-09-01 04:00:14 +02:00
|
|
|
}
|
2013-09-01 06:54:25 +02:00
|
|
|
|
|
|
|
opts.error = function (err) {
|
2014-01-13 07:27:45 +01:00
|
|
|
if (opts.errLogToConsole) {
|
2014-01-13 07:43:12 +01:00
|
|
|
gutil.log('[gulp-sass] ' + err)
|
2014-01-13 07:27:45 +01:00
|
|
|
return cb();
|
|
|
|
}
|
2014-01-10 22:34:30 +01:00
|
|
|
return cb(new gutil.PluginError('gulp-sass', err));
|
2013-09-01 06:54:25 +02:00
|
|
|
}
|
|
|
|
|
2013-09-01 04:00:14 +02:00
|
|
|
sass.render(opts);
|
2013-09-01 01:53:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return es.map(nodeSass);
|
2013-12-14 17:47:44 +01:00
|
|
|
}
|