@kosatyi/ejs 0.0.63 → 0.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/umd/index.js CHANGED
@@ -1,762 +1,747 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ejs = {}));
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ejs = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- function _typeof(o) {
8
- "@babel/helpers - typeof";
7
+ var path = {};
9
8
 
10
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
11
- return typeof o;
12
- } : function (o) {
13
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
14
- }, _typeof(o);
15
- }
16
-
17
- var typeProp = function typeProp() {
18
- var args = [].slice.call(arguments);
19
- var callback = args.shift();
20
- return args.filter(callback).pop();
21
- };
22
- var isFunction = function isFunction(v) {
23
- return typeof v === 'function';
24
- };
25
- var isString = function isString(v) {
26
- return typeof v === 'string';
27
- };
28
- var isBoolean = function isBoolean(v) {
29
- return typeof v === 'boolean';
30
- };
31
- var isObject = function isObject(v) {
32
- return _typeof(v) === 'object';
33
- };
34
- var isUndefined = function isUndefined(v) {
35
- return typeof v === 'undefined';
36
- };
37
-
38
- var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
39
- var isNode = function isNode() {
40
- return isNodeEnv;
41
- };
42
- var symbolEntities = {
43
- "'": "'",
44
- '\\': '\\',
45
- '\r': 'r',
46
- '\n': 'n',
47
- '\t': 't',
48
- "\u2028": 'u2028',
49
- "\u2029": 'u2029'
50
- };
51
- var htmlEntities = {
52
- '&': '&',
53
- '<': '&lt;',
54
- '>': '&gt;',
55
- '"': '&quot;',
56
- "'": '&#x27;'
57
- };
58
- var regexKeys = function regexKeys(obj) {
59
- return new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
60
- };
61
- var htmlEntitiesMatch = regexKeys(htmlEntities);
62
- var symbolEntitiesMatch = regexKeys(symbolEntities);
63
- var entities = function entities() {
64
- var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
65
- return ('' + string).replace(htmlEntitiesMatch, function (match) {
66
- return htmlEntities[match];
67
- });
68
- };
69
- var symbols = function symbols(string) {
70
- return ('' + string).replace(symbolEntitiesMatch, function (match) {
71
- return '\\' + symbolEntities[match];
72
- });
73
- };
74
- var safeValue = function safeValue(value, escape) {
75
- var check = value;
76
- return check == null ? '' : escape === true ? entities(check) : check;
77
- };
78
- var instanceOf = function instanceOf(object, instance) {
79
- return object instanceof instance;
80
- };
81
- var getPath = function getPath(context, name, strict) {
82
- var data = context;
83
- var chunks = String(name).split('.');
84
- var prop = chunks.pop();
85
- for (var i = 0; i < chunks.length; i++) {
86
- var part = chunks[i];
87
- if (isFunction(data['toJSON'])) {
88
- data = data.toJSON();
89
- }
90
- if (strict && data.hasOwnProperty(part) === false) {
91
- data = {};
92
- break;
93
- }
94
- data = data[part] = data[part] || {};
95
- }
96
- if (isFunction(data['toJSON'])) {
97
- data = data.toJSON();
98
- }
99
- return [data, prop];
100
- };
101
- var ext = function ext(path, defaults) {
102
- var ext = path.split('.').pop();
103
- if (ext !== defaults) {
104
- path = [path, defaults].join('.');
105
- }
106
- return path;
107
- };
108
- var extend = function extend() {
109
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
110
- args[_key] = arguments[_key];
111
- }
112
- var target = args.shift();
113
- return args.filter(function (source) {
114
- return source;
115
- }).reduce(function (target, source) {
116
- return Object.assign(target, source);
117
- }, target);
118
- };
119
- var noop = function noop() {};
120
- var each = function each(object, callback) {
121
- var prop;
122
- for (prop in object) {
123
- if (hasProp(object, prop)) {
124
- callback(object[prop], prop, object);
125
- }
126
- }
127
- };
128
- var map = function map(object, callback, context) {
129
- var result = [];
130
- each(object, function (value, key, object) {
131
- var item = callback(value, key, object);
132
- if (isUndefined(item) === false) {
133
- result.push(item);
134
- }
135
- });
136
- return result;
137
- };
138
- var filter = function filter(object, callback, context) {
139
- var isArray = object instanceof Array;
140
- var result = isArray ? [] : {};
141
- each(object, function (value, key, object) {
142
- var item = callback(value, key, object);
143
- if (isUndefined(item) === false) {
144
- if (isArray) {
145
- result.push(item);
146
- } else {
147
- result[key] = item;
148
- }
149
- }
150
- });
151
- return result;
152
- };
153
- var omit = function omit(object, list) {
154
- return filter(object, function (value, key) {
155
- if (list.indexOf(key) === -1) {
156
- return value;
157
- }
158
- });
159
- };
160
- var resolve$1 = function resolve(value, callback, context) {
161
- return Promise.resolve(value).then(callback.bind(context));
162
- };
163
- var hasProp = function hasProp(object, prop) {
164
- return object && object.hasOwnProperty(prop);
165
- };
166
-
167
- var defaults = {};
168
- defaults["export"] = 'ejsPrecompiled';
169
- defaults.watch = false;
170
- defaults.chokidar = null;
171
- defaults.path = 'views';
172
- defaults.resolver = null;
173
- defaults.extension = 'ejs';
174
- defaults.rmWhitespace = true;
175
- defaults.withObject = true;
176
- defaults.vars = {
177
- SCOPE: 'ejs',
178
- COMPONENT: 'ui',
179
- EXTEND: '$$e',
180
- BUFFER: '$$a',
181
- LAYOUT: '$$l',
182
- BLOCKS: '$$b',
183
- MACRO: '$$m',
184
- SAFE: '$$v'
185
- };
186
- defaults.token = {
187
- start: '<%',
188
- end: '%>',
189
- regex: '([\\s\\S]+?)'
190
- };
191
-
192
- var path = {};
193
-
194
- var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
195
- var space = ' ';
196
- var quote = '"';
197
- var equal = '=';
198
- var slash = '/';
199
- var lt = '<';
200
- var gt = '>';
201
- var element = function element(tag, attrs, content) {
202
- var result = [];
203
- var hasClosedTag = selfClosed.indexOf(tag) === -1;
204
- var attributes = map(attrs, function (value, key) {
205
- if (value !== null && value !== undefined) {
206
- return [entities(key), [quote, entities(value), quote].join('')].join(equal);
207
- }
208
- }).join(space);
209
- result.push([lt, tag, space, attributes, gt].join(''));
210
- if (content) {
211
- result.push(content instanceof Array ? content.join('') : content);
212
- }
213
- if (hasClosedTag) {
214
- result.push([lt, slash, tag, gt].join(''));
215
- }
216
- return result.join('');
217
- };
218
-
219
- var configSchema = function configSchema(config, options) {
220
- extend(config, {
221
- path: typeProp(isString, defaults.path, config.path, options.path),
222
- "export": typeProp(isString, defaults["export"], config["export"], options["export"]),
223
- resolver: typeProp(isFunction, defaults.resolver, config.resolver, options.resolver),
224
- extension: typeProp(isString, defaults.extension, config.extension, options.extension),
225
- withObject: typeProp(isBoolean, defaults.withObject, config.withObject, options.withObject),
226
- rmWhitespace: typeProp(isBoolean, defaults.rmWhitespace, config.rmWhitespace, options.rmWhitespace),
227
- watch: typeProp(isBoolean, defaults.watch, config.watch, options.watch),
228
- chokidar: typeProp(isObject, defaults["export"], config["export"], options["export"]),
229
- token: extend({}, defaults.token, config.token, options.token),
230
- vars: extend({}, defaults.vars, config.vars, options.vars)
231
- });
232
- };
233
-
234
- var resolvePath = function resolvePath(path, template) {
235
- template = [path, template].join('/');
236
- template = template.replace(/\/\//g, '/');
237
- return template;
238
- };
239
- var httpRequest = function httpRequest(path, template) {
240
- return fetch(resolvePath(path, template)).then(function (response) {
241
- return response.text();
242
- });
243
- };
244
- var fileSystem = function fileSystem(path$1, template) {
245
- return new Promise(function (resolve, reject) {
246
- path.readFile(resolvePath(path$1, template), function (error, data) {
247
- if (error) {
248
- reject(error);
249
- } else {
250
- resolve(data.toString());
251
- }
252
- });
253
- });
254
- };
255
- var fileResolver = function fileResolver(resolver) {
256
- return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
257
- };
258
- function Template(config, cache, compiler) {
259
- if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
260
- var template = {};
261
- var result = function result(template, content) {
262
- cache.set(template, content);
263
- return content;
9
+ var typeProp = function typeProp() {
10
+ var args = [].slice.call(arguments);
11
+ var callback = args.shift();
12
+ return args.filter(callback).pop();
264
13
  };
265
- var resolve = function resolve(path) {
266
- return template.resolver(template.path, path);
14
+ var isFunction = function isFunction(v) {
15
+ return typeof v === 'function';
267
16
  };
268
- var compile = function compile(content, template) {
269
- if (isFunction(content)) {
270
- return content;
271
- } else {
272
- return compiler.compile(content, template);
273
- }
274
- };
275
- var watcher = function watcher(config) {
276
- if (template.watcher) {
277
- template.watcher.unwatch('.');
278
- }
279
- if (config.watch && config.chokidar && isNode()) {
280
- return config.chokidar.watch('.', {
281
- cwd: template.path
282
- }).on('change', function (name) {
283
- cache.remove(name);
284
- });
285
- }
17
+ var isString = function isString(v) {
18
+ return typeof v === 'string';
286
19
  };
287
- this.configure = function (config) {
288
- template.path = config.path;
289
- template.chokidar = config.chokidar;
290
- template.resolver = fileResolver(config.resolver);
291
- template.watcher = watcher(config);
20
+ var isBoolean = function isBoolean(v) {
21
+ return typeof v === 'boolean';
292
22
  };
293
- this.get = function (template) {
294
- if (cache.exist(template)) {
295
- return cache.resolve(template);
296
- }
297
- return result(template, resolve(template).then(function (content) {
298
- return result(template, compile(content, template));
299
- }));
23
+ var isUndefined = function isUndefined(v) {
24
+ return typeof v === 'undefined';
300
25
  };
301
- this.configure(config);
302
- }
303
26
 
304
- var tagList = [{
305
- symbol: '-',
306
- format: function format(value) {
307
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
308
- }
309
- }, {
310
- symbol: '=',
311
- format: function format(value) {
312
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
313
- }
314
- }, {
315
- symbol: '#',
316
- format: function format(value) {
317
- return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
318
- }
319
- }, {
320
- symbol: '',
321
- format: function format(value) {
322
- return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
323
- }
324
- }];
325
- function matchTokens(regex, text, callback) {
326
- var index = 0;
327
- text.replace(regex, function () {
328
- var params = [].slice.call(arguments, 0, -1);
329
- var offset = params.pop();
330
- var match = params.shift();
331
- callback(params, index, offset);
332
- index = offset + match.length;
333
- return match;
334
- });
335
- }
336
- function Compiler(config) {
337
- if (instanceOf(this, Compiler) === false) return new Compiler(config);
338
- var compiler = {};
339
- this.configure = function (config) {
340
- compiler.withObject = config.withObject;
341
- compiler.rmWhitespace = config.rmWhitespace;
342
- compiler.token = config.token;
343
- compiler.vars = config.vars;
344
- compiler.matches = [];
345
- compiler.formats = [];
346
- compiler.slurp = {
347
- match: '[ \\t]*',
348
- start: [compiler.token.start, '_'],
349
- end: ['_', compiler.token.end]
350
- };
351
- tagList.forEach(function (item) {
352
- compiler.matches.push(compiler.token.start.concat(item.symbol).concat(compiler.token.regex).concat(compiler.token.end));
353
- compiler.formats.push(item.format.bind(compiler.vars));
27
+ var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
28
+ var isNode = function isNode() {
29
+ return isNodeEnv;
30
+ };
31
+ var symbolEntities = {
32
+ "'": "'",
33
+ '\\': '\\',
34
+ '\r': 'r',
35
+ '\n': 'n',
36
+ '\t': 't',
37
+ "\u2028": 'u2028',
38
+ "\u2029": 'u2029'
39
+ };
40
+ var htmlEntities = {
41
+ '&': '&amp;',
42
+ '<': '&lt;',
43
+ '>': '&gt;',
44
+ '"': '&quot;',
45
+ "'": '&#x27;'
46
+ };
47
+ var regexKeys = function regexKeys(obj) {
48
+ return new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
49
+ };
50
+ var htmlEntitiesMatch = regexKeys(htmlEntities);
51
+ var symbolEntitiesMatch = regexKeys(symbolEntities);
52
+ var entities = function entities() {
53
+ var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
54
+ return ('' + string).replace(htmlEntitiesMatch, function (match) {
55
+ return htmlEntities[match];
354
56
  });
355
- compiler.regex = new RegExp(compiler.matches.join('|').concat('|$'), 'g');
356
- compiler.slurpStart = new RegExp([compiler.slurp.match, compiler.slurp.start.join('')].join(''), 'gm');
357
- compiler.slurpEnd = new RegExp([compiler.slurp.end.join(''), compiler.slurp.match].join(''), 'gm');
358
57
  };
359
- this.compile = function (content, path) {
360
- var _compiler$vars = compiler.vars,
361
- SCOPE = _compiler$vars.SCOPE,
362
- SAFE = _compiler$vars.SAFE,
363
- BUFFER = _compiler$vars.BUFFER,
364
- COMPONENT = _compiler$vars.COMPONENT;
365
- if (compiler.rmWhitespace) {
366
- content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
367
- }
368
- content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
369
- var source = "".concat(BUFFER, "('");
370
- matchTokens(compiler.regex, content, function (params, index, offset) {
371
- source += symbols(content.slice(index, offset));
372
- params.forEach(function (value, index) {
373
- if (value) {
374
- source += compiler.formats[index](value);
375
- }
376
- });
58
+ var symbols = function symbols(string) {
59
+ return ('' + string).replace(symbolEntitiesMatch, function (match) {
60
+ return '\\' + symbolEntities[match];
377
61
  });
378
- source += "');";
379
- source = "try{".concat(source, "}catch(e){console.info(e)}");
380
- if (compiler.withObject) {
381
- source = "with(".concat(SCOPE, "){").concat(source, "}");
62
+ };
63
+ var safeValue = function safeValue(value, escape) {
64
+ var check = value;
65
+ return check == null ? '' : escape === true ? entities(check) : check;
66
+ };
67
+ var instanceOf = function instanceOf(object, instance) {
68
+ return Boolean(object instanceof instance);
69
+ };
70
+ var getPath = function getPath(context, name, strict) {
71
+ var data = context;
72
+ var chunks = String(name).split('.');
73
+ var prop = chunks.pop();
74
+ for (var i = 0; i < chunks.length; i++) {
75
+ var part = chunks[i];
76
+ if (isFunction(data['toJSON'])) {
77
+ data = data.toJSON();
78
+ }
79
+ if (strict && data.hasOwnProperty(part) === false) {
80
+ data = {};
81
+ break;
82
+ }
83
+ data = data[part] = data[part] || {};
382
84
  }
383
- source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
384
- source += "\n//# sourceURL=".concat(path);
385
- var result = null;
386
- try {
387
- result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
388
- result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
389
- } catch (e) {
390
- e.filename = path;
391
- e.source = source;
392
- throw e;
85
+ if (isFunction(data['toJSON'])) {
86
+ data = data.toJSON();
393
87
  }
394
- return result;
395
- };
396
- this.configure(config);
397
- }
398
-
399
- var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
400
- function Cache(config) {
401
- if (instanceOf(this, Cache) === false) return new Cache();
402
- var cache = {
403
- list: {}
88
+ return [data, prop];
404
89
  };
405
- this.configure = function (config) {
406
- cache.list = {};
407
- if (isNode() === false) {
408
- this.load(global[config["export"]]);
90
+ var ext = function ext(path, defaults) {
91
+ var ext = path.split('.').pop();
92
+ if (ext !== defaults) {
93
+ path = [path, defaults].join('.');
409
94
  }
95
+ return path;
410
96
  };
411
- this.load = function (data) {
412
- extend(cache.list, data || {});
413
- return this;
97
+ var extend = function extend() {
98
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
99
+ args[_key] = arguments[_key];
100
+ }
101
+ var target = args.shift();
102
+ return args.filter(function (source) {
103
+ return source;
104
+ }).reduce(function (target, source) {
105
+ return Object.assign(target, source);
106
+ }, target);
107
+ };
108
+ var noop = function noop() {};
109
+ var each = function each(object, callback) {
110
+ var prop;
111
+ for (prop in object) {
112
+ if (hasProp(object, prop)) {
113
+ callback(object[prop], prop, object);
114
+ }
115
+ }
414
116
  };
415
- this.get = function (key) {
416
- return cache.list[key];
117
+ var map = function map(object, callback, context) {
118
+ var result = [];
119
+ each(object, function (value, key, object) {
120
+ var item = callback(value, key, object);
121
+ if (isUndefined(item) === false) {
122
+ result.push(item);
123
+ }
124
+ });
125
+ return result;
417
126
  };
418
- this.set = function (key, value) {
419
- cache.list[key] = value;
420
- return this;
127
+ var filter = function filter(object, callback, context) {
128
+ var isArray = object instanceof Array;
129
+ var result = isArray ? [] : {};
130
+ each(object, function (value, key, object) {
131
+ var item = callback(value, key, object);
132
+ if (isUndefined(item) === false) {
133
+ if (isArray) {
134
+ result.push(item);
135
+ } else {
136
+ result[key] = item;
137
+ }
138
+ }
139
+ });
140
+ return result;
421
141
  };
422
- this.resolve = function (key) {
423
- return Promise.resolve(this.get(key));
142
+ var omit = function omit(object, list) {
143
+ return filter(object, function (value, key) {
144
+ if (list.indexOf(key) === -1) {
145
+ return value;
146
+ }
147
+ });
424
148
  };
425
- this.remove = function (key) {
426
- delete cache.list[key];
149
+ var resolve$1 = function resolve(value, callback, context) {
150
+ return Promise.resolve(value).then(callback.bind(context));
427
151
  };
428
- this.exist = function (key) {
429
- return hasProp(cache.list, key);
152
+ var hasProp = function hasProp(object, prop) {
153
+ return object && object.hasOwnProperty(prop);
430
154
  };
431
- }
432
155
 
433
- function resolve(list) {
434
- return Promise.all(list || []).then(function (list) {
435
- return list.join('');
436
- });
437
- }
438
- var createBuffer = function createBuffer() {
439
- var store = [],
440
- array = [];
441
- function buffer(value) {
442
- array.push(value);
443
- }
444
- buffer.start = function () {
445
- array = [];
446
- };
447
- buffer.backup = function () {
448
- store.push(array.concat());
449
- array = [];
156
+ var defaults = {};
157
+ defaults["export"] = 'ejsPrecompiled';
158
+ defaults.cache = true;
159
+ defaults.chokidar = null;
160
+ defaults.path = 'views';
161
+ defaults.resolver = null;
162
+ defaults.extension = 'ejs';
163
+ defaults.rmWhitespace = true;
164
+ defaults.withObject = true;
165
+ defaults.vars = {
166
+ SCOPE: 'ejs',
167
+ COMPONENT: 'ui',
168
+ EXTEND: '$$e',
169
+ BUFFER: '$$a',
170
+ LAYOUT: '$$l',
171
+ BLOCKS: '$$b',
172
+ MACRO: '$$m',
173
+ SAFE: '$$v'
174
+ };
175
+ defaults.token = {
176
+ start: '<%',
177
+ end: '%>',
178
+ regex: '([\\s\\S]+?)'
450
179
  };
451
- buffer.restore = function () {
452
- var result = array.concat();
453
- array = store.pop();
454
- return resolve(result);
455
- };
456
- buffer.error = function (e) {
457
- throw e;
180
+
181
+ var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
182
+ var space = ' ';
183
+ var quote = '"';
184
+ var equal = '=';
185
+ var slash = '/';
186
+ var lt = '<';
187
+ var gt = '>';
188
+ var element = function element(tag, attrs, content) {
189
+ var result = [];
190
+ var hasClosedTag = selfClosed.indexOf(tag) === -1;
191
+ var attributes = map(attrs, function (value, key) {
192
+ if (value !== null && value !== undefined) {
193
+ return [entities(key), [quote, entities(value), quote].join('')].join(equal);
194
+ }
195
+ }).join(space);
196
+ result.push([lt, tag, space, attributes, gt].join(''));
197
+ if (content) {
198
+ result.push(content instanceof Array ? content.join('') : content);
199
+ }
200
+ if (hasClosedTag) {
201
+ result.push([lt, slash, tag, gt].join(''));
202
+ }
203
+ return result.join('');
458
204
  };
459
- buffer.end = function () {
460
- return resolve(array);
205
+
206
+ var configSchema = function configSchema(config, options) {
207
+ extend(config, {
208
+ path: typeProp(isString, defaults.path, config.path, options.path),
209
+ "export": typeProp(isString, defaults["export"], config["export"], options["export"]),
210
+ resolver: typeProp(isFunction, defaults.resolver, config.resolver, options.resolver),
211
+ extension: typeProp(isString, defaults.extension, config.extension, options.extension),
212
+ withObject: typeProp(isBoolean, defaults.withObject, config.withObject, options.withObject),
213
+ rmWhitespace: typeProp(isBoolean, defaults.rmWhitespace, config.rmWhitespace, options.rmWhitespace),
214
+ cache: typeProp(isBoolean, defaults.cache, config.cache, options.cache),
215
+ token: extend({}, defaults.token, config.token, options.token),
216
+ vars: extend({}, defaults.vars, config.vars, options.vars)
217
+ });
461
218
  };
462
- return buffer;
463
- };
464
219
 
465
- function Context(config) {
466
- if (instanceOf(this, Context) === false) return new Context(config);
467
- this.configure = function (config, methods) {
468
- var _config$vars = config.vars,
469
- BLOCKS = _config$vars.BLOCKS,
470
- MACRO = _config$vars.MACRO,
471
- EXTEND = _config$vars.EXTEND,
472
- LAYOUT = _config$vars.LAYOUT,
473
- BUFFER = _config$vars.BUFFER,
474
- COMPONENT = _config$vars.COMPONENT;
475
- this.create = function (data) {
476
- return new Scope(data);
220
+ var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
221
+ function Cache(config) {
222
+ if (instanceOf(this, Cache) === false) return new Cache();
223
+ var cache = {
224
+ enabled: true,
225
+ list: {}
477
226
  };
478
- this.helpers = function (methods) {
479
- extend(Scope.prototype, methods || {});
227
+ this.configure = function (config) {
228
+ cache.enabled = config.cache;
229
+ if (isNode() === false) {
230
+ this.load(global[config["export"]]);
231
+ }
232
+ };
233
+ this.clear = function () {
234
+ cache.list = {};
235
+ };
236
+ this.load = function (data) {
237
+ if (cache.enabled) {
238
+ extend(cache.list, data || {});
239
+ }
240
+ return this;
241
+ };
242
+ this.get = function (key) {
243
+ if (cache.enabled) {
244
+ return cache.list[key];
245
+ }
246
+ };
247
+ this.set = function (key, value) {
248
+ if (cache.enabled) {
249
+ cache.list[key] = value;
250
+ }
251
+ return this;
252
+ };
253
+ this.resolve = function (key) {
254
+ return Promise.resolve(this.get(key));
255
+ };
256
+ this.remove = function (key) {
257
+ delete cache.list[key];
258
+ };
259
+ this.exist = function (key) {
260
+ return hasProp(cache.list, key);
480
261
  };
481
- function Scope(data) {
482
- this[BLOCKS] = {};
483
- this[MACRO] = {};
484
- extend(this, data || {});
262
+ }
263
+
264
+ var tagList = [{
265
+ symbol: '-',
266
+ format: function format(value) {
267
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
268
+ }
269
+ }, {
270
+ symbol: '=',
271
+ format: function format(value) {
272
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
273
+ }
274
+ }, {
275
+ symbol: '#',
276
+ format: function format(value) {
277
+ return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
485
278
  }
486
- Scope.prototype = extend({}, methods || {});
487
- Scope.method = Scope.define = function (name, value, writable, configurable, enumerable) {
488
- Object.defineProperty(Scope.prototype, name, {
489
- value: value,
490
- writable: writable || false,
491
- configurable: configurable || false,
492
- enumerable: enumerable || false
279
+ }, {
280
+ symbol: '',
281
+ format: function format(value) {
282
+ return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
283
+ }
284
+ }];
285
+ function matchTokens(regex, text, callback) {
286
+ var index = 0;
287
+ text.replace(regex, function () {
288
+ var params = [].slice.call(arguments, 0, -1);
289
+ var offset = params.pop();
290
+ var match = params.shift();
291
+ callback(params, index, offset);
292
+ index = offset + match.length;
293
+ return match;
294
+ });
295
+ }
296
+ function Compiler(config) {
297
+ if (instanceOf(this, Compiler) === false) return new Compiler(config);
298
+ var compiler = {};
299
+ this.configure = function (config) {
300
+ compiler.withObject = config.withObject;
301
+ compiler.rmWhitespace = config.rmWhitespace;
302
+ compiler.token = config.token;
303
+ compiler.vars = config.vars;
304
+ compiler.matches = [];
305
+ compiler.formats = [];
306
+ compiler.slurp = {
307
+ match: '[ \\t]*',
308
+ start: [compiler.token.start, '_'],
309
+ end: ['_', compiler.token.end]
310
+ };
311
+ tagList.forEach(function (item) {
312
+ compiler.matches.push(compiler.token.start.concat(item.symbol).concat(compiler.token.regex).concat(compiler.token.end));
313
+ compiler.formats.push(item.format.bind(compiler.vars));
493
314
  });
315
+ compiler.regex = new RegExp(compiler.matches.join('|').concat('|$'), 'g');
316
+ compiler.slurpStart = new RegExp([compiler.slurp.match, compiler.slurp.start.join('')].join(''), 'gm');
317
+ compiler.slurpEnd = new RegExp([compiler.slurp.end.join(''), compiler.slurp.match].join(''), 'gm');
494
318
  };
495
- Scope.define(BUFFER, createBuffer());
496
- Scope.define(BLOCKS, {}, true);
497
- Scope.define(MACRO, {}, true);
498
- Scope.define(LAYOUT, false, true);
499
- Scope.define(EXTEND, false, true);
500
- Scope.method('getMacro', function () {
501
- return this[MACRO];
502
- });
503
- Scope.method('getBuffer', function () {
504
- return this[BUFFER];
505
- });
506
- Scope.method('getComponent', function () {
507
- var context = this;
508
- if (COMPONENT in context) {
509
- return function () {
510
- return context[COMPONENT].apply(context, arguments);
511
- };
319
+ this.compile = function (content, path) {
320
+ var _compiler$vars = compiler.vars,
321
+ SCOPE = _compiler$vars.SCOPE,
322
+ SAFE = _compiler$vars.SAFE,
323
+ BUFFER = _compiler$vars.BUFFER,
324
+ COMPONENT = _compiler$vars.COMPONENT;
325
+ if (compiler.rmWhitespace) {
326
+ content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
512
327
  }
513
- return function () {
514
- console.log('%s function not defined', COMPONENT);
515
- };
516
- });
517
- Scope.method('getBlocks', function () {
518
- return this[BLOCKS];
519
- });
520
- Scope.method('setExtend', function (value) {
521
- this[EXTEND] = value;
522
- });
523
- Scope.method('getExtend', function () {
524
- return this[EXTEND];
525
- });
526
- Scope.method('setLayout', function (layout) {
527
- this[LAYOUT] = layout;
528
- });
529
- Scope.method('getLayout', function () {
530
- return this[LAYOUT];
531
- });
532
- Scope.method('clone', function (exclude_blocks) {
533
- var filter = [LAYOUT, EXTEND, BUFFER];
534
- if (exclude_blocks === true) {
535
- filter.push(BLOCKS);
328
+ content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
329
+ var source = "".concat(BUFFER, "('");
330
+ matchTokens(compiler.regex, content, function (params, index, offset) {
331
+ source += symbols(content.slice(index, offset));
332
+ params.forEach(function (value, index) {
333
+ if (value) {
334
+ source += compiler.formats[index](value);
335
+ }
336
+ });
337
+ });
338
+ source += "');";
339
+ source = "try{".concat(source, "}catch(e){console.info(e)}");
340
+ if (compiler.withObject) {
341
+ source = "with(".concat(SCOPE, "){").concat(source, "}");
536
342
  }
537
- return omit(this, filter);
538
- });
539
- Scope.method('extend', function (layout) {
540
- this.setExtend(true);
541
- this.setLayout(layout);
542
- });
543
- Scope.method('echo', function () {
544
- var buffer = this.getBuffer();
545
- var params = [].slice.call(arguments);
546
- params.forEach(buffer);
343
+ source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
344
+ source += "\n//# sourceURL=".concat(path);
345
+ var result = null;
346
+ try {
347
+ result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
348
+ result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
349
+ } catch (e) {
350
+ e.filename = path;
351
+ e.source = source;
352
+ throw e;
353
+ }
354
+ return result;
355
+ };
356
+ this.configure(config);
357
+ }
358
+
359
+ var resolvePath = function resolvePath(path, template) {
360
+ template = [path, template].join('/');
361
+ template = template.replace(/\/\//g, '/');
362
+ return template;
363
+ };
364
+ var httpRequest = function httpRequest(path, template) {
365
+ return fetch(resolvePath(path, template)).then(function (response) {
366
+ return response.text();
547
367
  });
548
- Scope.method('fn', function (callback) {
549
- var buffer = this.getBuffer();
550
- var context = this;
551
- return function () {
552
- buffer.backup();
553
- if (isFunction(callback)) {
554
- callback.apply(context, arguments);
368
+ };
369
+ var fileSystem = function fileSystem(path$1, template) {
370
+ return new Promise(function (resolve, reject) {
371
+ path.readFile(resolvePath(path$1, template), function (error, data) {
372
+ if (error) {
373
+ reject(error);
374
+ } else {
375
+ resolve(data.toString());
555
376
  }
556
- return buffer.restore();
557
- };
558
- });
559
- Scope.method('get', function (name, defaults) {
560
- var path = getPath(this, name, true);
561
- var result = path.shift();
562
- var prop = path.pop();
563
- return hasProp(result, prop) ? result[prop] : defaults;
377
+ });
564
378
  });
565
- Scope.method('set', function (name, value) {
566
- var path = getPath(this, name, false);
567
- var result = path.shift();
568
- var prop = path.pop();
569
- if (this.getExtend() && hasProp(result, prop)) {
570
- return result[prop];
379
+ };
380
+ var fileResolver = function fileResolver(resolver) {
381
+ return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
382
+ };
383
+ function Template(config, cache, compiler) {
384
+ if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
385
+ if (instanceOf(cache, Cache) === false) throw new TypeError('cache is not instance of Cache');
386
+ if (instanceOf(compiler, Compiler) === false) throw new TypeError('compiler is not instance of Compiler');
387
+ var template = {};
388
+ var result = function result(template, content) {
389
+ cache.set(template, content);
390
+ return content;
391
+ };
392
+ var resolve = function resolve(path) {
393
+ return template.resolver(template.path, path);
394
+ };
395
+ var compile = function compile(content, template) {
396
+ if (isFunction(content)) {
397
+ return content;
398
+ } else {
399
+ return compiler.compile(content, template);
571
400
  }
572
- return result[prop] = value;
401
+ };
402
+ this.configure = function (config) {
403
+ template.path = config.path;
404
+ template.cache = config.cache;
405
+ template.resolver = fileResolver(config.resolver);
406
+ };
407
+ this.get = function (template) {
408
+ if (cache.exist(template)) {
409
+ return cache.resolve(template);
410
+ }
411
+ return result(template, resolve(template).then(function (content) {
412
+ return result(template, compile(content, template));
413
+ }));
414
+ };
415
+ this.configure(config);
416
+ }
417
+
418
+ function resolve(list) {
419
+ return Promise.all(list || []).then(function (list) {
420
+ return list.join('');
573
421
  });
574
- Scope.method('macro', function (name, callback) {
575
- var list = this.getMacro();
576
- var macro = this.fn(callback);
577
- var context = this;
578
- list[name] = function () {
579
- return context.echo(macro.apply(undefined, arguments));
422
+ }
423
+ var createBuffer = function createBuffer() {
424
+ var store = [],
425
+ array = [];
426
+ function buffer(value) {
427
+ array.push(value);
428
+ }
429
+ buffer.start = function () {
430
+ array = [];
431
+ };
432
+ buffer.backup = function () {
433
+ store.push(array.concat());
434
+ array = [];
435
+ };
436
+ buffer.restore = function () {
437
+ var result = array.concat();
438
+ array = store.pop();
439
+ return resolve(result);
440
+ };
441
+ buffer.error = function (e) {
442
+ throw e;
443
+ };
444
+ buffer.end = function () {
445
+ return resolve(array);
446
+ };
447
+ return buffer;
448
+ };
449
+
450
+ function Context(config) {
451
+ if (instanceOf(this, Context) === false) return new Context(config);
452
+ this.configure = function (config, methods) {
453
+ var _config$vars = config.vars,
454
+ BLOCKS = _config$vars.BLOCKS,
455
+ MACRO = _config$vars.MACRO,
456
+ EXTEND = _config$vars.EXTEND,
457
+ LAYOUT = _config$vars.LAYOUT,
458
+ BUFFER = _config$vars.BUFFER,
459
+ COMPONENT = _config$vars.COMPONENT;
460
+ this.create = function (data) {
461
+ return new Scope(data);
580
462
  };
581
- });
582
- Scope.method('call', function (name) {
583
- var list = this.getMacro();
584
- var macro = list[name];
585
- var params = [].slice.call(arguments, 1);
586
- if (isFunction(macro)) {
587
- return macro.apply(macro, params);
463
+ this.helpers = function (methods) {
464
+ extend(Scope.prototype, methods || {});
465
+ };
466
+ function Scope(data) {
467
+ this[BLOCKS] = {};
468
+ this[MACRO] = {};
469
+ extend(this, data || {});
588
470
  }
589
- });
590
- Scope.method('block', function (name, callback) {
591
- var _this = this;
592
- var blocks = this.getBlocks();
593
- blocks[name] = blocks[name] || [];
594
- blocks[name].push(this.fn(callback));
595
- if (this.getExtend()) return;
596
- var list = Object.assign([], blocks[name]);
597
- var current = function current() {
598
- return list.shift();
471
+ Scope.prototype = extend({}, methods || {});
472
+ Scope.method = Scope.define = function (name, value, writable, configurable, enumerable) {
473
+ Object.defineProperty(Scope.prototype, name, {
474
+ value: value,
475
+ writable: writable || false,
476
+ configurable: configurable || false,
477
+ enumerable: enumerable || false
478
+ });
599
479
  };
600
- var next = function next() {
601
- var parent = current();
602
- if (parent) {
480
+ Scope.define(BUFFER, createBuffer());
481
+ Scope.define(BLOCKS, {}, true);
482
+ Scope.define(MACRO, {}, true);
483
+ Scope.define(LAYOUT, false, true);
484
+ Scope.define(EXTEND, false, true);
485
+ Scope.method('getMacro', function () {
486
+ return this[MACRO];
487
+ });
488
+ Scope.method('getBuffer', function () {
489
+ return this[BUFFER];
490
+ });
491
+ Scope.method('getComponent', function () {
492
+ var context = this;
493
+ if (COMPONENT in context) {
603
494
  return function () {
604
- _this.echo(parent(next()));
495
+ return context[COMPONENT].apply(context, arguments);
605
496
  };
606
- } else {
607
- return noop;
608
497
  }
609
- };
610
- this.echo(current()(next()));
611
- });
612
- Scope.method('include', function (path, data, cx) {
613
- var context = cx === false ? {} : this.clone(true);
614
- var params = extend(context, data || {});
615
- var promise = this.render(path, params);
616
- this.echo(promise);
617
- });
618
- Scope.method('use', function (path, namespace) {
619
- var promise = this.require(path);
620
- this.echo(resolve$1(promise, function (exports) {
498
+ return function () {
499
+ console.log('%s function not defined', COMPONENT);
500
+ };
501
+ });
502
+ Scope.method('getBlocks', function () {
503
+ return this[BLOCKS];
504
+ });
505
+ Scope.method('setExtend', function (value) {
506
+ this[EXTEND] = value;
507
+ });
508
+ Scope.method('getExtend', function () {
509
+ return this[EXTEND];
510
+ });
511
+ Scope.method('setLayout', function (layout) {
512
+ this[LAYOUT] = layout;
513
+ });
514
+ Scope.method('getLayout', function () {
515
+ return this[LAYOUT];
516
+ });
517
+ Scope.method('clone', function (exclude_blocks) {
518
+ var filter = [LAYOUT, EXTEND, BUFFER];
519
+ if (exclude_blocks === true) {
520
+ filter.push(BLOCKS);
521
+ }
522
+ return omit(this, filter);
523
+ });
524
+ Scope.method('extend', function (layout) {
525
+ this.setExtend(true);
526
+ this.setLayout(layout);
527
+ });
528
+ Scope.method('echo', function () {
529
+ var buffer = this.getBuffer();
530
+ var params = [].slice.call(arguments);
531
+ params.forEach(buffer);
532
+ });
533
+ Scope.method('fn', function (callback) {
534
+ var buffer = this.getBuffer();
535
+ var context = this;
536
+ return function () {
537
+ buffer.backup();
538
+ if (isFunction(callback)) {
539
+ callback.apply(context, arguments);
540
+ }
541
+ return buffer.restore();
542
+ };
543
+ });
544
+ Scope.method('get', function (name, defaults) {
545
+ var path = getPath(this, name, true);
546
+ var result = path.shift();
547
+ var prop = path.pop();
548
+ return hasProp(result, prop) ? result[prop] : defaults;
549
+ });
550
+ Scope.method('set', function (name, value) {
551
+ var path = getPath(this, name, false);
552
+ var result = path.shift();
553
+ var prop = path.pop();
554
+ if (this.getExtend() && hasProp(result, prop)) {
555
+ return result[prop];
556
+ }
557
+ return result[prop] = value;
558
+ });
559
+ Scope.method('macro', function (name, callback) {
621
560
  var list = this.getMacro();
622
- each(exports, function (macro, name) {
623
- list[[namespace, name].join('.')] = macro;
624
- });
625
- }, this));
626
- });
627
- Scope.method('async', function (promise, callback) {
628
- this.echo(resolve$1(promise, function (data) {
629
- return this.fn(callback)(data);
630
- }, this));
631
- });
632
- Scope.method('node', function (tag, attr, content) {
633
- return element(tag, attr, content);
634
- });
635
- Scope.method('el', function (tag, attr, content) {
636
- if (isFunction(content)) {
637
- content = this.fn(content)();
638
- }
639
- this.echo(resolve$1(content, function (content) {
561
+ var macro = this.fn(callback);
562
+ var context = this;
563
+ list[name] = function () {
564
+ return context.echo(macro.apply(undefined, arguments));
565
+ };
566
+ });
567
+ Scope.method('call', function (name) {
568
+ var list = this.getMacro();
569
+ var macro = list[name];
570
+ var params = [].slice.call(arguments, 1);
571
+ if (isFunction(macro)) {
572
+ return macro.apply(macro, params);
573
+ }
574
+ });
575
+ Scope.method('block', function (name, callback) {
576
+ var _this = this;
577
+ var blocks = this.getBlocks();
578
+ blocks[name] = blocks[name] || [];
579
+ blocks[name].push(this.fn(callback));
580
+ if (this.getExtend()) return;
581
+ var list = Object.assign([], blocks[name]);
582
+ var current = function current() {
583
+ return list.shift();
584
+ };
585
+ var next = function next() {
586
+ var parent = current();
587
+ if (parent) {
588
+ return function () {
589
+ _this.echo(parent(next()));
590
+ };
591
+ } else {
592
+ return noop;
593
+ }
594
+ };
595
+ this.echo(current()(next()));
596
+ });
597
+ Scope.method('include', function (path, data, cx) {
598
+ var context = cx === false ? {} : this.clone(true);
599
+ var params = extend(context, data || {});
600
+ var promise = this.render(path, params);
601
+ this.echo(promise);
602
+ });
603
+ Scope.method('use', function (path, namespace) {
604
+ var promise = this.require(path);
605
+ this.echo(resolve$1(promise, function (exports) {
606
+ var list = this.getMacro();
607
+ each(exports, function (macro, name) {
608
+ list[[namespace, name].join('.')] = macro;
609
+ });
610
+ }, this));
611
+ });
612
+ Scope.method('async', function (promise, callback) {
613
+ this.echo(resolve$1(promise, function (data) {
614
+ return this.fn(callback)(data);
615
+ }, this));
616
+ });
617
+ Scope.method('node', function (tag, attr, content) {
640
618
  return element(tag, attr, content);
641
- }, this));
642
- });
643
- Scope.method('each', function (object, callback) {
644
- if (isString(object)) {
645
- object = this.get(object, []);
646
- }
647
- each(object, callback);
648
- });
649
- };
650
- this.configure(config);
651
- }
619
+ });
620
+ Scope.method('el', function (tag, attr, content) {
621
+ if (isFunction(content)) {
622
+ content = this.fn(content)();
623
+ }
624
+ this.echo(resolve$1(content, function (content) {
625
+ return element(tag, attr, content);
626
+ }, this));
627
+ });
628
+ Scope.method('each', function (object, callback) {
629
+ if (isString(object)) {
630
+ object = this.get(object, []);
631
+ }
632
+ each(object, callback);
633
+ });
634
+ };
635
+ this.configure(config);
636
+ }
652
637
 
653
- function EJS(options) {
654
- if (instanceOf(this, EJS) === false) return new EJS(options);
655
- var scope = {};
656
- var config = {};
657
- configSchema(config, options || {});
658
- var context = new Context(config);
659
- var compiler = new Compiler(config);
660
- var cache = new Cache();
661
- var template = new Template(config, cache, compiler);
662
- var output = function output(path, scope) {
663
- return template.get(path).then(function (callback) {
664
- return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
665
- });
666
- };
667
- var require = function require(name) {
668
- var filepath = ext(name, config.extension);
669
- var scope = context.create({});
670
- return output(filepath, scope).then(function () {
671
- return scope.getMacro();
672
- });
673
- };
674
- var render = function render(name, data) {
675
- var filepath = ext(name, config.extension);
676
- var scope = context.create(data);
677
- return output(filepath, scope).then(function (content) {
678
- if (scope.getExtend()) {
679
- scope.setExtend(false);
680
- var layout = scope.getLayout();
681
- var _data = scope.clone();
682
- return render(layout, _data);
683
- }
684
- return content;
638
+ function EJS(options) {
639
+ if (instanceOf(this, EJS) === false) return new EJS(options);
640
+ var scope = {};
641
+ var config = {};
642
+ configSchema(config, options || {});
643
+ var context = new Context(config);
644
+ var compiler = new Compiler(config);
645
+ var cache = new Cache();
646
+ var template = new Template(config, cache, compiler);
647
+ var output = function output(path, scope) {
648
+ return template.get(path).then(function (callback) {
649
+ return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
650
+ });
651
+ };
652
+ var require = function require(name) {
653
+ var filepath = ext(name, config.extension);
654
+ var scope = context.create({});
655
+ return output(filepath, scope).then(function () {
656
+ return scope.getMacro();
657
+ });
658
+ };
659
+ var render = function render(name, data) {
660
+ var filepath = ext(name, config.extension);
661
+ var scope = context.create(data);
662
+ return output(filepath, scope).then(function (content) {
663
+ if (scope.getExtend()) {
664
+ scope.setExtend(false);
665
+ var layout = scope.getLayout();
666
+ var _data = scope.clone();
667
+ return render(layout, _data);
668
+ }
669
+ return content;
670
+ });
671
+ };
672
+ this.configure = function (options) {
673
+ options = options || {};
674
+ configSchema(config, options);
675
+ context.configure(config, scope);
676
+ compiler.configure(config);
677
+ cache.configure(config);
678
+ template.configure(config);
679
+ return config;
680
+ };
681
+ this.render = function (name, data) {
682
+ return render(name, data);
683
+ };
684
+ this.helpers = function (methods) {
685
+ context.helpers(Object.assign(scope, methods || {}));
686
+ };
687
+ this.preload = function (list) {
688
+ return cache.load(list || {});
689
+ };
690
+ this.create = function (options) {
691
+ return new EJS(options);
692
+ };
693
+ this.compile = function (content, path) {
694
+ return compiler.compile(content, path);
695
+ };
696
+ this.context = function (data) {
697
+ return context.create(data);
698
+ };
699
+ this.helpers({
700
+ require: require,
701
+ render: render
685
702
  });
686
- };
687
- this.configure = function (options) {
688
- options = options || {};
689
- configSchema(config, options);
690
- context.configure(config, scope);
691
- compiler.configure(config);
692
- cache.configure(config);
693
- template.configure(config);
694
- return config;
695
- };
696
- this.render = function (name, data) {
697
- return render(name, data);
698
- };
699
- this.helpers = function (methods) {
700
- context.helpers(Object.assign(scope, methods || {}));
701
- };
702
- this.preload = function (list) {
703
- return cache.load(list || {});
704
- };
705
- this.create = function (options) {
706
- return new EJS(options);
707
- };
708
- this.compile = function (content, path) {
709
- return compiler.compile(content, path);
710
- };
711
- this.context = function (data) {
712
- return context.create(data);
713
- };
714
- this.helpers({
715
- require: require,
716
- render: render
717
- });
718
- }
703
+ }
719
704
 
720
- var ejs = new EJS();
721
- var render = ejs.render,
722
- context = ejs.context,
723
- compile = ejs.compile,
724
- helpers = ejs.helpers,
725
- preload = ejs.preload,
726
- configure$1 = ejs.configure,
727
- create = ejs.create;
705
+ var ejs = new EJS();
706
+ var render = ejs.render,
707
+ context = ejs.context,
708
+ compile = ejs.compile,
709
+ helpers = ejs.helpers,
710
+ preload = ejs.preload,
711
+ configure = ejs.configure,
712
+ create = ejs.create;
728
713
 
729
- function __express(name, options, callback) {
730
- if (isFunction(options)) {
731
- callback = options;
732
- options = {};
714
+ function __express(name, options, callback) {
715
+ if (isFunction(options)) {
716
+ callback = options;
717
+ options = {};
718
+ }
719
+ options = options || {};
720
+ var settings = extend({}, options.settings);
721
+ var viewPath = typeProp(isString, defaults.path, settings['views']);
722
+ var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
723
+ var viewOptions = extend({}, settings['view options']);
724
+ var filename = path.relative(viewPath, name);
725
+ viewOptions.path = viewPath;
726
+ viewOptions.cache = viewCache;
727
+ configure(viewOptions);
728
+ return render(filename, options).then(function (content) {
729
+ callback(null, content);
730
+ })["catch"](function (error) {
731
+ callback(error);
732
+ });
733
733
  }
734
- options = options || {};
735
- var settings = extend({}, options.settings);
736
- var viewPath = typeProp(isString, defaults.path, settings['views']);
737
- var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
738
- var viewOptions = extend({}, settings['view options']);
739
- var filename = path.relative(viewPath, name);
740
- viewOptions.path = viewPath;
741
- viewOptions.cache = viewCache;
742
- configure(viewOptions);
743
- return this.render(filename, options).then(function (content) {
744
- callback(null, content);
745
- })["catch"](function (error) {
746
- callback(error);
747
- });
748
- }
749
734
 
750
- exports.EJS = EJS;
751
- exports.__express = __express;
752
- exports.compile = compile;
753
- exports.configure = configure$1;
754
- exports.context = context;
755
- exports.create = create;
756
- exports.element = element;
757
- exports.helpers = helpers;
758
- exports.preload = preload;
759
- exports.render = render;
760
- exports.safeValue = safeValue;
735
+ exports.EJS = EJS;
736
+ exports.__express = __express;
737
+ exports.compile = compile;
738
+ exports.configure = configure;
739
+ exports.context = context;
740
+ exports.create = create;
741
+ exports.element = element;
742
+ exports.helpers = helpers;
743
+ exports.preload = preload;
744
+ exports.render = render;
745
+ exports.safeValue = safeValue;
761
746
 
762
747
  }));