-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (34 loc) · 1.21 KB
/
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
34
35
var path = require('path');
var through = require('through-gulp');
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');
var superviews = require("superviews.js");
// file can be a vinyl file object or a string
// when a string it will construct a new one
module.exports = function(opt) {
opt = opt || {};
opt.mode = opt.mode || "es6";
// to preserve existing |undefined| behaviour and to introduce |newLine: ""| for binaries
if (typeof opt.newLine !== 'string') {
opt.newLine = '\n';
}
return through(function(file, encoding, callback) {
if (file.isNull()) {}
if (file.isBuffer()) {
var templateFile = new Buffer(decoder.write(file.contents));
templateFile = superviews(
decoder.write(templateFile)
.replace(/<require from=/g,"<delegating-import from=")
.replace(/<\/require>/g,"</delegating-import>")
.replace(/[\n\t\r]/g," ")
.replace(/ (\w*)\.((trigger)|(delegate))="([^"]+)"/g," on$1=\"{$event.preventDefault();$5}\"")
, null, null, opt.mode);
file.contents = new Buffer(templateFile);
}
if (file.isStream()) {}
this.push(file);
callback();
}, function(callback) {
callback();
});
};