-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (29 loc) · 796 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
module.exports = function(expressHandlebars){
if(typeof expressHandlebars === 'undefined'){
return section;
}
else{
if(!expressHandlebars){
throw new Error('The expressHandlebars object is null.');
}
expressHandlebars.helpers = expressHandlebars.helpers || {};
expressHandlebars.helpers.section = section;
}
// helper used to manage sections in handlebar templates
function section(name, options) {
var helper = this;
if (!this._sections) {
this._sections = {};
this._sections._get = function(arg){
if(typeof helper._sections[arg] === 'undefined'){
throw new Error('The section "' + arg + '" is required.')
}
return helper._sections[arg];
}
}
if(!this._sections[name]){
this._sections[name] = options.fn(this);
}
return null;
}
};