gulp-micro-tpl-compiler
Version:
gulp plugin develop for mtpl compiler
39 lines (37 loc) • 1.09 kB
JavaScript
var through = require('through-gulp');
var extend = require('extend-shallow');
var compiler = require('./lib/compiler');
var wrap = require('./lib/wrap');
function mtpl(options) {
// creating a stream through which each file will pass
var stream = through(function(file, encoding,callback) {
var opts = extend({
wrap: 'default',
lineNumber: false,
filepath: file.path,
relative: file.relative
}, options);
var data = '';
var result = null;
// console.log(opts.dirname);
// console.log(file.relative);
// do whatever necessary to process the file
if (file.isNull()) {
}
if (file.isBuffer()) {
// console.log(file.contents.toString());
data = compiler.process(file.contents.toString(), opts);
// console.log(data);
data = wrap(data, opts);
}
if (file.isStream()) {
}
file.contents = new Buffer(data);
this.push(file);
callback();
});
// returning the file stream
return stream;
};
// exporting the plugin
module.exports = mtpl;