function gulpSass(options, sync) { return through.obj(function(file, enc, cb) { var opts, filePush, errorM, callback, result; if (file.isNull()) { return cb(null, file); } if (file.isStream()) { return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); } if (path.basename(file.path).indexOf('_') === 0) { return cb(); } if (!file.contents.length) { file.path = gutil.replaceExtension(file.path, '.css'); return cb(null, file); } opts = clonedeep(options || {}); opts.data = file.contents.toString(); // we set the file path here so that libsass can correctly resolve import paths opts.file = file.path; // Ensure `indentedSyntax` is true if a `.sass` file if (path.extname(file.path) === '.sass') { opts.indentedSyntax = true; } // Ensure file's parent directory in the include path if (opts.includePaths) { if (typeof opts.includePaths === 'string') { opts.includePaths = [opts.includePaths]; } } else { opts.includePaths = []; } opts.includePaths.unshift(path.dirname(file.path)); // Generate Source Maps if plugin source-map present if (file.sourceMap) { opts.sourceMap = file.path; opts.omitSourceMapUrl = true; opts.sourceMapContents = true; } ////////////////////////////// // Handles returning the file to the stream ////////////////////////////// filePush = function filePush(sassObj) { var sassMap, sassMapFile, sassFileSrc, sassFileSrcPath, sourceFileIndex; // Build Source Maps! if (sassObj.map) { // Transform map into JSON sassMap = JSON.parse(sassObj.map.toString()); // Grab the stdout and transform it into stdin sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin'); // Grab the base file name that's being worked on sassFileSrc = file.relative; // Grab the path portion of the file that's being worked on sassFileSrcPath = path.dirname(sassFileSrc); if (sassFileSrcPath) { //Prepend the path to all files in the sources array except the file that's being worked on sourceFileIndex = sassMap.sources.indexOf(sassMapFile); sassMap.sources = sassMap.sources.map(function(source, index) { return (index === sourceFileIndex) ? source : path.join(sassFileSrcPath, source); }); } // Remove 'stdin' from souces and replace with filenames! sassMap.sources = sassMap.sources.filter(function(src) { if (src !== 'stdin') { return src; } }); // Replace the map file with the original file name (but new extension) sassMap.file = gutil.replaceExtension(sassFileSrc, '.css'); // Apply the map applySourceMap(file, sassMap); } file.contents = sassObj.css; file.path = gutil.replaceExtension(file.path, '.css'); cb(null, file); }; ////////////////////////////// // Handles error message ////////////////////////////// errorM = function errorM(error) { var relativePath = '', filePath = error.file === 'stdin' ? file.path : error.file, message = ''; filePath = filePath ? filePath : file.path; relativePath = path.relative(process.cwd(), filePath); message += gutil.colors.underline(relativePath) + '\n'; message += error.formatted; error.messageFormatted = message; error.messageOriginal = error.message; error.message = gutil.colors.stripColor(message); error.relativePath = relativePath; return cb(new gutil.PluginError( PLUGIN_NAME, error )); }; if (sync !== true) { ////////////////////////////// // Async Sass render ////////////////////////////// callback = function(error, obj) { if (error) { return errorM(error); } filePush(obj); ...
n/a
function logError(error) { var message = new gutil.PluginError('sass', error.messageFormatted).toString(); process.stderr.write(message + '\n'); this.emit('end'); }
n/a
function sync(options) { return gulpSass(options, true); }
...
**May 6, 2015**
* **Change** :arrow_up: Bump to Node Sass 3.0.0
## v2.0.0-alpha.1
**March 26, 2015**
* **New** Added `renderSync` option that can be used through `sass.sync()`
### March 24, 2015
* **Change** Updated to `node-sass` 3.0.0-alpha.1
* **New** Added support for `gulp-sourcemaps` including tests
* **New** Added `.editorconfig` for development consistency
* **New** Added linting and test for said linting
* **Change** Updated the README
...
render = function (opts, cb) { var options = getOptions(opts, cb); // options.error and options.success are for libsass binding options.error = function(err) { var payload = assign(new Error(), JSON.parse(err)); if (cb) { options.context.callback.call(options.context, payload, null); } }; options.success = function() { var result = options.result; var stats = endStats(result.stats); var payload = { css: result.css, map: result.map, stats: stats }; if (cb) { options.context.callback.call(options.context, null, payload); } }; var importer = options.importer; if (importer) { if (Array.isArray(importer)) { options.importer = []; importer.forEach(function(subject, index) { options.importer[index] = function(file, prev, bridge) { function done(result) { bridge.success(result === module.exports.NULL ? null : result); } var result = subject.call(options.context, file, prev, done); if (result !== undefined) { done(result); } }; }); } else { options.importer = function(file, prev, bridge) { function done(result) { bridge.success(result === module.exports.NULL ? null : result); } var result = importer.call(options.context, file, prev, done); if (result !== undefined) { done(result); } }; } } var functions = clonedeep(options.functions); if (functions) { options.functions = {}; Object.keys(functions).forEach(function(subject) { var cb = normalizeFunctionSignature(subject, functions[subject]); options.functions[cb.signature] = function() { var args = Array.prototype.slice.call(arguments), bridge = args.pop(); function done(data) { bridge.success(data); } var result = tryCallback(cb.callback.bind(options.context), args.concat(done)); if (result) { done(result); } }; }); } if (options.data) { binding.render(options); } else if (options.file) { binding.renderFile(options); } else { cb({status: 3, message: 'No input specified: provide a file name or a source string to process' }); } }
...
callback = function(error, obj) {
if (error) {
return errorM(error);
}
filePush(obj);
};
gulpSass.compiler.render(opts, callback);
}
else {
//////////////////////////////
// Sync Sass render
//////////////////////////////
try {
result = gulpSass.compiler.renderSync(opts);
...
renderSync = function (opts) { var options = getOptions(opts); var importer = options.importer; if (importer) { if (Array.isArray(importer)) { options.importer = []; importer.forEach(function(subject, index) { options.importer[index] = function(file, prev) { var result = subject.call(options.context, file, prev); return result === module.exports.NULL ? null : result; }; }); } else { options.importer = function(file, prev) { var result = importer.call(options.context, file, prev); return result === module.exports.NULL ? null : result; }; } } var functions = clonedeep(options.functions); if (options.functions) { options.functions = {}; Object.keys(functions).forEach(function(signature) { var cb = normalizeFunctionSignature(signature, functions[signature]); options.functions[cb.signature] = function() { return tryCallback(cb.callback.bind(options.context), arguments); }; }); } var status; if (options.data) { status = binding.renderSync(options); } else if (options.file) { status = binding.renderFileSync(options); } else { throw new Error('No input specified: provide a file name or a source string to process'); } var result = options.result; if (status) { result.stats = endStats(result.stats); return result; } throw assign(new Error(), JSON.parse(result.error)); }
...
gulpSass.compiler.render(opts, callback);
}
else {
//////////////////////////////
// Sync Sass render
//////////////////////////////
try {
result = gulpSass.compiler.renderSync(opts);
filePush(result);
}
catch (error) {
return errorM(error);
}
}
...
function SassBoolean() { [native code] }
n/a
function SassColor() { [native code] }
n/a
function SassError() { [native code] }
n/a
function SassList() { [native code] }
n/a
function SassMap() { [native code] }
n/a
function SassNull() { [native code] }
n/a
function SassNumber() { [native code] }
n/a
function SassString() { [native code] }
n/a
function getValue() { [native code] }
n/a
function getA() { [native code] }
n/a
function getB() { [native code] }
n/a
function getG() { [native code] }
n/a
function getR() { [native code] }
n/a
function setA() { [native code] }
n/a
function setB() { [native code] }
n/a
function setG() { [native code] }
n/a
function setR() { [native code] }
n/a
function getLength() { [native code] }
n/a
function getSeparator() { [native code] }
n/a
function getValue() { [native code] }
n/a
function setSeparator() { [native code] }
n/a
function setValue() { [native code] }
n/a
function getKey() { [native code] }
n/a
function getLength() { [native code] }
n/a
function getValue() { [native code] }
n/a
function setKey() { [native code] }
n/a
function setValue() { [native code] }
n/a
function getUnit() { [native code] }
n/a
function getValue() { [native code] }
n/a
function setUnit() { [native code] }
n/a
function setValue() { [native code] }
n/a
function getValue() { [native code] }
n/a
function setValue() { [native code] }
n/a