@kosatyi/ejs 0.0.12 → 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/build.js +33 -0
- package/dist/ejs.cjs +326 -412
- package/dist/ejs.js +326 -412
- package/dist/ejs.min.js +1 -1
- package/dist/ejs.mjs +322 -334
- package/package.json +5 -3
package/dist/ejs.mjs
CHANGED
|
@@ -12,19 +12,15 @@ defaults.path = 'views';
|
|
|
12
12
|
|
|
13
13
|
defaults.resolver = null;
|
|
14
14
|
|
|
15
|
-
defaults.extension =
|
|
16
|
-
template: 'ejs',
|
|
17
|
-
module: 'mjs',
|
|
18
|
-
};
|
|
15
|
+
defaults.extension = 'ejs';
|
|
19
16
|
|
|
20
17
|
defaults.vars = {
|
|
21
18
|
EXTEND: '$$$',
|
|
22
19
|
BUFFER: '$$a',
|
|
23
20
|
OUTPUT: '$$i',
|
|
24
21
|
LAYOUT: '$$l',
|
|
25
|
-
MACROS: '$$m',
|
|
26
|
-
PRINT: '$$j',
|
|
27
22
|
BLOCKS: '$$b',
|
|
23
|
+
MACRO: '$$m',
|
|
28
24
|
ERROR: '$$e',
|
|
29
25
|
SCOPE: '$$s',
|
|
30
26
|
SAFE: '$$v',
|
|
@@ -41,7 +37,6 @@ const typeProp = function () {
|
|
|
41
37
|
const callback = args.shift();
|
|
42
38
|
return args.filter(callback).pop()
|
|
43
39
|
};
|
|
44
|
-
|
|
45
40
|
const isFunction = (v) => typeof v === 'function';
|
|
46
41
|
const isString = (v) => typeof v === 'string';
|
|
47
42
|
const isBoolean = (v) => typeof v === 'boolean';
|
|
@@ -112,6 +107,8 @@ const extend = (...args) => {
|
|
|
112
107
|
}, target)
|
|
113
108
|
};
|
|
114
109
|
|
|
110
|
+
const noop = () => {};
|
|
111
|
+
|
|
115
112
|
const each = (object, callback) => {
|
|
116
113
|
let prop;
|
|
117
114
|
for (prop in object) {
|
|
@@ -160,6 +157,9 @@ const omit = (object, list) => {
|
|
|
160
157
|
})
|
|
161
158
|
};
|
|
162
159
|
|
|
160
|
+
const resolve$1 = (value,callback,context) =>
|
|
161
|
+
Promise.resolve(value).then(callback.bind(context));
|
|
162
|
+
|
|
163
163
|
const hasProp = (object, prop) => {
|
|
164
164
|
return object && object.hasOwnProperty(prop)
|
|
165
165
|
};
|
|
@@ -249,14 +249,13 @@ const match = (regex, text, callback) => {
|
|
|
249
249
|
};
|
|
250
250
|
/**
|
|
251
251
|
*
|
|
252
|
-
* @param {
|
|
252
|
+
* @param {object} config
|
|
253
253
|
* @return {function(*, *): Function}
|
|
254
254
|
* @constructor
|
|
255
255
|
*/
|
|
256
256
|
const Compiler = (config) => {
|
|
257
257
|
const token = config.token;
|
|
258
258
|
const vars = config.vars;
|
|
259
|
-
const module = config.extension.module;
|
|
260
259
|
const matches = [];
|
|
261
260
|
const formats = [];
|
|
262
261
|
const slurp = {
|
|
@@ -277,19 +276,15 @@ const Compiler = (config) => {
|
|
|
277
276
|
const slurpStart = new RegExp([slurp.match, slurp.start].join(''), 'gm');
|
|
278
277
|
const slurpEnd = new RegExp([slurp.end, slurp.match].join(''), 'gm');
|
|
279
278
|
/**
|
|
280
|
-
* @type
|
|
279
|
+
* @type function
|
|
281
280
|
* @name Compile
|
|
282
281
|
*/
|
|
283
282
|
return function (content, path) {
|
|
284
283
|
const { SCOPE, SAFE, BUFFER } = vars;
|
|
285
|
-
const extension = path.split('.').pop();
|
|
286
284
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
287
285
|
content = content
|
|
288
286
|
.replace(slurpStart, slurp.start)
|
|
289
287
|
.replace(slurpEnd, slurp.end);
|
|
290
|
-
if (extension === module) {
|
|
291
|
-
content = [token.start, content, token.end].join('\n');
|
|
292
|
-
}
|
|
293
288
|
let source = `${BUFFER}('`;
|
|
294
289
|
match(regex, content, (params, index, offset) => {
|
|
295
290
|
source += symbols(content.slice(index, offset));
|
|
@@ -298,6 +293,7 @@ const Compiler = (config) => {
|
|
|
298
293
|
});
|
|
299
294
|
});
|
|
300
295
|
source += `');`;
|
|
296
|
+
source = `try{${source}}catch(e){console.info(e)}`;
|
|
301
297
|
source = `with(${SCOPE}){${source}}`;
|
|
302
298
|
source = `${BUFFER}.start();${source}return ${BUFFER}.end();`;
|
|
303
299
|
source += `\n//# sourceURL=${path}`;
|
|
@@ -307,6 +303,7 @@ const Compiler = (config) => {
|
|
|
307
303
|
result.source = `(function(${SCOPE},${BUFFER},${SAFE}){\n${source}\n})`;
|
|
308
304
|
//result.source = result.toString()
|
|
309
305
|
} catch (e) {
|
|
306
|
+
console.log(e);
|
|
310
307
|
e.filename = path;
|
|
311
308
|
e.source = source;
|
|
312
309
|
throw e
|
|
@@ -417,275 +414,345 @@ const Buffer = () => {
|
|
|
417
414
|
array = store.pop();
|
|
418
415
|
return resolve(result)
|
|
419
416
|
};
|
|
417
|
+
buffer.error = function(e){
|
|
418
|
+
throw e
|
|
419
|
+
};
|
|
420
420
|
buffer.end = function () {
|
|
421
421
|
return resolve(array)
|
|
422
422
|
};
|
|
423
423
|
return buffer
|
|
424
424
|
};
|
|
425
425
|
|
|
426
|
-
|
|
427
|
-
*
|
|
428
|
-
* @param {{}} instance
|
|
429
|
-
* @method create
|
|
430
|
-
*/
|
|
431
|
-
const Component = (instance) => {
|
|
432
|
-
const defaults = extend({}, instance.props);
|
|
433
|
-
const create = instance.create;
|
|
434
|
-
return {
|
|
435
|
-
element,
|
|
436
|
-
create,
|
|
437
|
-
render(props) {
|
|
438
|
-
return this.create(extend({}, defaults, props))
|
|
439
|
-
},
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const Scope = (config, methods) => {
|
|
426
|
+
const configure = (config, methods) => {
|
|
444
427
|
/**
|
|
445
428
|
*
|
|
446
429
|
*/
|
|
447
|
-
const { EXTEND,
|
|
448
|
-
|
|
430
|
+
const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO, SCOPE } = config.vars;
|
|
449
431
|
/**
|
|
450
|
-
*
|
|
432
|
+
* @memberOf global
|
|
433
|
+
* @name [SCOPE]
|
|
451
434
|
* @param data
|
|
452
435
|
* @constructor
|
|
453
436
|
*/
|
|
454
437
|
function Scope(data = {}) {
|
|
455
|
-
this.
|
|
438
|
+
this.initBlocks();
|
|
439
|
+
this.initMacro();
|
|
456
440
|
extend(this, data);
|
|
457
|
-
this.setLayout(false);
|
|
458
|
-
this.setExtend(false);
|
|
459
441
|
}
|
|
460
442
|
/**
|
|
461
|
-
*
|
|
443
|
+
* @static
|
|
444
|
+
* @param methods
|
|
445
|
+
*/
|
|
446
|
+
Scope.helpers = (methods) => {
|
|
447
|
+
extend(Scope.prototype, methods);
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* @static
|
|
451
|
+
* @param name
|
|
452
|
+
* @param descriptor
|
|
453
|
+
*/
|
|
454
|
+
Scope.property = (name, descriptor) => {
|
|
455
|
+
Object.defineProperty(Scope.prototype, name, descriptor);
|
|
456
|
+
};
|
|
457
|
+
/**
|
|
458
|
+
* @static
|
|
459
|
+
* @param name
|
|
460
|
+
* @param method
|
|
462
461
|
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
value:
|
|
462
|
+
Scope.method = (name, method) => {
|
|
463
|
+
return Scope.property(name,{
|
|
464
|
+
value: method,
|
|
466
465
|
writable: false,
|
|
467
466
|
configurable: false,
|
|
468
467
|
enumerable: false
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
468
|
+
})
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
*
|
|
472
|
+
*/
|
|
473
|
+
Scope.property(BUFFER, {
|
|
474
|
+
value: Buffer(),
|
|
475
|
+
writable: false,
|
|
476
|
+
configurable: false,
|
|
477
|
+
enumerable: false
|
|
478
|
+
});
|
|
479
|
+
/**
|
|
480
|
+
*
|
|
481
|
+
*/
|
|
482
|
+
Scope.property(BLOCKS, {
|
|
483
|
+
value: {},
|
|
484
|
+
writable: true,
|
|
485
|
+
configurable: false,
|
|
486
|
+
enumerable: false
|
|
487
|
+
});
|
|
488
|
+
/**
|
|
489
|
+
*
|
|
490
|
+
*/
|
|
491
|
+
Scope.property(MACRO, {
|
|
492
|
+
value: {},
|
|
493
|
+
writable: true,
|
|
494
|
+
configurable: false,
|
|
495
|
+
enumerable: false
|
|
496
|
+
});
|
|
497
|
+
/**
|
|
498
|
+
*
|
|
499
|
+
*/
|
|
500
|
+
Scope.property(LAYOUT, {
|
|
501
|
+
value: false,
|
|
502
|
+
writable: true,
|
|
503
|
+
configurable: false,
|
|
504
|
+
enumerable: false
|
|
505
|
+
});
|
|
506
|
+
/**
|
|
507
|
+
*
|
|
508
|
+
*/
|
|
509
|
+
Scope.property(EXTEND, {
|
|
510
|
+
value: false,
|
|
511
|
+
writable: true,
|
|
512
|
+
configurable: false,
|
|
513
|
+
enumerable: false
|
|
514
|
+
});
|
|
515
|
+
/**
|
|
516
|
+
*
|
|
517
|
+
*/
|
|
518
|
+
Scope.method('initBlocks', function() {
|
|
519
|
+
this[BLOCKS] = {};
|
|
520
|
+
});
|
|
521
|
+
/**
|
|
522
|
+
*
|
|
523
|
+
*/
|
|
524
|
+
Scope.method('initMacro', function() {
|
|
525
|
+
this[MACRO] = {};
|
|
526
|
+
});
|
|
527
|
+
/**
|
|
528
|
+
*
|
|
529
|
+
*/
|
|
530
|
+
Scope.method('getMacro', function() {
|
|
531
|
+
return this[MACRO]
|
|
532
|
+
});
|
|
533
|
+
/**
|
|
534
|
+
*
|
|
535
|
+
*/
|
|
536
|
+
Scope.method('getBuffer', function() {
|
|
537
|
+
return this[BUFFER]
|
|
538
|
+
});
|
|
539
|
+
/**
|
|
540
|
+
*
|
|
541
|
+
*/
|
|
542
|
+
Scope.method('getBlocks', function() {
|
|
543
|
+
return this[BLOCKS]
|
|
544
|
+
});
|
|
545
|
+
/**
|
|
546
|
+
*
|
|
547
|
+
*/
|
|
548
|
+
Scope.method('setExtend', function(value) {
|
|
549
|
+
this[EXTEND] = value;
|
|
550
|
+
});
|
|
551
|
+
/**
|
|
552
|
+
*
|
|
553
|
+
*/
|
|
554
|
+
Scope.method('getExtend', function() {
|
|
555
|
+
return this[EXTEND]
|
|
556
|
+
});
|
|
557
|
+
/**
|
|
558
|
+
*
|
|
559
|
+
*/
|
|
560
|
+
Scope.method('setLayout', function(layout) {
|
|
561
|
+
this[LAYOUT] = layout;
|
|
562
|
+
});
|
|
563
|
+
/**
|
|
564
|
+
*
|
|
565
|
+
*/
|
|
566
|
+
Scope.method('getLayout', function() {
|
|
567
|
+
return this[LAYOUT]
|
|
568
|
+
});
|
|
569
|
+
/**
|
|
570
|
+
*
|
|
571
|
+
*/
|
|
572
|
+
Scope.method('clone', function(exclude_blocks) {
|
|
573
|
+
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
574
|
+
if (exclude_blocks === true) {
|
|
575
|
+
filter.push(BLOCKS);
|
|
543
576
|
}
|
|
577
|
+
return omit(this, filter)
|
|
544
578
|
});
|
|
545
|
-
|
|
546
|
-
Scope.helpers = (methods) => {
|
|
547
|
-
extend(Scope.prototype, methods);
|
|
548
|
-
};
|
|
549
|
-
|
|
550
579
|
/**
|
|
551
|
-
* @
|
|
580
|
+
* @methodOf global
|
|
581
|
+
* @function extend
|
|
582
|
+
* @param layout
|
|
552
583
|
*/
|
|
553
|
-
Scope.
|
|
584
|
+
Scope.method('extend', function(layout) {
|
|
585
|
+
this.setExtend(true);
|
|
586
|
+
this.setLayout(layout);
|
|
587
|
+
});
|
|
554
588
|
/**
|
|
555
|
-
* @
|
|
589
|
+
* @memberOf global
|
|
590
|
+
* @function echo
|
|
556
591
|
*/
|
|
557
|
-
Scope.
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
592
|
+
Scope.method('echo', function() {
|
|
593
|
+
const buffer = this.getBuffer();
|
|
594
|
+
const params = [].slice.call(arguments);
|
|
595
|
+
params.forEach(function(item) {
|
|
596
|
+
buffer(item);
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
/**
|
|
600
|
+
* @memberOf global
|
|
601
|
+
* @function fn
|
|
602
|
+
* @param callback
|
|
603
|
+
*/
|
|
604
|
+
Scope.method('fn', function(callback) {
|
|
605
|
+
const buffer = this.getBuffer();
|
|
606
|
+
const context = this;
|
|
607
|
+
return function() {
|
|
608
|
+
buffer.backup();
|
|
609
|
+
if (isFunction(callback)) {
|
|
610
|
+
callback.apply(context, arguments);
|
|
565
611
|
}
|
|
566
|
-
return
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
612
|
+
return buffer.restore()
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
/**
|
|
616
|
+
* @memberOf global
|
|
617
|
+
* @function get
|
|
618
|
+
* @param name
|
|
619
|
+
* @param [defaults]
|
|
620
|
+
*/
|
|
621
|
+
Scope.method('get', function(name,defaults) {
|
|
622
|
+
const path = getPath(this, name);
|
|
623
|
+
const result = path.shift();
|
|
624
|
+
const prop = path.pop();
|
|
625
|
+
return hasProp(result, prop) ? result[prop] : defaults
|
|
626
|
+
});
|
|
627
|
+
/**
|
|
628
|
+
* @memberOf global
|
|
629
|
+
* @function set
|
|
630
|
+
* @param name
|
|
631
|
+
* @param value
|
|
632
|
+
*/
|
|
633
|
+
Scope.method('set', function(name,value) {
|
|
634
|
+
const path = getPath(this, name);
|
|
635
|
+
const result = path.shift();
|
|
636
|
+
const prop = path.pop();
|
|
637
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
638
|
+
return result[prop]
|
|
639
|
+
}
|
|
640
|
+
return result[prop] = value
|
|
641
|
+
});
|
|
642
|
+
/**
|
|
643
|
+
* @memberOf global
|
|
644
|
+
* @function macro
|
|
645
|
+
* @param name
|
|
646
|
+
* @param callback
|
|
647
|
+
*/
|
|
648
|
+
Scope.method('macro', function(name, callback) {
|
|
649
|
+
const list = this.getMacro();
|
|
650
|
+
const macro = this.fn(callback);
|
|
651
|
+
const context = this;
|
|
652
|
+
list[name] = function() {
|
|
653
|
+
return context.echo(macro.apply(undefined, arguments))
|
|
654
|
+
};
|
|
655
|
+
});
|
|
656
|
+
/**
|
|
657
|
+
* @memberOf global
|
|
658
|
+
* @function call
|
|
659
|
+
* @param name
|
|
660
|
+
* @param {...*} args
|
|
661
|
+
*/
|
|
662
|
+
Scope.method('call', function(name) {
|
|
663
|
+
const list = this.getMacro();
|
|
664
|
+
const macro = list[name];
|
|
665
|
+
const params = [].slice.call(arguments, 1);
|
|
666
|
+
if (isFunction(macro)) {
|
|
667
|
+
return macro.apply(macro, params)
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
/**
|
|
671
|
+
* @memberOf global
|
|
672
|
+
* @function block
|
|
673
|
+
* @param name
|
|
674
|
+
* @param callback
|
|
675
|
+
*/
|
|
676
|
+
Scope.method('block',function(name,callback){
|
|
677
|
+
const blocks = this.getBlocks();
|
|
678
|
+
blocks[name] = blocks[name] || [];
|
|
679
|
+
blocks[name].push(this.fn(callback));
|
|
680
|
+
if (this.getExtend()) return
|
|
681
|
+
const list = Object.assign([], blocks[name]);
|
|
682
|
+
const current = function() {
|
|
683
|
+
return list.shift()
|
|
684
|
+
};
|
|
685
|
+
const next = () => {
|
|
686
|
+
const parent = current();
|
|
687
|
+
if (parent) {
|
|
688
|
+
return () => {
|
|
689
|
+
this.echo(parent(next()));
|
|
593
690
|
}
|
|
594
|
-
|
|
595
|
-
return
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
691
|
+
} else {
|
|
692
|
+
return noop
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
this.echo(current()(next()));
|
|
696
|
+
});
|
|
697
|
+
/**
|
|
698
|
+
* @memberOf global
|
|
699
|
+
* @function include
|
|
700
|
+
* @param path
|
|
701
|
+
* @param [data]
|
|
702
|
+
* @param [cx]
|
|
703
|
+
*/
|
|
704
|
+
Scope.method('include',function(path, data, cx){
|
|
705
|
+
const context = cx === false ? {} : this.clone(true);
|
|
706
|
+
const params = extend(context, data || {});
|
|
707
|
+
const promise = this.render(path, params);
|
|
708
|
+
this.echo(promise);
|
|
709
|
+
});
|
|
710
|
+
/**
|
|
711
|
+
* @memberOf global
|
|
712
|
+
* @function use
|
|
713
|
+
* @param path
|
|
714
|
+
* @param namespace
|
|
715
|
+
*/
|
|
716
|
+
Scope.method('use',function(path, namespace){
|
|
717
|
+
const promise = this.require(path);
|
|
718
|
+
this.echo(resolve$1(promise,function(exports){
|
|
719
|
+
const list = this.getMacro();
|
|
720
|
+
each(exports, function(macro, name) {
|
|
721
|
+
list[[namespace, name].join('.')] = macro;
|
|
722
|
+
});
|
|
723
|
+
},this));
|
|
724
|
+
});
|
|
725
|
+
/**
|
|
726
|
+
* @memberOf global
|
|
727
|
+
* @function async
|
|
728
|
+
* @param promise
|
|
729
|
+
* @param callback
|
|
730
|
+
*/
|
|
731
|
+
Scope.method('async',function(promise,callback){
|
|
732
|
+
this.echo(
|
|
733
|
+
resolve$1(promise, function(data) {
|
|
734
|
+
return this.fn(callback)(data)
|
|
735
|
+
}, this)
|
|
736
|
+
);
|
|
737
|
+
});
|
|
738
|
+
Scope.helpers(methods);
|
|
739
|
+
Scope.helpers({
|
|
623
740
|
/**
|
|
624
741
|
* @memberOf global
|
|
742
|
+
* @param tag
|
|
743
|
+
* @param attr
|
|
744
|
+
* @param content
|
|
625
745
|
*/
|
|
626
|
-
|
|
746
|
+
el(tag, attr, content) {
|
|
627
747
|
if (isFunction(content)) {
|
|
628
|
-
content = this.
|
|
748
|
+
content = this.fn(content)();
|
|
629
749
|
}
|
|
630
750
|
this.echo(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
* @memberOf global
|
|
636
|
-
* @param {String} namespace
|
|
637
|
-
* @param {Object} instance
|
|
638
|
-
*/
|
|
639
|
-
component(namespace, instance) {
|
|
640
|
-
instance = Component(instance);
|
|
641
|
-
this.set(
|
|
642
|
-
namespace,
|
|
643
|
-
function(props) {
|
|
644
|
-
this.echo(instance.render(props));
|
|
645
|
-
}.bind(this)
|
|
751
|
+
resolve$1(content, function(content) {
|
|
752
|
+
return element(tag, attr, content)
|
|
753
|
+
}, this)
|
|
646
754
|
);
|
|
647
755
|
},
|
|
648
|
-
/**
|
|
649
|
-
* @memberOf global
|
|
650
|
-
* @param name
|
|
651
|
-
* @param defaults
|
|
652
|
-
*/
|
|
653
|
-
get(name, defaults) {
|
|
654
|
-
const path = getPath(this, name);
|
|
655
|
-
const result = path.shift();
|
|
656
|
-
const prop = path.pop();
|
|
657
|
-
return hasProp(result, prop) ? result[prop] : defaults
|
|
658
|
-
},
|
|
659
|
-
/**
|
|
660
|
-
* @memberOf global
|
|
661
|
-
* @param {String} name
|
|
662
|
-
* @param value
|
|
663
|
-
* @return
|
|
664
|
-
*/
|
|
665
|
-
set(name, value) {
|
|
666
|
-
const path = getPath(this, name);
|
|
667
|
-
const result = path.shift();
|
|
668
|
-
const prop = path.pop();
|
|
669
|
-
if (this.getExtend()) {
|
|
670
|
-
if (hasProp(result, prop)) {
|
|
671
|
-
return result[prop]
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
result[prop] = value;
|
|
675
|
-
},
|
|
676
|
-
/**
|
|
677
|
-
* @memberOf global
|
|
678
|
-
* @param name
|
|
679
|
-
*/
|
|
680
|
-
call(name) {
|
|
681
|
-
const params = [].slice.call(arguments, 1);
|
|
682
|
-
const path = getPath(this, name);
|
|
683
|
-
const result = path.shift();
|
|
684
|
-
const prop = path.pop();
|
|
685
|
-
if (isFunction(result[prop])) {
|
|
686
|
-
return result[prop].apply(result, params)
|
|
687
|
-
}
|
|
688
|
-
},
|
|
689
756
|
/**
|
|
690
757
|
* @memberOf global
|
|
691
758
|
* @param object
|
|
@@ -696,89 +763,6 @@ const Scope = (config, methods) => {
|
|
|
696
763
|
object = this.get(object, []);
|
|
697
764
|
}
|
|
698
765
|
each(object, callback);
|
|
699
|
-
},
|
|
700
|
-
/**
|
|
701
|
-
* @memberOf global
|
|
702
|
-
* @param {String} layout
|
|
703
|
-
*/
|
|
704
|
-
extend(layout) {
|
|
705
|
-
this.setExtend(true);
|
|
706
|
-
this.setLayout(layout);
|
|
707
|
-
},
|
|
708
|
-
/**
|
|
709
|
-
* @memberOf global
|
|
710
|
-
* @param name
|
|
711
|
-
* @param callback
|
|
712
|
-
* @return {*}
|
|
713
|
-
*/
|
|
714
|
-
block(name, callback) {
|
|
715
|
-
const blocks = this.getBlocks();
|
|
716
|
-
blocks[name] = blocks[name] || [];
|
|
717
|
-
blocks[name].push(this.macro(callback));
|
|
718
|
-
if (this.getExtend() === false) {
|
|
719
|
-
const list = blocks[name];
|
|
720
|
-
const callback = function(){
|
|
721
|
-
const parent = list.shift();
|
|
722
|
-
if( parent ) {
|
|
723
|
-
const context = parent.__context;
|
|
724
|
-
return function(){
|
|
725
|
-
context.echo(parent(callback()));
|
|
726
|
-
}
|
|
727
|
-
} else {
|
|
728
|
-
return function(){}
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
this.echo(list.shift()(callback()));
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
/**
|
|
735
|
-
* @memberOf global
|
|
736
|
-
* @param {string} path
|
|
737
|
-
* @param {object} [data]
|
|
738
|
-
* @param {boolean} [cx]
|
|
739
|
-
*/
|
|
740
|
-
include(path, data, cx) {
|
|
741
|
-
const context = cx === false ? {} : this.clone(true);
|
|
742
|
-
const params = extend(context, data || {});
|
|
743
|
-
const promise = this.render(path, params);
|
|
744
|
-
this.echo(promise);
|
|
745
|
-
},
|
|
746
|
-
/**
|
|
747
|
-
* @memberOf global
|
|
748
|
-
* @param {string} path
|
|
749
|
-
*/
|
|
750
|
-
use(path) {
|
|
751
|
-
const scope = this;
|
|
752
|
-
const promise = this.require(path);
|
|
753
|
-
this.echo(promise);
|
|
754
|
-
return {
|
|
755
|
-
as(namespace) {
|
|
756
|
-
promise.then((exports) => {
|
|
757
|
-
scope.set(namespace, exports);
|
|
758
|
-
});
|
|
759
|
-
return this
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
},
|
|
763
|
-
/**
|
|
764
|
-
* @memberOf global
|
|
765
|
-
* @param {string} path
|
|
766
|
-
*/
|
|
767
|
-
from(path) {
|
|
768
|
-
const scope = this;
|
|
769
|
-
const promise = this.require(path);
|
|
770
|
-
this.echo(promise);
|
|
771
|
-
return {
|
|
772
|
-
use() {
|
|
773
|
-
const params = [].slice.call(arguments);
|
|
774
|
-
promise.then((exports) => {
|
|
775
|
-
params.forEach((name) => {
|
|
776
|
-
scope.set(name, exports[name]);
|
|
777
|
-
});
|
|
778
|
-
});
|
|
779
|
-
return this
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
766
|
}
|
|
783
767
|
});
|
|
784
768
|
return Scope
|
|
@@ -839,7 +823,7 @@ function init(options) {
|
|
|
839
823
|
})
|
|
840
824
|
},
|
|
841
825
|
render(name, data) {
|
|
842
|
-
const filepath = ext(name, config.extension
|
|
826
|
+
const filepath = ext(name, config.extension);
|
|
843
827
|
const scope = new view.scope(data);
|
|
844
828
|
return view.output(filepath, scope).then((content) => {
|
|
845
829
|
if (scope.getExtend()) {
|
|
@@ -852,10 +836,10 @@ function init(options) {
|
|
|
852
836
|
})
|
|
853
837
|
},
|
|
854
838
|
require(name) {
|
|
855
|
-
const filepath = ext(name, config.extension
|
|
839
|
+
const filepath = ext(name, config.extension);
|
|
856
840
|
const scope = new view.scope({});
|
|
857
841
|
return view.output(filepath, scope).then(() => {
|
|
858
|
-
return scope.
|
|
842
|
+
return scope.getMacro()
|
|
859
843
|
})
|
|
860
844
|
},
|
|
861
845
|
helpers(methods) {
|
|
@@ -871,10 +855,14 @@ function init(options) {
|
|
|
871
855
|
defaults.resolver,
|
|
872
856
|
options.resolver
|
|
873
857
|
);
|
|
874
|
-
config.extension =
|
|
858
|
+
config.extension = typeProp(
|
|
859
|
+
isString,
|
|
860
|
+
defaults.extension,
|
|
861
|
+
options.extension
|
|
862
|
+
);
|
|
875
863
|
config.token = extend({}, defaults.token, options.token);
|
|
876
864
|
config.vars = extend({}, defaults.vars, options.vars);
|
|
877
|
-
view.scope =
|
|
865
|
+
view.scope = configure(config, helpers);
|
|
878
866
|
view.compile = Compiler(config);
|
|
879
867
|
view.wrapper = Wrapper(config);
|
|
880
868
|
view.cache = Cache(config);
|