-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (46 loc) · 1.4 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
'use strict';
const path = require('path');
const _ = require('lodash');
const fs = require('fs');
/**
* Initializes an instance of Effe.
* @constructor
* @param {object} options - Configuration options to use.
*/
function Effe(options = {}) {
this.options = options;
this.Handlebars = require('handlebars');
this.layouts = {};
if (this.options.layouts) {
this._loadLayouts([path.join(__dirname, 'hbs/layouts'), this.options.layouts]);
} else {
this._loadLayouts(path.join(__dirname, 'hbs/layouts'));
}
if (this.options.partials) this._loadPartials(this.options.partials);
if (this.options.helpers) this._loadHelpers(this.options.helpers);
}
Effe.prototype._loadLayouts = require('./loadLayouts');
Effe.prototype._loadPartials = require('./loadPartials');
Effe.prototype._loadHelpers = require('./loadHelpers');
Effe.prototype._render = require('./render').render;
/**
* Make the object with the engines
* @param {Object} effe
* @return {Function}
*/
function makeRenderer(effe) {
return function(path, options, cb) {
options.filename = path;
exports.handlebars = {};
fs.readFile(path, function() {
exports.handlebars.render = effe
._render(_.toString(arguments[1]), options)
.then(html => cb(null, html));
});
};
}
module.exports = function(options) {
const effe = new Effe(options);
const handlebars = makeRenderer(effe);
return { handlebars };
};