UNPKG

804 BJavaScriptView Raw
1var es = require('event-stream');
2var compile = require('jade').compile;
3var clone = require('clone');
4var ext = require('gulp-util').replaceExtension;
5
6module.exports = function(options){
7 'use strict';
8
9 var opts = options ? clone(options) : {};
10
11 function jade(file, callback){
12 var newFile = clone(file);
13 var compiled = compile(String(newFile.contents), opts);
14 if(opts.client){
15 newFile.path = ext(newFile.path, '.js');
16 newFile.shortened = ext(newFile.shortened, '.js');
17 newFile.contents = new Buffer(compiled.toString());
18 } else {
19 newFile.path = ext(newFile.path, '.html');
20 newFile.shortened = ext(newFile.shortened, '.html');
21 newFile.contents = new Buffer(compiled(opts.data));
22 }
23
24 callback(null, newFile);
25 }
26
27 return es.map(jade);
28};