-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (63 loc) · 1.55 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
var engine = require("./lib/engine");
var conf = require("./lib/conf");
var sbook = require("./lib/spellbook");
var stupefy = {
init: function() {
if (this.conf)
{
if (this.conf.hasOwnProperty('plugins'))
{
for (var i = 0;i < this.conf.plugins.length;i++)
{
plob = require(this.conf.plugins[i])(stupefy);
stupefy.registerPlugin(plob);
}
}
if (this.conf.hasOwnProperty('tag_start') && this.conf.hasOwnProperty('tag_end')) {
stupefy.expr.start = this.conf.tag_start;
stupefy.expr.start = this.conf.tag_end;
} else {
stupefy.expr.start = "{%";
stupefy.expr.end = "%}"
if (!conf.autoTags)
stupefy.autoTags = true;
}
}
else {
stupefy.autoTags = true;
}
},
// log errors
error: (message) => {
console.error(message);
},
autoTags: false,
// expression structure
expr: {
start: "{%", // default values
end: "%}"
},
// register plugin object
registerPlugin: function(plob) {
// names of plugins
var names = Object.keys(plob);
for (var i = 0;i < names.length;i++)
{
var nm = names[i];
if (!this.engine.hasOwnProperty(nm)) {
this.engine[nm] = plob[nm];
}
else {
this.error("Already has plugin - " + nm);
}
}
},
// global scope variables
variables: { }
}
stupefy['conf'] = conf();
stupefy['sbook'] = sbook(stupefy); // sbook should be initialsed before engine as it requires it
stupefy['engine'] = engine(stupefy);
// stupefy['spells'] => spell files cache, built when spellbook.list() is called first.
// ^ ^ contains relative paths
module.exports = stupefy