This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
59 lines (49 loc) · 1.44 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var aglio = require('aglio');
var through2 = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var defaults = require('lodash.defaults');
var path = require('path');
module.exports = function (options) {
'use strict';
// Mixes in default options.
options = defaults(options || {}, {
compress: false,
paths: []
});
function transform(file, enc, next) {
var self = this;
if (file.isNull()) {
self.push(file); // pass along
return next();
}
if (file.isStream()) {
self.emit('error', new PluginError('gulp-aglio', 'Streaming not supported'));
return next();
}
var str = file.contents.toString('utf8');
// Clones the options object.
var opts = defaults({
theme: 'default'
}, options);
// Injects the path of the current file.
opts.filename = file.path;
// Inject includePath for relative includes
opts.includePath = opts.includePath || path.dirname(opts.filename);
try {
aglio.render(str, opts, function (err, html) {
if (err) {
self.emit('error', new PluginError('gulp-aglio', err));
} else {
file.contents = new Buffer(html);
file.path = gutil.replaceExtension(file.path, '.html');
self.push(file);
}
next();
});
} catch (err) {
self.emit('error', new PluginError('gulp-aglio', err));
}
}
return through2.obj(transform);
};