-
Notifications
You must be signed in to change notification settings - Fork 105
/
index.js
55 lines (48 loc) · 1.72 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
var panini;
var help = require('./lib/helpMessage');
var Handlebars = require('handlebars');
/**
* Initializes an instance of Panini.
* @constructor
* @param {object} options - Configuration options to use.
*/
function Panini(options) {
this.options = options;
this.Handlebars = Handlebars;
this.layouts = {};
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.')
}
}
Panini.prototype.refresh = require('./lib/refresh');
Panini.prototype.loadLayouts = require('./lib/loadLayouts');
Panini.prototype.loadPartials = require('./lib/loadPartials');
Panini.prototype.loadHelpers = require('./lib/loadHelpers');
Panini.prototype.loadBuiltinHelpers = require('./lib/loadBuiltinHelpers');
Panini.prototype.loadData = require('./lib/loadData');
Panini.prototype.render = require('./lib/render');
/**
* 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);
}
// Compile pages with the above helpers
return panini.render();
}
module.exports.Panini = Panini;
module.exports.Handlebars = Handlebars;
module.exports.refresh = function() {}
module.exports.help = function() {
help();
}