-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
29 lines (22 loc) · 810 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
module.exports = JadeStream;
var fs = require('fs')
, PassThrough = require('stream').PassThrough
, inherits = require('util').inherits
, StringDecoder = require('string_decoder').StringDecoder
, decoder = new StringDecoder('utf8')
, jade = require('jade');
function JadeStream (options) {
if (!(this instanceof JadeStream)) return new JadeStream(options);
PassThrough.call(this, options);
this._options = options;
}
inherits(JadeStream, PassThrough);
JadeStream.prototype._transform = function (chunk, enc, cb) {
cb(null, jade.render(decoder.write(chunk), this._options));
};
JadeStream.createReadStream = function (fileName, options) {
var jadeStream = new JadeStream();
jadeStream.end(jade.renderFile(fileName, options));
jadeStream._options = options;
return jadeStream;
};