@kosatyi/ejs 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ejs.cjs CHANGED
@@ -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
- EXTEND: '$$$',
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
- source = "with(".concat(SCOPE, "){").concat(source, "}");
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;
@@ -374,158 +375,89 @@ var Buffer = function Buffer() {
374
375
  };
375
376
 
376
377
  var configure = function configure(config, methods) {
377
- /**
378
- *
379
- */
380
378
  var _config$vars = config.vars,
381
379
  EXTEND = _config$vars.EXTEND,
382
380
  LAYOUT = _config$vars.LAYOUT,
383
381
  BLOCKS = _config$vars.BLOCKS,
384
382
  BUFFER = _config$vars.BUFFER,
385
383
  MACRO = _config$vars.MACRO;
386
- _config$vars.SCOPE;
387
- /**
388
- * @memberOf global
389
- * @name [SCOPE]
390
- * @param data
391
- * @constructor
392
- */
393
384
  function Scope() {
394
385
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
395
386
  this.initBlocks();
396
387
  this.initMacro();
397
388
  extend(this, data);
398
389
  }
399
- /**
400
- * @static
401
- * @param methods
402
- */
403
390
  Scope.helpers = function (methods) {
404
391
  extend(Scope.prototype, methods);
405
392
  };
406
- /**
407
- * @static
408
- * @param name
409
- * @param descriptor
410
- */
411
393
  Scope.property = function (name, descriptor) {
412
394
  Object.defineProperty(Scope.prototype, name, descriptor);
413
395
  };
414
- /**
415
- * @static
416
- * @param name
417
- * @param method
418
- */
419
396
  Scope.method = function (name, method) {
420
- return Scope.property(name, {
397
+ Object.defineProperty(Scope.prototype, name, {
421
398
  value: method,
422
399
  writable: false,
423
400
  configurable: false,
424
401
  enumerable: false
425
402
  });
426
403
  };
427
- /**
428
- *
429
- */
430
404
  Scope.property(BUFFER, {
431
405
  value: Buffer(),
432
406
  writable: false,
433
407
  configurable: false,
434
408
  enumerable: false
435
409
  });
436
- /**
437
- *
438
- */
439
410
  Scope.property(BLOCKS, {
440
411
  value: {},
441
412
  writable: true,
442
413
  configurable: false,
443
414
  enumerable: false
444
415
  });
445
- /**
446
- *
447
- */
448
416
  Scope.property(MACRO, {
449
417
  value: {},
450
418
  writable: true,
451
419
  configurable: false,
452
420
  enumerable: false
453
421
  });
454
- /**
455
- *
456
- */
457
422
  Scope.property(LAYOUT, {
458
423
  value: false,
459
424
  writable: true,
460
425
  configurable: false,
461
426
  enumerable: false
462
427
  });
463
- /**
464
- *
465
- */
466
428
  Scope.property(EXTEND, {
467
429
  value: false,
468
430
  writable: true,
469
431
  configurable: false,
470
432
  enumerable: false
471
433
  });
472
- /**
473
- *
474
- */
475
434
  Scope.method('initBlocks', function () {
476
435
  this[BLOCKS] = {};
477
436
  });
478
- /**
479
- *
480
- */
481
437
  Scope.method('initMacro', function () {
482
438
  this[MACRO] = {};
483
439
  });
484
- /**
485
- *
486
- */
487
440
  Scope.method('getMacro', function () {
488
441
  return this[MACRO];
489
442
  });
490
- /**
491
- *
492
- */
493
443
  Scope.method('getBuffer', function () {
494
444
  return this[BUFFER];
495
445
  });
496
- /**
497
- *
498
- */
499
446
  Scope.method('getBlocks', function () {
500
447
  return this[BLOCKS];
501
448
  });
502
- /**
503
- *
504
- */
505
449
  Scope.method('setExtend', function (value) {
506
450
  this[EXTEND] = value;
507
451
  });
508
- /**
509
- *
510
- */
511
452
  Scope.method('getExtend', function () {
512
453
  return this[EXTEND];
513
454
  });
514
- /**
515
- *
516
- */
517
455
  Scope.method('setLayout', function (layout) {
518
456
  this[LAYOUT] = layout;
519
457
  });
520
- /**
521
- *
522
- */
523
458
  Scope.method('getLayout', function () {
524
459
  return this[LAYOUT];
525
460
  });
526
- /**
527
- *
528
- */
529
461
  Scope.method('clone', function (exclude_blocks) {
530
462
  var filter = [LAYOUT, EXTEND, BUFFER];
531
463
  if (exclude_blocks === true) {
@@ -533,19 +465,10 @@ var configure = function configure(config, methods) {
533
465
  }
534
466
  return omit(this, filter);
535
467
  });
536
- /**
537
- * @methodOf global
538
- * @function extend
539
- * @param layout
540
- */
541
468
  Scope.method('extend', function (layout) {
542
469
  this.setExtend(true);
543
470
  this.setLayout(layout);
544
471
  });
545
- /**
546
- * @memberOf global
547
- * @function echo
548
- */
549
472
  Scope.method('echo', function () {
550
473
  var buffer = this.getBuffer();
551
474
  var params = [].slice.call(arguments);
@@ -553,11 +476,6 @@ var configure = function configure(config, methods) {
553
476
  buffer(item);
554
477
  });
555
478
  });
556
- /**
557
- * @memberOf global
558
- * @function fn
559
- * @param callback
560
- */
561
479
  Scope.method('fn', function (callback) {
562
480
  var buffer = this.getBuffer();
563
481
  var context = this;
@@ -569,24 +487,12 @@ var configure = function configure(config, methods) {
569
487
  return buffer.restore();
570
488
  };
571
489
  });
572
- /**
573
- * @memberOf global
574
- * @function get
575
- * @param name
576
- * @param [defaults]
577
- */
578
490
  Scope.method('get', function (name, defaults) {
579
491
  var path = getPath(this, name);
580
492
  var result = path.shift();
581
493
  var prop = path.pop();
582
494
  return hasProp(result, prop) ? result[prop] : defaults;
583
495
  });
584
- /**
585
- * @memberOf global
586
- * @function set
587
- * @param name
588
- * @param value
589
- */
590
496
  Scope.method('set', function (name, value) {
591
497
  var path = getPath(this, name);
592
498
  var result = path.shift();
@@ -596,12 +502,6 @@ var configure = function configure(config, methods) {
596
502
  }
597
503
  return result[prop] = value;
598
504
  });
599
- /**
600
- * @memberOf global
601
- * @function macro
602
- * @param name
603
- * @param callback
604
- */
605
505
  Scope.method('macro', function (name, callback) {
606
506
  var list = this.getMacro();
607
507
  var macro = this.fn(callback);
@@ -610,12 +510,6 @@ var configure = function configure(config, methods) {
610
510
  return context.echo(macro.apply(undefined, arguments));
611
511
  };
612
512
  });
613
- /**
614
- * @memberOf global
615
- * @function call
616
- * @param name
617
- * @param {...*} args
618
- */
619
513
  Scope.method('call', function (name) {
620
514
  var list = this.getMacro();
621
515
  var macro = list[name];
@@ -624,12 +518,6 @@ var configure = function configure(config, methods) {
624
518
  return macro.apply(macro, params);
625
519
  }
626
520
  });
627
- /**
628
- * @memberOf global
629
- * @function block
630
- * @param name
631
- * @param callback
632
- */
633
521
  Scope.method('block', function (name, callback) {
634
522
  var _this = this;
635
523
  var blocks = this.getBlocks();
@@ -652,25 +540,12 @@ var configure = function configure(config, methods) {
652
540
  };
653
541
  this.echo(current()(next()));
654
542
  });
655
- /**
656
- * @memberOf global
657
- * @function include
658
- * @param path
659
- * @param [data]
660
- * @param [cx]
661
- */
662
543
  Scope.method('include', function (path, data, cx) {
663
544
  var context = cx === false ? {} : this.clone(true);
664
545
  var params = extend(context, data || {});
665
546
  var promise = this.render(path, params);
666
547
  this.echo(promise);
667
548
  });
668
- /**
669
- * @memberOf global
670
- * @function use
671
- * @param path
672
- * @param namespace
673
- */
674
549
  Scope.method('use', function (path, namespace) {
675
550
  var promise = this.require(path);
676
551
  this.echo(resolve$1(promise, function (exports) {
@@ -680,45 +555,26 @@ var configure = function configure(config, methods) {
680
555
  });
681
556
  }, this));
682
557
  });
683
- /**
684
- * @memberOf global
685
- * @function async
686
- * @param promise
687
- * @param callback
688
- */
689
558
  Scope.method('async', function (promise, callback) {
690
559
  this.echo(resolve$1(promise, function (data) {
691
560
  return this.fn(callback)(data);
692
561
  }, this));
693
562
  });
694
- Scope.helpers(methods);
695
- Scope.helpers({
696
- /**
697
- * @memberOf global
698
- * @param tag
699
- * @param attr
700
- * @param content
701
- */
702
- el: function el(tag, attr, content) {
703
- if (isFunction(content)) {
704
- content = this.fn(content)();
705
- }
706
- this.echo(resolve$1(content, function (content) {
707
- return element(tag, attr, content);
708
- }, this));
709
- },
710
- /**
711
- * @memberOf global
712
- * @param object
713
- * @param callback
714
- */
715
- each: function each$1(object, callback) {
716
- if (isString(object)) {
717
- object = this.get(object, []);
718
- }
719
- each(object, callback);
563
+ Scope.method('el', function (tag, attr, content) {
564
+ if (isFunction(content)) {
565
+ content = this.fn(content)();
720
566
  }
567
+ this.echo(resolve$1(content, function (content) {
568
+ return element(tag, attr, content);
569
+ }, this));
721
570
  });
571
+ Scope.method('each', function (object, callback) {
572
+ if (isString(object)) {
573
+ object = this.get(object, []);
574
+ }
575
+ each(object, callback);
576
+ });
577
+ Scope.helpers(methods);
722
578
  return Scope;
723
579
  };
724
580
 
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
- EXTEND: '$$$',
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
- source = "with(".concat(SCOPE, "){").concat(source, "}");
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;
@@ -370,158 +371,89 @@
370
371
  };
371
372
 
372
373
  var configure = function configure(config, methods) {
373
- /**
374
- *
375
- */
376
374
  var _config$vars = config.vars,
377
375
  EXTEND = _config$vars.EXTEND,
378
376
  LAYOUT = _config$vars.LAYOUT,
379
377
  BLOCKS = _config$vars.BLOCKS,
380
378
  BUFFER = _config$vars.BUFFER,
381
379
  MACRO = _config$vars.MACRO;
382
- _config$vars.SCOPE;
383
- /**
384
- * @memberOf global
385
- * @name [SCOPE]
386
- * @param data
387
- * @constructor
388
- */
389
380
  function Scope() {
390
381
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
391
382
  this.initBlocks();
392
383
  this.initMacro();
393
384
  extend(this, data);
394
385
  }
395
- /**
396
- * @static
397
- * @param methods
398
- */
399
386
  Scope.helpers = function (methods) {
400
387
  extend(Scope.prototype, methods);
401
388
  };
402
- /**
403
- * @static
404
- * @param name
405
- * @param descriptor
406
- */
407
389
  Scope.property = function (name, descriptor) {
408
390
  Object.defineProperty(Scope.prototype, name, descriptor);
409
391
  };
410
- /**
411
- * @static
412
- * @param name
413
- * @param method
414
- */
415
392
  Scope.method = function (name, method) {
416
- return Scope.property(name, {
393
+ Object.defineProperty(Scope.prototype, name, {
417
394
  value: method,
418
395
  writable: false,
419
396
  configurable: false,
420
397
  enumerable: false
421
398
  });
422
399
  };
423
- /**
424
- *
425
- */
426
400
  Scope.property(BUFFER, {
427
401
  value: Buffer(),
428
402
  writable: false,
429
403
  configurable: false,
430
404
  enumerable: false
431
405
  });
432
- /**
433
- *
434
- */
435
406
  Scope.property(BLOCKS, {
436
407
  value: {},
437
408
  writable: true,
438
409
  configurable: false,
439
410
  enumerable: false
440
411
  });
441
- /**
442
- *
443
- */
444
412
  Scope.property(MACRO, {
445
413
  value: {},
446
414
  writable: true,
447
415
  configurable: false,
448
416
  enumerable: false
449
417
  });
450
- /**
451
- *
452
- */
453
418
  Scope.property(LAYOUT, {
454
419
  value: false,
455
420
  writable: true,
456
421
  configurable: false,
457
422
  enumerable: false
458
423
  });
459
- /**
460
- *
461
- */
462
424
  Scope.property(EXTEND, {
463
425
  value: false,
464
426
  writable: true,
465
427
  configurable: false,
466
428
  enumerable: false
467
429
  });
468
- /**
469
- *
470
- */
471
430
  Scope.method('initBlocks', function () {
472
431
  this[BLOCKS] = {};
473
432
  });
474
- /**
475
- *
476
- */
477
433
  Scope.method('initMacro', function () {
478
434
  this[MACRO] = {};
479
435
  });
480
- /**
481
- *
482
- */
483
436
  Scope.method('getMacro', function () {
484
437
  return this[MACRO];
485
438
  });
486
- /**
487
- *
488
- */
489
439
  Scope.method('getBuffer', function () {
490
440
  return this[BUFFER];
491
441
  });
492
- /**
493
- *
494
- */
495
442
  Scope.method('getBlocks', function () {
496
443
  return this[BLOCKS];
497
444
  });
498
- /**
499
- *
500
- */
501
445
  Scope.method('setExtend', function (value) {
502
446
  this[EXTEND] = value;
503
447
  });
504
- /**
505
- *
506
- */
507
448
  Scope.method('getExtend', function () {
508
449
  return this[EXTEND];
509
450
  });
510
- /**
511
- *
512
- */
513
451
  Scope.method('setLayout', function (layout) {
514
452
  this[LAYOUT] = layout;
515
453
  });
516
- /**
517
- *
518
- */
519
454
  Scope.method('getLayout', function () {
520
455
  return this[LAYOUT];
521
456
  });
522
- /**
523
- *
524
- */
525
457
  Scope.method('clone', function (exclude_blocks) {
526
458
  var filter = [LAYOUT, EXTEND, BUFFER];
527
459
  if (exclude_blocks === true) {
@@ -529,19 +461,10 @@
529
461
  }
530
462
  return omit(this, filter);
531
463
  });
532
- /**
533
- * @methodOf global
534
- * @function extend
535
- * @param layout
536
- */
537
464
  Scope.method('extend', function (layout) {
538
465
  this.setExtend(true);
539
466
  this.setLayout(layout);
540
467
  });
541
- /**
542
- * @memberOf global
543
- * @function echo
544
- */
545
468
  Scope.method('echo', function () {
546
469
  var buffer = this.getBuffer();
547
470
  var params = [].slice.call(arguments);
@@ -549,11 +472,6 @@
549
472
  buffer(item);
550
473
  });
551
474
  });
552
- /**
553
- * @memberOf global
554
- * @function fn
555
- * @param callback
556
- */
557
475
  Scope.method('fn', function (callback) {
558
476
  var buffer = this.getBuffer();
559
477
  var context = this;
@@ -565,24 +483,12 @@
565
483
  return buffer.restore();
566
484
  };
567
485
  });
568
- /**
569
- * @memberOf global
570
- * @function get
571
- * @param name
572
- * @param [defaults]
573
- */
574
486
  Scope.method('get', function (name, defaults) {
575
487
  var path = getPath(this, name);
576
488
  var result = path.shift();
577
489
  var prop = path.pop();
578
490
  return hasProp(result, prop) ? result[prop] : defaults;
579
491
  });
580
- /**
581
- * @memberOf global
582
- * @function set
583
- * @param name
584
- * @param value
585
- */
586
492
  Scope.method('set', function (name, value) {
587
493
  var path = getPath(this, name);
588
494
  var result = path.shift();
@@ -592,12 +498,6 @@
592
498
  }
593
499
  return result[prop] = value;
594
500
  });
595
- /**
596
- * @memberOf global
597
- * @function macro
598
- * @param name
599
- * @param callback
600
- */
601
501
  Scope.method('macro', function (name, callback) {
602
502
  var list = this.getMacro();
603
503
  var macro = this.fn(callback);
@@ -606,12 +506,6 @@
606
506
  return context.echo(macro.apply(undefined, arguments));
607
507
  };
608
508
  });
609
- /**
610
- * @memberOf global
611
- * @function call
612
- * @param name
613
- * @param {...*} args
614
- */
615
509
  Scope.method('call', function (name) {
616
510
  var list = this.getMacro();
617
511
  var macro = list[name];
@@ -620,12 +514,6 @@
620
514
  return macro.apply(macro, params);
621
515
  }
622
516
  });
623
- /**
624
- * @memberOf global
625
- * @function block
626
- * @param name
627
- * @param callback
628
- */
629
517
  Scope.method('block', function (name, callback) {
630
518
  var _this = this;
631
519
  var blocks = this.getBlocks();
@@ -648,25 +536,12 @@
648
536
  };
649
537
  this.echo(current()(next()));
650
538
  });
651
- /**
652
- * @memberOf global
653
- * @function include
654
- * @param path
655
- * @param [data]
656
- * @param [cx]
657
- */
658
539
  Scope.method('include', function (path, data, cx) {
659
540
  var context = cx === false ? {} : this.clone(true);
660
541
  var params = extend(context, data || {});
661
542
  var promise = this.render(path, params);
662
543
  this.echo(promise);
663
544
  });
664
- /**
665
- * @memberOf global
666
- * @function use
667
- * @param path
668
- * @param namespace
669
- */
670
545
  Scope.method('use', function (path, namespace) {
671
546
  var promise = this.require(path);
672
547
  this.echo(resolve$1(promise, function (exports) {
@@ -676,45 +551,26 @@
676
551
  });
677
552
  }, this));
678
553
  });
679
- /**
680
- * @memberOf global
681
- * @function async
682
- * @param promise
683
- * @param callback
684
- */
685
554
  Scope.method('async', function (promise, callback) {
686
555
  this.echo(resolve$1(promise, function (data) {
687
556
  return this.fn(callback)(data);
688
557
  }, this));
689
558
  });
690
- Scope.helpers(methods);
691
- Scope.helpers({
692
- /**
693
- * @memberOf global
694
- * @param tag
695
- * @param attr
696
- * @param content
697
- */
698
- el: function el(tag, attr, content) {
699
- if (isFunction(content)) {
700
- content = this.fn(content)();
701
- }
702
- this.echo(resolve$1(content, function (content) {
703
- return element(tag, attr, content);
704
- }, this));
705
- },
706
- /**
707
- * @memberOf global
708
- * @param object
709
- * @param callback
710
- */
711
- each: function each$1(object, callback) {
712
- if (isString(object)) {
713
- object = this.get(object, []);
714
- }
715
- each(object, callback);
559
+ Scope.method('el', function (tag, attr, content) {
560
+ if (isFunction(content)) {
561
+ content = this.fn(content)();
716
562
  }
563
+ this.echo(resolve$1(content, function (content) {
564
+ return element(tag, attr, content);
565
+ }, this));
717
566
  });
567
+ Scope.method('each', function (object, callback) {
568
+ if (isString(object)) {
569
+ object = this.get(object, []);
570
+ }
571
+ each(object, callback);
572
+ });
573
+ Scope.helpers(methods);
718
574
  return Scope;
719
575
  };
720
576
 
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:{EXTEND:"$$$",BUFFER:"$$a",OUTPUT:"$$i",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",ERROR:"$$e",SCOPE:"$$s",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={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},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)w(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}))},y=function(n,t,e){return Promise.resolve(n).then(t.bind(e))},w=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=">";function F(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([O,n,E,i,k].join("")),e&&r.push(e instanceof Array?e.join(""):e),o&&r.push([O,$,n,k].join("")),r.join("")}var B=[{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,"('")}}],R=function(n){var t=n.token,e=n.vars,r=[],o=[],i={match:"[ \\t]*",start:[t.start,"_"],end:["_",t.end]};B.forEach((function(n){r.push(t.start.concat(n.symbol).concat(t.regex).concat(t.end)),o.push(n.format.bind(e))}));var c=new RegExp(r.join("|").concat("|$"),"g"),a=new RegExp([i.match,i.start].join(""),"gm"),f=new RegExp([i.end,i.match].join(""),"gm");return function(n,t){var r=e.SCOPE,s=e.SAFE,l=e.BUFFER;n=(n=n.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(a,i.start).replace(f,i.end);var p="".concat(l,"('");!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}))}(c,n,(function(t,e,r){p+=(""+n.slice(e,r)).replace(h,(function(n){return"\\"+u[n]})),t.forEach((function(n,t){n&&(p+=o[t](n))}))})),p="try{".concat(p+="');","}catch(e){console.info(e)}"),p="with(".concat(r,"){").concat(p,"}"),p="".concat(l,".start();").concat(p,"return ").concat(l,".end();"),p+="\n//# sourceURL=".concat(t);var v=null;try{(v=new Function(r,l,s,p)).source="(function(".concat(r,",").concat(l,",").concat(s,"){\n").concat(p,"\n})")}catch(n){throw console.log(n),n.filename=t,n.source=p,n}return v}},S=function(n){return window.fetch(n).then((function(n){return n.text()}))},A=function(t){return new Promise((function(e,r){n.readFile(t,(function(n,t){n?r(n):e(t.toString())}))}))},P=function(t,e){return n.watch(".",{cwd:t}).on("change",(function(n){e.remove(n)})).on("error",(function(n){console.log("watcher error: "+n)}))},L=function(n,t,e){var o=n.path;n.token;var i=r(n.resolver)?n.resolver:c()?A:S,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()&&P(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)}},M=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(),M(e)},e.error=function(n){throw n},e.end=function(){return M(t)},e};var T,C,q,_,N,D=(C={},q={},_=function(n,t){var e=n.split(".").pop();return e!==t&&(n=[n,t].join(".")),n},N={element:F,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,C.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,C.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 C.export=e(o,t.export,n.export),C.path=e(o,t.path,n.path),C.resolver=e(r,t.resolver,n.resolver),C.extension=e(o,t.extension,n.extension),C.token=d({},t.token,n.token),C.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 e.SCOPE,s.helpers=function(n){d(s.prototype,n)},s.property=function(n,t){Object.defineProperty(s.prototype,n,t)},s.method=function(n,t){return s.property(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 w(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()&&w(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(y(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(y(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(y(e,(function(e){return F(n,t,e)}),this))},each:function(n,t){o(n)&&(n=this.get(n,[])),g(n,t)}}),s}(C,q),N.compile=R(C),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'}}(C),N.cache=function(n){var t=n.export,e={};return{preload:function(){return!1===c()&&this.load(window[t]),this},exist:function(n){return w(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()}(C),N.template=L(C,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(T||{}),N.helpers({require:function(n){return N.require(n,this)},render:function(n,t){return N.render(n,t)}}),N);return D}));
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={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},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.method("el",(function(n,t,e){r(e)&&(e=this.fn(e)()),this.echo(w(e,(function(e){return B(n,t,e)}),this))})),s.method("each",(function(n,t){o(n)&&(n=this.get(n,[])),g(n,t)})),s.helpers(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
- EXTEND: '$$$',
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
- source = `with(${SCOPE}){${source}}`;
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;
@@ -424,151 +426,83 @@ const Buffer = () => {
424
426
  };
425
427
 
426
428
  const configure = (config, methods) => {
427
- /**
428
- *
429
- */
430
- const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO, SCOPE } = config.vars;
431
- /**
432
- * @memberOf global
433
- * @name [SCOPE]
434
- * @param data
435
- * @constructor
436
- */
429
+ const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO } = config.vars;
437
430
  function Scope(data = {}) {
438
431
  this.initBlocks();
439
432
  this.initMacro();
440
433
  extend(this, data);
441
434
  }
442
- /**
443
- * @static
444
- * @param methods
445
- */
446
435
  Scope.helpers = (methods) => {
447
436
  extend(Scope.prototype, methods);
448
437
  };
449
- /**
450
- * @static
451
- * @param name
452
- * @param descriptor
453
- */
454
438
  Scope.property = (name, descriptor) => {
455
439
  Object.defineProperty(Scope.prototype, name, descriptor);
456
440
  };
457
- /**
458
- * @static
459
- * @param name
460
- * @param method
461
- */
462
441
  Scope.method = (name, method) => {
463
- return Scope.property(name,{
442
+ Object.defineProperty(Scope.prototype, name, {
464
443
  value: method,
465
444
  writable: false,
466
445
  configurable: false,
467
446
  enumerable: false
468
- })
447
+ });
469
448
  };
470
- /**
471
- *
472
- */
473
449
  Scope.property(BUFFER, {
474
450
  value: Buffer(),
475
451
  writable: false,
476
452
  configurable: false,
477
453
  enumerable: false
478
454
  });
479
- /**
480
- *
481
- */
482
455
  Scope.property(BLOCKS, {
483
456
  value: {},
484
457
  writable: true,
485
458
  configurable: false,
486
459
  enumerable: false
487
460
  });
488
- /**
489
- *
490
- */
491
461
  Scope.property(MACRO, {
492
462
  value: {},
493
463
  writable: true,
494
464
  configurable: false,
495
465
  enumerable: false
496
466
  });
497
- /**
498
- *
499
- */
500
467
  Scope.property(LAYOUT, {
501
468
  value: false,
502
469
  writable: true,
503
470
  configurable: false,
504
471
  enumerable: false
505
472
  });
506
- /**
507
- *
508
- */
509
473
  Scope.property(EXTEND, {
510
474
  value: false,
511
475
  writable: true,
512
476
  configurable: false,
513
477
  enumerable: false
514
478
  });
515
- /**
516
- *
517
- */
518
479
  Scope.method('initBlocks', function() {
519
480
  this[BLOCKS] = {};
520
481
  });
521
- /**
522
- *
523
- */
524
482
  Scope.method('initMacro', function() {
525
483
  this[MACRO] = {};
526
484
  });
527
- /**
528
- *
529
- */
530
485
  Scope.method('getMacro', function() {
531
486
  return this[MACRO]
532
487
  });
533
- /**
534
- *
535
- */
536
488
  Scope.method('getBuffer', function() {
537
489
  return this[BUFFER]
538
490
  });
539
- /**
540
- *
541
- */
542
491
  Scope.method('getBlocks', function() {
543
492
  return this[BLOCKS]
544
493
  });
545
- /**
546
- *
547
- */
548
494
  Scope.method('setExtend', function(value) {
549
495
  this[EXTEND] = value;
550
496
  });
551
- /**
552
- *
553
- */
554
497
  Scope.method('getExtend', function() {
555
498
  return this[EXTEND]
556
499
  });
557
- /**
558
- *
559
- */
560
500
  Scope.method('setLayout', function(layout) {
561
501
  this[LAYOUT] = layout;
562
502
  });
563
- /**
564
- *
565
- */
566
503
  Scope.method('getLayout', function() {
567
504
  return this[LAYOUT]
568
505
  });
569
- /**
570
- *
571
- */
572
506
  Scope.method('clone', function(exclude_blocks) {
573
507
  const filter = [LAYOUT, EXTEND, BUFFER];
574
508
  if (exclude_blocks === true) {
@@ -576,19 +510,10 @@ const configure = (config, methods) => {
576
510
  }
577
511
  return omit(this, filter)
578
512
  });
579
- /**
580
- * @methodOf global
581
- * @function extend
582
- * @param layout
583
- */
584
513
  Scope.method('extend', function(layout) {
585
514
  this.setExtend(true);
586
515
  this.setLayout(layout);
587
516
  });
588
- /**
589
- * @memberOf global
590
- * @function echo
591
- */
592
517
  Scope.method('echo', function() {
593
518
  const buffer = this.getBuffer();
594
519
  const params = [].slice.call(arguments);
@@ -596,11 +521,6 @@ const configure = (config, methods) => {
596
521
  buffer(item);
597
522
  });
598
523
  });
599
- /**
600
- * @memberOf global
601
- * @function fn
602
- * @param callback
603
- */
604
524
  Scope.method('fn', function(callback) {
605
525
  const buffer = this.getBuffer();
606
526
  const context = this;
@@ -612,24 +532,12 @@ const configure = (config, methods) => {
612
532
  return buffer.restore()
613
533
  }
614
534
  });
615
- /**
616
- * @memberOf global
617
- * @function get
618
- * @param name
619
- * @param [defaults]
620
- */
621
535
  Scope.method('get', function(name,defaults) {
622
536
  const path = getPath(this, name);
623
537
  const result = path.shift();
624
538
  const prop = path.pop();
625
539
  return hasProp(result, prop) ? result[prop] : defaults
626
540
  });
627
- /**
628
- * @memberOf global
629
- * @function set
630
- * @param name
631
- * @param value
632
- */
633
541
  Scope.method('set', function(name,value) {
634
542
  const path = getPath(this, name);
635
543
  const result = path.shift();
@@ -639,12 +547,6 @@ const configure = (config, methods) => {
639
547
  }
640
548
  return result[prop] = value
641
549
  });
642
- /**
643
- * @memberOf global
644
- * @function macro
645
- * @param name
646
- * @param callback
647
- */
648
550
  Scope.method('macro', function(name, callback) {
649
551
  const list = this.getMacro();
650
552
  const macro = this.fn(callback);
@@ -653,12 +555,6 @@ const configure = (config, methods) => {
653
555
  return context.echo(macro.apply(undefined, arguments))
654
556
  };
655
557
  });
656
- /**
657
- * @memberOf global
658
- * @function call
659
- * @param name
660
- * @param {...*} args
661
- */
662
558
  Scope.method('call', function(name) {
663
559
  const list = this.getMacro();
664
560
  const macro = list[name];
@@ -667,12 +563,6 @@ const configure = (config, methods) => {
667
563
  return macro.apply(macro, params)
668
564
  }
669
565
  });
670
- /**
671
- * @memberOf global
672
- * @function block
673
- * @param name
674
- * @param callback
675
- */
676
566
  Scope.method('block',function(name,callback){
677
567
  const blocks = this.getBlocks();
678
568
  blocks[name] = blocks[name] || [];
@@ -694,25 +584,12 @@ const configure = (config, methods) => {
694
584
  };
695
585
  this.echo(current()(next()));
696
586
  });
697
- /**
698
- * @memberOf global
699
- * @function include
700
- * @param path
701
- * @param [data]
702
- * @param [cx]
703
- */
704
587
  Scope.method('include',function(path, data, cx){
705
588
  const context = cx === false ? {} : this.clone(true);
706
589
  const params = extend(context, data || {});
707
590
  const promise = this.render(path, params);
708
591
  this.echo(promise);
709
592
  });
710
- /**
711
- * @memberOf global
712
- * @function use
713
- * @param path
714
- * @param namespace
715
- */
716
593
  Scope.method('use',function(path, namespace){
717
594
  const promise = this.require(path);
718
595
  this.echo(resolve$1(promise,function(exports){
@@ -722,12 +599,6 @@ const configure = (config, methods) => {
722
599
  });
723
600
  },this));
724
601
  });
725
- /**
726
- * @memberOf global
727
- * @function async
728
- * @param promise
729
- * @param callback
730
- */
731
602
  Scope.method('async',function(promise,callback){
732
603
  this.echo(
733
604
  resolve$1(promise, function(data) {
@@ -735,36 +606,23 @@ const configure = (config, methods) => {
735
606
  }, this)
736
607
  );
737
608
  });
738
- Scope.helpers(methods);
739
- Scope.helpers({
740
- /**
741
- * @memberOf global
742
- * @param tag
743
- * @param attr
744
- * @param content
745
- */
746
- el(tag, attr, content) {
747
- if (isFunction(content)) {
748
- content = this.fn(content)();
749
- }
750
- this.echo(
751
- resolve$1(content, function(content) {
752
- return element(tag, attr, content)
753
- }, this)
754
- );
755
- },
756
- /**
757
- * @memberOf global
758
- * @param object
759
- * @param callback
760
- */
761
- each(object, callback) {
762
- if (isString(object)) {
763
- object = this.get(object, []);
764
- }
765
- each(object, callback);
609
+ Scope.method('el',function(tag, attr, content){
610
+ if (isFunction(content)) {
611
+ content = this.fn(content)();
766
612
  }
613
+ this.echo(
614
+ resolve$1(content, function(content) {
615
+ return element(tag, attr, content)
616
+ }, this)
617
+ );
767
618
  });
619
+ Scope.method('each',function(object, callback){
620
+ if (isString(object)) {
621
+ object = this.get(object, []);
622
+ }
623
+ each(object, callback);
624
+ });
625
+ Scope.helpers(methods);
768
626
  return Scope
769
627
  };
770
628
 
package/ejs.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ declare namespace ejs {
2
+ // extend layout with blocks in current template file
3
+ function extend(layout: string);
4
+ // define block with custom **name** and callback
5
+ function block(name: string, callback );
6
+ // set property in current scope
7
+ function set(path: string, value: any);
8
+ // get property in current scope
9
+ function get(path: string, defaults: any );
10
+ // import macro from file **path** and set to current scope **name** property
11
+ function use(path: string, name: string);
12
+ // define macro function with custom **name**
13
+ function macro(name: string, callback );
14
+ // call macro function
15
+ function call(name: string, props?: object, callback?);
16
+ // asynchronous template execution
17
+ function async(promise: Promise<any>, callback?);
18
+ // asynchronous template execution
19
+ function fn(callback: Function);
20
+ // buffer output
21
+ function echo(...any);
22
+ // buffer output
23
+ function include();
24
+ // buffer output
25
+ function include();
26
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@kosatyi/ejs",
3
3
  "description": "EJS Templates",
4
4
  "homepage": "https://github.com/kosatyi/ejs",
5
- "version": "0.0.14",
5
+ "version": "0.0.16",
6
6
  "main": "dist/ejs.cjs",
7
7
  "module": "dist/ejs.mjs",
8
8
  "browser": "dist/ejs.js",
@@ -15,7 +15,8 @@
15
15
  "terser": "^5.16.1"
16
16
  },
17
17
  "files": [
18
- "dist"
18
+ "dist",
19
+ "ejs.d.ts"
19
20
  ],
20
21
  "scripts": {
21
22
  "build": "rollup -c",