wintersmith-sassy
Version:
sass plugin that dosn't suck and has source-maps
69 lines (59 loc) • 2.12 kB
JavaScript
// Generated by CoffeeScript 1.12.7
var path, sass,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
path = require('path');
sass = require('node-sass');
module.exports = function(env, callback) {
var SassPlugin, includePaths, options, ref, ref1;
options = (ref = env.config.sass) != null ? ref : {};
if (options.debug == null) {
options.debug = env.mode === 'preview';
}
includePaths = ((ref1 = options.includePaths) != null ? ref1 : []).map(function(path) {
return env.resolvePath(path);
});
SassPlugin = (function(superClass) {
extend(SassPlugin, superClass);
function SassPlugin(filepath1) {
this.filepath = filepath1;
}
SassPlugin.prototype.render = function(callback) {
var opts;
if ((path.basename(this.filename))[0] === '_') {
callback();
return;
}
opts = {
file: this.filepath.full,
includePaths: includePaths,
sourceMapEmbed: options.debug,
sourceMapContents: options.debug,
outputStyle: options.debug ? 'nested' : 'compressed'
};
return sass.render(opts, function(error, result) {
var rv;
if (error == null) {
rv = result.css;
}
return callback(error, rv);
});
};
SassPlugin.prototype.getFilename = function() {
return this.filepath.relative.replace(/s(a|c)ss$/, 'css');
};
SassPlugin.prototype.getView = function() {
return function() {
var callback;
callback = arguments[arguments.length - 1];
return this.render(callback);
};
};
return SassPlugin;
})(env.ContentPlugin);
SassPlugin.fromFile = function(filepath, callback) {
return callback(null, new SassPlugin(filepath));
};
env.registerContentPlugin('styles', '**/*.*(sass|scss)', SassPlugin);
return callback();
};