forked from gulp-community/gulp-haml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (33 loc) · 947 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
'use strict';
var map = require('map-stream');
var rext = require('replace-ext');
var util = require('gulp-util');
var _ = require('lodash');
var compilers = {
creationix: require('haml'),
visionmedia: require('hamljs'),
};
module.exports = function(opts) {
var options = _.merge({
ext: '.html',
compiler: 'creationix',
compilerOpts: {}
}, opts);
// Map each file to this function
function hamlStream(file, cb) {
// Remember that contents is ALWAYS a buffer
if (file.isNull()) {
return cb(null, file); // pass along
}
if (file.isStream()) {
return cb(new util.PluginError('gulp-haml', 'Streaming not supported'));
}
var html = compilers[options.compiler]
.render(file.contents.toString('utf8'), options.compilerOpts);
file.path = rext(file.path, options.ext);
file.contents = new Buffer(html);
cb(null, file);
}
// Return a stream
return map(hamlStream);
};