@kosatyi/ejs 0.0.33 → 0.0.35

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
@@ -22,6 +22,7 @@ defaults.rmWhitespace = true;
22
22
  defaults.withObject = false;
23
23
  defaults.vars = {
24
24
  SCOPE: 'ejs',
25
+ COMPONENT: 'ui',
25
26
  EXTEND: '$$e',
26
27
  BUFFER: '$$a',
27
28
  LAYOUT: '$$l',
@@ -49,6 +50,9 @@ var isString = function isString(v) {
49
50
  var isBoolean = function isBoolean(v) {
50
51
  return typeof v === 'boolean';
51
52
  };
53
+ var isUndefined = function isUndefined(v) {
54
+ return typeof v === 'undefined';
55
+ };
52
56
 
53
57
  var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
54
58
  var isNode = function isNode() {
@@ -129,7 +133,7 @@ var map = function map(object, callback, context) {
129
133
  var result = [];
130
134
  each(object, function (value, key, object) {
131
135
  var item = callback(value, key, object);
132
- if (item !== undefined) {
136
+ if (isUndefined(item) === false) {
133
137
  result.push(item);
134
138
  }
135
139
  });
@@ -140,7 +144,7 @@ var filter = function filter(object, callback, context) {
140
144
  var result = isArray ? [] : {};
141
145
  each(object, function (value, key, object) {
142
146
  var item = callback(value, key, object);
143
- if (item !== undefined) {
147
+ if (isUndefined(item) === false) {
144
148
  if (isArray) {
145
149
  result.push(item);
146
150
  } else {
@@ -312,7 +316,8 @@ var Compiler = /*#__PURE__*/function () {
312
316
  var _this$vars = this.vars,
313
317
  SCOPE = _this$vars.SCOPE,
314
318
  SAFE = _this$vars.SAFE,
315
- BUFFER = _this$vars.BUFFER;
319
+ BUFFER = _this$vars.BUFFER,
320
+ COMPONENT = _this$vars.COMPONENT;
316
321
  if (this.rmWhitespace) {
317
322
  content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
318
323
  }
@@ -335,8 +340,8 @@ var Compiler = /*#__PURE__*/function () {
335
340
  source += "\n//# sourceURL=".concat(path);
336
341
  var result = null;
337
342
  try {
338
- result = new Function(SCOPE, BUFFER, SAFE, source);
339
- result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
343
+ result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
344
+ result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
340
345
  } catch (e) {
341
346
  e.filename = path;
342
347
  e.source = source;
@@ -348,40 +353,6 @@ var Compiler = /*#__PURE__*/function () {
348
353
  return Compiler;
349
354
  }();
350
355
 
351
- var Bundler = /*#__PURE__*/function () {
352
- function Bundler(config) {
353
- _classCallCheck(this, Bundler);
354
- this.configure(config);
355
- }
356
- _createClass(Bundler, [{
357
- key: "configure",
358
- value: function configure(config) {
359
- this.namespace = config["export"];
360
- this.useStrict = config.withObject === false;
361
- }
362
- }, {
363
- key: "wrapper",
364
- value: function wrapper(list) {
365
- var out = '';
366
- out += '(function(global,factory){';
367
- out += 'typeof exports === "object" && typeof module !== "undefined" ?';
368
- out += 'module.exports = factory():';
369
- out += 'typeof define === "function" && define.amd ? define(factory):';
370
- out += '(global = typeof globalThis !== "undefined" ? globalThis:';
371
- out += 'global || self,global["' + this.namespace + '"] = factory())';
372
- out += '})(this,(function(){';
373
- if (this.useStrict) out += "'use strict';\n";
374
- out += 'var list = {};\n';
375
- list.forEach(function (item) {
376
- out += 'list[' + JSON.stringify(item.name) + ']=' + String(item.content) + ';\n';
377
- });
378
- out += 'return list;}));\n';
379
- return out;
380
- }
381
- }]);
382
- return Bundler;
383
- }();
384
-
385
356
  var resolvePath = function resolvePath(path, template) {
386
357
  template = [path, template].join('/');
387
358
  template = template.replace(/\/\//g, '/');
@@ -516,7 +487,8 @@ var Context = /*#__PURE__*/function () {
516
487
  LAYOUT = _config$vars.LAYOUT,
517
488
  BLOCKS = _config$vars.BLOCKS,
518
489
  BUFFER = _config$vars.BUFFER,
519
- MACRO = _config$vars.MACRO;
490
+ MACRO = _config$vars.MACRO,
491
+ COMPONENT = _config$vars.COMPONENT;
520
492
  this.create = function (data) {
521
493
  return new Scope(data);
522
494
  };
@@ -558,6 +530,9 @@ var Context = /*#__PURE__*/function () {
558
530
  Scope.method('getBuffer', function () {
559
531
  return this[BUFFER];
560
532
  });
533
+ Scope.method('getComponent', function () {
534
+ return this[COMPONENT];
535
+ });
561
536
  Scope.method('getBlocks', function () {
562
537
  return this[BLOCKS];
563
538
  });
@@ -690,6 +665,7 @@ var Context = /*#__PURE__*/function () {
690
665
  }
691
666
  each(object, callback);
692
667
  });
668
+ Scope.method(COMPONENT, function () {}, true);
693
669
  }
694
670
  }]);
695
671
  return Context;
@@ -769,21 +745,19 @@ var init = function init(options) {
769
745
  configSchema(config, options || {});
770
746
  var context = new Context(config);
771
747
  var compiler = new Compiler(config);
772
- var bundler = new Bundler(config);
773
748
  var cache = new Cache(config);
774
749
  var template = new Template(config, cache, compiler);
775
750
  var configure = function configure(options) {
776
751
  configSchema(config, options);
777
752
  context.configure(config, scope);
778
753
  compiler.configure(config);
779
- bundler.configure(config);
780
754
  cache.configure(config);
781
755
  template.configure(config);
782
756
  return config;
783
757
  };
784
758
  var output = function output(path, scope) {
785
759
  return template.get(path).then(function (callback) {
786
- return callback.call(scope, scope, scope.getBuffer(), safeValue);
760
+ return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
787
761
  });
788
762
  };
789
763
  var _require = function require(name) {
@@ -832,9 +806,6 @@ var init = function init(options) {
832
806
  var preload = function preload(list) {
833
807
  return cache.load(list);
834
808
  };
835
- var wrapper = function wrapper(list) {
836
- return bundler.wrapper(list);
837
- };
838
809
  var compile = function compile(content, path) {
839
810
  return compiler.compile(content, path);
840
811
  };
@@ -853,7 +824,6 @@ var init = function init(options) {
853
824
  render: _render,
854
825
  helpers: helpers,
855
826
  configure: configure,
856
- wrapper: wrapper,
857
827
  compile: compile,
858
828
  create: create,
859
829
  preload: preload,
package/dist/ejs.js CHANGED
@@ -16,6 +16,7 @@
16
16
  defaults.withObject = false;
17
17
  defaults.vars = {
18
18
  SCOPE: 'ejs',
19
+ COMPONENT: 'ui',
19
20
  EXTEND: '$$e',
20
21
  BUFFER: '$$a',
21
22
  LAYOUT: '$$l',
@@ -43,6 +44,9 @@
43
44
  var isBoolean = function isBoolean(v) {
44
45
  return typeof v === 'boolean';
45
46
  };
47
+ var isUndefined = function isUndefined(v) {
48
+ return typeof v === 'undefined';
49
+ };
46
50
 
47
51
  var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
48
52
  var isNode = function isNode() {
@@ -123,7 +127,7 @@
123
127
  var result = [];
124
128
  each(object, function (value, key, object) {
125
129
  var item = callback(value, key, object);
126
- if (item !== undefined) {
130
+ if (isUndefined(item) === false) {
127
131
  result.push(item);
128
132
  }
129
133
  });
@@ -134,7 +138,7 @@
134
138
  var result = isArray ? [] : {};
135
139
  each(object, function (value, key, object) {
136
140
  var item = callback(value, key, object);
137
- if (item !== undefined) {
141
+ if (isUndefined(item) === false) {
138
142
  if (isArray) {
139
143
  result.push(item);
140
144
  } else {
@@ -306,7 +310,8 @@
306
310
  var _this$vars = this.vars,
307
311
  SCOPE = _this$vars.SCOPE,
308
312
  SAFE = _this$vars.SAFE,
309
- BUFFER = _this$vars.BUFFER;
313
+ BUFFER = _this$vars.BUFFER,
314
+ COMPONENT = _this$vars.COMPONENT;
310
315
  if (this.rmWhitespace) {
311
316
  content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
312
317
  }
@@ -329,8 +334,8 @@
329
334
  source += "\n//# sourceURL=".concat(path);
330
335
  var result = null;
331
336
  try {
332
- result = new Function(SCOPE, BUFFER, SAFE, source);
333
- result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
337
+ result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
338
+ result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
334
339
  } catch (e) {
335
340
  e.filename = path;
336
341
  e.source = source;
@@ -342,40 +347,6 @@
342
347
  return Compiler;
343
348
  }();
344
349
 
345
- var Bundler = /*#__PURE__*/function () {
346
- function Bundler(config) {
347
- _classCallCheck(this, Bundler);
348
- this.configure(config);
349
- }
350
- _createClass(Bundler, [{
351
- key: "configure",
352
- value: function configure(config) {
353
- this.namespace = config["export"];
354
- this.useStrict = config.withObject === false;
355
- }
356
- }, {
357
- key: "wrapper",
358
- value: function wrapper(list) {
359
- var out = '';
360
- out += '(function(global,factory){';
361
- out += 'typeof exports === "object" && typeof module !== "undefined" ?';
362
- out += 'module.exports = factory():';
363
- out += 'typeof define === "function" && define.amd ? define(factory):';
364
- out += '(global = typeof globalThis !== "undefined" ? globalThis:';
365
- out += 'global || self,global["' + this.namespace + '"] = factory())';
366
- out += '})(this,(function(){';
367
- if (this.useStrict) out += "'use strict';\n";
368
- out += 'var list = {};\n';
369
- list.forEach(function (item) {
370
- out += 'list[' + JSON.stringify(item.name) + ']=' + String(item.content) + ';\n';
371
- });
372
- out += 'return list;}));\n';
373
- return out;
374
- }
375
- }]);
376
- return Bundler;
377
- }();
378
-
379
350
  var resolvePath = function resolvePath(path, template) {
380
351
  template = [path, template].join('/');
381
352
  template = template.replace(/\/\//g, '/');
@@ -510,7 +481,8 @@
510
481
  LAYOUT = _config$vars.LAYOUT,
511
482
  BLOCKS = _config$vars.BLOCKS,
512
483
  BUFFER = _config$vars.BUFFER,
513
- MACRO = _config$vars.MACRO;
484
+ MACRO = _config$vars.MACRO,
485
+ COMPONENT = _config$vars.COMPONENT;
514
486
  this.create = function (data) {
515
487
  return new Scope(data);
516
488
  };
@@ -552,6 +524,9 @@
552
524
  Scope.method('getBuffer', function () {
553
525
  return this[BUFFER];
554
526
  });
527
+ Scope.method('getComponent', function () {
528
+ return this[COMPONENT];
529
+ });
555
530
  Scope.method('getBlocks', function () {
556
531
  return this[BLOCKS];
557
532
  });
@@ -684,6 +659,7 @@
684
659
  }
685
660
  each(object, callback);
686
661
  });
662
+ Scope.method(COMPONENT, function () {}, true);
687
663
  }
688
664
  }]);
689
665
  return Context;
@@ -763,21 +739,19 @@
763
739
  configSchema(config, options || {});
764
740
  var context = new Context(config);
765
741
  var compiler = new Compiler(config);
766
- var bundler = new Bundler(config);
767
742
  var cache = new Cache(config);
768
743
  var template = new Template(config, cache, compiler);
769
744
  var configure = function configure(options) {
770
745
  configSchema(config, options);
771
746
  context.configure(config, scope);
772
747
  compiler.configure(config);
773
- bundler.configure(config);
774
748
  cache.configure(config);
775
749
  template.configure(config);
776
750
  return config;
777
751
  };
778
752
  var output = function output(path, scope) {
779
753
  return template.get(path).then(function (callback) {
780
- return callback.call(scope, scope, scope.getBuffer(), safeValue);
754
+ return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
781
755
  });
782
756
  };
783
757
  var _require = function require(name) {
@@ -826,9 +800,6 @@
826
800
  var preload = function preload(list) {
827
801
  return cache.load(list);
828
802
  };
829
- var wrapper = function wrapper(list) {
830
- return bundler.wrapper(list);
831
- };
832
803
  var compile = function compile(content, path) {
833
804
  return compiler.compile(content, path);
834
805
  };
@@ -847,7 +818,6 @@
847
818
  render: _render,
848
819
  helpers: helpers,
849
820
  configure: configure,
850
- wrapper: wrapper,
851
821
  compile: compile,
852
822
  create: create,
853
823
  preload: preload,
package/dist/ejs.min.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ejs={})}(this,(function(t){"use strict";var e={},n={export:"ejsPrecompiled",cache:!0,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!1,vars:{SCOPE:"ejs",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},r=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},i=function(t){return"function"==typeof t},o=function(t){return"string"==typeof t},c=function(t){return"boolean"==typeof t},u="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),s=function(){return u},a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},f={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},h=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},l=h(f),p=h(a),v=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(l,(function(t){return f[t]}))},d=function(t,e,n){return null==(n=t)?"":e?v(n):n},m=function(t,e){var n=t,r=e.split("."),i=r.pop();return r.forEach((function(t){n=n[t]=n[t]||{}})),[n,i]},g=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},y=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),r)},b=function(){},w=function(t,e){var n;for(n in t)k(t,n)&&e(t[n],n,t)},j=function(t,e){return function(t,e,n){var r=t instanceof Array,i=r?[]:{};return w(t,(function(t,n,o){var c=e(t,n,o);void 0!==c&&(r?i.push(c):i[n]=c)})),i}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},x=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},k=function(t,e){return t&&t.hasOwnProperty(e)},E=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],O=" ",F='"',P="/",S="<",B=">",R=function(t,e,n){var r=[],i=-1===E.indexOf(t),o=function(t,e,n){var r=[];return w(t,(function(t,n,i){var o=e(t,n,i);void 0!==o&&r.push(o)})),r}(e,(function(t,e){if(null!=t)return[v(e),[F,v(t),F].join("")].join("=")})).join(O);return r.push([S,t,O,o,B].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([S,P,t,B].join("")),r.join("")};function $(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function T(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,A(r.key),r)}}function U(t,e,n){return e&&T(t.prototype,e),n&&T(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function A(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var M=[{symbol:"-",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(t){return"')\n/**".concat(t,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(t){return"')\n".concat(t.trim(),"\n").concat(this.BUFFER,"('")}}],_=function(){function t(e){$(this,t),this.configure(e)}return U(t,[{key:"configure",value:function(t){var e=this;this.withObject=t.withObject,this.rmWhitespace=t.rmWhitespace,this.token=t.token,this.vars=t.vars,this.matches=[],this.formats=[],this.slurp={match:"[ \\t]*",start:[this.token.start,"_"],end:["_",this.token.end]},M.forEach((function(t){e.matches.push(e.token.start.concat(t.symbol).concat(e.token.regex).concat(e.token.end)),e.formats.push(t.format.bind(e.vars))})),this.regex=new RegExp(this.matches.join("|").concat("|$"),"g"),this.slurpStart=new RegExp([this.slurp.match,this.slurp.start.join("")].join(""),"gm"),this.slurpEnd=new RegExp([this.slurp.end.join(""),this.slurp.match].join(""),"gm")}},{key:"truncate",value:function(t){return t&&t.replace(/^(?:\r\n|\r|\n)/,"")}},{key:"compile",value:function(t,e){var n=this,r=this.vars,i=r.SCOPE,o=r.SAFE,c=r.BUFFER;this.rmWhitespace&&(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=t.replace(this.slurpStart,this.token.start).replace(this.slurpEnd,this.token.end);var u,s,f,h="".concat(c,"('");u=this.regex,s=function(e,r,i){h+=(""+t.slice(r,i)).replace(p,(function(t){return"\\"+a[t]})),e.forEach((function(t,e){t&&(h+=n.formats[e](t))}))},f=0,t.replace(u,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return s(t,f,e),f=e+n.length,n})),h="try{".concat(h+="');","}catch(e){console.info(e)}"),this.withObject&&(h="with(".concat(i,"){").concat(h,"}")),h="".concat(c,".start();").concat(h,"return ").concat(c,".end();"),h+="\n//# sourceURL=".concat(e);var l=null;try{(l=new Function(i,c,o,h)).source="(function(".concat(i,",").concat(c,",").concat(o,"){\n").concat(h,"\n})")}catch(t){throw t.filename=e,t.source=h,t}return l}}]),t}(),L=function(){function t(e){$(this,t),this.configure(e)}return U(t,[{key:"configure",value:function(t){this.namespace=t.export,this.useStrict=!1===t.withObject}},{key:"wrapper",value:function(t){var e="";return e+="(function(global,factory){",e+='typeof exports === "object" && typeof module !== "undefined" ?',e+="module.exports = factory():",e+='typeof define === "function" && define.amd ? define(factory):',e+='(global = typeof globalThis !== "undefined" ? globalThis:',e+='global || self,global["'+this.namespace+'"] = factory())',e+="})(this,(function(){",this.useStrict&&(e+="'use strict';\n"),e+="var list = {};\n",t.forEach((function(t){e+="list["+JSON.stringify(t.name)+"]="+String(t.content)+";\n"})),e+="return list;}));\n"}}]),t}(),W=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},C=function(t,e){return fetch(W(t,e)).then((function(t){return t.text()}))},N=function(t,n){return new Promise((function(r,i){e.readFile(W(t,n),(function(t,e){t?i(t):r(e.toString())}))}))},q=function(){function t(e,n,r){$(this,t),this.cache=n,this.watcher=null,this.compiler=r,this.configure(e)}return U(t,[{key:"configure",value:function(t){var n,r,o;this.path=t.path,this.resolver=i(t.resolver)?t.resolver:s()?N:C,(n=this.watcher)&&n.unwatch("."),t.watch&&s()&&(this.watcher=(r=this.cache,o=this.path,e.watch(".",{cwd:r}).on("change",(function(t){o.remove(t)})).on("error",(function(t){console.log("watcher error: "+t)}))))}},{key:"resolve",value:function(t){return this.resolver(this.path,t)}},{key:"result",value:function(t,e){return this.cache.set(t,e),e}},{key:"compile",value:function(t,e){return i(t)?t:this.compiler.compile(t,e)}},{key:"get",value:function(t){var e=this;if(this.cache.exist(t))return this.cache.resolve(t);var n=this.resolve(t).then((function(n){return e.result(t,e.compile(n,t))}));return this.result(t,n)}}]),t}(),D=function(t){return Promise.all(t).then((function(t){return t.join("")}))},K=function(){function t(e){$(this,t),this.configure(e)}return U(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,c=n.LAYOUT,u=n.BLOCKS,s=n.BUFFER,a=n.MACRO;function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),y(this,t)}this.create=function(t){return new f(t)},this.helpers=function(t){y(f.prototype,t)},f.prototype=y({},e||{}),f.defineProp=f.method=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];Object.defineProperty(f.prototype,t,{value:e,writable:n,configurable:r,enumerable:i})},f.defineProp(s,function(){var t=[],e=[];function n(t){e.push(t)}return n.start=function(){e=[]},n.backup=function(){t.push(e.concat()),e=[]},n.restore=function(){var n=e.concat();return e=t.pop(),D(n)},n.error=function(t){throw t},n.end=function(){return D(e)},n}()),f.defineProp(u,{},!0),f.defineProp(a,{},!0),f.defineProp(c,!1,!0),f.defineProp(r,!1,!0),f.method("initBlocks",(function(){this[u]={}})),f.method("initMacro",(function(){this[a]={}})),f.method("getMacro",(function(){return this[a]})),f.method("getBuffer",(function(){return this[s]})),f.method("getBlocks",(function(){return this[u]})),f.method("setExtend",(function(t){this[r]=t})),f.method("getExtend",(function(){return this[r]})),f.method("setLayout",(function(t){this[c]=t})),f.method("getLayout",(function(){return this[c]})),f.method("clone",(function(t){var e=[c,r,s];return!0===t&&e.push(u),j(this,e)})),f.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),f.method("echo",(function(){var t=this.getBuffer(),e=[].slice.call(arguments);e.forEach(t)})),f.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),i(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=m(this,t),r=n.shift(),i=n.pop();return k(r,i)?r[i]:e})),f.method("set",(function(t,e){var n=m(this,t),r=n.shift(),i=n.pop();return this.getExtend()&&k(r,i)?r[i]:r[i]=e})),f.method("macro",(function(t,e){var n=this.getMacro(),r=this.fn(e),i=this;n[t]=function(){return i.echo(r.apply(void 0,arguments))}})),f.method("call",(function(t){var e=this.getMacro(),n=e[t],r=[].slice.call(arguments,1);if(i(n))return n.apply(n,r)})),f.method("block",(function(t,e){var n=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(e)),!this.getExtend()){var i=Object.assign([],r[t]),o=function(){return i.shift()};this.echo(o()(function t(){var e=o();return e?function(){n.echo(e(t()))}:b}()))}})),f.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),i=y(r,e||{}),o=this.render(t,i);this.echo(o)})),f.method("use",(function(t,e){var n=this.require(t);this.echo(x(n,(function(t){var n=this.getMacro();w(t,(function(t,r){n[[e,r].join(".")]=t}))}),this))})),f.method("async",(function(t,e){this.echo(x(t,(function(t){return this.fn(e)(t)}),this))})),f.method("node",(function(t,e,n){return R(t,e,n)})),f.method("el",(function(t,e,n){i(n)&&(n=this.fn(n)()),this.echo(x(n,(function(n){return R(t,e,n)}),this))})),f.method("each",(function(t,e){o(t)&&(t=this.get(t,[])),w(t,e)}))}}]),t}(),X="undefined"!=typeof globalThis?globalThis:window||self,Y=function(){function t(e){var n,r,i;$(this,t),n=this,i={},(r=A(r="list"))in n?Object.defineProperty(n,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[r]=i,this.configure(e),!1===s()&&this.load(X[this.namespace])}return U(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return y(this.list,t),this}},{key:"exist",value:function(t){return k(this.list,t)}},{key:"get",value:function(t){return this.list[t]}},{key:"remove",value:function(t){delete this.list[t]}},{key:"resolve",value:function(t){return Promise.resolve(this.get(t))}},{key:"set",value:function(t,e){return this.list[t]=e,this}}]),t}(),J=function(t,e){y(t,{export:r(o,n.export,t.export,e.export),path:r(o,n.path,t.path,e.path),resolver:r(i,n.resolver,t.resolver,e.resolver),extension:r(o,n.extension,t.extension,e.extension),withObject:r(c,n.withObject,t.withObject,e.withObject),rmWhitespace:r(c,n.rmWhitespace,t.rmWhitespace,e.rmWhitespace),token:y({},n.token,t.token,e.token),vars:y({},n.vars,t.vars,e.vars)})},V=function t(u){var s={},a={};J(s,u||{});var f=new K(s),h=new _(s),l=new L(s),p=new Y(s),v=new q(s,p,h),m=function(t){return J(s,t),f.configure(s,a),h.configure(s),l.configure(s),p.configure(s),v.configure(s),s},b=function(t,e){return v.get(t).then((function(t){return t.call(e,e,e.getBuffer(),d)}))},w=function(t,e){var n=g(t,s.extension),r=f.create(e);return b(n,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),n=r.clone();return w(e,n)}return t}))},j=function(t){f.helpers(y(a,t||{}))};return j({require:function(t){return function(t){var e=g(t,s.extension),n=f.create({});return b(e,n).then((function(){return n.getMacro()}))}(t)},render:function(t,e){return w(t,e)}}),{render:w,helpers:j,configure:m,wrapper:function(t){return l.wrapper(t)},compile:function(t,e){return h.compile(t,e)},create:function(e){return t(e)},preload:function(t){return p.load(t)},__express:function(t,u,s){i(u)&&(s=u,u={});var a=y({},(u=u||{}).settings),f=r(o,n.path,a.views),h=r(c,n.cache,a["view cache"]),l=y({},a["view options"]),p=e.relative(f,t);return l.path=f,l.cache=h,m(l),w(p,u).then((function(t){s(null,t)})).catch((function(t){s(t)}))}}}({}),z=V.render,G=V.helpers,H=V.configure,I=V.wrapper,Q=V.compile,Z=V.create,tt=V.preload,et=V.__express;t.__express=et,t.compile=Q,t.configure=H,t.create=Z,t.element=R,t.helpers=G,t.preload=tt,t.render=z,t.safeValue=d,t.wrapper=I,Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ejs={})}(this,(function(t){"use strict";var e={},n={export:"ejsPrecompiled",cache:!0,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!1,vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},r=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},i=function(t){return"function"==typeof t},o=function(t){return"string"==typeof t},c=function(t){return"boolean"==typeof t},u=function(t){return void 0===t},s="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a=function(){return s},h={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},f={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},l=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},p=l(f),v=l(h),d=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(p,(function(t){return f[t]}))},m=function(t,e,n){return null==(n=t)?"":e?d(n):n},g=function(t,e){var n=t,r=e.split("."),i=r.pop();return r.forEach((function(t){n=n[t]=n[t]||{}})),[n,i]},y=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},b=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),r)},w=function(){},j=function(t,e){var n;for(n in t)E(t,n)&&e(t[n],n,t)},k=function(t,e){return function(t,e,n){var r=t instanceof Array,i=r?[]:{};return j(t,(function(t,n,o){var c=e(t,n,o);!1===u(c)&&(r?i.push(c):i[n]=c)})),i}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},x=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},E=function(t,e){return t&&t.hasOwnProperty(e)},O=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],F=" ",P='"',B="/",R="<",S=">",$=function(t,e,n){var r=[],i=-1===O.indexOf(t),o=function(t,e,n){var r=[];return j(t,(function(t,n,i){var o=e(t,n,i);!1===u(o)&&r.push(o)})),r}(e,(function(t,e){if(null!=t)return[d(e),[P,d(t),P].join("")].join("=")})).join(F);return r.push([R,t,F,o,S].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([R,B,t,S].join("")),r.join("")};function M(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function T(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,U(r.key),r)}}function C(t,e,n){return e&&T(t.prototype,e),n&&T(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function U(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var A=[{symbol:"-",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(t){return"')\n/**".concat(t,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(t){return"')\n".concat(t.trim(),"\n").concat(this.BUFFER,"('")}}],_=function(){function t(e){M(this,t),this.configure(e)}return C(t,[{key:"configure",value:function(t){var e=this;this.withObject=t.withObject,this.rmWhitespace=t.rmWhitespace,this.token=t.token,this.vars=t.vars,this.matches=[],this.formats=[],this.slurp={match:"[ \\t]*",start:[this.token.start,"_"],end:["_",this.token.end]},A.forEach((function(t){e.matches.push(e.token.start.concat(t.symbol).concat(e.token.regex).concat(e.token.end)),e.formats.push(t.format.bind(e.vars))})),this.regex=new RegExp(this.matches.join("|").concat("|$"),"g"),this.slurpStart=new RegExp([this.slurp.match,this.slurp.start.join("")].join(""),"gm"),this.slurpEnd=new RegExp([this.slurp.end.join(""),this.slurp.match].join(""),"gm")}},{key:"truncate",value:function(t){return t&&t.replace(/^(?:\r\n|\r|\n)/,"")}},{key:"compile",value:function(t,e){var n=this,r=this.vars,i=r.SCOPE,o=r.SAFE,c=r.BUFFER,u=r.COMPONENT;this.rmWhitespace&&(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=t.replace(this.slurpStart,this.token.start).replace(this.slurpEnd,this.token.end);var s,a,f,l="".concat(c,"('");s=this.regex,a=function(e,r,i){l+=(""+t.slice(r,i)).replace(v,(function(t){return"\\"+h[t]})),e.forEach((function(t,e){t&&(l+=n.formats[e](t))}))},f=0,t.replace(s,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return a(t,f,e),f=e+n.length,n})),l="try{".concat(l+="');","}catch(e){console.info(e)}"),this.withObject&&(l="with(".concat(i,"){").concat(l,"}")),l="".concat(c,".start();").concat(l,"return ").concat(c,".end();"),l+="\n//# sourceURL=".concat(e);var p=null;try{(p=new Function(i,u,c,o,l)).source="(function(".concat(i,",").concat(u,",").concat(c,",").concat(o,"){\n").concat(l,"\n})")}catch(t){throw t.filename=e,t.source=l,t}return p}}]),t}(),L=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},N=function(t,e){return fetch(L(t,e)).then((function(t){return t.text()}))},W=function(t,n){return new Promise((function(r,i){e.readFile(L(t,n),(function(t,e){t?i(t):r(e.toString())}))}))},q=function(){function t(e,n,r){M(this,t),this.cache=n,this.watcher=null,this.compiler=r,this.configure(e)}return C(t,[{key:"configure",value:function(t){var n,r,o;this.path=t.path,this.resolver=i(t.resolver)?t.resolver:a()?W:N,(n=this.watcher)&&n.unwatch("."),t.watch&&a()&&(this.watcher=(r=this.cache,o=this.path,e.watch(".",{cwd:r}).on("change",(function(t){o.remove(t)})).on("error",(function(t){console.log("watcher error: "+t)}))))}},{key:"resolve",value:function(t){return this.resolver(this.path,t)}},{key:"result",value:function(t,e){return this.cache.set(t,e),e}},{key:"compile",value:function(t,e){return i(t)?t:this.compiler.compile(t,e)}},{key:"get",value:function(t){var e=this;if(this.cache.exist(t))return this.cache.resolve(t);var n=this.resolve(t).then((function(n){return e.result(t,e.compile(n,t))}));return this.result(t,n)}}]),t}(),D=function(t){return Promise.all(t).then((function(t){return t.join("")}))},K=function(){function t(e){M(this,t),this.configure(e)}return C(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,c=n.LAYOUT,u=n.BLOCKS,s=n.BUFFER,a=n.MACRO,h=n.COMPONENT;function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),b(this,t)}this.create=function(t){return new f(t)},this.helpers=function(t){b(f.prototype,t)},f.prototype=b({},e||{}),f.defineProp=f.method=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];Object.defineProperty(f.prototype,t,{value:e,writable:n,configurable:r,enumerable:i})},f.defineProp(s,function(){var t=[],e=[];function n(t){e.push(t)}return n.start=function(){e=[]},n.backup=function(){t.push(e.concat()),e=[]},n.restore=function(){var n=e.concat();return e=t.pop(),D(n)},n.error=function(t){throw t},n.end=function(){return D(e)},n}()),f.defineProp(u,{},!0),f.defineProp(a,{},!0),f.defineProp(c,!1,!0),f.defineProp(r,!1,!0),f.method("initBlocks",(function(){this[u]={}})),f.method("initMacro",(function(){this[a]={}})),f.method("getMacro",(function(){return this[a]})),f.method("getBuffer",(function(){return this[s]})),f.method("getComponent",(function(){return this[h]})),f.method("getBlocks",(function(){return this[u]})),f.method("setExtend",(function(t){this[r]=t})),f.method("getExtend",(function(){return this[r]})),f.method("setLayout",(function(t){this[c]=t})),f.method("getLayout",(function(){return this[c]})),f.method("clone",(function(t){var e=[c,r,s];return!0===t&&e.push(u),k(this,e)})),f.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),f.method("echo",(function(){var t=this.getBuffer(),e=[].slice.call(arguments);e.forEach(t)})),f.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),i(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=g(this,t),r=n.shift(),i=n.pop();return E(r,i)?r[i]:e})),f.method("set",(function(t,e){var n=g(this,t),r=n.shift(),i=n.pop();return this.getExtend()&&E(r,i)?r[i]:r[i]=e})),f.method("macro",(function(t,e){var n=this.getMacro(),r=this.fn(e),i=this;n[t]=function(){return i.echo(r.apply(void 0,arguments))}})),f.method("call",(function(t){var e=this.getMacro(),n=e[t],r=[].slice.call(arguments,1);if(i(n))return n.apply(n,r)})),f.method("block",(function(t,e){var n=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(e)),!this.getExtend()){var i=Object.assign([],r[t]),o=function(){return i.shift()};this.echo(o()(function t(){var e=o();return e?function(){n.echo(e(t()))}:w}()))}})),f.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),i=b(r,e||{}),o=this.render(t,i);this.echo(o)})),f.method("use",(function(t,e){var n=this.require(t);this.echo(x(n,(function(t){var n=this.getMacro();j(t,(function(t,r){n[[e,r].join(".")]=t}))}),this))})),f.method("async",(function(t,e){this.echo(x(t,(function(t){return this.fn(e)(t)}),this))})),f.method("node",(function(t,e,n){return $(t,e,n)})),f.method("el",(function(t,e,n){i(n)&&(n=this.fn(n)()),this.echo(x(n,(function(n){return $(t,e,n)}),this))})),f.method("each",(function(t,e){o(t)&&(t=this.get(t,[])),j(t,e)})),f.method(h,(function(){}),!0)}}]),t}(),X="undefined"!=typeof globalThis?globalThis:window||self,Y=function(){function t(e){var n,r,i;M(this,t),n=this,i={},(r=U(r="list"))in n?Object.defineProperty(n,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[r]=i,this.configure(e),!1===a()&&this.load(X[this.namespace])}return C(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return b(this.list,t),this}},{key:"exist",value:function(t){return E(this.list,t)}},{key:"get",value:function(t){return this.list[t]}},{key:"remove",value:function(t){delete this.list[t]}},{key:"resolve",value:function(t){return Promise.resolve(this.get(t))}},{key:"set",value:function(t,e){return this.list[t]=e,this}}]),t}(),V=function(t,e){b(t,{export:r(o,n.export,t.export,e.export),path:r(o,n.path,t.path,e.path),resolver:r(i,n.resolver,t.resolver,e.resolver),extension:r(o,n.extension,t.extension,e.extension),withObject:r(c,n.withObject,t.withObject,e.withObject),rmWhitespace:r(c,n.rmWhitespace,t.rmWhitespace,e.rmWhitespace),token:b({},n.token,t.token,e.token),vars:b({},n.vars,t.vars,e.vars)})},z=function t(u){var s={},a={};V(s,u||{});var h=new K(s),f=new _(s),l=new Y(s),p=new q(s,l,f),v=function(t){return V(s,t),h.configure(s,a),f.configure(s),l.configure(s),p.configure(s),s},d=function(t,e){return p.get(t).then((function(t){return t.call(e,e,e.getComponent(),e.getBuffer(),m)}))},g=function(t,e){var n=y(t,s.extension),r=h.create(e);return d(n,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),n=r.clone();return g(e,n)}return t}))},w=function(t){h.helpers(b(a,t||{}))};return w({require:function(t){return function(t){var e=y(t,s.extension),n=h.create({});return d(e,n).then((function(){return n.getMacro()}))}(t)},render:function(t,e){return g(t,e)}}),{render:g,helpers:w,configure:v,compile:function(t,e){return f.compile(t,e)},create:function(e){return t(e)},preload:function(t){return l.load(t)},__express:function(t,u,s){i(u)&&(s=u,u={});var a=b({},(u=u||{}).settings),h=r(o,n.path,a.views),f=r(c,n.cache,a["view cache"]),l=b({},a["view options"]),p=e.relative(h,t);return l.path=h,l.cache=f,v(l),g(p,u).then((function(t){s(null,t)})).catch((function(t){s(t)}))}}}({}),G=z.render,H=z.helpers,I=z.configure,J=z.wrapper,Q=z.compile,Z=z.create,tt=z.preload,et=z.__express;t.__express=et,t.compile=Q,t.configure=I,t.create=Z,t.element=$,t.helpers=H,t.preload=tt,t.render=G,t.safeValue=m,t.wrapper=J,Object.defineProperty(t,"__esModule",{value:!0})}));
package/dist/ejs.mjs CHANGED
@@ -20,6 +20,7 @@ defaults.withObject = false;
20
20
 
21
21
  defaults.vars = {
22
22
  SCOPE: 'ejs',
23
+ COMPONENT: 'ui',
23
24
  EXTEND: '$$e',
24
25
  BUFFER: '$$a',
25
26
  LAYOUT: '$$l',
@@ -42,8 +43,12 @@ const typeProp = function () {
42
43
  const isFunction = (v) => typeof v === 'function';
43
44
  const isString = (v) => typeof v === 'string';
44
45
  const isBoolean = (v) => typeof v === 'boolean';
46
+ const isUndefined = (v) => typeof v === 'undefined';
45
47
 
46
- const isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
48
+ const isNodeEnv =
49
+ Object.prototype.toString.call(
50
+ typeof process !== 'undefined' ? process : 0
51
+ ) === '[object process]';
47
52
 
48
53
  const isNode = () => isNodeEnv;
49
54
 
@@ -134,7 +139,7 @@ const map = (object, callback, context) => {
134
139
  object,
135
140
  (value, key, object) => {
136
141
  let item = callback(value, key, object);
137
- if (item !== undefined) {
142
+ if (isUndefined(item) === false) {
138
143
  result.push(item);
139
144
  }
140
145
  });
@@ -148,7 +153,7 @@ const filter = (object, callback, context) => {
148
153
  object,
149
154
  (value, key, object) => {
150
155
  let item = callback(value, key, object);
151
- if (item !== undefined) {
156
+ if (isUndefined(item) === false) {
152
157
  if (isArray) {
153
158
  result.push(item);
154
159
  } else {
@@ -167,7 +172,7 @@ const omit = (object, list) => {
167
172
  })
168
173
  };
169
174
 
170
- const resolve$1 = (value,callback,context) =>
175
+ const resolve$1 = (value, callback, context) =>
171
176
  Promise.resolve(value).then(callback.bind(context));
172
177
 
173
178
  const hasProp = (object, prop) => {
@@ -262,6 +267,7 @@ class Compiler {
262
267
  constructor(config) {
263
268
  this.configure(config);
264
269
  }
270
+
265
271
  configure(config) {
266
272
  this.withObject = config.withObject;
267
273
  this.rmWhitespace = config.rmWhitespace;
@@ -293,11 +299,13 @@ class Compiler {
293
299
  'gm'
294
300
  );
295
301
  }
302
+
296
303
  truncate(value) {
297
304
  return value && value.replace(/^(?:\r\n|\r|\n)/, '')
298
305
  }
306
+
299
307
  compile(content, path) {
300
- const { SCOPE, SAFE, BUFFER } = this.vars;
308
+ const { SCOPE, SAFE, BUFFER, COMPONENT } = this.vars;
301
309
  if (this.rmWhitespace) {
302
310
  content = content
303
311
  .replace(/[\r\n]+/g, '\n')
@@ -324,8 +332,8 @@ class Compiler {
324
332
  source += `\n//# sourceURL=${path}`;
325
333
  let result = null;
326
334
  try {
327
- result = new Function(SCOPE, BUFFER, SAFE, source);
328
- result.source = `(function(${SCOPE},${BUFFER},${SAFE}){\n${source}\n})`;
335
+ result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
336
+ result.source = `(function(${SCOPE},${COMPONENT},${BUFFER},${SAFE}){\n${source}\n})`;
329
337
  } catch (e) {
330
338
  e.filename = path;
331
339
  e.source = source;
@@ -335,38 +343,6 @@ class Compiler {
335
343
  }
336
344
  }
337
345
 
338
- class Bundler {
339
- constructor(config) {
340
- this.configure(config);
341
- }
342
- configure(config) {
343
- this.namespace = config.export;
344
- this.useStrict = config.withObject === false;
345
- }
346
- wrapper(list) {
347
- let out = '';
348
- out += '(function(global,factory){';
349
- out += 'typeof exports === "object" && typeof module !== "undefined" ?';
350
- out += 'module.exports = factory():';
351
- out += 'typeof define === "function" && define.amd ? define(factory):';
352
- out += '(global = typeof globalThis !== "undefined" ? globalThis:';
353
- out += 'global || self,global["' + this.namespace + '"] = factory())';
354
- out += '})(this,(function(){';
355
- if (this.useStrict) out += "'use strict';\n";
356
- out += 'var list = {};\n';
357
- list.forEach((item) => {
358
- out +=
359
- 'list[' +
360
- JSON.stringify(item.name) +
361
- ']=' +
362
- String(item.content) +
363
- ';\n';
364
- });
365
- out += 'return list;}));\n';
366
- return out
367
- }
368
- }
369
-
370
346
  const resolvePath = (path, template) => {
371
347
  template = [path, template].join('/');
372
348
  template = template.replace(/\/\//g, '/');
@@ -487,20 +463,26 @@ class Context {
487
463
  constructor(config) {
488
464
  this.configure(config);
489
465
  }
466
+
490
467
  configure(config, methods) {
491
- const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO } = config.vars;
468
+ const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO, COMPONENT } = config.vars;
469
+
492
470
  this.create = (data) => {
493
471
  return new Scope(data)
494
472
  };
473
+
495
474
  this.helpers = (methods) => {
496
475
  extend(Scope.prototype, methods);
497
476
  };
477
+
498
478
  function Scope(data = {}) {
499
479
  this.initBlocks();
500
480
  this.initMacro();
501
481
  extend(this, data);
502
482
  }
483
+
503
484
  Scope.prototype = extend({}, methods || {});
485
+
504
486
  Scope.defineProp = Scope.method = (
505
487
  name,
506
488
  value,
@@ -515,38 +497,57 @@ class Context {
515
497
  enumerable,
516
498
  });
517
499
  };
500
+
518
501
  Scope.defineProp(BUFFER, createBuffer());
502
+
519
503
  Scope.defineProp(BLOCKS, {}, true);
504
+
520
505
  Scope.defineProp(MACRO, {}, true);
506
+
521
507
  Scope.defineProp(LAYOUT, false, true);
508
+
522
509
  Scope.defineProp(EXTEND, false, true);
510
+
523
511
  Scope.method('initBlocks', function () {
524
512
  this[BLOCKS] = {};
525
513
  });
514
+
526
515
  Scope.method('initMacro', function () {
527
516
  this[MACRO] = {};
528
517
  });
518
+
529
519
  Scope.method('getMacro', function () {
530
520
  return this[MACRO]
531
521
  });
522
+
532
523
  Scope.method('getBuffer', function () {
533
524
  return this[BUFFER]
534
525
  });
526
+
527
+ Scope.method('getComponent', function () {
528
+ return this[COMPONENT]
529
+ });
530
+
535
531
  Scope.method('getBlocks', function () {
536
532
  return this[BLOCKS]
537
533
  });
534
+
538
535
  Scope.method('setExtend', function (value) {
539
536
  this[EXTEND] = value;
540
537
  });
538
+
541
539
  Scope.method('getExtend', function () {
542
540
  return this[EXTEND]
543
541
  });
542
+
544
543
  Scope.method('setLayout', function (layout) {
545
544
  this[LAYOUT] = layout;
546
545
  });
546
+
547
547
  Scope.method('getLayout', function () {
548
548
  return this[LAYOUT]
549
549
  });
550
+
550
551
  Scope.method('clone', function (exclude_blocks) {
551
552
  const filter = [LAYOUT, EXTEND, BUFFER];
552
553
  if (exclude_blocks === true) {
@@ -554,15 +555,18 @@ class Context {
554
555
  }
555
556
  return omit(this, filter)
556
557
  });
558
+
557
559
  Scope.method('extend', function (layout) {
558
560
  this.setExtend(true);
559
561
  this.setLayout(layout);
560
562
  });
563
+
561
564
  Scope.method('echo', function () {
562
565
  const buffer = this.getBuffer();
563
566
  const params = [].slice.call(arguments);
564
567
  params.forEach(buffer);
565
568
  });
569
+
566
570
  Scope.method('fn', function (callback) {
567
571
  const buffer = this.getBuffer();
568
572
  const context = this;
@@ -574,12 +578,14 @@ class Context {
574
578
  return buffer.restore()
575
579
  }
576
580
  });
581
+
577
582
  Scope.method('get', function (name, defaults) {
578
583
  const path = getPath(this, name);
579
584
  const result = path.shift();
580
585
  const prop = path.pop();
581
586
  return hasProp(result, prop) ? result[prop] : defaults
582
587
  });
588
+
583
589
  Scope.method('set', function (name, value) {
584
590
  const path = getPath(this, name);
585
591
  const result = path.shift();
@@ -589,6 +595,7 @@ class Context {
589
595
  }
590
596
  return (result[prop] = value)
591
597
  });
598
+
592
599
  Scope.method('macro', function (name, callback) {
593
600
  const list = this.getMacro();
594
601
  const macro = this.fn(callback);
@@ -597,6 +604,7 @@ class Context {
597
604
  return context.echo(macro.apply(undefined, arguments))
598
605
  };
599
606
  });
607
+
600
608
  Scope.method('call', function (name) {
601
609
  const list = this.getMacro();
602
610
  const macro = list[name];
@@ -605,6 +613,7 @@ class Context {
605
613
  return macro.apply(macro, params)
606
614
  }
607
615
  });
616
+
608
617
  Scope.method('block', function (name, callback) {
609
618
  const blocks = this.getBlocks();
610
619
  blocks[name] = blocks[name] || [];
@@ -626,12 +635,14 @@ class Context {
626
635
  };
627
636
  this.echo(current()(next()));
628
637
  });
638
+
629
639
  Scope.method('include', function (path, data, cx) {
630
640
  const context = cx === false ? {} : this.clone(true);
631
641
  const params = extend(context, data || {});
632
642
  const promise = this.render(path, params);
633
643
  this.echo(promise);
634
644
  });
645
+
635
646
  Scope.method('use', function (path, namespace) {
636
647
  const promise = this.require(path);
637
648
  this.echo(
@@ -647,6 +658,7 @@ class Context {
647
658
  )
648
659
  );
649
660
  });
661
+
650
662
  Scope.method('async', function (promise, callback) {
651
663
  this.echo(
652
664
  resolve$1(
@@ -658,9 +670,11 @@ class Context {
658
670
  )
659
671
  );
660
672
  });
673
+
661
674
  Scope.method('node', function (tag, attr, content) {
662
675
  return element(tag, attr, content)
663
676
  });
677
+
664
678
  Scope.method('el', function (tag, attr, content) {
665
679
  if (isFunction(content)) {
666
680
  content = this.fn(content)();
@@ -675,12 +689,15 @@ class Context {
675
689
  )
676
690
  );
677
691
  });
692
+
678
693
  Scope.method('each', function (object, callback) {
679
694
  if (isString(object)) {
680
695
  object = this.get(object, []);
681
696
  }
682
697
  each(object, callback);
683
698
  });
699
+
700
+ Scope.method(COMPONENT, function () {}, true);
684
701
  }
685
702
  }
686
703
 
@@ -770,7 +787,6 @@ const init = (options) => {
770
787
 
771
788
  const context = new Context(config);
772
789
  const compiler = new Compiler(config);
773
- const bundler = new Bundler(config);
774
790
  const cache = new Cache(config);
775
791
  const template = new Template(config, cache, compiler);
776
792
 
@@ -778,7 +794,6 @@ const init = (options) => {
778
794
  configSchema(config, options);
779
795
  context.configure(config, scope);
780
796
  compiler.configure(config);
781
- bundler.configure(config);
782
797
  cache.configure(config);
783
798
  template.configure(config);
784
799
  return config
@@ -786,7 +801,13 @@ const init = (options) => {
786
801
 
787
802
  const output = (path, scope) => {
788
803
  return template.get(path).then(function (callback) {
789
- return callback.call(scope, scope, scope.getBuffer(), safeValue)
804
+ return callback.call(
805
+ scope,
806
+ scope,
807
+ scope.getComponent(),
808
+ scope.getBuffer(),
809
+ safeValue
810
+ )
790
811
  })
791
812
  };
792
813
 
@@ -843,7 +864,6 @@ const init = (options) => {
843
864
  })
844
865
  };
845
866
  const preload = (list) => cache.load(list);
846
- const wrapper = (list) => bundler.wrapper(list);
847
867
  const compile = (content, path) => compiler.compile(content, path);
848
868
  const create = (options) => {
849
869
  return init(options)
@@ -860,7 +880,6 @@ const init = (options) => {
860
880
  render,
861
881
  helpers,
862
882
  configure,
863
- wrapper,
864
883
  compile,
865
884
  create,
866
885
  preload,
package/global.d.ts CHANGED
@@ -3,42 +3,42 @@ declare global {
3
3
  * extend layout with blocks in current template file
4
4
  * @param layout
5
5
  */
6
- function extend(layout: string);
6
+ function extend(layout: string)
7
7
 
8
8
  /**
9
9
  * define block with custom **name** and callback
10
10
  * @param name
11
11
  * @param [callback]
12
12
  */
13
- function block(name: string, callback?);
13
+ function block(name: string, callback?)
14
14
 
15
15
  /**
16
16
  * set property in current scope
17
17
  * @param path
18
18
  * @param value
19
19
  */
20
- function set(path: string, value: any);
20
+ function set(path: string, value: any)
21
21
 
22
22
  /**
23
23
  * get property in current scope
24
24
  * @param path
25
25
  * @param defaults
26
26
  */
27
- function get(path: string, defaults?: any);
27
+ function get(path: string, defaults?: any)
28
28
 
29
29
  /**
30
30
  * import macro from file **path** and set to current scope **name** property
31
31
  * @param path
32
32
  * @param name
33
33
  */
34
- function use(path: string, name: string);
34
+ function use(path: string, name: string)
35
35
 
36
36
  /**
37
37
  * define macro function with custom **name**
38
38
  * @param name
39
39
  * @param callback
40
40
  */
41
- function macro(name: string, callback);
41
+ function macro(name: string, callback)
42
42
 
43
43
  /**
44
44
  * call macro function
@@ -46,20 +46,20 @@ declare global {
46
46
  * @param props
47
47
  * @param callback
48
48
  */
49
- function call(name: string, props?: object, callback?);
49
+ function call(name: string, props?: object, callback?)
50
50
 
51
51
  /**
52
52
  * asynchronous template execution
53
53
  * @param promise
54
54
  * @param callback
55
55
  */
56
- function async(promise: Promise<any>, callback?);
56
+ function async(promise: Promise<any>, callback?)
57
57
 
58
58
  /**
59
59
  * asynchronous template execution
60
60
  * @param callback
61
61
  */
62
- function fn(callback: Function);
62
+ function fn(callback: Function)
63
63
 
64
64
  /**
65
65
  *
@@ -67,13 +67,13 @@ declare global {
67
67
  * @param {object} attrs
68
68
  * @param {function} content
69
69
  */
70
- function el(tag: string, attrs?: object, content?: any);
70
+ function el(tag: string, attrs?: object, content?: any)
71
71
 
72
72
  /**
73
73
  * buffer output
74
74
  * @param any
75
75
  */
76
- function echo(...any);
76
+ function echo(...any)
77
77
 
78
78
  /**
79
79
  * append rendered template from file
@@ -81,16 +81,21 @@ declare global {
81
81
  * @param data
82
82
  * @param cx
83
83
  */
84
- function include(path: string, data?: object, cx?: boolean);
84
+ function include(path: string, data?: object, cx?: boolean)
85
85
 
86
86
  /**
87
87
  *
88
88
  * @param value
89
89
  * @param callback
90
90
  */
91
- function each(value:any,callback:Function);
91
+ function each(value: any, callback: Function)
92
92
 
93
+ /**
94
+ * define block with custom **name** and callback
95
+ * @param {string} name
96
+ * @param {object} [props]
97
+ */
98
+ function ui(name: string, props?)
93
99
  }
94
100
 
95
101
  export = global
96
-
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.33",
5
+ "version": "0.0.35",
6
6
  "main": "dist/ejs.cjs",
7
7
  "module": "dist/ejs.mjs",
8
8
  "browser": "dist/ejs.js",
@@ -26,7 +26,8 @@
26
26
  "devDependencies": {
27
27
  "@babel/core": "^7.20.12",
28
28
  "@babel/preset-env": "^7.20.2",
29
- "@kosatyi/ejs-bundle": "^1.0.6",
29
+ "@kosatyi/ejs-bundle": "^1.0.8",
30
+ "@kosatyi/ejs": "file:./",
30
31
  "@kosatyi/rollup": "^0.0.1"
31
32
  },
32
33
  "license": "MIT",