@kosatyi/ejs 0.0.11 → 0.0.12

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
@@ -111,7 +111,6 @@ var extend = function extend() {
111
111
  return Object.assign(target, source);
112
112
  }, target);
113
113
  };
114
- var noop = function noop() {};
115
114
  var each = function each(object, callback) {
116
115
  var prop;
117
116
 
@@ -461,7 +460,10 @@ var Scope = function Scope(config, methods) {
461
460
 
462
461
  function Scope() {
463
462
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
463
+ this.setBlocks({});
464
464
  extend(this, data);
465
+ this.setLayout(false);
466
+ this.setExtend(false);
465
467
  }
466
468
  /**
467
469
  *
@@ -473,27 +475,6 @@ var Scope = function Scope(config, methods) {
473
475
  writable: false,
474
476
  configurable: false,
475
477
  enumerable: false
476
- }), _defineProperty(_Object$definePropert, BLOCKS, {
477
- value: {},
478
- writable: false,
479
- configurable: false,
480
- enumerable: false
481
- }), _defineProperty(_Object$definePropert, EXTEND, {
482
- value: false,
483
- writable: true,
484
- configurable: false,
485
- enumerable: false
486
- }), _defineProperty(_Object$definePropert, LAYOUT, {
487
- value: false,
488
- writable: true,
489
- configurable: false,
490
- enumerable: false
491
- }), _defineProperty(_Object$definePropert, "setBuffer", {
492
- value: function value(_value) {
493
- this[BUFFER] = _value;
494
- },
495
- writable: false,
496
- configurable: false
497
478
  }), _defineProperty(_Object$definePropert, "getBuffer", {
498
479
  value: function value() {
499
480
  return this[BUFFER];
@@ -501,8 +482,8 @@ var Scope = function Scope(config, methods) {
501
482
  writable: false,
502
483
  configurable: false
503
484
  }), _defineProperty(_Object$definePropert, "setBlocks", {
504
- value: function value(_value2) {
505
- this[BLOCKS] = _value2;
485
+ value: function value(_value) {
486
+ this[BLOCKS] = _value;
506
487
  },
507
488
  writable: false,
508
489
  configurable: false
@@ -513,8 +494,8 @@ var Scope = function Scope(config, methods) {
513
494
  writable: false,
514
495
  configurable: false
515
496
  }), _defineProperty(_Object$definePropert, "setExtend", {
516
- value: function value(_value3) {
517
- this[EXTEND] = _value3;
497
+ value: function value(_value2) {
498
+ this[EXTEND] = _value2;
518
499
  },
519
500
  writable: false,
520
501
  configurable: false
@@ -599,7 +580,9 @@ var Scope = function Scope(config, methods) {
599
580
  return echo === true ? this.echo(result) : result;
600
581
  }.bind(this);
601
582
 
602
- macro.ctx = this;
583
+ macro.__context = this;
584
+ macro.__source = callback;
585
+ macro.__layout = this.getLayout();
603
586
  return macro;
604
587
  },
605
588
 
@@ -731,23 +714,26 @@ var Scope = function Scope(config, methods) {
731
714
  */
732
715
  block: function block(name, callback) {
733
716
  var blocks = this.getBlocks();
734
- var macro = this.macro(callback);
735
- var block = blocks[name];
736
-
737
- if (this.getExtend()) {
738
- if (block) {
739
- block.parent = function () {
740
- this.echo(macro());
741
- }.bind(block.ctx);
742
- } else {
743
- blocks[name] = macro;
744
- }
745
- } else {
746
- if (block) {
747
- this.echo(block(block.parent));
748
- } else {
749
- this.echo(macro(noop));
750
- }
717
+ blocks[name] = blocks[name] || [];
718
+ blocks[name].push(this.macro(callback));
719
+
720
+ if (this.getExtend() === false) {
721
+ var list = blocks[name];
722
+
723
+ var _callback = function _callback() {
724
+ var parent = list.shift();
725
+
726
+ if (parent) {
727
+ var context = parent.__context;
728
+ return function () {
729
+ context.echo(parent(_callback()));
730
+ };
731
+ } else {
732
+ return function () {};
733
+ }
734
+ };
735
+
736
+ this.echo(list.shift()(_callback()));
751
737
  }
752
738
  },
753
739
 
package/dist/ejs.js CHANGED
@@ -107,7 +107,6 @@
107
107
  return Object.assign(target, source);
108
108
  }, target);
109
109
  };
110
- var noop = function noop() {};
111
110
  var each = function each(object, callback) {
112
111
  var prop;
113
112
 
@@ -457,7 +456,10 @@
457
456
 
458
457
  function Scope() {
459
458
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
459
+ this.setBlocks({});
460
460
  extend(this, data);
461
+ this.setLayout(false);
462
+ this.setExtend(false);
461
463
  }
462
464
  /**
463
465
  *
@@ -469,27 +471,6 @@
469
471
  writable: false,
470
472
  configurable: false,
471
473
  enumerable: false
472
- }), _defineProperty(_Object$definePropert, BLOCKS, {
473
- value: {},
474
- writable: false,
475
- configurable: false,
476
- enumerable: false
477
- }), _defineProperty(_Object$definePropert, EXTEND, {
478
- value: false,
479
- writable: true,
480
- configurable: false,
481
- enumerable: false
482
- }), _defineProperty(_Object$definePropert, LAYOUT, {
483
- value: false,
484
- writable: true,
485
- configurable: false,
486
- enumerable: false
487
- }), _defineProperty(_Object$definePropert, "setBuffer", {
488
- value: function value(_value) {
489
- this[BUFFER] = _value;
490
- },
491
- writable: false,
492
- configurable: false
493
474
  }), _defineProperty(_Object$definePropert, "getBuffer", {
494
475
  value: function value() {
495
476
  return this[BUFFER];
@@ -497,8 +478,8 @@
497
478
  writable: false,
498
479
  configurable: false
499
480
  }), _defineProperty(_Object$definePropert, "setBlocks", {
500
- value: function value(_value2) {
501
- this[BLOCKS] = _value2;
481
+ value: function value(_value) {
482
+ this[BLOCKS] = _value;
502
483
  },
503
484
  writable: false,
504
485
  configurable: false
@@ -509,8 +490,8 @@
509
490
  writable: false,
510
491
  configurable: false
511
492
  }), _defineProperty(_Object$definePropert, "setExtend", {
512
- value: function value(_value3) {
513
- this[EXTEND] = _value3;
493
+ value: function value(_value2) {
494
+ this[EXTEND] = _value2;
514
495
  },
515
496
  writable: false,
516
497
  configurable: false
@@ -595,7 +576,9 @@
595
576
  return echo === true ? this.echo(result) : result;
596
577
  }.bind(this);
597
578
 
598
- macro.ctx = this;
579
+ macro.__context = this;
580
+ macro.__source = callback;
581
+ macro.__layout = this.getLayout();
599
582
  return macro;
600
583
  },
601
584
 
@@ -727,23 +710,26 @@
727
710
  */
728
711
  block: function block(name, callback) {
729
712
  var blocks = this.getBlocks();
730
- var macro = this.macro(callback);
731
- var block = blocks[name];
732
-
733
- if (this.getExtend()) {
734
- if (block) {
735
- block.parent = function () {
736
- this.echo(macro());
737
- }.bind(block.ctx);
738
- } else {
739
- blocks[name] = macro;
740
- }
741
- } else {
742
- if (block) {
743
- this.echo(block(block.parent));
744
- } else {
745
- this.echo(macro(noop));
746
- }
713
+ blocks[name] = blocks[name] || [];
714
+ blocks[name].push(this.macro(callback));
715
+
716
+ if (this.getExtend() === false) {
717
+ var list = blocks[name];
718
+
719
+ var _callback = function _callback() {
720
+ var parent = list.shift();
721
+
722
+ if (parent) {
723
+ var context = parent.__context;
724
+ return function () {
725
+ context.echo(parent(_callback()));
726
+ };
727
+ } else {
728
+ return function () {};
729
+ }
730
+ };
731
+
732
+ this.echo(list.shift()(_callback()));
747
733
  }
748
734
  },
749
735
 
package/dist/ejs.min.js CHANGED
@@ -1 +1 @@
1
- !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).ejs=t()}(this,(function(){"use strict";var n={},t={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:{template:"ejs",module:"mjs"},vars:{EXTEND:"$$$",BUFFER:"$$a",OUTPUT:"$$i",LAYOUT:"$$l",MACROS:"$$m",PRINT:"$$j",BLOCKS:"$$b",ERROR:"$$e",SCOPE:"$$s",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},e=function(){var n=[].slice.call(arguments),t=n.shift();return n.filter(t).pop()},r=function(n){return"function"==typeof n},o=function(n){return"string"==typeof n},i=function(n){return"boolean"==typeof n},u=new Function("try {return this===global;}catch(e){return false;}"),c={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},a={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},f=function(n){return new RegExp(["[",Object.keys(n).join(""),"]"].join(""),"g")},s=f(a),l=f(c),h=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+n).replace(s,(function(n){return a[n]}))},p=function(n,t,e){return null==(e=n)?"":t?h(e):e},v=function(n,t){var e=n,r=t.split("."),o=r.pop();return r.forEach((function(n){e=e[n]=e[n]||{}})),[e,o]},d=function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var r=t.shift();return t.filter((function(n){return n})).reduce((function(n,t){return Object.assign(n,t)}),r)},g=function(){},b=function(n,t){var e;for(e in n)w(n,e)&&t(n[e],e,n)},m=function(n,t){return function(n,t,e){var r=n instanceof Array,o=r?[]:{};return b(n,(function(n,e,i){var u=t(n,e,i);void 0!==u&&(r?o.push(u):o[e]=u)})),o}(n,(function(n,e){if(-1===t.indexOf(e))return n}))},w=function(n,t){return n&&n.hasOwnProperty(t)},x=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],E=" ",y='"',j="/",$="<",O=">";function k(n,t,e){var r=[],o=-1===x.indexOf(n),i=function(n,t,e){var r=[];return b(n,(function(n,e,o){var i=t(n,e,o);void 0!==i&&r.push(i)})),r}(t,(function(n,t){if(null!=n)return[h(t),[y,h(n),y].join("")].join("=")})).join(E);return r.push([$,n,E,i,O].join("")),e&&r.push(e instanceof Array?e.join(""):e),o&&r.push([$,j,n,O].join("")),r.join("")}var F=[{symbol:"-",format:function(n){return"'+\n".concat(this.SAFE,"(").concat(n,",1)+\n'")}},{symbol:"=",format:function(n){return"'+\n".concat(this.SAFE,"(").concat(n,")+\n'")}},{symbol:"#",format:function(n){return"'+\n/**".concat(n,"**/+\n'")}},{symbol:"",format:function(n){return"')\n".concat(n,"\n").concat(this.BUFFER,"('")}}],R=function(n){var t=n.token,e=n.vars,r=n.extension.module,o=[],i=[],u={match:"[ \\t]*",start:[t.start,"_"],end:["_",t.end]};F.forEach((function(n){o.push(t.start.concat(n.symbol).concat(t.regex).concat(t.end)),i.push(n.format.bind(e))}));var a=new RegExp(o.join("|").concat("|$"),"g"),f=new RegExp([u.match,u.start].join(""),"gm"),s=new RegExp([u.end,u.match].join(""),"gm");return function(n,o){var h=e.SCOPE,p=e.SAFE,v=e.BUFFER,d=o.split(".").pop();n=(n=n.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(f,u.start).replace(s,u.end),d===r&&(n=[t.start,n,t.end].join("\n"));var g="".concat(v,"('");!function(n,t,e){var r=0;t.replace(n,(function(){var n=[].slice.call(arguments,0,-1),t=n.pop(),o=n.shift();return e(n,r,t),r=t+o.length,o}))}(a,n,(function(t,e,r){g+=(""+n.slice(e,r)).replace(l,(function(n){return"\\"+c[n]})),t.forEach((function(n,t){n&&(g+=i[t](n))}))})),g+="');",g="with(".concat(h,"){").concat(g,"}"),g="".concat(v,".start();").concat(g,"return ").concat(v,".end();"),g+="\n//# sourceURL=".concat(o);var b=null;try{(b=new Function(h,v,p,g)).source="(function(".concat(h,",").concat(v,",").concat(p,"){\n").concat(g,"\n})")}catch(n){throw n.filename=o,n.source=g,n}return b}},B=function(n){return window.fetch(n).then((function(n){return n.text()}))},S=function(t){return new Promise((function(e,r){n.readFile(t,(function(n,t){n?r(n):e(t.toString())}))}))},A=function(t,e){return n.watch(".",{cwd:t}).on("change",(function(n){e.remove(n)})).on("error",(function(n){console.log("watcher error: "+n)}))},P=function(n,t,e){var o=n.path;n.token;var i=r(n.resolver)?n.resolver:u()?S:B,c=function(n){return i(function(n){return(n=[o,n].join("/")).replace(/\/\//g,"/")}(n))},a=function(n,e){return t.set(e,n),n};return n.watch&&u()&&A(o,t),function(n){if(t.exist(n))return t.resolve(n);var r=c(n).then((function(t){return a(e(t,n),n)}));return a(r,n)}};function L(n,t,e){return t in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e,n}var T=function(n){return Promise.all(n).then((function(n){return n.join("")}))},U=function(){var n=[],t=[];function e(n){t.push(n)}return e.start=function(){t=[]},e.backup=function(){n.push(t.concat()),t=[]},e.restore=function(){var e=t.concat();return t=n.pop(),T(e)},e.end=function(){return T(t)},e},q=function(n,t){var e,i=n.vars,u=i.EXTEND,c=i.MACROS,a=i.LAYOUT,f=i.BLOCKS,s=i.BUFFER;function l(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};d(this,n)}return Object.defineProperties(l.prototype,(L(e={},s,{value:U(),writable:!1,configurable:!1,enumerable:!1}),L(e,f,{value:{},writable:!1,configurable:!1,enumerable:!1}),L(e,u,{value:!1,writable:!0,configurable:!1,enumerable:!1}),L(e,a,{value:!1,writable:!0,configurable:!1,enumerable:!1}),L(e,"setBuffer",{value:function(n){this[s]=n},writable:!1,configurable:!1}),L(e,"getBuffer",{value:function(){return this[s]},writable:!1,configurable:!1}),L(e,"setBlocks",{value:function(n){this[f]=n},writable:!1,configurable:!1}),L(e,"getBlocks",{value:function(){return this[f]},writable:!1,configurable:!1}),L(e,"setExtend",{value:function(n){this[u]=n},writable:!1,configurable:!1}),L(e,"getExtend",{value:function(){return this[u]},writable:!1,configurable:!1}),L(e,"setLayout",{value:function(n){this[a]=n},writable:!1,configurable:!1}),L(e,"getLayout",{value:function(){return this[a]},writable:!1,configurable:!1}),e)),l.helpers=function(n){d(l.prototype,n)},l.helpers(t),l.helpers({clone:function(n){var t=[a,u,c,s];return!0===n&&t.push(f),m(this,t)},echo:function(){var n=this.getBuffer(),t=[].slice.call(arguments);t.forEach((function(t){n(t)}))},macro:function(n,t){var e=this.getBuffer(),o=function(){e.backup(),r(n)&&n.apply(this,arguments);var o=e.restore();return!0===t?this.echo(o):o}.bind(this);return o.ctx=this,o},resolve:function(n,t){return Promise.resolve(n).then(t.bind(this))},async:function(n,t){var e=this;this.echo(this.resolve(n,(function(n){return e.macro(t)(n)})))},node:k,element:function(n,t,e){r(e)&&(e=this.macro(e)()),this.echo(this.resolve(e,(function(e){return k(n,t,e)})))},component:function(n,t){t=function(n){var t=d({},n.props);return{element:k,create:n.create,render:function(n){return this.create(d({},t,n))}}}(t),this.set(n,function(n){this.echo(t.render(n))}.bind(this))},get:function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();return w(r,o)?r[o]:t},set:function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();if(this.getExtend()&&w(r,o))return r[o];r[o]=t},call:function(n){var t=[].slice.call(arguments,1),e=v(this,n),o=e.shift(),i=e.pop();if(r(o[i]))return o[i].apply(o,t)},each:function(n,t){o(n)&&(n=this.get(n,[])),b(n,t)},extend:function(n){this.setExtend(!0),this.setLayout(n)},block:function(n,t){var e=this.getBlocks(),r=this.macro(t),o=e[n];this.getExtend()?o?o.parent=function(){this.echo(r())}.bind(o.ctx):e[n]=r:o?this.echo(o(o.parent)):this.echo(r(g))},include:function(n,t,e){var r=!1===e?{}:this.clone(!0),o=d(r,t||{}),i=this.render(n,o);this.echo(i)},use:function(n){var t=this,e=this.require(n);return this.echo(e),{as:function(n){return e.then((function(e){t.set(n,e)})),this}}},from:function(n){var t=this,e=this.require(n);return this.echo(e),{use:function(){var n=[].slice.call(arguments);return e.then((function(e){n.forEach((function(n){t.set(n,e[n])}))})),this}}}}),l};var C,N,_,D,K,M=(N={},_={},D=function(n,t){var e=n.split(".").pop();return e!==t&&(n=[n,t].join(".")),n},K={element:k,output:function(n,t){return K.template(n).then((function(n){return n.call(t,t,t.getBuffer(),p)}))},render:function(n,t){var e=D(n,N.extension.template),r=new K.scope(t);return K.output(e,r).then((function(n){if(r.getExtend()){r.setExtend(!1);var t=r.getLayout(),e=r.clone();return K.render(t,e)}return n}))},require:function(n){var t=D(n,N.extension.module),e=new K.scope({});return K.output(t,e).then((function(){return e.clone(!0)}))},helpers:function(n){d(_,n=n||{}),K.scope.helpers(n)},configure:function(n){return N.export=e(o,t.export,n.export),N.path=e(o,t.path,n.path),N.resolver=e(r,t.resolver,n.resolver),N.extension=d({},t.extension,n.extension),N.token=d({},t.token,n.token),N.vars=d({},t.vars,n.vars),K.scope=q(N,_),K.compile=R(N),K.wrapper=function(n){var t=n.export;return function(n){var e="(function(o){\n";return n.forEach((function(n){e+="o["+JSON.stringify(n.name)+"]="+String(n.content)+"\n"})),e+='})(window["'+t+'"] = window["'+t+'"] || {});\n'}}(N),K.cache=function(n){var t=n.export,e={};return{preload:function(){return!1===u()&&this.load(window[t]),this},exist:function(n){return w(e,n)},get:function(n){return e[n]},remove:function(n){delete e[n]},resolve:function(n){return Promise.resolve(this.get(n))},set:function(n,t){return e[n]=t,this},load:function(n){return d(e,n),this}}.preload()}(N),K.template=P(N,K.cache,K.compile),K},__express:function(u,c,a){r(c)&&(a=c,c={});var f=d({},(c=c||{}).settings),s=e(o,f.views,t.path),l=e(i,f["view cache"],t.cache),h=d({},f["view options"]),p=n.relative(s,u);return h.path=s,h.cache=l,K.configure(h),K.render(p,c).then((function(n){a(null,n)})).catch((function(n){a(n)}))}},K.configure(C||{}),K.helpers({require:function(n){return K.require(n,this)},render:function(n,t){return K.render(n,t)}}),K);return M}));
1
+ !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).ejs=t()}(this,(function(){"use strict";var n={},t={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:{template:"ejs",module:"mjs"},vars:{EXTEND:"$$$",BUFFER:"$$a",OUTPUT:"$$i",LAYOUT:"$$l",MACROS:"$$m",PRINT:"$$j",BLOCKS:"$$b",ERROR:"$$e",SCOPE:"$$s",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},e=function(){var n=[].slice.call(arguments),t=n.shift();return n.filter(t).pop()},r=function(n){return"function"==typeof n},o=function(n){return"string"==typeof n},i=function(n){return"boolean"==typeof n},u=new Function("try {return this===global;}catch(e){return false;}"),c={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},a={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},s=function(n){return new RegExp(["[",Object.keys(n).join(""),"]"].join(""),"g")},f=s(a),l=s(c),h=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+n).replace(f,(function(n){return a[n]}))},p=function(n,t,e){return null==(e=n)?"":t?h(e):e},v=function(n,t){var e=n,r=t.split("."),o=r.pop();return r.forEach((function(n){e=e[n]=e[n]||{}})),[e,o]},d=function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var r=t.shift();return t.filter((function(n){return n})).reduce((function(n,t){return Object.assign(n,t)}),r)},g=function(n,t){var e;for(e in n)b(n,e)&&t(n[e],e,n)},m=function(n,t){return function(n,t,e){var r=n instanceof Array,o=r?[]:{};return g(n,(function(n,e,i){var u=t(n,e,i);void 0!==u&&(r?o.push(u):o[e]=u)})),o}(n,(function(n,e){if(-1===t.indexOf(e))return n}))},b=function(n,t){return n&&n.hasOwnProperty(t)},w=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],x=" ",y='"',E="/",j="<",$=">";function O(n,t,e){var r=[],o=-1===w.indexOf(n),i=function(n,t,e){var r=[];return g(n,(function(n,e,o){var i=t(n,e,o);void 0!==i&&r.push(i)})),r}(t,(function(n,t){if(null!=n)return[h(t),[y,h(n),y].join("")].join("=")})).join(x);return r.push([j,n,x,i,$].join("")),e&&r.push(e instanceof Array?e.join(""):e),o&&r.push([j,E,n,$].join("")),r.join("")}var k=[{symbol:"-",format:function(n){return"'+\n".concat(this.SAFE,"(").concat(n,",1)+\n'")}},{symbol:"=",format:function(n){return"'+\n".concat(this.SAFE,"(").concat(n,")+\n'")}},{symbol:"#",format:function(n){return"'+\n/**".concat(n,"**/+\n'")}},{symbol:"",format:function(n){return"')\n".concat(n,"\n").concat(this.BUFFER,"('")}}],F=function(n){var t=n.token,e=n.vars,r=n.extension.module,o=[],i=[],u={match:"[ \\t]*",start:[t.start,"_"],end:["_",t.end]};k.forEach((function(n){o.push(t.start.concat(n.symbol).concat(t.regex).concat(t.end)),i.push(n.format.bind(e))}));var a=new RegExp(o.join("|").concat("|$"),"g"),s=new RegExp([u.match,u.start].join(""),"gm"),f=new RegExp([u.end,u.match].join(""),"gm");return function(n,o){var h=e.SCOPE,p=e.SAFE,v=e.BUFFER,d=o.split(".").pop();n=(n=n.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(s,u.start).replace(f,u.end),d===r&&(n=[t.start,n,t.end].join("\n"));var g="".concat(v,"('");!function(n,t,e){var r=0;t.replace(n,(function(){var n=[].slice.call(arguments,0,-1),t=n.pop(),o=n.shift();return e(n,r,t),r=t+o.length,o}))}(a,n,(function(t,e,r){g+=(""+n.slice(e,r)).replace(l,(function(n){return"\\"+c[n]})),t.forEach((function(n,t){n&&(g+=i[t](n))}))})),g+="');",g="with(".concat(h,"){").concat(g,"}"),g="".concat(v,".start();").concat(g,"return ").concat(v,".end();"),g+="\n//# sourceURL=".concat(o);var m=null;try{(m=new Function(h,v,p,g)).source="(function(".concat(h,",").concat(v,",").concat(p,"){\n").concat(g,"\n})")}catch(n){throw n.filename=o,n.source=g,n}return m}},R=function(n){return window.fetch(n).then((function(n){return n.text()}))},B=function(t){return new Promise((function(e,r){n.readFile(t,(function(n,t){n?r(n):e(t.toString())}))}))},S=function(t,e){return n.watch(".",{cwd:t}).on("change",(function(n){e.remove(n)})).on("error",(function(n){console.log("watcher error: "+n)}))},_=function(n,t,e){var o=n.path;n.token;var i=r(n.resolver)?n.resolver:u()?B:R,c=function(n){return i(function(n){return(n=[o,n].join("/")).replace(/\/\//g,"/")}(n))},a=function(n,e){return t.set(e,n),n};return n.watch&&u()&&S(o,t),function(n){if(t.exist(n))return t.resolve(n);var r=c(n).then((function(t){return a(e(t,n),n)}));return a(r,n)}};function A(n,t,e){return t in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e,n}var L=function(n){return Promise.all(n).then((function(n){return n.join("")}))},P=function(){var n=[],t=[];function e(n){t.push(n)}return e.start=function(){t=[]},e.backup=function(){n.push(t.concat()),t=[]},e.restore=function(){var e=t.concat();return t=n.pop(),L(e)},e.end=function(){return L(t)},e},T=function(n,t){var e,i=n.vars,u=i.EXTEND,c=i.MACROS,a=i.LAYOUT,s=i.BLOCKS,f=i.BUFFER;function l(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setBlocks({}),d(this,n),this.setLayout(!1),this.setExtend(!1)}return Object.defineProperties(l.prototype,(A(e={},f,{value:P(),writable:!1,configurable:!1,enumerable:!1}),A(e,"getBuffer",{value:function(){return this[f]},writable:!1,configurable:!1}),A(e,"setBlocks",{value:function(n){this[s]=n},writable:!1,configurable:!1}),A(e,"getBlocks",{value:function(){return this[s]},writable:!1,configurable:!1}),A(e,"setExtend",{value:function(n){this[u]=n},writable:!1,configurable:!1}),A(e,"getExtend",{value:function(){return this[u]},writable:!1,configurable:!1}),A(e,"setLayout",{value:function(n){this[a]=n},writable:!1,configurable:!1}),A(e,"getLayout",{value:function(){return this[a]},writable:!1,configurable:!1}),e)),l.helpers=function(n){d(l.prototype,n)},l.helpers(t),l.helpers({clone:function(n){var t=[a,u,c,f];return!0===n&&t.push(s),m(this,t)},echo:function(){var n=this.getBuffer(),t=[].slice.call(arguments);t.forEach((function(t){n(t)}))},macro:function(n,t){var e=this.getBuffer(),o=function(){e.backup(),r(n)&&n.apply(this,arguments);var o=e.restore();return!0===t?this.echo(o):o}.bind(this);return o.__context=this,o.__source=n,o.__layout=this.getLayout(),o},resolve:function(n,t){return Promise.resolve(n).then(t.bind(this))},async:function(n,t){var e=this;this.echo(this.resolve(n,(function(n){return e.macro(t)(n)})))},node:O,element:function(n,t,e){r(e)&&(e=this.macro(e)()),this.echo(this.resolve(e,(function(e){return O(n,t,e)})))},component:function(n,t){t=function(n){var t=d({},n.props);return{element:O,create:n.create,render:function(n){return this.create(d({},t,n))}}}(t),this.set(n,function(n){this.echo(t.render(n))}.bind(this))},get:function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();return b(r,o)?r[o]:t},set:function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();if(this.getExtend()&&b(r,o))return r[o];r[o]=t},call:function(n){var t=[].slice.call(arguments,1),e=v(this,n),o=e.shift(),i=e.pop();if(r(o[i]))return o[i].apply(o,t)},each:function(n,t){o(n)&&(n=this.get(n,[])),g(n,t)},extend:function(n){this.setExtend(!0),this.setLayout(n)},block:function(n,t){var e=this.getBlocks();if(e[n]=e[n]||[],e[n].push(this.macro(t)),!1===this.getExtend()){var r=e[n];this.echo(r.shift()(function n(){var t=r.shift();if(t){var e=t.__context;return function(){e.echo(t(n()))}}return function(){}}()))}},include:function(n,t,e){var r=!1===e?{}:this.clone(!0),o=d(r,t||{}),i=this.render(n,o);this.echo(i)},use:function(n){var t=this,e=this.require(n);return this.echo(e),{as:function(n){return e.then((function(e){t.set(n,e)})),this}}},from:function(n){var t=this,e=this.require(n);return this.echo(e),{use:function(){var n=[].slice.call(arguments);return e.then((function(e){n.forEach((function(n){t.set(n,e[n])}))})),this}}}}),l};var U,q,C,N,D,K=(q={},C={},N=function(n,t){var e=n.split(".").pop();return e!==t&&(n=[n,t].join(".")),n},D={element:O,output:function(n,t){return D.template(n).then((function(n){return n.call(t,t,t.getBuffer(),p)}))},render:function(n,t){var e=N(n,q.extension.template),r=new D.scope(t);return D.output(e,r).then((function(n){if(r.getExtend()){r.setExtend(!1);var t=r.getLayout(),e=r.clone();return D.render(t,e)}return n}))},require:function(n){var t=N(n,q.extension.module),e=new D.scope({});return D.output(t,e).then((function(){return e.clone(!0)}))},helpers:function(n){d(C,n=n||{}),D.scope.helpers(n)},configure:function(n){return q.export=e(o,t.export,n.export),q.path=e(o,t.path,n.path),q.resolver=e(r,t.resolver,n.resolver),q.extension=d({},t.extension,n.extension),q.token=d({},t.token,n.token),q.vars=d({},t.vars,n.vars),D.scope=T(q,C),D.compile=F(q),D.wrapper=function(n){var t=n.export;return function(n){var e="(function(o){\n";return n.forEach((function(n){e+="o["+JSON.stringify(n.name)+"]="+String(n.content)+"\n"})),e+='})(window["'+t+'"] = window["'+t+'"] || {});\n'}}(q),D.cache=function(n){var t=n.export,e={};return{preload:function(){return!1===u()&&this.load(window[t]),this},exist:function(n){return b(e,n)},get:function(n){return e[n]},remove:function(n){delete e[n]},resolve:function(n){return Promise.resolve(this.get(n))},set:function(n,t){return e[n]=t,this},load:function(n){return d(e,n),this}}.preload()}(q),D.template=_(q,D.cache,D.compile),D},__express:function(u,c,a){r(c)&&(a=c,c={});var s=d({},(c=c||{}).settings),f=e(o,s.views,t.path),l=e(i,s["view cache"],t.cache),h=d({},s["view options"]),p=n.relative(f,u);return h.path=f,h.cache=l,D.configure(h),D.render(p,c).then((function(n){a(null,n)})).catch((function(n){a(n)}))}},D.configure(U||{}),D.helpers({require:function(n){return D.require(n,this)},render:function(n,t){return D.render(n,t)}}),D);return K}));
package/dist/ejs.mjs CHANGED
@@ -112,8 +112,6 @@ const extend = (...args) => {
112
112
  }, target)
113
113
  };
114
114
 
115
- const noop = () => {};
116
-
117
115
  const each = (object, callback) => {
118
116
  let prop;
119
117
  for (prop in object) {
@@ -447,13 +445,17 @@ const Scope = (config, methods) => {
447
445
  *
448
446
  */
449
447
  const { EXTEND, MACROS, LAYOUT, BLOCKS, BUFFER } = config.vars;
448
+
450
449
  /**
451
450
  *
452
451
  * @param data
453
452
  * @constructor
454
453
  */
455
454
  function Scope(data = {}) {
455
+ this.setBlocks({});
456
456
  extend(this, data);
457
+ this.setLayout(false);
458
+ this.setExtend(false);
457
459
  }
458
460
  /**
459
461
  *
@@ -463,82 +465,82 @@ const Scope = (config, methods) => {
463
465
  value: Buffer(),
464
466
  writable: false,
465
467
  configurable: false,
466
- enumerable: false,
467
- },
468
- [BLOCKS]: {
469
- value: {},
470
- writable: false,
471
- configurable: false,
472
- enumerable: false,
473
- },
474
- [EXTEND]: {
475
- value: false,
476
- writable: true,
477
- configurable: false,
478
- enumerable: false,
479
- },
480
- [LAYOUT]: {
481
- value: false,
482
- writable: true,
483
- configurable: false,
484
- enumerable: false,
485
- },
486
- setBuffer: {
487
- value(value) {
488
- this[BUFFER] = value;
489
- },
490
- writable: false,
491
- configurable: false,
492
- },
468
+ enumerable: false
469
+ },
470
+ // [BLOCKS]: {
471
+ // value: {},
472
+ // writable: true,
473
+ // configurable: false,
474
+ // enumerable: false
475
+ // },
476
+ // [EXTEND]: {
477
+ // value: false,
478
+ // writable: true,
479
+ // configurable: false,
480
+ // enumerable: false
481
+ // },
482
+ // [LAYOUT]: {
483
+ // value: false,
484
+ // writable: true,
485
+ // configurable: false,
486
+ // enumerable: false
487
+ // },
488
+ // setBuffer: {
489
+ // value(value) {
490
+ // this[BUFFER] = value
491
+ // },
492
+ // writable: false,
493
+ // configurable: false
494
+ // },
493
495
  getBuffer: {
494
496
  value() {
495
497
  return this[BUFFER]
496
498
  },
497
499
  writable: false,
498
- configurable: false,
500
+ configurable: false
499
501
  },
500
502
  setBlocks: {
501
503
  value(value) {
502
504
  this[BLOCKS] = value;
503
505
  },
504
506
  writable: false,
505
- configurable: false,
507
+ configurable: false
506
508
  },
507
509
  getBlocks: {
508
510
  value() {
509
511
  return this[BLOCKS]
510
512
  },
511
513
  writable: false,
512
- configurable: false,
514
+ configurable: false
513
515
  },
514
516
  setExtend: {
515
517
  value(value) {
516
518
  this[EXTEND] = value;
517
519
  },
518
520
  writable: false,
519
- configurable: false,
521
+ configurable: false
520
522
  },
521
523
  getExtend: {
522
524
  value() {
523
525
  return this[EXTEND]
524
526
  },
525
527
  writable: false,
526
- configurable: false,
528
+ configurable: false
527
529
  },
528
530
  setLayout: {
529
531
  value(layout) {
530
532
  this[LAYOUT] = layout;
531
533
  },
532
534
  writable: false,
533
- configurable: false,
535
+ configurable: false
534
536
  },
535
537
  getLayout: {
536
538
  value() {
537
539
  return this[LAYOUT]
538
540
  },
539
541
  writable: false,
540
- configurable: false,
541
- },
542
+ configurable: false
543
+ }
542
544
  });
543
545
 
544
546
  Scope.helpers = (methods) => {
@@ -571,7 +573,7 @@ const Scope = (config, methods) => {
571
573
  echo() {
572
574
  const buffer = this.getBuffer();
573
575
  const params = [].slice.call(arguments);
574
- params.forEach(function (item) {
576
+ params.forEach(function(item) {
575
577
  buffer(item);
576
578
  });
577
579
  },
@@ -584,7 +586,7 @@ const Scope = (config, methods) => {
584
586
  */
585
587
  macro(callback, echo) {
586
588
  const buffer = this.getBuffer();
587
- const macro = function () {
589
+ const macro = function() {
588
590
  buffer.backup();
589
591
  if (isFunction(callback)) {
590
592
  callback.apply(this, arguments);
@@ -592,7 +594,9 @@ const Scope = (config, methods) => {
592
594
  const result = buffer.restore();
593
595
  return echo === true ? this.echo(result) : result
594
596
  }.bind(this);
595
- macro.ctx = this;
597
+ macro.__context = this;
598
+ macro.__source = callback;
599
+ macro.__layout = this.getLayout();
596
600
  return macro
597
601
  },
598
602
  /**
@@ -636,7 +640,7 @@ const Scope = (config, methods) => {
636
640
  instance = Component(instance);
637
641
  this.set(
638
642
  namespace,
639
- function (props) {
643
+ function(props) {
640
644
  this.echo(instance.render(props));
641
645
  }.bind(this)
642
646
  );
@@ -709,22 +713,22 @@ const Scope = (config, methods) => {
709
713
  */
710
714
  block(name, callback) {
711
715
  const blocks = this.getBlocks();
712
- const macro = this.macro(callback);
713
- const block = blocks[name];
714
- if (this.getExtend()) {
715
- if (block) {
716
- block.parent = function () {
717
- this.echo(macro());
718
- }.bind(block.ctx);
719
- } else {
720
- blocks[name] = macro;
721
- }
722
- } else {
723
- if (block) {
724
- this.echo(block(block.parent));
725
- } else {
726
- this.echo(macro(noop));
727
- }
716
+ blocks[name] = blocks[name] || [];
717
+ blocks[name].push(this.macro(callback));
718
+ if (this.getExtend() === false) {
719
+ const list = blocks[name];
720
+ const callback = function(){
721
+ const parent = list.shift();
722
+ if( parent ) {
723
+ const context = parent.__context;
724
+ return function(){
725
+ context.echo(parent(callback()));
726
+ }
727
+ } else {
728
+ return function(){}
729
+ }
730
+ };
731
+ this.echo(list.shift()(callback()));
728
732
  }
729
733
  },
730
734
  /**
@@ -753,7 +757,7 @@ const Scope = (config, methods) => {
753
757
  scope.set(namespace, exports);
754
758
  });
755
759
  return this
756
- },
760
+ }
757
761
  }
758
762
  },
759
763
  /**
@@ -773,9 +777,9 @@ const Scope = (config, methods) => {
773
777
  });
774
778
  });
775
779
  return this
776
- },
780
+ }
777
781
  }
778
- },
782
+ }
779
783
  });
780
784
  return Scope
781
785
  };
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.11",
5
+ "version": "0.0.12",
6
6
  "main": "dist/ejs.cjs",
7
7
  "module": "dist/ejs.mjs",
8
8
  "browser": "dist/ejs.js",