-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 913 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
34
35
36
37
38
39
var map = require('map-stream')
, handlebars = require('handlebars')
, es = require('event-stream')
, clone = require('clone')
, rename = require('gulp-rename');
module.exports = function(options){
var opts = options ? options : {};
function compile(file, cb){
var path = file.path;
var compiledTemplate;
if(path.match('partials') !== null){
basename = path.split(/\\|\//g).pop().split('.').shift();
handlebars.registerPartial(basename, file.contents.toString());
return cb();
}
setTimeout(function(){
compiledTemplate = handlebars.compile(file.contents.toString())();
var newFile = clone(file);
newFile.contents = new Buffer(compiledTemplate);
return cb(null, newFile);
}, 1000);
}
var doRename = function(dir, base, ext){
// Change the extension to .js
dir.extname = ".html";
return dir;
};
return es.pipeline(
map(compile),
rename(doRename)
);
};