@kosatyi/ejs 0.0.13 → 0.0.14

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