forked from foundation/panini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (64 loc) · 2.19 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var panini;
var help = require('./lib/helpMessage');
/**
* Initializes an instance of Panini.
* @constructor
* @param {object} options - Configuration options to use.
*/
function Panini(options) {
// configuration defaults
const defaults = {
debug: 0
};
this.options = options;
this.Handlebars = require('handlebars');
this.layouts = {};
this.pageLayouts = {};
this.data = {};
if (!options.layouts) {
throw new Error('Panini error: you must specify a directory for layouts.');
}
if (!options.root) {
throw new Error('Panini error: you must specify the root folder that pages live in.')
}
let debug;
if (!options.debug) {
debug = defaults.debug;
}
else {
this.options.debug ? debug = true : debug = false;
}
this.debug = debug;
}
Panini.prototype.refresh = require('./lib/refresh');
Panini.prototype.loadLayouts = require('./lib/loadLayouts');
Panini.prototype.loadPageLayouts = require('./lib/loadPageLayouts');
Panini.prototype.loadPartials = require('./lib/loadPartials');
Panini.prototype.loadDecorators = require('./lib/loadDecorators');
Panini.prototype.loadHelpers = require('./lib/loadHelpers');
Panini.prototype.loadBuiltinHelpers = require('./lib/loadBuiltinHelpers');
Panini.prototype.loadData = require('./lib/loadData');
Panini.prototype.render = require('./lib/render');
Panini.prototype.debugging = require('./lib/debugging');
/**
* Gulp stream function that renders HTML pages. The first time the function is invoked in the stream, a new instance of Panini is created with the given options.
* @param {object} options - Configuration options to pass to the new Panini instance.
* @returns {function} Transform stream function that renders HTML pages.
*/
module.exports = function(options) {
if (!panini) {
panini = new Panini(options);
panini.loadBuiltinHelpers();
panini.refresh();
module.exports.refresh = panini.refresh.bind(panini);
// expose Handlebars to the outside
module.exports.Handlebars = panini.Handlebars;
}
// Compile pages with the above helpers
return panini.render();
}
module.exports.Panini = Panini;
module.exports.refresh = function() {};
module.exports.help = function() {
help();
};