DRY'ed out the push back into the stream
This commit is contained in:
parent
7a2f8ac259
commit
ca990d0981
42
index.js
42
index.js
|
@ -15,6 +15,7 @@ var PLUGIN_NAME = 'gulp-sass';
|
||||||
var gulpSass = function gulpSass(options, sync) {
|
var gulpSass = function gulpSass(options, sync) {
|
||||||
return through.obj(function(file, enc, cb) {
|
return through.obj(function(file, enc, cb) {
|
||||||
var opts,
|
var opts,
|
||||||
|
filePush,
|
||||||
callback,
|
callback,
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
@ -37,39 +38,44 @@ var gulpSass = function gulpSass(options, sync) {
|
||||||
opts.omitSourceMapUrl = true;
|
opts.omitSourceMapUrl = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
// Handles returning the file to the stream
|
||||||
|
//////////////////////////////
|
||||||
|
filePush = function filePush(sassObj) {
|
||||||
|
// Build Source Maps!
|
||||||
|
if (sassObj.map) {
|
||||||
|
applySourceMap(file, JSON.parse(sassObj.map.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
file.contents = sassObj.css;
|
||||||
|
file.path = gutil.replaceExtension(file.path, '.css');
|
||||||
|
|
||||||
|
cb(null, file);
|
||||||
|
};
|
||||||
|
|
||||||
if (sync !== true) {
|
if (sync !== true) {
|
||||||
|
//////////////////////////////
|
||||||
|
// Async Sass render
|
||||||
|
//////////////////////////////
|
||||||
callback = function(error, obj) {
|
callback = function(error, obj) {
|
||||||
if (error) {
|
if (error) {
|
||||||
return cb(new gutil.PluginError(
|
return cb(new gutil.PluginError(
|
||||||
PLUGIN_NAME, error.message + ' ' + gutil.colors.cyan('line ' + error.line) + ' in ' + gutil.colors.magenta(error.file)
|
PLUGIN_NAME, error.message + ' ' + gutil.colors.cyan('line ' + error.line) + ' in ' + gutil.colors.magenta(error.file)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
// Build Source Maps!
|
filePush(obj);
|
||||||
if (obj.map) {
|
|
||||||
applySourceMap(file, JSON.parse(obj.map.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
file.contents = obj.css;
|
|
||||||
file.path = gutil.replaceExtension(file.path, '.css');
|
|
||||||
|
|
||||||
cb(null, file);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sass.render(opts, callback);
|
sass.render(opts, callback);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
//////////////////////////////
|
||||||
|
// Sync Sass render
|
||||||
|
//////////////////////////////
|
||||||
try {
|
try {
|
||||||
result = sass.renderSync(opts);
|
result = sass.renderSync(opts);
|
||||||
|
|
||||||
// Build Source Maps!
|
filePush(result);
|
||||||
if (result.map) {
|
|
||||||
applySourceMap(file, JSON.parse(result.map.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
file.contents = result.css;
|
|
||||||
file.path = gutil.replaceExtension(file.path, '.css');
|
|
||||||
|
|
||||||
cb(null, file);
|
|
||||||
}
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
return cb(new gutil.PluginError(
|
return cb(new gutil.PluginError(
|
||||||
|
|
Loading…
Reference in a new issue