forked from mozilla/nunjucks
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
72 lines (57 loc) · 1.88 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
var lib = require('./src/lib');
var env = require('./src/environment');
var compiler = require('./src/compiler');
var parser = require('./src/parser');
var lexer = require('./src/lexer');
var runtime = require('./src/runtime');
var Loader = require('./src/loader');
var loaders = require('./src/loaders');
var precompile = require('./src/precompile');
module.exports = {};
module.exports.Environment = env.Environment;
module.exports.Template = env.Template;
module.exports.Loader = Loader;
module.exports.FileSystemLoader = loaders.FileSystemLoader;
module.exports.WebLoader = loaders.WebLoader;
module.exports.compiler = compiler;
module.exports.parser = parser;
module.exports.lexer = lexer;
module.exports.runtime = runtime;
// A single instance of an environment, since this is so commonly used
var e;
module.exports.configure = function(templatesPath, opts) {
opts = opts || {};
if(lib.isObject(templatesPath)) {
opts = templatesPath;
templatesPath = null;
}
var noWatch = 'watch' in opts ? !opts.watch : false;
var loader = loaders.FileSystemLoader || loaders.WebLoader;
e = new env.Environment(new loader(templatesPath, noWatch), opts);
if(opts && opts.express) {
e.express(opts.express);
}
return e;
};
module.exports.compile = function(src, env, path, eagerCompile) {
if(!e) {
module.exports.configure();
}
return new module.exports.Template(src, env, path, eagerCompile);
};
module.exports.render = function(name, ctx, cb) {
if(!e) {
module.exports.configure();
}
return e.render(name, ctx, cb);
};
module.exports.renderString = function(src, ctx, cb) {
if(!e) {
module.exports.configure();
}
return e.renderString(src, ctx, cb);
};
if(precompile) {
module.exports.precompile = precompile.precompile;
module.exports.precompileString = precompile.precompileString;
}