-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (23 loc) · 778 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
var through = require('through2'),
html2jade = require('html2jade'),
gutil = require('gulp-util'),
PluginError = gutil.PluginError;
module.exports = function(options) {
var stream, content, pathIndex;
options = options || {};
stream = through.obj(function(file, enc, callback) {
if ( file.isBuffer() ) content = file.contents.toString();
if (!content) throw new PluginError('grunt-html2jade', 'Missing content');
// Change file extension
pathIndex = file.path.lastIndexOf('.');
file.path = file.path.slice(0, pathIndex + 1) + 'jade';
options.outdir = false;
html2jade.convertHtml(content, options, function (err, jade) {
file.contents = new Buffer(jade);
this.push(file);
callback();
}.bind(this));
});
return stream;
}