@kosatyi/ejs 0.0.13 → 0.0.15

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/ejs.cjs CHANGED
@@ -15,20 +15,15 @@ defaults["export"] = 'ejs.precompiled';
15
15
  defaults.cache = true;
16
16
  defaults.path = 'views';
17
17
  defaults.resolver = null;
18
- defaults.extension = {
19
- template: 'ejs',
20
- module: 'mjs'
21
- };
18
+ defaults.extension = 'ejs';
19
+ defaults.withObject = false;
22
20
  defaults.vars = {
23
- EXTEND: '$$$',
21
+ SCOPE: 'ejs',
22
+ EXTEND: '$$e',
24
23
  BUFFER: '$$a',
25
- OUTPUT: '$$i',
26
24
  LAYOUT: '$$l',
27
- MACROS: '$$m',
28
- PRINT: '$$j',
29
25
  BLOCKS: '$$b',
30
- ERROR: '$$e',
31
- SCOPE: '$$s',
26
+ MACRO: '$$m',
32
27
  SAFE: '$$v'
33
28
  };
34
29
  defaults.token = {
@@ -69,11 +64,9 @@ var htmlEntities = {
69
64
  '"': '"',
70
65
  "'": '''
71
66
  };
72
-
73
67
  var regexKeys = function regexKeys(obj) {
74
68
  return new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
75
69
  };
76
-
77
70
  var htmlEntitiesMatch = regexKeys(htmlEntities);
78
71
  var symbolEntitiesMatch = regexKeys(symbolEntities);
79
72
  var entities = function entities() {
@@ -103,7 +96,6 @@ var extend = function extend() {
103
96
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
104
97
  args[_key] = arguments[_key];
105
98
  }
106
-
107
99
  var target = args.shift();
108
100
  return args.filter(function (source) {
109
101
  return source;
@@ -111,9 +103,9 @@ var extend = function extend() {
111
103
  return Object.assign(target, source);
112
104
  }, target);
113
105
  };
106
+ var noop = function noop() {};
114
107
  var each = function each(object, callback) {
115
108
  var prop;
116
-
117
109
  for (prop in object) {
118
110
  if (hasProp(object, prop)) {
119
111
  callback(object[prop], prop, object);
@@ -124,7 +116,6 @@ var map = function map(object, callback, context) {
124
116
  var result = [];
125
117
  each(object, function (value, key, object) {
126
118
  var item = callback(value, key, object);
127
-
128
119
  if (item !== undefined) {
129
120
  result.push(item);
130
121
  }
@@ -136,7 +127,6 @@ var filter = function filter(object, callback, context) {
136
127
  var result = isArray ? [] : {};
137
128
  each(object, function (value, key, object) {
138
129
  var item = callback(value, key, object);
139
-
140
130
  if (item !== undefined) {
141
131
  if (isArray) {
142
132
  result.push(item);
@@ -154,6 +144,9 @@ var omit = function omit(object, list) {
154
144
  }
155
145
  });
156
146
  };
147
+ var resolve$1 = function resolve(value, callback, context) {
148
+ return Promise.resolve(value).then(callback.bind(context));
149
+ };
157
150
  var hasProp = function hasProp(object, prop) {
158
151
  return object && object.hasOwnProperty(prop);
159
152
  };
@@ -174,15 +167,12 @@ function element(tag, attrs, content) {
174
167
  }
175
168
  }).join(space);
176
169
  result.push([lt, tag, space, attributes, gt].join(''));
177
-
178
170
  if (content) {
179
171
  result.push(content instanceof Array ? content.join('') : content);
180
172
  }
181
-
182
173
  if (hasClosedTag) {
183
174
  result.push([lt, slash, tag, gt].join(''));
184
175
  }
185
-
186
176
  return result.join('');
187
177
  }
188
178
 
@@ -207,7 +197,6 @@ var tags = [{
207
197
  return "')\n".concat(value, "\n").concat(this.BUFFER, "('");
208
198
  }
209
199
  }];
210
-
211
200
  var match = function match(regex, text, callback) {
212
201
  var index = 0;
213
202
  text.replace(regex, function () {
@@ -221,16 +210,14 @@ var match = function match(regex, text, callback) {
221
210
  };
222
211
  /**
223
212
  *
224
- * @param {Object} config
213
+ * @param {object} config
225
214
  * @return {function(*, *): Function}
226
215
  * @constructor
227
216
  */
228
-
229
-
230
217
  var Compiler = function Compiler(config) {
218
+ var withObject = config.withObject;
231
219
  var token = config.token;
232
220
  var vars = config.vars;
233
- var module = config.extension.module;
234
221
  var matches = [];
235
222
  var formats = [];
236
223
  var slurp = {
@@ -246,22 +233,15 @@ var Compiler = function Compiler(config) {
246
233
  var slurpStart = new RegExp([slurp.match, slurp.start].join(''), 'gm');
247
234
  var slurpEnd = new RegExp([slurp.end, slurp.match].join(''), 'gm');
248
235
  /**
249
- * @type Function
236
+ * @type function
250
237
  * @name Compile
251
238
  */
252
-
253
239
  return function (content, path) {
254
240
  var SCOPE = vars.SCOPE,
255
- SAFE = vars.SAFE,
256
- BUFFER = vars.BUFFER;
257
- var extension = path.split('.').pop();
241
+ SAFE = vars.SAFE,
242
+ BUFFER = vars.BUFFER;
258
243
  content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
259
244
  content = content.replace(slurpStart, slurp.start).replace(slurpEnd, slurp.end);
260
-
261
- if (extension === module) {
262
- content = [token.start, content, token.end].join('\n');
263
- }
264
-
265
245
  var source = "".concat(BUFFER, "('");
266
246
  match(regex, content, function (params, index, offset) {
267
247
  source += symbols(content.slice(index, offset));
@@ -270,20 +250,22 @@ var Compiler = function Compiler(config) {
270
250
  });
271
251
  });
272
252
  source += "');";
273
- source = "with(".concat(SCOPE, "){").concat(source, "}");
253
+ source = "try{".concat(source, "}catch(e){console.info(e)}");
254
+ if (withObject) {
255
+ source = "with(".concat(SCOPE, "){").concat(source, "}");
256
+ }
274
257
  source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
275
258
  source += "\n//# sourceURL=".concat(path);
276
259
  var result = null;
277
-
278
260
  try {
279
261
  result = new Function(SCOPE, BUFFER, SAFE, source);
280
- result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})"); //result.source = result.toString()
262
+ result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
281
263
  } catch (e) {
264
+ console.log(e);
282
265
  e.filename = path;
283
266
  e.source = source;
284
267
  throw e;
285
268
  }
286
-
287
269
  return result;
288
270
  };
289
271
  };
@@ -305,7 +287,6 @@ var HttpRequest = function HttpRequest(template) {
305
287
  return response.text();
306
288
  });
307
289
  };
308
-
309
290
  var FileSystem = function FileSystem(template) {
310
291
  return new Promise(function (resolve, reject) {
311
292
  fs__default["default"].readFile(template, function (error, data) {
@@ -317,7 +298,6 @@ var FileSystem = function FileSystem(template) {
317
298
  });
318
299
  });
319
300
  };
320
-
321
301
  var Watcher = function Watcher(path, cache) {
322
302
  return chokidar__default["default"].watch('.', {
323
303
  cwd: path
@@ -327,60 +307,37 @@ var Watcher = function Watcher(path, cache) {
327
307
  console.log('watcher error: ' + error);
328
308
  });
329
309
  };
330
-
331
310
  var Template = function Template(config, cache, compile) {
332
311
  var path = config.path;
333
312
  config.token || {};
334
313
  var resolver = isFunction(config.resolver) ? config.resolver : isNode() ? FileSystem : HttpRequest;
335
-
336
314
  var normalize = function normalize(template) {
337
315
  template = [path, template].join('/');
338
316
  template = template.replace(/\/\//g, '/');
339
317
  return template;
340
318
  };
341
-
342
319
  var resolve = function resolve(template) {
343
320
  return resolver(normalize(template));
344
321
  };
345
-
346
322
  var result = function result(content, template) {
347
323
  cache.set(template, content);
348
324
  return content;
349
325
  };
350
-
351
326
  var get = function get(template) {
352
327
  if (cache.exist(template)) {
353
328
  return cache.resolve(template);
354
329
  }
355
-
356
330
  var content = resolve(template).then(function (content) {
357
331
  return result(compile(content, template), template);
358
332
  });
359
333
  return result(content, template);
360
334
  };
361
-
362
335
  if (config.watch && isNode()) {
363
336
  Watcher(path, cache);
364
337
  }
365
-
366
338
  return get;
367
339
  };
368
340
 
369
- function _defineProperty(obj, key, value) {
370
- if (key in obj) {
371
- Object.defineProperty(obj, key, {
372
- value: value,
373
- enumerable: true,
374
- configurable: true,
375
- writable: true
376
- });
377
- } else {
378
- obj[key] = value;
379
- }
380
-
381
- return obj;
382
- }
383
-
384
341
  var resolve = function resolve(list) {
385
342
  return Promise.all(list).then(function (list) {
386
343
  return list.join('');
@@ -390,408 +347,249 @@ var resolve = function resolve(list) {
390
347
  *
391
348
  * @return {function}
392
349
  */
393
-
394
-
395
350
  var Buffer = function Buffer() {
396
351
  var store = [],
397
- array = [];
398
-
352
+ array = [];
399
353
  function buffer(value) {
400
354
  array.push(value);
401
355
  }
402
-
403
356
  buffer.start = function () {
404
357
  array = [];
405
358
  };
406
-
407
359
  buffer.backup = function () {
408
360
  store.push(array.concat());
409
361
  array = [];
410
362
  };
411
-
412
363
  buffer.restore = function () {
413
364
  var result = array.concat();
414
365
  array = store.pop();
415
366
  return resolve(result);
416
367
  };
417
-
368
+ buffer.error = function (e) {
369
+ throw e;
370
+ };
418
371
  buffer.end = function () {
419
372
  return resolve(array);
420
373
  };
421
-
422
374
  return buffer;
423
375
  };
424
376
 
425
377
  /**
426
- *
427
- * @param {{}} instance
428
- * @method create
378
+ * @memberOf global
379
+ * @class
380
+ * @alias ejs
381
+ * @param config
382
+ * @param methods
383
+ * @return {Scope}
429
384
  */
430
385
 
431
- var Component = function Component(instance) {
432
- var defaults = extend({}, instance.props);
433
- var create = instance.create;
434
- return {
435
- element: element,
436
- create: create,
437
- render: function render(props) {
438
- return this.create(extend({}, defaults, props));
439
- }
440
- };
441
- };
442
-
443
- var Scope = function Scope(config, methods) {
444
- var _Object$definePropert;
445
-
446
- /**
447
- *
448
- */
386
+ var configure = function configure(config, methods) {
449
387
  var _config$vars = config.vars,
450
- EXTEND = _config$vars.EXTEND,
451
- MACROS = _config$vars.MACROS,
452
- LAYOUT = _config$vars.LAYOUT,
453
- BLOCKS = _config$vars.BLOCKS,
454
- BUFFER = _config$vars.BUFFER;
388
+ EXTEND = _config$vars.EXTEND,
389
+ LAYOUT = _config$vars.LAYOUT,
390
+ BLOCKS = _config$vars.BLOCKS,
391
+ BUFFER = _config$vars.BUFFER,
392
+ MACRO = _config$vars.MACRO;
393
+
455
394
  /**
456
395
  *
457
396
  * @param data
458
397
  * @constructor
459
398
  */
460
-
461
399
  function Scope() {
462
400
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
463
- this.setBlocks({});
401
+ this.initBlocks();
402
+ this.initMacro();
464
403
  extend(this, data);
465
- this.setLayout(false);
466
- this.setExtend(false);
467
404
  }
468
- /**
469
- *
470
- */
471
-
472
-
473
- Object.defineProperties(Scope.prototype, (_Object$definePropert = {}, _defineProperty(_Object$definePropert, BUFFER, {
405
+ Scope.helpers = function (methods) {
406
+ extend(Scope.prototype, methods);
407
+ };
408
+ Scope.property = function (name, descriptor) {
409
+ Object.defineProperty(Scope.prototype, name, descriptor);
410
+ };
411
+ Scope.method = function (name, method) {
412
+ Object.defineProperty(Scope.prototype, name, {
413
+ value: method,
414
+ writable: false,
415
+ configurable: false,
416
+ enumerable: false
417
+ });
418
+ };
419
+ Scope.property(BUFFER, {
474
420
  value: Buffer(),
475
421
  writable: false,
476
422
  configurable: false,
477
423
  enumerable: false
478
- }), _defineProperty(_Object$definePropert, "getBuffer", {
479
- value: function value() {
480
- return this[BUFFER];
481
- },
482
- writable: false,
483
- configurable: false
484
- }), _defineProperty(_Object$definePropert, "setBlocks", {
485
- value: function value(_value) {
486
- this[BLOCKS] = _value;
487
- },
488
- writable: false,
489
- configurable: false
490
- }), _defineProperty(_Object$definePropert, "getBlocks", {
491
- value: function value() {
492
- return this[BLOCKS];
493
- },
494
- writable: false,
495
- configurable: false
496
- }), _defineProperty(_Object$definePropert, "setExtend", {
497
- value: function value(_value2) {
498
- this[EXTEND] = _value2;
499
- },
500
- writable: false,
501
- configurable: false
502
- }), _defineProperty(_Object$definePropert, "getExtend", {
503
- value: function value() {
504
- return this[EXTEND];
505
- },
506
- writable: false,
507
- configurable: false
508
- }), _defineProperty(_Object$definePropert, "setLayout", {
509
- value: function value(layout) {
510
- this[LAYOUT] = layout;
511
- },
512
- writable: false,
513
- configurable: false
514
- }), _defineProperty(_Object$definePropert, "getLayout", {
515
- value: function value() {
516
- return this[LAYOUT];
517
- },
518
- writable: false,
519
- configurable: false
520
- }), _Object$definePropert));
521
-
522
- Scope.helpers = function (methods) {
523
- extend(Scope.prototype, methods);
524
- };
525
- /**
526
- * @lends Scope.prototype
527
- */
528
-
529
-
530
- Scope.helpers(methods);
531
- /**
532
- * @lends Scope.prototype
533
- */
534
-
535
- Scope.helpers({
536
- /**
537
- * @return {*}
538
- */
539
- clone: function clone(exclude_blocks) {
540
- var filter = [LAYOUT, EXTEND, MACROS, BUFFER];
541
-
542
- if (exclude_blocks === true) {
543
- filter.push(BLOCKS);
424
+ });
425
+ Scope.property(BLOCKS, {
426
+ value: {},
427
+ writable: true,
428
+ configurable: false,
429
+ enumerable: false
430
+ });
431
+ Scope.property(MACRO, {
432
+ value: {},
433
+ writable: true,
434
+ configurable: false,
435
+ enumerable: false
436
+ });
437
+ Scope.property(LAYOUT, {
438
+ value: false,
439
+ writable: true,
440
+ configurable: false,
441
+ enumerable: false
442
+ });
443
+ Scope.property(EXTEND, {
444
+ value: false,
445
+ writable: true,
446
+ configurable: false,
447
+ enumerable: false
448
+ });
449
+ Scope.method('initBlocks', function () {
450
+ this[BLOCKS] = {};
451
+ });
452
+ Scope.method('initMacro', function () {
453
+ this[MACRO] = {};
454
+ });
455
+ Scope.method('getMacro', function () {
456
+ return this[MACRO];
457
+ });
458
+ Scope.method('getBuffer', function () {
459
+ return this[BUFFER];
460
+ });
461
+ Scope.method('getBlocks', function () {
462
+ return this[BLOCKS];
463
+ });
464
+ Scope.method('setExtend', function (value) {
465
+ this[EXTEND] = value;
466
+ });
467
+ Scope.method('getExtend', function () {
468
+ return this[EXTEND];
469
+ });
470
+ Scope.method('setLayout', function (layout) {
471
+ this[LAYOUT] = layout;
472
+ });
473
+ Scope.method('getLayout', function () {
474
+ return this[LAYOUT];
475
+ });
476
+ Scope.method('clone', function (exclude_blocks) {
477
+ var filter = [LAYOUT, EXTEND, BUFFER];
478
+ if (exclude_blocks === true) {
479
+ filter.push(BLOCKS);
480
+ }
481
+ return omit(this, filter);
482
+ });
483
+ Scope.method('extend', function (layout) {
484
+ this.setExtend(true);
485
+ this.setLayout(layout);
486
+ });
487
+ Scope.method('echo', function () {
488
+ var buffer = this.getBuffer();
489
+ var params = [].slice.call(arguments);
490
+ params.forEach(function (item) {
491
+ buffer(item);
492
+ });
493
+ });
494
+ Scope.method('fn', function (callback) {
495
+ var buffer = this.getBuffer();
496
+ var context = this;
497
+ return function () {
498
+ buffer.backup();
499
+ if (isFunction(callback)) {
500
+ callback.apply(context, arguments);
544
501
  }
545
-
546
- return omit(this, filter);
547
- },
548
-
549
- /**
550
- * Join values to output buffer
551
- * @memberOf global
552
- * @type Function
553
- */
554
- echo: function echo() {
555
- var buffer = this.getBuffer();
556
- var params = [].slice.call(arguments);
557
- params.forEach(function (item) {
558
- buffer(item);
502
+ return buffer.restore();
503
+ };
504
+ });
505
+ Scope.method('get', function (name, defaults) {
506
+ var path = getPath(this, name);
507
+ var result = path.shift();
508
+ var prop = path.pop();
509
+ return hasProp(result, prop) ? result[prop] : defaults;
510
+ });
511
+ Scope.method('set', function (name, value) {
512
+ var path = getPath(this, name);
513
+ var result = path.shift();
514
+ var prop = path.pop();
515
+ if (this.getExtend() && hasProp(result, prop)) {
516
+ return result[prop];
517
+ }
518
+ return result[prop] = value;
519
+ });
520
+ Scope.method('macro', function (name, callback) {
521
+ var list = this.getMacro();
522
+ var macro = this.fn(callback);
523
+ var context = this;
524
+ list[name] = function () {
525
+ return context.echo(macro.apply(undefined, arguments));
526
+ };
527
+ });
528
+ Scope.method('call', function (name) {
529
+ var list = this.getMacro();
530
+ var macro = list[name];
531
+ var params = [].slice.call(arguments, 1);
532
+ if (isFunction(macro)) {
533
+ return macro.apply(macro, params);
534
+ }
535
+ });
536
+ Scope.method('block', function (name, callback) {
537
+ var _this = this;
538
+ var blocks = this.getBlocks();
539
+ blocks[name] = blocks[name] || [];
540
+ blocks[name].push(this.fn(callback));
541
+ if (this.getExtend()) return;
542
+ var list = Object.assign([], blocks[name]);
543
+ var current = function current() {
544
+ return list.shift();
545
+ };
546
+ var next = function next() {
547
+ var parent = current();
548
+ if (parent) {
549
+ return function () {
550
+ _this.echo(parent(next()));
551
+ };
552
+ } else {
553
+ return noop;
554
+ }
555
+ };
556
+ this.echo(current()(next()));
557
+ });
558
+ Scope.method('include', function (path, data, cx) {
559
+ var context = cx === false ? {} : this.clone(true);
560
+ var params = extend(context, data || {});
561
+ var promise = this.render(path, params);
562
+ this.echo(promise);
563
+ });
564
+ Scope.method('use', function (path, namespace) {
565
+ var promise = this.require(path);
566
+ this.echo(resolve$1(promise, function (exports) {
567
+ var list = this.getMacro();
568
+ each(exports, function (macro, name) {
569
+ list[[namespace, name].join('.')] = macro;
559
570
  });
560
- },
561
-
562
- /**
563
- * Buffered output callback
564
- * @type Function
565
- * @param {Function} callback
566
- * @param {Boolean} [echo]
567
- * @return {Function}
568
- */
569
- macro: function macro(callback, echo) {
570
- var buffer = this.getBuffer();
571
-
572
- var macro = function () {
573
- buffer.backup();
574
-
575
- if (isFunction(callback)) {
576
- callback.apply(this, arguments);
577
- }
578
-
579
- var result = buffer.restore();
580
- return echo === true ? this.echo(result) : result;
581
- }.bind(this);
582
-
583
- macro.__context = this;
584
- macro.__source = callback;
585
- macro.__layout = this.getLayout();
586
- return macro;
587
- },
588
-
589
- /**
590
- * @memberOf global
591
- * @param value
592
- * @param callback
593
- * @return {Promise<unknown>}
594
- */
595
- resolve: function resolve(value, callback) {
596
- return Promise.resolve(value).then(callback.bind(this));
597
- },
598
-
599
- /**
600
- * @memberOf global
601
- */
602
- async: function async(promise, callback) {
603
- var _this = this;
604
-
605
- this.echo(this.resolve(promise, function (data) {
606
- return _this.macro(callback)(data);
607
- }));
608
- },
609
-
610
- /**
611
- * @memberOf global
612
- */
613
- node: element,
614
-
615
- /**
616
- * @memberOf global
617
- */
618
- element: function element$1(tag, attr, content) {
571
+ }, this));
572
+ });
573
+ Scope.method('async', function (promise, callback) {
574
+ this.echo(resolve$1(promise, function (data) {
575
+ return this.fn(callback)(data);
576
+ }, this));
577
+ });
578
+ Scope.helpers(methods);
579
+ Scope.helpers({
580
+ el: function el(tag, attr, content) {
619
581
  if (isFunction(content)) {
620
- content = this.macro(content)();
582
+ content = this.fn(content)();
621
583
  }
622
-
623
- this.echo(this.resolve(content, function (content) {
584
+ this.echo(resolve$1(content, function (content) {
624
585
  return element(tag, attr, content);
625
- }));
626
- },
627
-
628
- /**
629
- * @memberOf global
630
- * @param {String} namespace
631
- * @param {Object} instance
632
- */
633
- component: function component(namespace, instance) {
634
- instance = Component(instance);
635
- this.set(namespace, function (props) {
636
- this.echo(instance.render(props));
637
- }.bind(this));
638
- },
639
-
640
- /**
641
- * @memberOf global
642
- * @param name
643
- * @param defaults
644
- */
645
- get: function get(name, defaults) {
646
- var path = getPath(this, name);
647
- var result = path.shift();
648
- var prop = path.pop();
649
- return hasProp(result, prop) ? result[prop] : defaults;
650
- },
651
-
652
- /**
653
- * @memberOf global
654
- * @param {String} name
655
- * @param value
656
- * @return
657
- */
658
- set: function set(name, value) {
659
- var path = getPath(this, name);
660
- var result = path.shift();
661
- var prop = path.pop();
662
-
663
- if (this.getExtend()) {
664
- if (hasProp(result, prop)) {
665
- return result[prop];
666
- }
667
- }
668
-
669
- result[prop] = value;
670
- },
671
-
672
- /**
673
- * @memberOf global
674
- * @param name
675
- */
676
- call: function call(name) {
677
- var params = [].slice.call(arguments, 1);
678
- var path = getPath(this, name);
679
- var result = path.shift();
680
- var prop = path.pop();
681
-
682
- if (isFunction(result[prop])) {
683
- return result[prop].apply(result, params);
684
- }
586
+ }, this));
685
587
  },
686
-
687
- /**
688
- * @memberOf global
689
- * @param object
690
- * @param callback
691
- */
692
588
  each: function each$1(object, callback) {
693
589
  if (isString(object)) {
694
590
  object = this.get(object, []);
695
591
  }
696
-
697
592
  each(object, callback);
698
- },
699
-
700
- /**
701
- * @memberOf global
702
- * @param {String} layout
703
- */
704
- extend: function extend(layout) {
705
- this.setExtend(true);
706
- this.setLayout(layout);
707
- },
708
-
709
- /**
710
- * @memberOf global
711
- * @param name
712
- * @param callback
713
- * @return {*}
714
- */
715
- block: function block(name, callback) {
716
- var blocks = this.getBlocks();
717
- blocks[name] = blocks[name] || [];
718
- blocks[name].push(this.macro(callback));
719
- if (this.getExtend()) return;
720
-
721
- var current = function current() {
722
- return blocks[name].shift();
723
- };
724
-
725
- var next = function next() {
726
- var parent = current();
727
-
728
- if (parent) {
729
- var context = parent.__context;
730
- return function () {
731
- context.echo(parent(next()));
732
- };
733
- } else {
734
- return function () {};
735
- }
736
- };
737
-
738
- this.echo(current()(next()));
739
- },
740
-
741
- /**
742
- * @memberOf global
743
- * @param {string} path
744
- * @param {object} [data]
745
- * @param {boolean} [cx]
746
- */
747
- include: function include(path, data, cx) {
748
- var context = cx === false ? {} : this.clone(true);
749
- var params = extend(context, data || {});
750
- var promise = this.render(path, params);
751
- this.echo(promise);
752
- },
753
-
754
- /**
755
- * @memberOf global
756
- * @param {string} path
757
- */
758
- use: function use(path) {
759
- var scope = this;
760
-
761
- var promise = this.require(path);
762
-
763
- this.echo(promise);
764
- return {
765
- as: function as(namespace) {
766
- promise.then(function (exports) {
767
- scope.set(namespace, exports);
768
- });
769
- return this;
770
- }
771
- };
772
- },
773
-
774
- /**
775
- * @memberOf global
776
- * @param {string} path
777
- */
778
- from: function from(path) {
779
- var scope = this;
780
-
781
- var promise = this.require(path);
782
-
783
- this.echo(promise);
784
- return {
785
- use: function use() {
786
- var params = [].slice.call(arguments);
787
- promise.then(function (exports) {
788
- params.forEach(function (name) {
789
- scope.set(name, exports[name]);
790
- });
791
- });
792
- return this;
793
- }
794
- };
795
593
  }
796
594
  });
797
595
  return Scope;
@@ -805,7 +603,6 @@ function Cache(config) {
805
603
  if (isNode() === false) {
806
604
  this.load(window[namespace]);
807
605
  }
808
-
809
606
  return this;
810
607
  },
811
608
  exist: function exist(key) {
@@ -838,17 +635,13 @@ function init(options) {
838
635
  */
839
636
  var config = {};
840
637
  var _helpers = {};
841
-
842
638
  var ext = function ext(path, defaults) {
843
639
  var ext = path.split('.').pop();
844
-
845
640
  if (ext !== defaults) {
846
641
  path = [path, defaults].join('.');
847
642
  }
848
-
849
643
  return path;
850
644
  };
851
-
852
645
  var view = {
853
646
  element: element,
854
647
  output: function output(path, scope) {
@@ -857,26 +650,23 @@ function init(options) {
857
650
  });
858
651
  },
859
652
  render: function render(name, data) {
860
- var filepath = ext(name, config.extension.template);
653
+ var filepath = ext(name, config.extension);
861
654
  var scope = new view.scope(data);
862
655
  return view.output(filepath, scope).then(function (content) {
863
656
  if (scope.getExtend()) {
864
657
  scope.setExtend(false);
865
658
  var layout = scope.getLayout();
866
-
867
659
  var _data = scope.clone();
868
-
869
660
  return view.render(layout, _data);
870
661
  }
871
-
872
662
  return content;
873
663
  });
874
664
  },
875
665
  require: function require(name) {
876
- var filepath = ext(name, config.extension.module);
666
+ var filepath = ext(name, config.extension);
877
667
  var scope = new view.scope({});
878
668
  return view.output(filepath, scope).then(function () {
879
- return scope.clone(true);
669
+ return scope.getMacro();
880
670
  });
881
671
  },
882
672
  helpers: function helpers(methods) {
@@ -884,14 +674,14 @@ function init(options) {
884
674
  extend(_helpers, methods);
885
675
  view.scope.helpers(methods);
886
676
  },
887
- configure: function configure(options) {
677
+ configure: function configure$1(options) {
888
678
  config["export"] = typeProp(isString, defaults["export"], options["export"]);
889
679
  config.path = typeProp(isString, defaults.path, options.path);
890
680
  config.resolver = typeProp(isFunction, defaults.resolver, options.resolver);
891
- config.extension = extend({}, defaults.extension, options.extension);
681
+ config.extension = typeProp(isString, defaults.extension, options.extension);
892
682
  config.token = extend({}, defaults.token, options.token);
893
683
  config.vars = extend({}, defaults.vars, options.vars);
894
- view.scope = Scope(config, _helpers);
684
+ view.scope = configure(config, _helpers);
895
685
  view.compile = Compiler(config);
896
686
  view.wrapper = Wrapper(config);
897
687
  view.cache = Cache(config);
@@ -903,7 +693,6 @@ function init(options) {
903
693
  callback = options;
904
694
  options = {};
905
695
  }
906
-
907
696
  options = options || {};
908
697
  var settings = extend({}, options.settings);
909
698
  var viewPath = typeProp(isString, settings['views'], defaults.path);
@@ -923,12 +712,10 @@ function init(options) {
923
712
  /**
924
713
  *
925
714
  */
926
-
927
715
  view.configure(options || {});
928
716
  /**
929
717
  *
930
718
  */
931
-
932
719
  view.helpers({
933
720
  require: function require(name) {
934
721
  return view.require(name, this);
@@ -939,7 +726,6 @@ function init(options) {
939
726
  });
940
727
  return view;
941
728
  }
942
-
943
729
  var index = init();
944
730
 
945
731
  module.exports = index;