@kosatyi/ejs 0.0.14 → 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 +19 -146
- package/dist/ejs.js +19 -146
- package/dist/ejs.min.js +1 -1
- package/dist/ejs.mjs +21 -146
- package/package.json +1 -1
package/dist/ejs.cjs
CHANGED
|
@@ -16,15 +16,14 @@ defaults.cache = true;
|
|
|
16
16
|
defaults.path = 'views';
|
|
17
17
|
defaults.resolver = null;
|
|
18
18
|
defaults.extension = 'ejs';
|
|
19
|
+
defaults.withObject = false;
|
|
19
20
|
defaults.vars = {
|
|
20
|
-
|
|
21
|
+
SCOPE: 'ejs',
|
|
22
|
+
EXTEND: '$$e',
|
|
21
23
|
BUFFER: '$$a',
|
|
22
|
-
OUTPUT: '$$i',
|
|
23
24
|
LAYOUT: '$$l',
|
|
24
25
|
BLOCKS: '$$b',
|
|
25
26
|
MACRO: '$$m',
|
|
26
|
-
ERROR: '$$e',
|
|
27
|
-
SCOPE: '$$s',
|
|
28
27
|
SAFE: '$$v'
|
|
29
28
|
};
|
|
30
29
|
defaults.token = {
|
|
@@ -216,6 +215,7 @@ var match = function match(regex, text, callback) {
|
|
|
216
215
|
* @constructor
|
|
217
216
|
*/
|
|
218
217
|
var Compiler = function Compiler(config) {
|
|
218
|
+
var withObject = config.withObject;
|
|
219
219
|
var token = config.token;
|
|
220
220
|
var vars = config.vars;
|
|
221
221
|
var matches = [];
|
|
@@ -251,14 +251,15 @@ var Compiler = function Compiler(config) {
|
|
|
251
251
|
});
|
|
252
252
|
source += "');";
|
|
253
253
|
source = "try{".concat(source, "}catch(e){console.info(e)}");
|
|
254
|
-
|
|
254
|
+
if (withObject) {
|
|
255
|
+
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
256
|
+
}
|
|
255
257
|
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
256
258
|
source += "\n//# sourceURL=".concat(path);
|
|
257
259
|
var result = null;
|
|
258
260
|
try {
|
|
259
261
|
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
260
262
|
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
261
|
-
//result.source = result.toString()
|
|
262
263
|
} catch (e) {
|
|
263
264
|
console.log(e);
|
|
264
265
|
e.filename = path;
|
|
@@ -373,20 +374,25 @@ var Buffer = function Buffer() {
|
|
|
373
374
|
return buffer;
|
|
374
375
|
};
|
|
375
376
|
|
|
377
|
+
/**
|
|
378
|
+
* @memberOf global
|
|
379
|
+
* @class
|
|
380
|
+
* @alias ejs
|
|
381
|
+
* @param config
|
|
382
|
+
* @param methods
|
|
383
|
+
* @return {Scope}
|
|
384
|
+
*/
|
|
385
|
+
|
|
376
386
|
var configure = function configure(config, methods) {
|
|
377
|
-
/**
|
|
378
|
-
*
|
|
379
|
-
*/
|
|
380
387
|
var _config$vars = config.vars,
|
|
381
388
|
EXTEND = _config$vars.EXTEND,
|
|
382
389
|
LAYOUT = _config$vars.LAYOUT,
|
|
383
390
|
BLOCKS = _config$vars.BLOCKS,
|
|
384
391
|
BUFFER = _config$vars.BUFFER,
|
|
385
392
|
MACRO = _config$vars.MACRO;
|
|
386
|
-
|
|
393
|
+
|
|
387
394
|
/**
|
|
388
|
-
*
|
|
389
|
-
* @name [SCOPE]
|
|
395
|
+
*
|
|
390
396
|
* @param data
|
|
391
397
|
* @constructor
|
|
392
398
|
*/
|
|
@@ -396,136 +402,77 @@ var configure = function configure(config, methods) {
|
|
|
396
402
|
this.initMacro();
|
|
397
403
|
extend(this, data);
|
|
398
404
|
}
|
|
399
|
-
/**
|
|
400
|
-
* @static
|
|
401
|
-
* @param methods
|
|
402
|
-
*/
|
|
403
405
|
Scope.helpers = function (methods) {
|
|
404
406
|
extend(Scope.prototype, methods);
|
|
405
407
|
};
|
|
406
|
-
/**
|
|
407
|
-
* @static
|
|
408
|
-
* @param name
|
|
409
|
-
* @param descriptor
|
|
410
|
-
*/
|
|
411
408
|
Scope.property = function (name, descriptor) {
|
|
412
409
|
Object.defineProperty(Scope.prototype, name, descriptor);
|
|
413
410
|
};
|
|
414
|
-
/**
|
|
415
|
-
* @static
|
|
416
|
-
* @param name
|
|
417
|
-
* @param method
|
|
418
|
-
*/
|
|
419
411
|
Scope.method = function (name, method) {
|
|
420
|
-
|
|
412
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
421
413
|
value: method,
|
|
422
414
|
writable: false,
|
|
423
415
|
configurable: false,
|
|
424
416
|
enumerable: false
|
|
425
417
|
});
|
|
426
418
|
};
|
|
427
|
-
/**
|
|
428
|
-
*
|
|
429
|
-
*/
|
|
430
419
|
Scope.property(BUFFER, {
|
|
431
420
|
value: Buffer(),
|
|
432
421
|
writable: false,
|
|
433
422
|
configurable: false,
|
|
434
423
|
enumerable: false
|
|
435
424
|
});
|
|
436
|
-
/**
|
|
437
|
-
*
|
|
438
|
-
*/
|
|
439
425
|
Scope.property(BLOCKS, {
|
|
440
426
|
value: {},
|
|
441
427
|
writable: true,
|
|
442
428
|
configurable: false,
|
|
443
429
|
enumerable: false
|
|
444
430
|
});
|
|
445
|
-
/**
|
|
446
|
-
*
|
|
447
|
-
*/
|
|
448
431
|
Scope.property(MACRO, {
|
|
449
432
|
value: {},
|
|
450
433
|
writable: true,
|
|
451
434
|
configurable: false,
|
|
452
435
|
enumerable: false
|
|
453
436
|
});
|
|
454
|
-
/**
|
|
455
|
-
*
|
|
456
|
-
*/
|
|
457
437
|
Scope.property(LAYOUT, {
|
|
458
438
|
value: false,
|
|
459
439
|
writable: true,
|
|
460
440
|
configurable: false,
|
|
461
441
|
enumerable: false
|
|
462
442
|
});
|
|
463
|
-
/**
|
|
464
|
-
*
|
|
465
|
-
*/
|
|
466
443
|
Scope.property(EXTEND, {
|
|
467
444
|
value: false,
|
|
468
445
|
writable: true,
|
|
469
446
|
configurable: false,
|
|
470
447
|
enumerable: false
|
|
471
448
|
});
|
|
472
|
-
/**
|
|
473
|
-
*
|
|
474
|
-
*/
|
|
475
449
|
Scope.method('initBlocks', function () {
|
|
476
450
|
this[BLOCKS] = {};
|
|
477
451
|
});
|
|
478
|
-
/**
|
|
479
|
-
*
|
|
480
|
-
*/
|
|
481
452
|
Scope.method('initMacro', function () {
|
|
482
453
|
this[MACRO] = {};
|
|
483
454
|
});
|
|
484
|
-
/**
|
|
485
|
-
*
|
|
486
|
-
*/
|
|
487
455
|
Scope.method('getMacro', function () {
|
|
488
456
|
return this[MACRO];
|
|
489
457
|
});
|
|
490
|
-
/**
|
|
491
|
-
*
|
|
492
|
-
*/
|
|
493
458
|
Scope.method('getBuffer', function () {
|
|
494
459
|
return this[BUFFER];
|
|
495
460
|
});
|
|
496
|
-
/**
|
|
497
|
-
*
|
|
498
|
-
*/
|
|
499
461
|
Scope.method('getBlocks', function () {
|
|
500
462
|
return this[BLOCKS];
|
|
501
463
|
});
|
|
502
|
-
/**
|
|
503
|
-
*
|
|
504
|
-
*/
|
|
505
464
|
Scope.method('setExtend', function (value) {
|
|
506
465
|
this[EXTEND] = value;
|
|
507
466
|
});
|
|
508
|
-
/**
|
|
509
|
-
*
|
|
510
|
-
*/
|
|
511
467
|
Scope.method('getExtend', function () {
|
|
512
468
|
return this[EXTEND];
|
|
513
469
|
});
|
|
514
|
-
/**
|
|
515
|
-
*
|
|
516
|
-
*/
|
|
517
470
|
Scope.method('setLayout', function (layout) {
|
|
518
471
|
this[LAYOUT] = layout;
|
|
519
472
|
});
|
|
520
|
-
/**
|
|
521
|
-
*
|
|
522
|
-
*/
|
|
523
473
|
Scope.method('getLayout', function () {
|
|
524
474
|
return this[LAYOUT];
|
|
525
475
|
});
|
|
526
|
-
/**
|
|
527
|
-
*
|
|
528
|
-
*/
|
|
529
476
|
Scope.method('clone', function (exclude_blocks) {
|
|
530
477
|
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
531
478
|
if (exclude_blocks === true) {
|
|
@@ -533,19 +480,10 @@ var configure = function configure(config, methods) {
|
|
|
533
480
|
}
|
|
534
481
|
return omit(this, filter);
|
|
535
482
|
});
|
|
536
|
-
/**
|
|
537
|
-
* @methodOf global
|
|
538
|
-
* @function extend
|
|
539
|
-
* @param layout
|
|
540
|
-
*/
|
|
541
483
|
Scope.method('extend', function (layout) {
|
|
542
484
|
this.setExtend(true);
|
|
543
485
|
this.setLayout(layout);
|
|
544
486
|
});
|
|
545
|
-
/**
|
|
546
|
-
* @memberOf global
|
|
547
|
-
* @function echo
|
|
548
|
-
*/
|
|
549
487
|
Scope.method('echo', function () {
|
|
550
488
|
var buffer = this.getBuffer();
|
|
551
489
|
var params = [].slice.call(arguments);
|
|
@@ -553,11 +491,6 @@ var configure = function configure(config, methods) {
|
|
|
553
491
|
buffer(item);
|
|
554
492
|
});
|
|
555
493
|
});
|
|
556
|
-
/**
|
|
557
|
-
* @memberOf global
|
|
558
|
-
* @function fn
|
|
559
|
-
* @param callback
|
|
560
|
-
*/
|
|
561
494
|
Scope.method('fn', function (callback) {
|
|
562
495
|
var buffer = this.getBuffer();
|
|
563
496
|
var context = this;
|
|
@@ -569,24 +502,12 @@ var configure = function configure(config, methods) {
|
|
|
569
502
|
return buffer.restore();
|
|
570
503
|
};
|
|
571
504
|
});
|
|
572
|
-
/**
|
|
573
|
-
* @memberOf global
|
|
574
|
-
* @function get
|
|
575
|
-
* @param name
|
|
576
|
-
* @param [defaults]
|
|
577
|
-
*/
|
|
578
505
|
Scope.method('get', function (name, defaults) {
|
|
579
506
|
var path = getPath(this, name);
|
|
580
507
|
var result = path.shift();
|
|
581
508
|
var prop = path.pop();
|
|
582
509
|
return hasProp(result, prop) ? result[prop] : defaults;
|
|
583
510
|
});
|
|
584
|
-
/**
|
|
585
|
-
* @memberOf global
|
|
586
|
-
* @function set
|
|
587
|
-
* @param name
|
|
588
|
-
* @param value
|
|
589
|
-
*/
|
|
590
511
|
Scope.method('set', function (name, value) {
|
|
591
512
|
var path = getPath(this, name);
|
|
592
513
|
var result = path.shift();
|
|
@@ -596,12 +517,6 @@ var configure = function configure(config, methods) {
|
|
|
596
517
|
}
|
|
597
518
|
return result[prop] = value;
|
|
598
519
|
});
|
|
599
|
-
/**
|
|
600
|
-
* @memberOf global
|
|
601
|
-
* @function macro
|
|
602
|
-
* @param name
|
|
603
|
-
* @param callback
|
|
604
|
-
*/
|
|
605
520
|
Scope.method('macro', function (name, callback) {
|
|
606
521
|
var list = this.getMacro();
|
|
607
522
|
var macro = this.fn(callback);
|
|
@@ -610,12 +525,6 @@ var configure = function configure(config, methods) {
|
|
|
610
525
|
return context.echo(macro.apply(undefined, arguments));
|
|
611
526
|
};
|
|
612
527
|
});
|
|
613
|
-
/**
|
|
614
|
-
* @memberOf global
|
|
615
|
-
* @function call
|
|
616
|
-
* @param name
|
|
617
|
-
* @param {...*} args
|
|
618
|
-
*/
|
|
619
528
|
Scope.method('call', function (name) {
|
|
620
529
|
var list = this.getMacro();
|
|
621
530
|
var macro = list[name];
|
|
@@ -624,12 +533,6 @@ var configure = function configure(config, methods) {
|
|
|
624
533
|
return macro.apply(macro, params);
|
|
625
534
|
}
|
|
626
535
|
});
|
|
627
|
-
/**
|
|
628
|
-
* @memberOf global
|
|
629
|
-
* @function block
|
|
630
|
-
* @param name
|
|
631
|
-
* @param callback
|
|
632
|
-
*/
|
|
633
536
|
Scope.method('block', function (name, callback) {
|
|
634
537
|
var _this = this;
|
|
635
538
|
var blocks = this.getBlocks();
|
|
@@ -652,25 +555,12 @@ var configure = function configure(config, methods) {
|
|
|
652
555
|
};
|
|
653
556
|
this.echo(current()(next()));
|
|
654
557
|
});
|
|
655
|
-
/**
|
|
656
|
-
* @memberOf global
|
|
657
|
-
* @function include
|
|
658
|
-
* @param path
|
|
659
|
-
* @param [data]
|
|
660
|
-
* @param [cx]
|
|
661
|
-
*/
|
|
662
558
|
Scope.method('include', function (path, data, cx) {
|
|
663
559
|
var context = cx === false ? {} : this.clone(true);
|
|
664
560
|
var params = extend(context, data || {});
|
|
665
561
|
var promise = this.render(path, params);
|
|
666
562
|
this.echo(promise);
|
|
667
563
|
});
|
|
668
|
-
/**
|
|
669
|
-
* @memberOf global
|
|
670
|
-
* @function use
|
|
671
|
-
* @param path
|
|
672
|
-
* @param namespace
|
|
673
|
-
*/
|
|
674
564
|
Scope.method('use', function (path, namespace) {
|
|
675
565
|
var promise = this.require(path);
|
|
676
566
|
this.echo(resolve$1(promise, function (exports) {
|
|
@@ -680,12 +570,6 @@ var configure = function configure(config, methods) {
|
|
|
680
570
|
});
|
|
681
571
|
}, this));
|
|
682
572
|
});
|
|
683
|
-
/**
|
|
684
|
-
* @memberOf global
|
|
685
|
-
* @function async
|
|
686
|
-
* @param promise
|
|
687
|
-
* @param callback
|
|
688
|
-
*/
|
|
689
573
|
Scope.method('async', function (promise, callback) {
|
|
690
574
|
this.echo(resolve$1(promise, function (data) {
|
|
691
575
|
return this.fn(callback)(data);
|
|
@@ -693,12 +577,6 @@ var configure = function configure(config, methods) {
|
|
|
693
577
|
});
|
|
694
578
|
Scope.helpers(methods);
|
|
695
579
|
Scope.helpers({
|
|
696
|
-
/**
|
|
697
|
-
* @memberOf global
|
|
698
|
-
* @param tag
|
|
699
|
-
* @param attr
|
|
700
|
-
* @param content
|
|
701
|
-
*/
|
|
702
580
|
el: function el(tag, attr, content) {
|
|
703
581
|
if (isFunction(content)) {
|
|
704
582
|
content = this.fn(content)();
|
|
@@ -707,11 +585,6 @@ var configure = function configure(config, methods) {
|
|
|
707
585
|
return element(tag, attr, content);
|
|
708
586
|
}, this));
|
|
709
587
|
},
|
|
710
|
-
/**
|
|
711
|
-
* @memberOf global
|
|
712
|
-
* @param object
|
|
713
|
-
* @param callback
|
|
714
|
-
*/
|
|
715
588
|
each: function each$1(object, callback) {
|
|
716
589
|
if (isString(object)) {
|
|
717
590
|
object = this.get(object, []);
|
package/dist/ejs.js
CHANGED
|
@@ -12,15 +12,14 @@
|
|
|
12
12
|
defaults.path = 'views';
|
|
13
13
|
defaults.resolver = null;
|
|
14
14
|
defaults.extension = 'ejs';
|
|
15
|
+
defaults.withObject = false;
|
|
15
16
|
defaults.vars = {
|
|
16
|
-
|
|
17
|
+
SCOPE: 'ejs',
|
|
18
|
+
EXTEND: '$$e',
|
|
17
19
|
BUFFER: '$$a',
|
|
18
|
-
OUTPUT: '$$i',
|
|
19
20
|
LAYOUT: '$$l',
|
|
20
21
|
BLOCKS: '$$b',
|
|
21
22
|
MACRO: '$$m',
|
|
22
|
-
ERROR: '$$e',
|
|
23
|
-
SCOPE: '$$s',
|
|
24
23
|
SAFE: '$$v'
|
|
25
24
|
};
|
|
26
25
|
defaults.token = {
|
|
@@ -212,6 +211,7 @@
|
|
|
212
211
|
* @constructor
|
|
213
212
|
*/
|
|
214
213
|
var Compiler = function Compiler(config) {
|
|
214
|
+
var withObject = config.withObject;
|
|
215
215
|
var token = config.token;
|
|
216
216
|
var vars = config.vars;
|
|
217
217
|
var matches = [];
|
|
@@ -247,14 +247,15 @@
|
|
|
247
247
|
});
|
|
248
248
|
source += "');";
|
|
249
249
|
source = "try{".concat(source, "}catch(e){console.info(e)}");
|
|
250
|
-
|
|
250
|
+
if (withObject) {
|
|
251
|
+
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
252
|
+
}
|
|
251
253
|
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
252
254
|
source += "\n//# sourceURL=".concat(path);
|
|
253
255
|
var result = null;
|
|
254
256
|
try {
|
|
255
257
|
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
256
258
|
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
257
|
-
//result.source = result.toString()
|
|
258
259
|
} catch (e) {
|
|
259
260
|
console.log(e);
|
|
260
261
|
e.filename = path;
|
|
@@ -369,20 +370,25 @@
|
|
|
369
370
|
return buffer;
|
|
370
371
|
};
|
|
371
372
|
|
|
373
|
+
/**
|
|
374
|
+
* @memberOf global
|
|
375
|
+
* @class
|
|
376
|
+
* @alias ejs
|
|
377
|
+
* @param config
|
|
378
|
+
* @param methods
|
|
379
|
+
* @return {Scope}
|
|
380
|
+
*/
|
|
381
|
+
|
|
372
382
|
var configure = function configure(config, methods) {
|
|
373
|
-
/**
|
|
374
|
-
*
|
|
375
|
-
*/
|
|
376
383
|
var _config$vars = config.vars,
|
|
377
384
|
EXTEND = _config$vars.EXTEND,
|
|
378
385
|
LAYOUT = _config$vars.LAYOUT,
|
|
379
386
|
BLOCKS = _config$vars.BLOCKS,
|
|
380
387
|
BUFFER = _config$vars.BUFFER,
|
|
381
388
|
MACRO = _config$vars.MACRO;
|
|
382
|
-
|
|
389
|
+
|
|
383
390
|
/**
|
|
384
|
-
*
|
|
385
|
-
* @name [SCOPE]
|
|
391
|
+
*
|
|
386
392
|
* @param data
|
|
387
393
|
* @constructor
|
|
388
394
|
*/
|
|
@@ -392,136 +398,77 @@
|
|
|
392
398
|
this.initMacro();
|
|
393
399
|
extend(this, data);
|
|
394
400
|
}
|
|
395
|
-
/**
|
|
396
|
-
* @static
|
|
397
|
-
* @param methods
|
|
398
|
-
*/
|
|
399
401
|
Scope.helpers = function (methods) {
|
|
400
402
|
extend(Scope.prototype, methods);
|
|
401
403
|
};
|
|
402
|
-
/**
|
|
403
|
-
* @static
|
|
404
|
-
* @param name
|
|
405
|
-
* @param descriptor
|
|
406
|
-
*/
|
|
407
404
|
Scope.property = function (name, descriptor) {
|
|
408
405
|
Object.defineProperty(Scope.prototype, name, descriptor);
|
|
409
406
|
};
|
|
410
|
-
/**
|
|
411
|
-
* @static
|
|
412
|
-
* @param name
|
|
413
|
-
* @param method
|
|
414
|
-
*/
|
|
415
407
|
Scope.method = function (name, method) {
|
|
416
|
-
|
|
408
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
417
409
|
value: method,
|
|
418
410
|
writable: false,
|
|
419
411
|
configurable: false,
|
|
420
412
|
enumerable: false
|
|
421
413
|
});
|
|
422
414
|
};
|
|
423
|
-
/**
|
|
424
|
-
*
|
|
425
|
-
*/
|
|
426
415
|
Scope.property(BUFFER, {
|
|
427
416
|
value: Buffer(),
|
|
428
417
|
writable: false,
|
|
429
418
|
configurable: false,
|
|
430
419
|
enumerable: false
|
|
431
420
|
});
|
|
432
|
-
/**
|
|
433
|
-
*
|
|
434
|
-
*/
|
|
435
421
|
Scope.property(BLOCKS, {
|
|
436
422
|
value: {},
|
|
437
423
|
writable: true,
|
|
438
424
|
configurable: false,
|
|
439
425
|
enumerable: false
|
|
440
426
|
});
|
|
441
|
-
/**
|
|
442
|
-
*
|
|
443
|
-
*/
|
|
444
427
|
Scope.property(MACRO, {
|
|
445
428
|
value: {},
|
|
446
429
|
writable: true,
|
|
447
430
|
configurable: false,
|
|
448
431
|
enumerable: false
|
|
449
432
|
});
|
|
450
|
-
/**
|
|
451
|
-
*
|
|
452
|
-
*/
|
|
453
433
|
Scope.property(LAYOUT, {
|
|
454
434
|
value: false,
|
|
455
435
|
writable: true,
|
|
456
436
|
configurable: false,
|
|
457
437
|
enumerable: false
|
|
458
438
|
});
|
|
459
|
-
/**
|
|
460
|
-
*
|
|
461
|
-
*/
|
|
462
439
|
Scope.property(EXTEND, {
|
|
463
440
|
value: false,
|
|
464
441
|
writable: true,
|
|
465
442
|
configurable: false,
|
|
466
443
|
enumerable: false
|
|
467
444
|
});
|
|
468
|
-
/**
|
|
469
|
-
*
|
|
470
|
-
*/
|
|
471
445
|
Scope.method('initBlocks', function () {
|
|
472
446
|
this[BLOCKS] = {};
|
|
473
447
|
});
|
|
474
|
-
/**
|
|
475
|
-
*
|
|
476
|
-
*/
|
|
477
448
|
Scope.method('initMacro', function () {
|
|
478
449
|
this[MACRO] = {};
|
|
479
450
|
});
|
|
480
|
-
/**
|
|
481
|
-
*
|
|
482
|
-
*/
|
|
483
451
|
Scope.method('getMacro', function () {
|
|
484
452
|
return this[MACRO];
|
|
485
453
|
});
|
|
486
|
-
/**
|
|
487
|
-
*
|
|
488
|
-
*/
|
|
489
454
|
Scope.method('getBuffer', function () {
|
|
490
455
|
return this[BUFFER];
|
|
491
456
|
});
|
|
492
|
-
/**
|
|
493
|
-
*
|
|
494
|
-
*/
|
|
495
457
|
Scope.method('getBlocks', function () {
|
|
496
458
|
return this[BLOCKS];
|
|
497
459
|
});
|
|
498
|
-
/**
|
|
499
|
-
*
|
|
500
|
-
*/
|
|
501
460
|
Scope.method('setExtend', function (value) {
|
|
502
461
|
this[EXTEND] = value;
|
|
503
462
|
});
|
|
504
|
-
/**
|
|
505
|
-
*
|
|
506
|
-
*/
|
|
507
463
|
Scope.method('getExtend', function () {
|
|
508
464
|
return this[EXTEND];
|
|
509
465
|
});
|
|
510
|
-
/**
|
|
511
|
-
*
|
|
512
|
-
*/
|
|
513
466
|
Scope.method('setLayout', function (layout) {
|
|
514
467
|
this[LAYOUT] = layout;
|
|
515
468
|
});
|
|
516
|
-
/**
|
|
517
|
-
*
|
|
518
|
-
*/
|
|
519
469
|
Scope.method('getLayout', function () {
|
|
520
470
|
return this[LAYOUT];
|
|
521
471
|
});
|
|
522
|
-
/**
|
|
523
|
-
*
|
|
524
|
-
*/
|
|
525
472
|
Scope.method('clone', function (exclude_blocks) {
|
|
526
473
|
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
527
474
|
if (exclude_blocks === true) {
|
|
@@ -529,19 +476,10 @@
|
|
|
529
476
|
}
|
|
530
477
|
return omit(this, filter);
|
|
531
478
|
});
|
|
532
|
-
/**
|
|
533
|
-
* @methodOf global
|
|
534
|
-
* @function extend
|
|
535
|
-
* @param layout
|
|
536
|
-
*/
|
|
537
479
|
Scope.method('extend', function (layout) {
|
|
538
480
|
this.setExtend(true);
|
|
539
481
|
this.setLayout(layout);
|
|
540
482
|
});
|
|
541
|
-
/**
|
|
542
|
-
* @memberOf global
|
|
543
|
-
* @function echo
|
|
544
|
-
*/
|
|
545
483
|
Scope.method('echo', function () {
|
|
546
484
|
var buffer = this.getBuffer();
|
|
547
485
|
var params = [].slice.call(arguments);
|
|
@@ -549,11 +487,6 @@
|
|
|
549
487
|
buffer(item);
|
|
550
488
|
});
|
|
551
489
|
});
|
|
552
|
-
/**
|
|
553
|
-
* @memberOf global
|
|
554
|
-
* @function fn
|
|
555
|
-
* @param callback
|
|
556
|
-
*/
|
|
557
490
|
Scope.method('fn', function (callback) {
|
|
558
491
|
var buffer = this.getBuffer();
|
|
559
492
|
var context = this;
|
|
@@ -565,24 +498,12 @@
|
|
|
565
498
|
return buffer.restore();
|
|
566
499
|
};
|
|
567
500
|
});
|
|
568
|
-
/**
|
|
569
|
-
* @memberOf global
|
|
570
|
-
* @function get
|
|
571
|
-
* @param name
|
|
572
|
-
* @param [defaults]
|
|
573
|
-
*/
|
|
574
501
|
Scope.method('get', function (name, defaults) {
|
|
575
502
|
var path = getPath(this, name);
|
|
576
503
|
var result = path.shift();
|
|
577
504
|
var prop = path.pop();
|
|
578
505
|
return hasProp(result, prop) ? result[prop] : defaults;
|
|
579
506
|
});
|
|
580
|
-
/**
|
|
581
|
-
* @memberOf global
|
|
582
|
-
* @function set
|
|
583
|
-
* @param name
|
|
584
|
-
* @param value
|
|
585
|
-
*/
|
|
586
507
|
Scope.method('set', function (name, value) {
|
|
587
508
|
var path = getPath(this, name);
|
|
588
509
|
var result = path.shift();
|
|
@@ -592,12 +513,6 @@
|
|
|
592
513
|
}
|
|
593
514
|
return result[prop] = value;
|
|
594
515
|
});
|
|
595
|
-
/**
|
|
596
|
-
* @memberOf global
|
|
597
|
-
* @function macro
|
|
598
|
-
* @param name
|
|
599
|
-
* @param callback
|
|
600
|
-
*/
|
|
601
516
|
Scope.method('macro', function (name, callback) {
|
|
602
517
|
var list = this.getMacro();
|
|
603
518
|
var macro = this.fn(callback);
|
|
@@ -606,12 +521,6 @@
|
|
|
606
521
|
return context.echo(macro.apply(undefined, arguments));
|
|
607
522
|
};
|
|
608
523
|
});
|
|
609
|
-
/**
|
|
610
|
-
* @memberOf global
|
|
611
|
-
* @function call
|
|
612
|
-
* @param name
|
|
613
|
-
* @param {...*} args
|
|
614
|
-
*/
|
|
615
524
|
Scope.method('call', function (name) {
|
|
616
525
|
var list = this.getMacro();
|
|
617
526
|
var macro = list[name];
|
|
@@ -620,12 +529,6 @@
|
|
|
620
529
|
return macro.apply(macro, params);
|
|
621
530
|
}
|
|
622
531
|
});
|
|
623
|
-
/**
|
|
624
|
-
* @memberOf global
|
|
625
|
-
* @function block
|
|
626
|
-
* @param name
|
|
627
|
-
* @param callback
|
|
628
|
-
*/
|
|
629
532
|
Scope.method('block', function (name, callback) {
|
|
630
533
|
var _this = this;
|
|
631
534
|
var blocks = this.getBlocks();
|
|
@@ -648,25 +551,12 @@
|
|
|
648
551
|
};
|
|
649
552
|
this.echo(current()(next()));
|
|
650
553
|
});
|
|
651
|
-
/**
|
|
652
|
-
* @memberOf global
|
|
653
|
-
* @function include
|
|
654
|
-
* @param path
|
|
655
|
-
* @param [data]
|
|
656
|
-
* @param [cx]
|
|
657
|
-
*/
|
|
658
554
|
Scope.method('include', function (path, data, cx) {
|
|
659
555
|
var context = cx === false ? {} : this.clone(true);
|
|
660
556
|
var params = extend(context, data || {});
|
|
661
557
|
var promise = this.render(path, params);
|
|
662
558
|
this.echo(promise);
|
|
663
559
|
});
|
|
664
|
-
/**
|
|
665
|
-
* @memberOf global
|
|
666
|
-
* @function use
|
|
667
|
-
* @param path
|
|
668
|
-
* @param namespace
|
|
669
|
-
*/
|
|
670
560
|
Scope.method('use', function (path, namespace) {
|
|
671
561
|
var promise = this.require(path);
|
|
672
562
|
this.echo(resolve$1(promise, function (exports) {
|
|
@@ -676,12 +566,6 @@
|
|
|
676
566
|
});
|
|
677
567
|
}, this));
|
|
678
568
|
});
|
|
679
|
-
/**
|
|
680
|
-
* @memberOf global
|
|
681
|
-
* @function async
|
|
682
|
-
* @param promise
|
|
683
|
-
* @param callback
|
|
684
|
-
*/
|
|
685
569
|
Scope.method('async', function (promise, callback) {
|
|
686
570
|
this.echo(resolve$1(promise, function (data) {
|
|
687
571
|
return this.fn(callback)(data);
|
|
@@ -689,12 +573,6 @@
|
|
|
689
573
|
});
|
|
690
574
|
Scope.helpers(methods);
|
|
691
575
|
Scope.helpers({
|
|
692
|
-
/**
|
|
693
|
-
* @memberOf global
|
|
694
|
-
* @param tag
|
|
695
|
-
* @param attr
|
|
696
|
-
* @param content
|
|
697
|
-
*/
|
|
698
576
|
el: function el(tag, attr, content) {
|
|
699
577
|
if (isFunction(content)) {
|
|
700
578
|
content = this.fn(content)();
|
|
@@ -703,11 +581,6 @@
|
|
|
703
581
|
return element(tag, attr, content);
|
|
704
582
|
}, this));
|
|
705
583
|
},
|
|
706
|
-
/**
|
|
707
|
-
* @memberOf global
|
|
708
|
-
* @param object
|
|
709
|
-
* @param callback
|
|
710
|
-
*/
|
|
711
584
|
each: function each$1(object, callback) {
|
|
712
585
|
if (isString(object)) {
|
|
713
586
|
object = this.get(object, []);
|
package/dist/ejs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).ejs=t()}(this,(function(){"use strict";var n={},t={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:"ejs",vars:{
|
|
1
|
+
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).ejs=t()}(this,(function(){"use strict";var n={},t={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:"ejs",withObject:!1,vars:{SCOPE:"ejs",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},e=function(){var n=[].slice.call(arguments),t=n.shift();return n.filter(t).pop()},r=function(n){return"function"==typeof n},o=function(n){return"string"==typeof n},i=function(n){return"boolean"==typeof n},c=new Function("try {return this===global;}catch(e){return false;}"),u={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},a={"&":"&","<":"<",">":">",'"':""","'":"'"},f=function(n){return new RegExp(["[",Object.keys(n).join(""),"]"].join(""),"g")},s=f(a),h=f(u),l=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+n).replace(s,(function(n){return a[n]}))},p=function(n,t,e){return null==(e=n)?"":t?l(e):e},v=function(n,t){var e=n,r=t.split("."),o=r.pop();return r.forEach((function(n){e=e[n]=e[n]||{}})),[e,o]},d=function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var r=t.shift();return t.filter((function(n){return n})).reduce((function(n,t){return Object.assign(n,t)}),r)},m=function(){},g=function(n,t){var e;for(e in n)y(n,e)&&t(n[e],e,n)},b=function(n,t){return function(n,t,e){var r=n instanceof Array,o=r?[]:{};return g(n,(function(n,e,i){var c=t(n,e,i);void 0!==c&&(r?o.push(c):o[e]=c)})),o}(n,(function(n,e){if(-1===t.indexOf(e))return n}))},w=function(n,t,e){return Promise.resolve(n).then(t.bind(e))},y=function(n,t){return n&&n.hasOwnProperty(t)},x=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],E=" ",j='"',O="/",k="<",F=">";function B(n,t,e){var r=[],o=-1===x.indexOf(n),i=function(n,t,e){var r=[];return g(n,(function(n,e,o){var i=t(n,e,o);void 0!==i&&r.push(i)})),r}(t,(function(n,t){if(null!=n)return[l(t),[j,l(n),j].join("")].join("=")})).join(E);return r.push([k,n,E,i,F].join("")),e&&r.push(e instanceof Array?e.join(""):e),o&&r.push([k,O,n,F].join("")),r.join("")}var $=[{symbol:"-",format:function(n){return"'+\n".concat(this.SAFE,"(").concat(n,",1)+\n'")}},{symbol:"=",format:function(n){return"'+\n".concat(this.SAFE,"(").concat(n,")+\n'")}},{symbol:"#",format:function(n){return"'+\n/**".concat(n,"**/+\n'")}},{symbol:"",format:function(n){return"')\n".concat(n,"\n").concat(this.BUFFER,"('")}}],S=function(n){var t=n.withObject,e=n.token,r=n.vars,o=[],i=[],c={match:"[ \\t]*",start:[e.start,"_"],end:["_",e.end]};$.forEach((function(n){o.push(e.start.concat(n.symbol).concat(e.regex).concat(e.end)),i.push(n.format.bind(r))}));var a=new RegExp(o.join("|").concat("|$"),"g"),f=new RegExp([c.match,c.start].join(""),"gm"),s=new RegExp([c.end,c.match].join(""),"gm");return function(n,e){var o=r.SCOPE,l=r.SAFE,p=r.BUFFER;n=(n=n.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(f,c.start).replace(s,c.end);var v="".concat(p,"('");!function(n,t,e){var r=0;t.replace(n,(function(){var n=[].slice.call(arguments,0,-1),t=n.pop(),o=n.shift();return e(n,r,t),r=t+o.length,o}))}(a,n,(function(t,e,r){v+=(""+n.slice(e,r)).replace(h,(function(n){return"\\"+u[n]})),t.forEach((function(n,t){n&&(v+=i[t](n))}))})),v="try{".concat(v+="');","}catch(e){console.info(e)}"),t&&(v="with(".concat(o,"){").concat(v,"}")),v="".concat(p,".start();").concat(v,"return ").concat(p,".end();"),v+="\n//# sourceURL=".concat(e);var d=null;try{(d=new Function(o,p,l,v)).source="(function(".concat(o,",").concat(p,",").concat(l,"){\n").concat(v,"\n})")}catch(n){throw console.log(n),n.filename=e,n.source=v,n}return d}},A=function(n){return window.fetch(n).then((function(n){return n.text()}))},R=function(t){return new Promise((function(e,r){n.readFile(t,(function(n,t){n?r(n):e(t.toString())}))}))},L=function(t,e){return n.watch(".",{cwd:t}).on("change",(function(n){e.remove(n)})).on("error",(function(n){console.log("watcher error: "+n)}))},M=function(n,t,e){var o=n.path;n.token;var i=r(n.resolver)?n.resolver:c()?R:A,u=function(n){return i(function(n){return(n=[o,n].join("/")).replace(/\/\//g,"/")}(n))},a=function(n,e){return t.set(e,n),n};return n.watch&&c()&&L(o,t),function(n){if(t.exist(n))return t.resolve(n);var r=u(n).then((function(t){return a(e(t,n),n)}));return a(r,n)}},P=function(n){return Promise.all(n).then((function(n){return n.join("")}))},U=function(){var n=[],t=[];function e(n){t.push(n)}return e.start=function(){t=[]},e.backup=function(){n.push(t.concat()),t=[]},e.restore=function(){var e=t.concat();return t=n.pop(),P(e)},e.error=function(n){throw n},e.end=function(){return P(t)},e};var C,T,q,_,N,D=(T={},q={},_=function(n,t){var e=n.split(".").pop();return e!==t&&(n=[n,t].join(".")),n},N={element:B,output:function(n,t){return N.template(n).then((function(n){return n.call(t,t,t.getBuffer(),p)}))},render:function(n,t){var e=_(n,T.extension),r=new N.scope(t);return N.output(e,r).then((function(n){if(r.getExtend()){r.setExtend(!1);var t=r.getLayout(),e=r.clone();return N.render(t,e)}return n}))},require:function(n){var t=_(n,T.extension),e=new N.scope({});return N.output(t,e).then((function(){return e.getMacro()}))},helpers:function(n){d(q,n=n||{}),N.scope.helpers(n)},configure:function(n){return T.export=e(o,t.export,n.export),T.path=e(o,t.path,n.path),T.resolver=e(r,t.resolver,n.resolver),T.extension=e(o,t.extension,n.extension),T.token=d({},t.token,n.token),T.vars=d({},t.vars,n.vars),N.scope=function(n,t){var e=n.vars,i=e.EXTEND,c=e.LAYOUT,u=e.BLOCKS,a=e.BUFFER,f=e.MACRO;function s(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),d(this,n)}return s.helpers=function(n){d(s.prototype,n)},s.property=function(n,t){Object.defineProperty(s.prototype,n,t)},s.method=function(n,t){Object.defineProperty(s.prototype,n,{value:t,writable:!1,configurable:!1,enumerable:!1})},s.property(a,{value:U(),writable:!1,configurable:!1,enumerable:!1}),s.property(u,{value:{},writable:!0,configurable:!1,enumerable:!1}),s.property(f,{value:{},writable:!0,configurable:!1,enumerable:!1}),s.property(c,{value:!1,writable:!0,configurable:!1,enumerable:!1}),s.property(i,{value:!1,writable:!0,configurable:!1,enumerable:!1}),s.method("initBlocks",(function(){this[u]={}})),s.method("initMacro",(function(){this[f]={}})),s.method("getMacro",(function(){return this[f]})),s.method("getBuffer",(function(){return this[a]})),s.method("getBlocks",(function(){return this[u]})),s.method("setExtend",(function(n){this[i]=n})),s.method("getExtend",(function(){return this[i]})),s.method("setLayout",(function(n){this[c]=n})),s.method("getLayout",(function(){return this[c]})),s.method("clone",(function(n){var t=[c,i,a];return!0===n&&t.push(u),b(this,t)})),s.method("extend",(function(n){this.setExtend(!0),this.setLayout(n)})),s.method("echo",(function(){var n=this.getBuffer();[].slice.call(arguments).forEach((function(t){n(t)}))})),s.method("fn",(function(n){var t=this.getBuffer(),e=this;return function(){return t.backup(),r(n)&&n.apply(e,arguments),t.restore()}})),s.method("get",(function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();return y(r,o)?r[o]:t})),s.method("set",(function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();return this.getExtend()&&y(r,o)?r[o]:r[o]=t})),s.method("macro",(function(n,t){var e=this.getMacro(),r=this.fn(t),o=this;e[n]=function(){return o.echo(r.apply(void 0,arguments))}})),s.method("call",(function(n){var t=this.getMacro()[n],e=[].slice.call(arguments,1);if(r(t))return t.apply(t,e)})),s.method("block",(function(n,t){var e=this,r=this.getBlocks();if(r[n]=r[n]||[],r[n].push(this.fn(t)),!this.getExtend()){var o=Object.assign([],r[n]),i=function(){return o.shift()};this.echo(i()(function n(){var t=i();return t?function(){e.echo(t(n()))}:m}()))}})),s.method("include",(function(n,t,e){var r=!1===e?{}:this.clone(!0),o=d(r,t||{}),i=this.render(n,o);this.echo(i)})),s.method("use",(function(n,t){var e=this.require(n);this.echo(w(e,(function(n){var e=this.getMacro();g(n,(function(n,r){e[[t,r].join(".")]=n}))}),this))})),s.method("async",(function(n,t){this.echo(w(n,(function(n){return this.fn(t)(n)}),this))})),s.helpers(t),s.helpers({el:function(n,t,e){r(e)&&(e=this.fn(e)()),this.echo(w(e,(function(e){return B(n,t,e)}),this))},each:function(n,t){o(n)&&(n=this.get(n,[])),g(n,t)}}),s}(T,q),N.compile=S(T),N.wrapper=function(n){var t=n.export;return function(n){var e="(function(o){\n";return n.forEach((function(n){e+="o["+JSON.stringify(n.name)+"]="+String(n.content)+"\n"})),e+='})(window["'+t+'"] = window["'+t+'"] || {});\n'}}(T),N.cache=function(n){var t=n.export,e={};return{preload:function(){return!1===c()&&this.load(window[t]),this},exist:function(n){return y(e,n)},get:function(n){return e[n]},remove:function(n){delete e[n]},resolve:function(n){return Promise.resolve(this.get(n))},set:function(n,t){return e[n]=t,this},load:function(n){return d(e,n),this}}.preload()}(T),N.template=M(T,N.cache,N.compile),N},__express:function(c,u,a){r(u)&&(a=u,u={});var f=d({},(u=u||{}).settings),s=e(o,f.views,t.path),h=e(i,f["view cache"],t.cache),l=d({},f["view options"]),p=n.relative(s,c);return l.path=s,l.cache=h,N.configure(l),N.render(p,u).then((function(n){a(null,n)})).catch((function(n){a(n)}))}},N.configure(C||{}),N.helpers({require:function(n){return N.require(n,this)},render:function(n,t){return N.render(n,t)}}),N);return D}));
|
package/dist/ejs.mjs
CHANGED
|
@@ -14,15 +14,15 @@ defaults.resolver = null;
|
|
|
14
14
|
|
|
15
15
|
defaults.extension = 'ejs';
|
|
16
16
|
|
|
17
|
+
defaults.withObject = false;
|
|
18
|
+
|
|
17
19
|
defaults.vars = {
|
|
18
|
-
|
|
20
|
+
SCOPE: 'ejs',
|
|
21
|
+
EXTEND: '$$e',
|
|
19
22
|
BUFFER: '$$a',
|
|
20
|
-
OUTPUT: '$$i',
|
|
21
23
|
LAYOUT: '$$l',
|
|
22
24
|
BLOCKS: '$$b',
|
|
23
25
|
MACRO: '$$m',
|
|
24
|
-
ERROR: '$$e',
|
|
25
|
-
SCOPE: '$$s',
|
|
26
26
|
SAFE: '$$v',
|
|
27
27
|
};
|
|
28
28
|
|
|
@@ -254,6 +254,7 @@ const match = (regex, text, callback) => {
|
|
|
254
254
|
* @constructor
|
|
255
255
|
*/
|
|
256
256
|
const Compiler = (config) => {
|
|
257
|
+
const withObject = config.withObject;
|
|
257
258
|
const token = config.token;
|
|
258
259
|
const vars = config.vars;
|
|
259
260
|
const matches = [];
|
|
@@ -294,14 +295,15 @@ const Compiler = (config) => {
|
|
|
294
295
|
});
|
|
295
296
|
source += `');`;
|
|
296
297
|
source = `try{${source}}catch(e){console.info(e)}`;
|
|
297
|
-
|
|
298
|
+
if(withObject) {
|
|
299
|
+
source = `with(${SCOPE}){${source}}`;
|
|
300
|
+
}
|
|
298
301
|
source = `${BUFFER}.start();${source}return ${BUFFER}.end();`;
|
|
299
302
|
source += `\n//# sourceURL=${path}`;
|
|
300
303
|
let result = null;
|
|
301
304
|
try {
|
|
302
305
|
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
303
306
|
result.source = `(function(${SCOPE},${BUFFER},${SAFE}){\n${source}\n})`;
|
|
304
|
-
//result.source = result.toString()
|
|
305
307
|
} catch (e) {
|
|
306
308
|
console.log(e);
|
|
307
309
|
e.filename = path;
|
|
@@ -423,14 +425,20 @@ const Buffer = () => {
|
|
|
423
425
|
return buffer
|
|
424
426
|
};
|
|
425
427
|
|
|
428
|
+
/**
|
|
429
|
+
* @memberOf global
|
|
430
|
+
* @class
|
|
431
|
+
* @alias ejs
|
|
432
|
+
* @param config
|
|
433
|
+
* @param methods
|
|
434
|
+
* @return {Scope}
|
|
435
|
+
*/
|
|
436
|
+
|
|
426
437
|
const configure = (config, methods) => {
|
|
438
|
+
const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO } = config.vars;
|
|
439
|
+
|
|
427
440
|
/**
|
|
428
441
|
*
|
|
429
|
-
*/
|
|
430
|
-
const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO, SCOPE } = config.vars;
|
|
431
|
-
/**
|
|
432
|
-
* @memberOf global
|
|
433
|
-
* @name [SCOPE]
|
|
434
442
|
* @param data
|
|
435
443
|
* @constructor
|
|
436
444
|
*/
|
|
@@ -439,136 +447,77 @@ const configure = (config, methods) => {
|
|
|
439
447
|
this.initMacro();
|
|
440
448
|
extend(this, data);
|
|
441
449
|
}
|
|
442
|
-
/**
|
|
443
|
-
* @static
|
|
444
|
-
* @param methods
|
|
445
|
-
*/
|
|
446
450
|
Scope.helpers = (methods) => {
|
|
447
451
|
extend(Scope.prototype, methods);
|
|
448
452
|
};
|
|
449
|
-
/**
|
|
450
|
-
* @static
|
|
451
|
-
* @param name
|
|
452
|
-
* @param descriptor
|
|
453
|
-
*/
|
|
454
453
|
Scope.property = (name, descriptor) => {
|
|
455
454
|
Object.defineProperty(Scope.prototype, name, descriptor);
|
|
456
455
|
};
|
|
457
|
-
/**
|
|
458
|
-
* @static
|
|
459
|
-
* @param name
|
|
460
|
-
* @param method
|
|
461
|
-
*/
|
|
462
456
|
Scope.method = (name, method) => {
|
|
463
|
-
|
|
457
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
464
458
|
value: method,
|
|
465
459
|
writable: false,
|
|
466
460
|
configurable: false,
|
|
467
461
|
enumerable: false
|
|
468
|
-
})
|
|
462
|
+
});
|
|
469
463
|
};
|
|
470
|
-
/**
|
|
471
|
-
*
|
|
472
|
-
*/
|
|
473
464
|
Scope.property(BUFFER, {
|
|
474
465
|
value: Buffer(),
|
|
475
466
|
writable: false,
|
|
476
467
|
configurable: false,
|
|
477
468
|
enumerable: false
|
|
478
469
|
});
|
|
479
|
-
/**
|
|
480
|
-
*
|
|
481
|
-
*/
|
|
482
470
|
Scope.property(BLOCKS, {
|
|
483
471
|
value: {},
|
|
484
472
|
writable: true,
|
|
485
473
|
configurable: false,
|
|
486
474
|
enumerable: false
|
|
487
475
|
});
|
|
488
|
-
/**
|
|
489
|
-
*
|
|
490
|
-
*/
|
|
491
476
|
Scope.property(MACRO, {
|
|
492
477
|
value: {},
|
|
493
478
|
writable: true,
|
|
494
479
|
configurable: false,
|
|
495
480
|
enumerable: false
|
|
496
481
|
});
|
|
497
|
-
/**
|
|
498
|
-
*
|
|
499
|
-
*/
|
|
500
482
|
Scope.property(LAYOUT, {
|
|
501
483
|
value: false,
|
|
502
484
|
writable: true,
|
|
503
485
|
configurable: false,
|
|
504
486
|
enumerable: false
|
|
505
487
|
});
|
|
506
|
-
/**
|
|
507
|
-
*
|
|
508
|
-
*/
|
|
509
488
|
Scope.property(EXTEND, {
|
|
510
489
|
value: false,
|
|
511
490
|
writable: true,
|
|
512
491
|
configurable: false,
|
|
513
492
|
enumerable: false
|
|
514
493
|
});
|
|
515
|
-
/**
|
|
516
|
-
*
|
|
517
|
-
*/
|
|
518
494
|
Scope.method('initBlocks', function() {
|
|
519
495
|
this[BLOCKS] = {};
|
|
520
496
|
});
|
|
521
|
-
/**
|
|
522
|
-
*
|
|
523
|
-
*/
|
|
524
497
|
Scope.method('initMacro', function() {
|
|
525
498
|
this[MACRO] = {};
|
|
526
499
|
});
|
|
527
|
-
/**
|
|
528
|
-
*
|
|
529
|
-
*/
|
|
530
500
|
Scope.method('getMacro', function() {
|
|
531
501
|
return this[MACRO]
|
|
532
502
|
});
|
|
533
|
-
/**
|
|
534
|
-
*
|
|
535
|
-
*/
|
|
536
503
|
Scope.method('getBuffer', function() {
|
|
537
504
|
return this[BUFFER]
|
|
538
505
|
});
|
|
539
|
-
/**
|
|
540
|
-
*
|
|
541
|
-
*/
|
|
542
506
|
Scope.method('getBlocks', function() {
|
|
543
507
|
return this[BLOCKS]
|
|
544
508
|
});
|
|
545
|
-
/**
|
|
546
|
-
*
|
|
547
|
-
*/
|
|
548
509
|
Scope.method('setExtend', function(value) {
|
|
549
510
|
this[EXTEND] = value;
|
|
550
511
|
});
|
|
551
|
-
/**
|
|
552
|
-
*
|
|
553
|
-
*/
|
|
554
512
|
Scope.method('getExtend', function() {
|
|
555
513
|
return this[EXTEND]
|
|
556
514
|
});
|
|
557
|
-
/**
|
|
558
|
-
*
|
|
559
|
-
*/
|
|
560
515
|
Scope.method('setLayout', function(layout) {
|
|
561
516
|
this[LAYOUT] = layout;
|
|
562
517
|
});
|
|
563
|
-
/**
|
|
564
|
-
*
|
|
565
|
-
*/
|
|
566
518
|
Scope.method('getLayout', function() {
|
|
567
519
|
return this[LAYOUT]
|
|
568
520
|
});
|
|
569
|
-
/**
|
|
570
|
-
*
|
|
571
|
-
*/
|
|
572
521
|
Scope.method('clone', function(exclude_blocks) {
|
|
573
522
|
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
574
523
|
if (exclude_blocks === true) {
|
|
@@ -576,19 +525,10 @@ const configure = (config, methods) => {
|
|
|
576
525
|
}
|
|
577
526
|
return omit(this, filter)
|
|
578
527
|
});
|
|
579
|
-
/**
|
|
580
|
-
* @methodOf global
|
|
581
|
-
* @function extend
|
|
582
|
-
* @param layout
|
|
583
|
-
*/
|
|
584
528
|
Scope.method('extend', function(layout) {
|
|
585
529
|
this.setExtend(true);
|
|
586
530
|
this.setLayout(layout);
|
|
587
531
|
});
|
|
588
|
-
/**
|
|
589
|
-
* @memberOf global
|
|
590
|
-
* @function echo
|
|
591
|
-
*/
|
|
592
532
|
Scope.method('echo', function() {
|
|
593
533
|
const buffer = this.getBuffer();
|
|
594
534
|
const params = [].slice.call(arguments);
|
|
@@ -596,11 +536,6 @@ const configure = (config, methods) => {
|
|
|
596
536
|
buffer(item);
|
|
597
537
|
});
|
|
598
538
|
});
|
|
599
|
-
/**
|
|
600
|
-
* @memberOf global
|
|
601
|
-
* @function fn
|
|
602
|
-
* @param callback
|
|
603
|
-
*/
|
|
604
539
|
Scope.method('fn', function(callback) {
|
|
605
540
|
const buffer = this.getBuffer();
|
|
606
541
|
const context = this;
|
|
@@ -612,24 +547,12 @@ const configure = (config, methods) => {
|
|
|
612
547
|
return buffer.restore()
|
|
613
548
|
}
|
|
614
549
|
});
|
|
615
|
-
/**
|
|
616
|
-
* @memberOf global
|
|
617
|
-
* @function get
|
|
618
|
-
* @param name
|
|
619
|
-
* @param [defaults]
|
|
620
|
-
*/
|
|
621
550
|
Scope.method('get', function(name,defaults) {
|
|
622
551
|
const path = getPath(this, name);
|
|
623
552
|
const result = path.shift();
|
|
624
553
|
const prop = path.pop();
|
|
625
554
|
return hasProp(result, prop) ? result[prop] : defaults
|
|
626
555
|
});
|
|
627
|
-
/**
|
|
628
|
-
* @memberOf global
|
|
629
|
-
* @function set
|
|
630
|
-
* @param name
|
|
631
|
-
* @param value
|
|
632
|
-
*/
|
|
633
556
|
Scope.method('set', function(name,value) {
|
|
634
557
|
const path = getPath(this, name);
|
|
635
558
|
const result = path.shift();
|
|
@@ -639,12 +562,6 @@ const configure = (config, methods) => {
|
|
|
639
562
|
}
|
|
640
563
|
return result[prop] = value
|
|
641
564
|
});
|
|
642
|
-
/**
|
|
643
|
-
* @memberOf global
|
|
644
|
-
* @function macro
|
|
645
|
-
* @param name
|
|
646
|
-
* @param callback
|
|
647
|
-
*/
|
|
648
565
|
Scope.method('macro', function(name, callback) {
|
|
649
566
|
const list = this.getMacro();
|
|
650
567
|
const macro = this.fn(callback);
|
|
@@ -653,12 +570,6 @@ const configure = (config, methods) => {
|
|
|
653
570
|
return context.echo(macro.apply(undefined, arguments))
|
|
654
571
|
};
|
|
655
572
|
});
|
|
656
|
-
/**
|
|
657
|
-
* @memberOf global
|
|
658
|
-
* @function call
|
|
659
|
-
* @param name
|
|
660
|
-
* @param {...*} args
|
|
661
|
-
*/
|
|
662
573
|
Scope.method('call', function(name) {
|
|
663
574
|
const list = this.getMacro();
|
|
664
575
|
const macro = list[name];
|
|
@@ -667,12 +578,6 @@ const configure = (config, methods) => {
|
|
|
667
578
|
return macro.apply(macro, params)
|
|
668
579
|
}
|
|
669
580
|
});
|
|
670
|
-
/**
|
|
671
|
-
* @memberOf global
|
|
672
|
-
* @function block
|
|
673
|
-
* @param name
|
|
674
|
-
* @param callback
|
|
675
|
-
*/
|
|
676
581
|
Scope.method('block',function(name,callback){
|
|
677
582
|
const blocks = this.getBlocks();
|
|
678
583
|
blocks[name] = blocks[name] || [];
|
|
@@ -694,25 +599,12 @@ const configure = (config, methods) => {
|
|
|
694
599
|
};
|
|
695
600
|
this.echo(current()(next()));
|
|
696
601
|
});
|
|
697
|
-
/**
|
|
698
|
-
* @memberOf global
|
|
699
|
-
* @function include
|
|
700
|
-
* @param path
|
|
701
|
-
* @param [data]
|
|
702
|
-
* @param [cx]
|
|
703
|
-
*/
|
|
704
602
|
Scope.method('include',function(path, data, cx){
|
|
705
603
|
const context = cx === false ? {} : this.clone(true);
|
|
706
604
|
const params = extend(context, data || {});
|
|
707
605
|
const promise = this.render(path, params);
|
|
708
606
|
this.echo(promise);
|
|
709
607
|
});
|
|
710
|
-
/**
|
|
711
|
-
* @memberOf global
|
|
712
|
-
* @function use
|
|
713
|
-
* @param path
|
|
714
|
-
* @param namespace
|
|
715
|
-
*/
|
|
716
608
|
Scope.method('use',function(path, namespace){
|
|
717
609
|
const promise = this.require(path);
|
|
718
610
|
this.echo(resolve$1(promise,function(exports){
|
|
@@ -722,12 +614,6 @@ const configure = (config, methods) => {
|
|
|
722
614
|
});
|
|
723
615
|
},this));
|
|
724
616
|
});
|
|
725
|
-
/**
|
|
726
|
-
* @memberOf global
|
|
727
|
-
* @function async
|
|
728
|
-
* @param promise
|
|
729
|
-
* @param callback
|
|
730
|
-
*/
|
|
731
617
|
Scope.method('async',function(promise,callback){
|
|
732
618
|
this.echo(
|
|
733
619
|
resolve$1(promise, function(data) {
|
|
@@ -737,12 +623,6 @@ const configure = (config, methods) => {
|
|
|
737
623
|
});
|
|
738
624
|
Scope.helpers(methods);
|
|
739
625
|
Scope.helpers({
|
|
740
|
-
/**
|
|
741
|
-
* @memberOf global
|
|
742
|
-
* @param tag
|
|
743
|
-
* @param attr
|
|
744
|
-
* @param content
|
|
745
|
-
*/
|
|
746
626
|
el(tag, attr, content) {
|
|
747
627
|
if (isFunction(content)) {
|
|
748
628
|
content = this.fn(content)();
|
|
@@ -753,11 +633,6 @@ const configure = (config, methods) => {
|
|
|
753
633
|
}, this)
|
|
754
634
|
);
|
|
755
635
|
},
|
|
756
|
-
/**
|
|
757
|
-
* @memberOf global
|
|
758
|
-
* @param object
|
|
759
|
-
* @param callback
|
|
760
|
-
*/
|
|
761
636
|
each(object, callback) {
|
|
762
637
|
if (isString(object)) {
|
|
763
638
|
object = this.get(object, []);
|