@kosatyi/ejs 0.0.35 → 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() {
@@ -502,22 +503,26 @@ var Context = /*#__PURE__*/function () {
502
503
  extend(this, data);
503
504
  }
504
505
  Scope.prototype = extend({}, methods || {});
505
- Scope.defineProp = Scope.method = function (name, value) {
506
- var writable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
507
- var configurable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
508
- var enumerable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
509
- Object.defineProperty(Scope.prototype, name, {
506
+ /**
507
+ * @param {string} name
508
+ * @param {*} value
509
+ * @param {boolean} [writable]
510
+ * @param {boolean} [configurable]
511
+ * @param {boolean} [enumerable]
512
+ */
513
+ Scope.define = Scope.method = function (name, value, writable, configurable, enumerable) {
514
+ return Object.defineProperty(Scope.prototype, name, {
510
515
  value: value,
511
- writable: writable,
512
- configurable: configurable,
513
- enumerable: enumerable
516
+ writable: writable || false,
517
+ configurable: configurable || false,
518
+ enumerable: enumerable || false
514
519
  });
515
520
  };
516
- Scope.defineProp(BUFFER, createBuffer());
517
- Scope.defineProp(BLOCKS, {}, true);
518
- Scope.defineProp(MACRO, {}, true);
519
- Scope.defineProp(LAYOUT, false, true);
520
- Scope.defineProp(EXTEND, false, true);
521
+ Scope.define(BUFFER, createBuffer());
522
+ Scope.define(BLOCKS, {}, true);
523
+ Scope.define(MACRO, {}, true);
524
+ Scope.define(LAYOUT, false, true);
525
+ Scope.define(EXTEND, false, true);
521
526
  Scope.method('initBlocks', function () {
522
527
  this[BLOCKS] = {};
523
528
  });
@@ -531,7 +536,15 @@ var Context = /*#__PURE__*/function () {
531
536
  return this[BUFFER];
532
537
  });
533
538
  Scope.method('getComponent', function () {
534
- return this[COMPONENT];
539
+ var context = this;
540
+ if (COMPONENT in context) {
541
+ return function () {
542
+ return context[COMPONENT].apply(context, arguments);
543
+ };
544
+ }
545
+ return function () {
546
+ console.log('%s function not defined', COMPONENT);
547
+ };
535
548
  });
536
549
  Scope.method('getBlocks', function () {
537
550
  return this[BLOCKS];
@@ -665,7 +678,6 @@ var Context = /*#__PURE__*/function () {
665
678
  }
666
679
  each(object, callback);
667
680
  });
668
- Scope.method(COMPONENT, function () {}, true);
669
681
  }
670
682
  }]);
671
683
  return Context;
@@ -834,7 +846,6 @@ var _init = init({}),
834
846
  render = _init.render,
835
847
  helpers = _init.helpers,
836
848
  configure = _init.configure,
837
- wrapper = _init.wrapper,
838
849
  compile = _init.compile,
839
850
  create = _init.create,
840
851
  preload = _init.preload,
@@ -849,4 +860,3 @@ exports.helpers = helpers;
849
860
  exports.preload = preload;
850
861
  exports.render = render;
851
862
  exports.safeValue = safeValue;
852
- 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() {
@@ -496,22 +497,26 @@
496
497
  extend(this, data);
497
498
  }
498
499
  Scope.prototype = extend({}, methods || {});
499
- Scope.defineProp = Scope.method = function (name, value) {
500
- var writable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
501
- var configurable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
502
- var enumerable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
503
- Object.defineProperty(Scope.prototype, name, {
500
+ /**
501
+ * @param {string} name
502
+ * @param {*} value
503
+ * @param {boolean} [writable]
504
+ * @param {boolean} [configurable]
505
+ * @param {boolean} [enumerable]
506
+ */
507
+ Scope.define = Scope.method = function (name, value, writable, configurable, enumerable) {
508
+ return Object.defineProperty(Scope.prototype, name, {
504
509
  value: value,
505
- writable: writable,
506
- configurable: configurable,
507
- enumerable: enumerable
510
+ writable: writable || false,
511
+ configurable: configurable || false,
512
+ enumerable: enumerable || false
508
513
  });
509
514
  };
510
- Scope.defineProp(BUFFER, createBuffer());
511
- Scope.defineProp(BLOCKS, {}, true);
512
- Scope.defineProp(MACRO, {}, true);
513
- Scope.defineProp(LAYOUT, false, true);
514
- Scope.defineProp(EXTEND, false, true);
515
+ Scope.define(BUFFER, createBuffer());
516
+ Scope.define(BLOCKS, {}, true);
517
+ Scope.define(MACRO, {}, true);
518
+ Scope.define(LAYOUT, false, true);
519
+ Scope.define(EXTEND, false, true);
515
520
  Scope.method('initBlocks', function () {
516
521
  this[BLOCKS] = {};
517
522
  });
@@ -525,7 +530,15 @@
525
530
  return this[BUFFER];
526
531
  });
527
532
  Scope.method('getComponent', function () {
528
- return this[COMPONENT];
533
+ var context = this;
534
+ if (COMPONENT in context) {
535
+ return function () {
536
+ return context[COMPONENT].apply(context, arguments);
537
+ };
538
+ }
539
+ return function () {
540
+ console.log('%s function not defined', COMPONENT);
541
+ };
529
542
  });
530
543
  Scope.method('getBlocks', function () {
531
544
  return this[BLOCKS];
@@ -659,7 +672,6 @@
659
672
  }
660
673
  each(object, callback);
661
674
  });
662
- Scope.method(COMPONENT, function () {}, true);
663
675
  }
664
676
  }]);
665
677
  return Context;
@@ -828,7 +840,6 @@
828
840
  render = _init.render,
829
841
  helpers = _init.helpers,
830
842
  configure = _init.configure,
831
- wrapper = _init.wrapper,
832
843
  compile = _init.compile,
833
844
  create = _init.create,
834
845
  preload = _init.preload,
@@ -843,7 +854,6 @@
843
854
  exports.preload = preload;
844
855
  exports.render = render;
845
856
  exports.safeValue = safeValue;
846
- exports.wrapper = wrapper;
847
857
 
848
858
  Object.defineProperty(exports, '__esModule', { value: true });
849
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=" ",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})}));
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
@@ -463,50 +463,52 @@ class Context {
463
463
  constructor(config) {
464
464
  this.configure(config);
465
465
  }
466
-
467
466
  configure(config, methods) {
468
467
  const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO, COMPONENT } = config.vars;
469
-
470
468
  this.create = (data) => {
471
469
  return new Scope(data)
472
470
  };
473
-
474
471
  this.helpers = (methods) => {
472
+ console.log('extend', Scope.prototype, methods);
475
473
  extend(Scope.prototype, methods);
476
474
  };
477
-
478
475
  function Scope(data = {}) {
479
476
  this.initBlocks();
480
477
  this.initMacro();
481
478
  extend(this, data);
482
479
  }
483
-
484
480
  Scope.prototype = extend({}, methods || {});
485
-
486
- Scope.defineProp = Scope.method = (
481
+ /**
482
+ * @param {string} name
483
+ * @param {*} value
484
+ * @param {boolean} [writable]
485
+ * @param {boolean} [configurable]
486
+ * @param {boolean} [enumerable]
487
+ */
488
+ Scope.define = Scope.method = (
487
489
  name,
488
490
  value,
489
- writable = false,
490
- configurable = false,
491
- enumerable = false
491
+ writable,
492
+ configurable,
493
+ enumerable
492
494
  ) => {
493
- Object.defineProperty(Scope.prototype, name, {
494
- value,
495
- writable,
496
- configurable,
497
- enumerable,
498
- });
495
+ return Object.defineProperty(Scope.prototype, name, {
496
+ value: value,
497
+ writable: writable || false,
498
+ configurable: configurable || false,
499
+ enumerable: enumerable || false,
500
+ })
499
501
  };
500
502
 
501
- Scope.defineProp(BUFFER, createBuffer());
503
+ Scope.define(BUFFER, createBuffer());
502
504
 
503
- Scope.defineProp(BLOCKS, {}, true);
505
+ Scope.define(BLOCKS, {}, true);
504
506
 
505
- Scope.defineProp(MACRO, {}, true);
507
+ Scope.define(MACRO, {}, true);
506
508
 
507
- Scope.defineProp(LAYOUT, false, true);
509
+ Scope.define(LAYOUT, false, true);
508
510
 
509
- Scope.defineProp(EXTEND, false, true);
511
+ Scope.define(EXTEND, false, true);
510
512
 
511
513
  Scope.method('initBlocks', function () {
512
514
  this[BLOCKS] = {};
@@ -525,7 +527,15 @@ class Context {
525
527
  });
526
528
 
527
529
  Scope.method('getComponent', function () {
528
- return this[COMPONENT]
530
+ const context = this;
531
+ if (COMPONENT in context) {
532
+ return function () {
533
+ return context[COMPONENT].apply(context, arguments)
534
+ }
535
+ }
536
+ return function () {
537
+ console.log('%s function not defined', COMPONENT);
538
+ }
529
539
  });
530
540
 
531
541
  Scope.method('getBlocks', function () {
@@ -696,8 +706,6 @@ class Context {
696
706
  }
697
707
  each(object, callback);
698
708
  });
699
-
700
- Scope.method(COMPONENT, function () {}, true);
701
709
  }
702
710
  }
703
711
 
@@ -891,11 +899,10 @@ const {
891
899
  render,
892
900
  helpers,
893
901
  configure,
894
- wrapper,
895
902
  compile,
896
903
  create,
897
904
  preload,
898
905
  __express,
899
906
  } = init({});
900
907
 
901
- 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.35",
5
+ "version": "0.0.37",
6
6
  "main": "dist/ejs.cjs",
7
7
  "module": "dist/ejs.mjs",
8
8
  "browser": "dist/ejs.js",