1 | var es = require('event-stream');
|
2 | var compile = require('jade').compile;
|
3 | var clone = require('clone');
|
4 | var ext = require('gulp-util').replaceExtension;
|
5 |
|
6 | module.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 | };
|