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