@kosatyi/ejs 0.0.68 → 0.0.70

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