@kosatyi/ejs 0.0.36 → 0.0.37

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
@@ -493,6 +493,7 @@ var Context = /*#__PURE__*/function () {
493
493
  return new Scope(data);
494
494
  };
495
495
  this.helpers = function (methods) {
496
+ console.log('extend', Scope.prototype, methods);
496
497
  extend(Scope.prototype, methods);
497
498
  };
498
499
  function Scope() {
@@ -535,7 +536,13 @@ var Context = /*#__PURE__*/function () {
535
536
  return this[BUFFER];
536
537
  });
537
538
  Scope.method('getComponent', function () {
538
- return this[COMPONENT] || function () {
539
+ var context = this;
540
+ if (COMPONENT in context) {
541
+ return function () {
542
+ return context[COMPONENT].apply(context, arguments);
543
+ };
544
+ }
545
+ return function () {
539
546
  console.log('%s function not defined', COMPONENT);
540
547
  };
541
548
  });
@@ -839,7 +846,6 @@ var _init = init({}),
839
846
  render = _init.render,
840
847
  helpers = _init.helpers,
841
848
  configure = _init.configure,
842
- wrapper = _init.wrapper,
843
849
  compile = _init.compile,
844
850
  create = _init.create,
845
851
  preload = _init.preload,
@@ -854,4 +860,3 @@ exports.helpers = helpers;
854
860
  exports.preload = preload;
855
861
  exports.render = render;
856
862
  exports.safeValue = safeValue;
857
- exports.wrapper = wrapper;
package/dist/ejs.js CHANGED
@@ -487,6 +487,7 @@
487
487
  return new Scope(data);
488
488
  };
489
489
  this.helpers = function (methods) {
490
+ console.log('extend', Scope.prototype, methods);
490
491
  extend(Scope.prototype, methods);
491
492
  };
492
493
  function Scope() {
@@ -529,7 +530,13 @@
529
530
  return this[BUFFER];
530
531
  });
531
532
  Scope.method('getComponent', function () {
532
- return this[COMPONENT] || function () {
533
+ var context = this;
534
+ if (COMPONENT in context) {
535
+ return function () {
536
+ return context[COMPONENT].apply(context, arguments);
537
+ };
538
+ }
539
+ return function () {
533
540
  console.log('%s function not defined', COMPONENT);
534
541
  };
535
542
  });
@@ -833,7 +840,6 @@
833
840
  render = _init.render,
834
841
  helpers = _init.helpers,
835
842
  configure = _init.configure,
836
- wrapper = _init.wrapper,
837
843
  compile = _init.compile,
838
844
  create = _init.create,
839
845
  preload = _init.preload,
@@ -848,7 +854,6 @@
848
854
  exports.preload = preload;
849
855
  exports.render = render;
850
856
  exports.safeValue = safeValue;
851
- exports.wrapper = wrapper;
852
857
 
853
858
  Object.defineProperty(exports, '__esModule', { value: true });
854
859
 
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",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=" ",B='"',P="/",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),[B,d(t),B].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,P,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.define=f.method=function(t,e,n,r,i){return Object.defineProperty(f.prototype,t,{value:e,writable:n||!1,configurable:r||!1,enumerable:i||!1})},f.define(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.define(u,{},!0),f.define(a,{},!0),f.define(c,!1,!0),f.define(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]||function(){console.log("%s function not defined",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)}))}}]),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})}));
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)},x=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}))},k=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=" ",B='"',P="/",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),[B,d(t),B].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,P,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){console.log("extend",f.prototype,t),b(f.prototype,t)},f.prototype=b({},e||{}),f.define=f.method=function(t,e,n,r,i){return Object.defineProperty(f.prototype,t,{value:e,writable:n||!1,configurable:r||!1,enumerable:i||!1})},f.define(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.define(u,{},!0),f.define(a,{},!0),f.define(c,!1,!0),f.define(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(){var t=this;return h in t?function(){return t[h].apply(t,arguments)}:function(){console.log("%s function not defined",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),x(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(k(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(k(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(k(n,(function(n){return $(t,e,n)}),this))})),f.method("each",(function(t,e){o(t)&&(t=this.get(t,[])),j(t,e)}))}}]),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.compile,Q=z.create,Z=z.preload,tt=z.__express;t.__express=tt,t.compile=J,t.configure=I,t.create=Q,t.element=$,t.helpers=H,t.preload=Z,t.render=G,t.safeValue=m,Object.defineProperty(t,"__esModule",{value:!0})}));
package/dist/ejs.mjs CHANGED
@@ -469,6 +469,7 @@ class Context {
469
469
  return new Scope(data)
470
470
  };
471
471
  this.helpers = (methods) => {
472
+ console.log('extend', Scope.prototype, methods);
472
473
  extend(Scope.prototype, methods);
473
474
  };
474
475
  function Scope(data = {}) {
@@ -526,12 +527,15 @@ class Context {
526
527
  });
527
528
 
528
529
  Scope.method('getComponent', function () {
529
- return (
530
- this[COMPONENT] ||
531
- function () {
532
- console.log('%s function not defined', COMPONENT);
530
+ const context = this;
531
+ if (COMPONENT in context) {
532
+ return function () {
533
+ return context[COMPONENT].apply(context, arguments)
533
534
  }
534
- )
535
+ }
536
+ return function () {
537
+ console.log('%s function not defined', COMPONENT);
538
+ }
535
539
  });
536
540
 
537
541
  Scope.method('getBlocks', function () {
@@ -895,11 +899,10 @@ const {
895
899
  render,
896
900
  helpers,
897
901
  configure,
898
- wrapper,
899
902
  compile,
900
903
  create,
901
904
  preload,
902
905
  __express,
903
906
  } = init({});
904
907
 
905
- export { __express, compile, configure, create, element, helpers, preload, render, safeValue, wrapper };
908
+ export { __express, compile, configure, create, element, helpers, preload, render, safeValue };
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.36",
5
+ "version": "0.0.37",
6
6
  "main": "dist/ejs.cjs",
7
7
  "module": "dist/ejs.mjs",
8
8
  "browser": "dist/ejs.js",