-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 999 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
40
41
42
43
44
'use strict';
var jadePhp = require('jade2php');
var through = require('through2');
var ext = require('gulp-util').replaceExtension;
var PluginError = require('gulp-util').PluginError;
var merge = require('merge');
function handleExtension(filepath, opts){
return ext(filepath, '');
}
module.exports = function(options){
var defaultOptions = {
omitPhpRuntime: true,
omitPhpExtractor: true
};
var opts = merge(defaultOptions, options);
function CompileJade(file, enc, cb){
opts.filename = file.path;
if (file.data) {
opts.data = file.data;
}
file.path = handleExtension(file.path, opts);
if(file.isStream()){
return cb(new PluginError('gulp-jade', 'Streaming not supported'));
}
if(file.isBuffer()){
try {
file.contents = new Buffer(jadePhp(String(file.contents), opts));
} catch(e) {
return cb(new PluginError('gulp-jade', e));
}
}
cb(null, file);
}
return through.obj(CompileJade);
};