gulp-haml-coffee-compile
Version:
haml-coffee compile for gulp
61 lines (53 loc) • 1.55 kB
JavaScript
// Generated by CoffeeScript 1.9.3
var _, gutil, hamlc, map, path, rext;
map = require("map-stream");
rext = require("replace-ext");
hamlc = require("haml-coffee");
gutil = require("gulp-util");
_ = require("underscore");
path = require("path");
module.exports = function(options) {
var compileOpts, defaultOpts, hamlStream;
if (options == null) {
options = {};
}
defaultOpts = {
name: "",
compile: {
includePath: true,
pathRelativeTo: "./"
}
};
options = _.extend(defaultOpts, options);
compileOpts = options.compile;
delete options.compile;
hamlStream = function(file, cb) {
var e, filePath, output, temp;
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
return cb(new Error("gulp-haml-coffee: Streaming not supported"));
}
filePath = path.relative(compileOpts.pathRelativeTo, file.path);
if (compileOpts.includePath) {
temp = filePath.split('/');
temp.pop();
options.name = temp.join("/") + "/";
}
options.name += filePath.split('/').pop().split('.')[0];
output = void 0;
try {
output = hamlc.template(file.contents.toString(), options.name, options.namespace);
file.path = rext(file.path, ".js");
} catch (_error) {
e = _error;
throw new gutil.PluginError("gulp-haml-coffee", "Error compiling " + file.path + ": " + e, {
showStack: true
});
}
file.contents = new Buffer(output.toString("utf8"));
cb(null, file);
};
return map(hamlStream);
};