|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 'use strict';
-
- var lib = require('./src/lib');
-
- var _require = require('./src/environment'),
- Environment = _require.Environment,
- Template = _require.Template;
-
- var Loader = require('./src/loader');
-
- var loaders = require('./src/loaders');
-
- var precompile = require('./src/precompile');
-
- var compiler = require('./src/compiler');
-
- var parser = require('./src/parser');
-
- var lexer = require('./src/lexer');
-
- var runtime = require('./src/runtime');
-
- var nodes = require('./src/nodes');
-
- var installJinjaCompat = require('./src/jinja-compat'); // A single instance of an environment, since this is so commonly used
-
-
- var e;
-
- function configure(templatesPath, opts) {
- opts = opts || {};
-
- if (lib.isObject(templatesPath)) {
- opts = templatesPath;
- templatesPath = null;
- }
-
- var TemplateLoader;
-
- if (loaders.FileSystemLoader) {
- TemplateLoader = new loaders.FileSystemLoader(templatesPath, {
- watch: opts.watch,
- noCache: opts.noCache
- });
- } else if (loaders.WebLoader) {
- TemplateLoader = new loaders.WebLoader(templatesPath, {
- useCache: opts.web && opts.web.useCache,
- async: opts.web && opts.web.async
- });
- }
-
- e = new Environment(TemplateLoader, opts);
-
- if (opts && opts.express) {
- e.express(opts.express);
- }
-
- return e;
- }
-
- module.exports = {
- Environment: Environment,
- Template: Template,
- Loader: Loader,
- FileSystemLoader: loaders.FileSystemLoader,
- NodeResolveLoader: loaders.NodeResolveLoader,
- PrecompiledLoader: loaders.PrecompiledLoader,
- WebLoader: loaders.WebLoader,
- compiler: compiler,
- parser: parser,
- lexer: lexer,
- runtime: runtime,
- lib: lib,
- nodes: nodes,
- installJinjaCompat: installJinjaCompat,
- configure: configure,
- reset: function reset() {
- e = undefined;
- },
- compile: function compile(src, env, path, eagerCompile) {
- if (!e) {
- configure();
- }
-
- return new Template(src, env, path, eagerCompile);
- },
- render: function render(name, ctx, cb) {
- if (!e) {
- configure();
- }
-
- return e.render(name, ctx, cb);
- },
- renderString: function renderString(src, ctx, cb) {
- if (!e) {
- configure();
- }
-
- return e.renderString(src, ctx, cb);
- },
- precompile: precompile ? precompile.precompile : undefined,
- precompileString: precompile ? precompile.precompileString : undefined
- };
|