@kosatyi/ejs 0.0.77 → 0.0.79
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/bin/bundler.js +43 -0
- package/dist/cjs/browser.js +50 -11
- package/dist/cjs/bundler.js +171 -0
- package/dist/cjs/index.js +50 -11
- package/dist/cjs/worker.js +111 -31
- package/dist/esm/browser.js +63 -21
- package/dist/esm/bundler.js +168 -0
- package/dist/esm/index.js +63 -21
- package/dist/esm/worker.js +104 -28
- package/dist/umd/browser.js +50 -11
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/index.js +50 -11
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +111 -31
- package/dist/umd/worker.min.js +1 -1
- package/package.json +19 -7
- package/types/bundler.d.ts +30 -0
- package/types/ejs.d.ts +91 -0
- package/types/global.d.ts +2 -87
package/dist/umd/browser.js
CHANGED
|
@@ -327,7 +327,7 @@
|
|
|
327
327
|
});
|
|
328
328
|
});
|
|
329
329
|
source += "');";
|
|
330
|
-
source = "try{".concat(source, "}catch(e){
|
|
330
|
+
source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
|
|
331
331
|
if (compiler.withObject) {
|
|
332
332
|
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
333
333
|
}
|
|
@@ -439,11 +439,36 @@
|
|
|
439
439
|
return result.join('');
|
|
440
440
|
};
|
|
441
441
|
|
|
442
|
+
function TemplateError(message) {
|
|
443
|
+
this.code = 1;
|
|
444
|
+
this.name = 'TemplateError';
|
|
445
|
+
this.message = message;
|
|
446
|
+
Error.call(this);
|
|
447
|
+
}
|
|
448
|
+
Object.setPrototypeOf(TemplateNotFound.prototype, Error.prototype);
|
|
449
|
+
function TemplateNotFound(message) {
|
|
450
|
+
TemplateError.call(this);
|
|
451
|
+
this.code = 404;
|
|
452
|
+
this.name = 'TemplateNotFound';
|
|
453
|
+
this.message = message;
|
|
454
|
+
}
|
|
455
|
+
Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
|
|
456
|
+
function TemplateSyntaxError(message) {
|
|
457
|
+
TemplateError.call(this);
|
|
458
|
+
this.code = 500;
|
|
459
|
+
this.name = 'TemplateSyntaxError';
|
|
460
|
+
this.message = message;
|
|
461
|
+
}
|
|
462
|
+
Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
|
|
463
|
+
|
|
442
464
|
function resolve(list) {
|
|
443
465
|
return Promise.all(list || []).then(function (list) {
|
|
444
466
|
return list.join('');
|
|
445
467
|
});
|
|
446
468
|
}
|
|
469
|
+
function reject(error) {
|
|
470
|
+
return Promise.reject(new TemplateSyntaxError(error.message));
|
|
471
|
+
}
|
|
447
472
|
function createBuffer() {
|
|
448
473
|
var store = [],
|
|
449
474
|
array = [];
|
|
@@ -463,7 +488,7 @@
|
|
|
463
488
|
return resolve(result);
|
|
464
489
|
};
|
|
465
490
|
buffer.error = function (e) {
|
|
466
|
-
|
|
491
|
+
return reject(e);
|
|
467
492
|
};
|
|
468
493
|
buffer.end = function () {
|
|
469
494
|
return resolve(array);
|
|
@@ -488,6 +513,11 @@
|
|
|
488
513
|
this.helpers = function (methods) {
|
|
489
514
|
extend(Scope.prototype, methods || {});
|
|
490
515
|
};
|
|
516
|
+
/**
|
|
517
|
+
* @name ContextScope
|
|
518
|
+
* @param data
|
|
519
|
+
* @constructor
|
|
520
|
+
*/
|
|
491
521
|
function Scope(data) {
|
|
492
522
|
this[BLOCKS] = {};
|
|
493
523
|
this[MACRO] = {};
|
|
@@ -633,8 +663,8 @@
|
|
|
633
663
|
var prop = path.pop();
|
|
634
664
|
return hasProp(result, prop) ? result[prop] : defaults;
|
|
635
665
|
},
|
|
636
|
-
writable:
|
|
637
|
-
configurable:
|
|
666
|
+
writable: true,
|
|
667
|
+
configurable: true,
|
|
638
668
|
enumerable: false
|
|
639
669
|
}), _defineProperty(_Object$definePropert, "set", {
|
|
640
670
|
value: function value(name, _value2) {
|
|
@@ -699,6 +729,13 @@
|
|
|
699
729
|
writable: false,
|
|
700
730
|
configurable: false,
|
|
701
731
|
enumerable: false
|
|
732
|
+
}), _defineProperty(_Object$definePropert, "hasBlock", {
|
|
733
|
+
value: function value(name) {
|
|
734
|
+
return this.getBlocks().hasOwnProperty(name);
|
|
735
|
+
},
|
|
736
|
+
writable: false,
|
|
737
|
+
configurable: false,
|
|
738
|
+
enumerable: false
|
|
702
739
|
}), _defineProperty(_Object$definePropert, "include", {
|
|
703
740
|
value: function value(path, data, cx) {
|
|
704
741
|
var context = cx === false ? {} : this.clone(true);
|
|
@@ -774,13 +811,15 @@
|
|
|
774
811
|
var compiler = new Compiler(config);
|
|
775
812
|
var cache = new Cache();
|
|
776
813
|
var template = new Template(config, cache, compiler);
|
|
777
|
-
var output = function output(path,
|
|
778
|
-
var
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
})
|
|
814
|
+
var output = function output(path, scope) {
|
|
815
|
+
var globalHelpers = config.globalHelpers;
|
|
816
|
+
var params = [scope, scope.getComponent(), scope.getBuffer(), safeValue].concat(globalHelpers.filter(function (name) {
|
|
817
|
+
return isFunction(scope[name]);
|
|
818
|
+
}).map(function (name) {
|
|
819
|
+
return scope[name].bind(scope);
|
|
820
|
+
}));
|
|
782
821
|
return template.get(path).then(function (callback) {
|
|
783
|
-
return callback.apply(
|
|
822
|
+
return callback.apply(scope, params);
|
|
784
823
|
});
|
|
785
824
|
};
|
|
786
825
|
var require = function require(name) {
|
|
@@ -841,7 +880,7 @@
|
|
|
841
880
|
return fetch(joinPath(path, template)).then(function (response) {
|
|
842
881
|
return response.text();
|
|
843
882
|
}, function (reason) {
|
|
844
|
-
return
|
|
883
|
+
return new TemplateError(reason);
|
|
845
884
|
});
|
|
846
885
|
};
|
|
847
886
|
|
package/dist/umd/browser.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ejs={})}(this,(function(e){"use strict";var n=function(){var e=[].slice.call(arguments),n=e.shift();return e.filter(n).pop()},t=function(e){return Array.isArray(e)},r=function(e){return"function"==typeof e},i=function(e){return"string"==typeof e},o=function(e){return"boolean"==typeof e},u=function(e){return void 0===e},c="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a=function(){return c},l={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},s={"&":"&","<":"<",">":">",'"':""","'":"'"},f=function(e){return new RegExp(["[",Object.keys(e).join(""),"]"].join(""),"g")},h=f(s),p=f(l),b=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(h,(function(e){return s[e]}))},v=function(e){return(""+e).replace(p,(function(e){return"\\"+l[e]}))},g=function(e,n){var t=e;return null==t?"":!0===n?b(t):t},m=function(e,n){return Boolean(e instanceof n)},d=function(e,n,t){for(var i=e,o=String(n).split("."),u=o.pop(),c=0;c<o.length;c++){var a=o[c];if(r(i.toJSON)&&(i=i.toJSON()),t&&!1===i.hasOwnProperty(a)){i={};break}i=i[a]=i[a]||{}}return r(i.toJSON)&&(i=i.toJSON()),[i,u]},w=function(e,n){var t=e.split(".").pop();return t!==n&&(e=[e,n].join(".")),e},y=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];return t.filter((function(e){return e})).reduce((function(e,n){return Object.assign(e,n)}),e)},j=function(){},E=function(e,n){var t;for(t in e)k(e,t)&&n(e[t],t,e)},x=function(e,n){return function(e,n,t){var r=e instanceof Array,i=r?[]:{};return E(e,(function(e,t,o){var c=n(e,t,o);!1===u(c)&&(r?i.push(c):i[t]=c)})),i}(e,(function(e,t){if(-1===n.indexOf(t))return e}))},O=function(e,n,t){return Promise.resolve(e).then(n.bind(t))},k=function(e,n){return e&&e.hasOwnProperty(n)},F={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:function(e,n){return Promise.resolve(["resolver is not defined",e,n].join(" "))},extension:"ejs",rmWhitespace:!0,withObject:!0,globalHelpers:[],vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},S=function(e,u){y(e,{path:n(i,F.path,e.path,u.path),export:n(i,F.export,e.export,u.export),resolver:n(r,F.resolver,e.resolver,u.resolver),extension:n(i,F.extension,e.extension,u.extension),withObject:n(o,F.withObject,e.withObject,u.withObject),rmWhitespace:n(o,F.rmWhitespace,e.rmWhitespace,u.rmWhitespace),cache:n(o,F.cache,e.cache,u.cache),token:y({},F.token,e.token,u.token),vars:y({},F.vars,e.vars,u.vars),globalHelpers:n(t,F.globalHelpers,e.globalHelpers,u.globalHelpers)})},B="undefined"!=typeof globalThis?globalThis:window||self;function P(e){if(!1===m(this,P))return new P;var n={enabled:!0,list:{}};this.configure=function(e){n.enabled=e.cache,!1===a()&&this.load(B[e.export])},this.clear=function(){n.list={}},this.load=function(e){return n.enabled&&y(n.list,e||{}),this},this.get=function(e){if(n.enabled)return n.list[e]},this.set=function(e,t){return n.enabled&&(n.list[e]=t),this},this.resolve=function(e){return Promise.resolve(this.get(e))},this.remove=function(e){delete n.list[e]},this.exist=function(e){return k(n.list,e)}}var R=[{symbol:"-",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(e){return"')\n/**".concat(e,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(e){return"')\n".concat(e.trim(),"\n").concat(this.BUFFER,"('")}}];function T(e){if(!1===m(this,T))return new T(e);var n={};this.configure=function(e){n.withObject=e.withObject,n.rmWhitespace=e.rmWhitespace,n.token=e.token,n.vars=e.vars,n.globalHelpers=e.globalHelpers,n.matches=[],n.formats=[],n.slurp={match:"[ \\t]*",start:[n.token.start,"_"],end:["_",n.token.end]},R.forEach((function(e){n.matches.push(n.token.start.concat(e.symbol).concat(n.token.regex).concat(n.token.end)),n.formats.push(e.format.bind(n.vars))})),n.regex=new RegExp(n.matches.join("|").concat("|$"),"g"),n.slurpStart=new RegExp([n.slurp.match,n.slurp.start.join("")].join(""),"gm"),n.slurpEnd=new RegExp([n.slurp.end.join(""),n.slurp.match].join(""),"gm")},this.compile=function(e,t){var r=n.vars,i=r.SCOPE,o=r.SAFE,u=r.BUFFER,c=r.COMPONENT,a=n.globalHelpers;e=String(e),n.rmWhitespace&&(e=e.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),e=e.replace(n.slurpStart,n.token.start).replace(n.slurpEnd,n.token.end);var l,s,f,h="".concat(u,"('");l=n.regex,s=function(t,r,i){h+=v(e.slice(r,i)),t.forEach((function(e,t){e&&(h+=n.formats[t](e))}))},f=0,e.replace(l,(function(){var e=[].slice.call(arguments,0,-1),n=e.pop(),t=e.shift();return s(e,f,n),f=n+t.length,t})),h="try{".concat(h+="');","}catch(e){console.info(e)}"),n.withObject&&(h="with(".concat(i,"){").concat(h,"}")),h="".concat(u,".start();").concat(h,"return ").concat(u,".end();"),h+="\n//# sourceURL=".concat(t);var p=null,b=[i,c,u,o].concat(a);try{(p=Function.apply(null,b.concat(h))).source="(function(".concat(b.join(","),"){\n").concat(h,"\n})")}catch(e){throw e.filename=t,e.source=h,e}return p},this.configure(e)}function $(e,n,t){if(!1===m(this,$))return new $(e,n,t);if(!1===m(n,P))throw new TypeError("cache is not instance of Cache");if(!1===m(t,T))throw new TypeError("compiler is not instance of Compiler");var i={},o=function(e){return i.resolver(i.path,e)};this.configure=function(e){i.path=e.path,i.cache=e.cache,r(e.resolver)&&(i.resolver=e.resolver)},this.get=function(e){return n.exist(e)?n.resolve(e):o(e).then((function(i){return function(e,t){return n.set(e,t),t}(e,function(e,n){return r(e)?e:t.compile(e,n)}(i,e))}))},this.configure(e)}function A(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var C=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],N=" ",U='"',M="/",H="<",L=">",W=function(e,n,t){var r=[],i=-1===C.indexOf(e),o=function(e,n,t){var r=[];return E(e,(function(e,t,i){var o=n(e,t,i);!1===u(o)&&r.push(o)})),r}(n,(function(e,n){if(null!=e)return[b(n),[U,b(e),U].join("")].join("=")})).join(N);return r.push([H,e,N,o,L].join("")),t&&r.push(t instanceof Array?t.join(""):t),i&&r.push([H,M,e,L].join("")),r.join("")};function J(e){return Promise.all(e||[]).then((function(e){return e.join("")}))}function q(){var e=[],n=[];function t(e){n.push(e)}return t.start=function(){n=[]},t.backup=function(){e.push(n.concat()),n=[]},t.restore=function(){var t=n.concat();return n=e.pop(),J(t)},t.error=function(e){throw e},t.end=function(){return J(n)},t}function D(e){if(!1===m(this,D))return new D(e);this.configure=function(e,n){var t,o=e.vars,u=o.BLOCKS,c=o.MACRO,a=o.EXTEND,l=o.LAYOUT,s=o.BUFFER,f=o.COMPONENT;function h(e){this[u]={},this[c]={},y(this,e||{})}this.create=function(e){return new h(e)},this.helpers=function(e){y(h.prototype,e||{})},h.prototype=y({},n||{}),Object.defineProperties(h.prototype,(A(t={},s,{value:q(),writable:!0,configurable:!1,enumerable:!1}),A(t,u,{value:{},writable:!0,configurable:!1,enumerable:!1}),A(t,c,{value:{},writable:!0,configurable:!1,enumerable:!1}),A(t,l,{value:!1,writable:!0,configurable:!1,enumerable:!1}),A(t,a,{value:!1,writable:!0,configurable:!1,enumerable:!1}),A(t,"getMacro",{value:function(){return this[c]},writable:!1,configurable:!1,enumerable:!1}),A(t,"getBuffer",{value:function(){return this[s]},writable:!1,configurable:!1,enumerable:!1}),A(t,"getComponent",{value:function(){var e=this;return f in e?function(){return e[f].apply(e,arguments)}:function(){console.log("%s function not defined",f)}},writable:!1,configurable:!1,enumerable:!1}),A(t,"getBlocks",{value:function(){return this[u]},writable:!1,configurable:!1,enumerable:!1}),A(t,"setExtend",{value:function(e){this[a]=e},writable:!1,configurable:!1,enumerable:!1}),A(t,"getExtend",{value:function(){return this[a]},writable:!1,configurable:!1,enumerable:!1}),A(t,"setLayout",{value:function(e){this[l]=e},writable:!1,configurable:!1,enumerable:!1}),A(t,"getLayout",{value:function(){return this[l]},writable:!1,configurable:!1,enumerable:!1}),A(t,"clone",{value:function(e){var n=[l,a,s];return!0===e&&n.push(u),x(this,n)},writable:!1,configurable:!1,enumerable:!1}),A(t,"extend",{value:function(e){this.setExtend(!0),this.setLayout(e)},writable:!1,configurable:!1,enumerable:!1}),A(t,"echo",{value:function(e){var n=this.getBuffer();[].slice.call(arguments).forEach(n)},writable:!1,configurable:!1,enumerable:!1}),A(t,"fn",{value:function(e){var n=this.getBuffer(),t=this;return function(){return n.backup(),r(e)&&e.apply(t,arguments),n.restore()}},writable:!1,configurable:!1,enumerable:!1}),A(t,"get",{value:function(e,n){var t=d(this,e,!0),r=t.shift(),i=t.pop();return k(r,i)?r[i]:n},writable:!1,configurable:!1,enumerable:!1}),A(t,"set",{value:function(e,n){var t=d(this,e,!1),r=t.shift(),i=t.pop();return this.getExtend()&&k(r,i)?r[i]:r[i]=n},writable:!1,configurable:!1,enumerable:!1}),A(t,"macro",{value:function(e,n){var t=this.getMacro(),r=this.fn(n),i=this;t[e]=function(){return i.echo(r.apply(void 0,arguments))}},writable:!1,configurable:!1,enumerable:!1}),A(t,"call",{value:function(e){var n=this.getMacro()[e],t=[].slice.call(arguments,1);if(r(n))return n.apply(n,t)},writable:!1,configurable:!1,enumerable:!1}),A(t,"block",{value:function(e,n){var t=this,r=this.getBlocks();if(r[e]=r[e]||[],r[e].push(this.fn(n)),!this.getExtend()){var i=Object.assign([],r[e]),o=function(){return i.shift()};this.echo(o()(function e(){var n=o();return n?function(){t.echo(n(e()))}:j}()))}},writable:!1,configurable:!1,enumerable:!1}),A(t,"include",{value:function(e,n,t){var r=!1===t?{}:this.clone(!0),i=y(r,n||{}),o=this.render(e,i);this.echo(o)},writable:!1,configurable:!1,enumerable:!1}),A(t,"use",{value:function(e,n){var t=this.require(e);this.echo(O(t,(function(e){var t=this.getMacro();E(e,(function(e,r){t[[n,r].join(".")]=e}))}),this))},writable:!1,configurable:!1,enumerable:!1}),A(t,"async",{value:function(e,n){this.echo(O(e,(function(e){return this.fn(n)(e)}),this))},writable:!1,configurable:!1,enumerable:!1}),A(t,"each",{value:function(e,n){i(e)&&(e=this.get(e,[])),E(e,n)},writable:!1,configurable:!1,enumerable:!1}),A(t,"element",{value:function(e,n,t){return W(e,n,t)},writable:!1,configurable:!1,enumerable:!1}),A(t,"el",{value:function(e,n,t){r(t)&&(t=this.fn(t)()),this.echo(O(t,(function(t){return this.element(e,n,t)}),this))},writable:!1,configurable:!1,enumerable:!1}),t))},this.configure(e)}var K=new function e(n){if(!1===m(this,e))return new e(n);var t={},i={};S(i,n||{});var o=new D(i),u=new T(i),c=new P,a=new $(i,c,u),l=function(e,n){var t=[n,n.getComponent(),n.getBuffer(),g];return i.globalHelpers.forEach((function(e){r(n[e])&&t.push(n[e].bind(n))})),a.get(e).then((function(e){return e.apply(n,t)}))},s=function e(n,t){var r=w(n,i.extension),u=o.create(t);return l(r,u).then((function(n){if(u.getExtend()){u.setExtend(!1);var t=u.getLayout(),r=u.clone();return e(t,r)}return n}))};return this.configure=function(e){return S(i,e=e||{}),o.configure(i,t),u.configure(i),c.configure(i),a.configure(i),i},this.render=function(e,n){return s(e,n)},this.helpers=function(e){o.helpers(y(t,e))},this.preload=function(e){return c.load(e||{})},this.create=function(n){return new e(n)},this.compile=function(e,n){return u.compile(e,n)},this.context=function(e){return o.create(e)},this.helpers({require:function(e){var n=w(e,i.extension),t=o.create({});return l(n,t).then((function(){return t.getMacro()}))},render:s}),this}({resolver:function(e,n){return fetch(function(e,n){return(n=[e,n].join("/")).replace(/\/\//g,"/")}(e,n)).then((function(e){return e.text()}),(function(e){return String(e)}))}}),X=K.render,Y=K.context,_=K.compile,z=K.helpers,G=K.preload,I=K.configure,Q=K.create;e.compile=_,e.configure=I,e.context=Y,e.create=Q,e.helpers=z,e.preload=G,e.render=X}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ejs={})}(this,(function(e){"use strict";var t=function(){var e=[].slice.call(arguments),t=e.shift();return e.filter(t).pop()},n=function(e){return Array.isArray(e)},r=function(e){return"function"==typeof e},i=function(e){return"string"==typeof e},o=function(e){return"boolean"==typeof e},u=function(e){return void 0===e},c="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},l={"&":"&","<":"<",">":">",'"':""","'":"'"},s=function(e){return new RegExp(["[",Object.keys(e).join(""),"]"].join(""),"g")},f=s(l),h=s(a),p=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(f,(function(e){return l[e]}))},b=function(e,t){var n=e;return null==n?"":!0===t?p(n):n},g=function(e,t){return Boolean(e instanceof t)},v=function(e,t,n){for(var i=e,o=String(t).split("."),u=o.pop(),c=0;c<o.length;c++){var a=o[c];if(r(i.toJSON)&&(i=i.toJSON()),n&&!1===i.hasOwnProperty(a)){i={};break}i=i[a]=i[a]||{}}return r(i.toJSON)&&(i=i.toJSON()),[i,u]},m=function(e,t){var n=e.split(".").pop();return n!==t&&(e=[e,t].join(".")),e},d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return n.filter((function(e){return e})).reduce((function(e,t){return Object.assign(e,t)}),e)},w=function(){},y=function(e,t){var n;for(n in e)O(e,n)&&t(e[n],n,e)},j=function(e,t){return function(e,t){var n=e instanceof Array,r=n?[]:{};return y(e,(function(e,i,o){var c=t(e,i,o);!1===u(c)&&(n?r.push(c):r[i]=c)})),r}(e,(function(e,n){if(-1===t.indexOf(n))return e}))},E=function(e,t,n){return Promise.resolve(e).then(t.bind(n))},O=function(e,t){return e&&e.hasOwnProperty(t)},x={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:function(e,t){return Promise.resolve(["resolver is not defined",e,t].join(" "))},extension:"ejs",rmWhitespace:!0,withObject:!0,globalHelpers:[],vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},k=function(e,u){d(e,{path:t(i,x.path,e.path,u.path),export:t(i,x.export,e.export,u.export),resolver:t(r,x.resolver,e.resolver,u.resolver),extension:t(i,x.extension,e.extension,u.extension),withObject:t(o,x.withObject,e.withObject,u.withObject),rmWhitespace:t(o,x.rmWhitespace,e.rmWhitespace,u.rmWhitespace),cache:t(o,x.cache,e.cache,u.cache),token:d({},x.token,e.token,u.token),vars:d({},x.vars,e.vars,u.vars),globalHelpers:t(n,x.globalHelpers,e.globalHelpers,u.globalHelpers)})},F="undefined"!=typeof globalThis?globalThis:window||self;function S(e){if(!1===g(this,S))return new S;var t={enabled:!0,list:{}};this.configure=function(e){t.enabled=e.cache,!1===c&&this.load(F[e.export])},this.clear=function(){t.list={}},this.load=function(e){return t.enabled&&d(t.list,e||{}),this},this.get=function(e){if(t.enabled)return t.list[e]},this.set=function(e,n){return t.enabled&&(t.list[e]=n),this},this.resolve=function(e){return Promise.resolve(this.get(e))},this.remove=function(e){delete t.list[e]},this.exist=function(e){return O(t.list,e)}}var P=[{symbol:"-",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(e){return"')\n/**".concat(e,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(e){return"')\n".concat(e.trim(),"\n").concat(this.BUFFER,"('")}}];function B(e){if(!1===g(this,B))return new B(e);var t={};this.configure=function(e){t.withObject=e.withObject,t.rmWhitespace=e.rmWhitespace,t.token=e.token,t.vars=e.vars,t.globalHelpers=e.globalHelpers,t.matches=[],t.formats=[],t.slurp={match:"[ \\t]*",start:[t.token.start,"_"],end:["_",t.token.end]},P.forEach((function(e){t.matches.push(t.token.start.concat(e.symbol).concat(t.token.regex).concat(t.token.end)),t.formats.push(e.format.bind(t.vars))})),t.regex=new RegExp(t.matches.join("|").concat("|$"),"g"),t.slurpStart=new RegExp([t.slurp.match,t.slurp.start.join("")].join(""),"gm"),t.slurpEnd=new RegExp([t.slurp.end.join(""),t.slurp.match].join(""),"gm")},this.compile=function(e,n){var r=t.vars,i=r.SCOPE,o=r.SAFE,u=r.BUFFER,c=r.COMPONENT,l=t.globalHelpers;e=String(e),t.rmWhitespace&&(e=e.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),e=e.replace(t.slurpStart,t.token.start).replace(t.slurpEnd,t.token.end);var s,f,p,b="".concat(u,"('");s=t.regex,f=function(n,r,i){b+=(""+e.slice(r,i)).replace(h,(function(e){return"\\"+a[e]})),n.forEach((function(e,n){e&&(b+=t.formats[n](e))}))},p=0,e.replace(s,(function(){var e=[].slice.call(arguments,0,-1),t=e.pop(),n=e.shift();return f(e,p,t),p=t+n.length,n})),b="try{".concat(b+="');","}catch(e){return ").concat(u,".error(e)}"),t.withObject&&(b="with(".concat(i,"){").concat(b,"}")),b="".concat(u,".start();").concat(b,"return ").concat(u,".end();"),b+="\n//# sourceURL=".concat(n);var g=null,v=[i,c,u,o].concat(l);try{(g=Function.apply(null,v.concat(b))).source="(function(".concat(v.join(","),"){\n").concat(b,"\n})")}catch(e){throw e.filename=n,e.source=b,e}return g},this.configure(e)}function T(e,t,n){if(!1===g(this,T))return new T(e,t,n);if(!1===g(t,S))throw new TypeError("cache is not instance of Cache");if(!1===g(n,B))throw new TypeError("compiler is not instance of Compiler");var i={},o=function(e){return i.resolver(i.path,e)};this.configure=function(e){i.path=e.path,i.cache=e.cache,r(e.resolver)&&(i.resolver=e.resolver)},this.get=function(e){return t.exist(e)?t.resolve(e):o(e).then((function(i){return function(e,n){return t.set(e,n),n}(e,function(e,t){return r(e)?e:n.compile(e,t)}(i,e))}))},this.configure(e)}function R(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var N=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],$=" ",A='"',C="/",U="<",M=">",H=function(e,t,n){var r=[],i=-1===N.indexOf(e),o=function(e,t){var n=[];return y(e,(function(e,r,i){var o=t(e,r,i);!1===u(o)&&n.push(o)})),n}(t,(function(e,t){if(null!=e)return[p(t),[A,p(e),A].join("")].join("=")})).join($);return r.push([U,e,$,o,M].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([U,C,e,M].join("")),r.join("")};function L(e){this.code=1,this.name="TemplateError",this.message=e,Error.call(this)}function W(e){L.call(this),this.code=404,this.name="TemplateNotFound",this.message=e}function J(e){L.call(this),this.code=500,this.name="TemplateSyntaxError",this.message=e}function q(e){return Promise.all(e||[]).then((function(e){return e.join("")}))}function D(){var e=[],t=[];function n(e){t.push(e)}return n.start=function(){t=[]},n.backup=function(){e.push(t.concat()),t=[]},n.restore=function(){var n=t.concat();return t=e.pop(),q(n)},n.error=function(e){return t=e,Promise.reject(new J(t.message));var t},n.end=function(){return q(t)},n}function K(e){if(!1===g(this,K))return new K(e);this.configure=function(e,t){var n,o=e.vars,u=o.BLOCKS,c=o.MACRO,a=o.EXTEND,l=o.LAYOUT,s=o.BUFFER,f=o.COMPONENT;function h(e){this[u]={},this[c]={},d(this,e||{})}this.create=function(e){return new h(e)},this.helpers=function(e){d(h.prototype,e||{})},h.prototype=d({},t||{}),Object.defineProperties(h.prototype,(R(n={},s,{value:D(),writable:!0,configurable:!1,enumerable:!1}),R(n,u,{value:{},writable:!0,configurable:!1,enumerable:!1}),R(n,c,{value:{},writable:!0,configurable:!1,enumerable:!1}),R(n,l,{value:!1,writable:!0,configurable:!1,enumerable:!1}),R(n,a,{value:!1,writable:!0,configurable:!1,enumerable:!1}),R(n,"getMacro",{value:function(){return this[c]},writable:!1,configurable:!1,enumerable:!1}),R(n,"getBuffer",{value:function(){return this[s]},writable:!1,configurable:!1,enumerable:!1}),R(n,"getComponent",{value:function(){var e=this;return f in e?function(){return e[f].apply(e,arguments)}:function(){console.log("%s function not defined",f)}},writable:!1,configurable:!1,enumerable:!1}),R(n,"getBlocks",{value:function(){return this[u]},writable:!1,configurable:!1,enumerable:!1}),R(n,"setExtend",{value:function(e){this[a]=e},writable:!1,configurable:!1,enumerable:!1}),R(n,"getExtend",{value:function(){return this[a]},writable:!1,configurable:!1,enumerable:!1}),R(n,"setLayout",{value:function(e){this[l]=e},writable:!1,configurable:!1,enumerable:!1}),R(n,"getLayout",{value:function(){return this[l]},writable:!1,configurable:!1,enumerable:!1}),R(n,"clone",{value:function(e){var t=[l,a,s];return!0===e&&t.push(u),j(this,t)},writable:!1,configurable:!1,enumerable:!1}),R(n,"extend",{value:function(e){this.setExtend(!0),this.setLayout(e)},writable:!1,configurable:!1,enumerable:!1}),R(n,"echo",{value:function(e){var t=this.getBuffer();[].slice.call(arguments).forEach(t)},writable:!1,configurable:!1,enumerable:!1}),R(n,"fn",{value:function(e){var t=this.getBuffer(),n=this;return function(){return t.backup(),r(e)&&e.apply(n,arguments),t.restore()}},writable:!1,configurable:!1,enumerable:!1}),R(n,"get",{value:function(e,t){var n=v(this,e,!0),r=n.shift(),i=n.pop();return O(r,i)?r[i]:t},writable:!0,configurable:!0,enumerable:!1}),R(n,"set",{value:function(e,t){var n=v(this,e,!1),r=n.shift(),i=n.pop();return this.getExtend()&&O(r,i)?r[i]:r[i]=t},writable:!1,configurable:!1,enumerable:!1}),R(n,"macro",{value:function(e,t){var n=this.getMacro(),r=this.fn(t),i=this;n[e]=function(){return i.echo(r.apply(void 0,arguments))}},writable:!1,configurable:!1,enumerable:!1}),R(n,"call",{value:function(e){var t=this.getMacro()[e],n=[].slice.call(arguments,1);if(r(t))return t.apply(t,n)},writable:!1,configurable:!1,enumerable:!1}),R(n,"block",{value:function(e,t){var n=this,r=this.getBlocks();if(r[e]=r[e]||[],r[e].push(this.fn(t)),!this.getExtend()){var i=Object.assign([],r[e]),o=function(){return i.shift()};this.echo(o()(function e(){var t=o();return t?function(){n.echo(t(e()))}:w}()))}},writable:!1,configurable:!1,enumerable:!1}),R(n,"hasBlock",{value:function(e){return this.getBlocks().hasOwnProperty(e)},writable:!1,configurable:!1,enumerable:!1}),R(n,"include",{value:function(e,t,n){var r=!1===n?{}:this.clone(!0),i=d(r,t||{}),o=this.render(e,i);this.echo(o)},writable:!1,configurable:!1,enumerable:!1}),R(n,"use",{value:function(e,t){var n=this.require(e);this.echo(E(n,(function(e){var n=this.getMacro();y(e,(function(e,r){n[[t,r].join(".")]=e}))}),this))},writable:!1,configurable:!1,enumerable:!1}),R(n,"async",{value:function(e,t){this.echo(E(e,(function(e){return this.fn(t)(e)}),this))},writable:!1,configurable:!1,enumerable:!1}),R(n,"each",{value:function(e,t){i(e)&&(e=this.get(e,[])),y(e,t)},writable:!1,configurable:!1,enumerable:!1}),R(n,"element",{value:function(e,t,n){return H(e,t,n)},writable:!1,configurable:!1,enumerable:!1}),R(n,"el",{value:function(e,t,n){r(n)&&(n=this.fn(n)()),this.echo(E(n,(function(n){return this.element(e,t,n)}),this))},writable:!1,configurable:!1,enumerable:!1}),n))},this.configure(e)}Object.setPrototypeOf(W.prototype,Error.prototype),Object.setPrototypeOf(W.prototype,L.prototype),Object.setPrototypeOf(J.prototype,L.prototype);var X=new function e(t){if(!1===g(this,e))return new e(t);var n={},i={};k(i,t||{});var o=new K(i),u=new B(i),c=new S,a=new T(i,c,u),l=function(e,t){var n=i.globalHelpers,o=[t,t.getComponent(),t.getBuffer(),b].concat(n.filter((function(e){return r(t[e])})).map((function(e){return t[e].bind(t)})));return a.get(e).then((function(e){return e.apply(t,o)}))},s=function e(t,n){var r=m(t,i.extension),u=o.create(n);return l(r,u).then((function(t){if(u.getExtend()){u.setExtend(!1);var n=u.getLayout(),r=u.clone();return e(n,r)}return t}))};return this.configure=function(e){return k(i,e=e||{}),o.configure(i,n),u.configure(i),c.configure(i),a.configure(i),i},this.render=function(e,t){return s(e,t)},this.helpers=function(e){o.helpers(d(n,e))},this.preload=function(e){return c.load(e||{})},this.create=function(t){return new e(t)},this.compile=function(e,t){return u.compile(e,t)},this.context=function(e){return o.create(e)},this.helpers({require:function(e){var t=m(e,i.extension),n=o.create({});return l(t,n).then((function(){return n.getMacro()}))},render:s}),this}({resolver:function(e,t){return fetch(function(e,t){return(t=[e,t].join("/")).replace(/\/\//g,"/")}(e,t)).then((function(e){return e.text()}),(function(e){return new L(e)}))}}),Y=X.render,_=X.context,z=X.compile,G=X.helpers,I=X.preload,Q=X.configure,V=X.create;e.compile=z,e.configure=Q,e.context=_,e.create=V,e.helpers=G,e.preload=I,e.render=Y}));
|
package/dist/umd/index.js
CHANGED
|
@@ -327,7 +327,7 @@
|
|
|
327
327
|
});
|
|
328
328
|
});
|
|
329
329
|
source += "');";
|
|
330
|
-
source = "try{".concat(source, "}catch(e){
|
|
330
|
+
source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
|
|
331
331
|
if (compiler.withObject) {
|
|
332
332
|
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
333
333
|
}
|
|
@@ -439,11 +439,36 @@
|
|
|
439
439
|
return result.join('');
|
|
440
440
|
};
|
|
441
441
|
|
|
442
|
+
function TemplateError(message) {
|
|
443
|
+
this.code = 1;
|
|
444
|
+
this.name = 'TemplateError';
|
|
445
|
+
this.message = message;
|
|
446
|
+
Error.call(this);
|
|
447
|
+
}
|
|
448
|
+
Object.setPrototypeOf(TemplateNotFound.prototype, Error.prototype);
|
|
449
|
+
function TemplateNotFound(message) {
|
|
450
|
+
TemplateError.call(this);
|
|
451
|
+
this.code = 404;
|
|
452
|
+
this.name = 'TemplateNotFound';
|
|
453
|
+
this.message = message;
|
|
454
|
+
}
|
|
455
|
+
Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
|
|
456
|
+
function TemplateSyntaxError(message) {
|
|
457
|
+
TemplateError.call(this);
|
|
458
|
+
this.code = 500;
|
|
459
|
+
this.name = 'TemplateSyntaxError';
|
|
460
|
+
this.message = message;
|
|
461
|
+
}
|
|
462
|
+
Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
|
|
463
|
+
|
|
442
464
|
function resolve(list) {
|
|
443
465
|
return Promise.all(list || []).then(function (list) {
|
|
444
466
|
return list.join('');
|
|
445
467
|
});
|
|
446
468
|
}
|
|
469
|
+
function reject(error) {
|
|
470
|
+
return Promise.reject(new TemplateSyntaxError(error.message));
|
|
471
|
+
}
|
|
447
472
|
function createBuffer() {
|
|
448
473
|
var store = [],
|
|
449
474
|
array = [];
|
|
@@ -463,7 +488,7 @@
|
|
|
463
488
|
return resolve(result);
|
|
464
489
|
};
|
|
465
490
|
buffer.error = function (e) {
|
|
466
|
-
|
|
491
|
+
return reject(e);
|
|
467
492
|
};
|
|
468
493
|
buffer.end = function () {
|
|
469
494
|
return resolve(array);
|
|
@@ -488,6 +513,11 @@
|
|
|
488
513
|
this.helpers = function (methods) {
|
|
489
514
|
extend(Scope.prototype, methods || {});
|
|
490
515
|
};
|
|
516
|
+
/**
|
|
517
|
+
* @name ContextScope
|
|
518
|
+
* @param data
|
|
519
|
+
* @constructor
|
|
520
|
+
*/
|
|
491
521
|
function Scope(data) {
|
|
492
522
|
this[BLOCKS] = {};
|
|
493
523
|
this[MACRO] = {};
|
|
@@ -633,8 +663,8 @@
|
|
|
633
663
|
var prop = path.pop();
|
|
634
664
|
return hasProp(result, prop) ? result[prop] : defaults;
|
|
635
665
|
},
|
|
636
|
-
writable:
|
|
637
|
-
configurable:
|
|
666
|
+
writable: true,
|
|
667
|
+
configurable: true,
|
|
638
668
|
enumerable: false
|
|
639
669
|
}), _defineProperty(_Object$definePropert, "set", {
|
|
640
670
|
value: function value(name, _value2) {
|
|
@@ -699,6 +729,13 @@
|
|
|
699
729
|
writable: false,
|
|
700
730
|
configurable: false,
|
|
701
731
|
enumerable: false
|
|
732
|
+
}), _defineProperty(_Object$definePropert, "hasBlock", {
|
|
733
|
+
value: function value(name) {
|
|
734
|
+
return this.getBlocks().hasOwnProperty(name);
|
|
735
|
+
},
|
|
736
|
+
writable: false,
|
|
737
|
+
configurable: false,
|
|
738
|
+
enumerable: false
|
|
702
739
|
}), _defineProperty(_Object$definePropert, "include", {
|
|
703
740
|
value: function value(path, data, cx) {
|
|
704
741
|
var context = cx === false ? {} : this.clone(true);
|
|
@@ -774,13 +811,15 @@
|
|
|
774
811
|
var compiler = new Compiler(config);
|
|
775
812
|
var cache = new Cache();
|
|
776
813
|
var template = new Template(config, cache, compiler);
|
|
777
|
-
var output = function output(path,
|
|
778
|
-
var
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
})
|
|
814
|
+
var output = function output(path, scope) {
|
|
815
|
+
var globalHelpers = config.globalHelpers;
|
|
816
|
+
var params = [scope, scope.getComponent(), scope.getBuffer(), safeValue].concat(globalHelpers.filter(function (name) {
|
|
817
|
+
return isFunction(scope[name]);
|
|
818
|
+
}).map(function (name) {
|
|
819
|
+
return scope[name].bind(scope);
|
|
820
|
+
}));
|
|
782
821
|
return template.get(path).then(function (callback) {
|
|
783
|
-
return callback.apply(
|
|
822
|
+
return callback.apply(scope, params);
|
|
784
823
|
});
|
|
785
824
|
};
|
|
786
825
|
var require = function require(name) {
|
|
@@ -843,7 +882,7 @@
|
|
|
843
882
|
return new Promise(function (resolve, reject) {
|
|
844
883
|
path.readFile(joinPath(path$1, template), function (error, data) {
|
|
845
884
|
if (error) {
|
|
846
|
-
reject(error);
|
|
885
|
+
reject(new TemplateError(error));
|
|
847
886
|
} else {
|
|
848
887
|
resolve(data.toString());
|
|
849
888
|
}
|
package/dist/umd/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ejs={})}(this,(function(e){"use strict";var n=function(){var e=[].slice.call(arguments),n=e.shift();return e.filter(n).pop()},t=function(e){return Array.isArray(e)},r=function(e){return"function"==typeof e},i=function(e){return"string"==typeof e},o=function(e){return"boolean"==typeof e},u=function(e){return void 0===e},c="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a=function(){return c},l={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},s={"&":"&","<":"<",">":">",'"':""","'":"'"},f=function(e){return new RegExp(["[",Object.keys(e).join(""),"]"].join(""),"g")},h=f(s),p=f(l),b=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(h,(function(e){return s[e]}))},v=function(e){return(""+e).replace(p,(function(e){return"\\"+l[e]}))},g=function(e,n){var t=e;return null==t?"":!0===n?b(t):t},m=function(e,n){return Boolean(e instanceof n)},w=function(e,n,t){for(var i=e,o=String(n).split("."),u=o.pop(),c=0;c<o.length;c++){var a=o[c];if(r(i.toJSON)&&(i=i.toJSON()),t&&!1===i.hasOwnProperty(a)){i={};break}i=i[a]=i[a]||{}}return r(i.toJSON)&&(i=i.toJSON()),[i,u]},d=function(e,n){var t=e.split(".").pop();return t!==n&&(e=[e,n].join(".")),e},y=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];return t.filter((function(e){return e})).reduce((function(e,n){return Object.assign(e,n)}),e)},j=function(){},E=function(e,n){var t;for(t in e)k(e,t)&&n(e[t],t,e)},x=function(e,n){return function(e,n,t){var r=e instanceof Array,i=r?[]:{};return E(e,(function(e,t,o){var c=n(e,t,o);!1===u(c)&&(r?i.push(c):i[t]=c)})),i}(e,(function(e,t){if(-1===n.indexOf(t))return e}))},O=function(e,n,t){return Promise.resolve(e).then(n.bind(t))},k=function(e,n){return e&&e.hasOwnProperty(n)},F={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:function(e,n){return Promise.resolve(["resolver is not defined",e,n].join(" "))},extension:"ejs",rmWhitespace:!0,withObject:!0,globalHelpers:[],vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},S=function(e,u){y(e,{path:n(i,F.path,e.path,u.path),export:n(i,F.export,e.export,u.export),resolver:n(r,F.resolver,e.resolver,u.resolver),extension:n(i,F.extension,e.extension,u.extension),withObject:n(o,F.withObject,e.withObject,u.withObject),rmWhitespace:n(o,F.rmWhitespace,e.rmWhitespace,u.rmWhitespace),cache:n(o,F.cache,e.cache,u.cache),token:y({},F.token,e.token,u.token),vars:y({},F.vars,e.vars,u.vars),globalHelpers:n(t,F.globalHelpers,e.globalHelpers,u.globalHelpers)})},B="undefined"!=typeof globalThis?globalThis:window||self;function P(e){if(!1===m(this,P))return new P;var n={enabled:!0,list:{}};this.configure=function(e){n.enabled=e.cache,!1===a()&&this.load(B[e.export])},this.clear=function(){n.list={}},this.load=function(e){return n.enabled&&y(n.list,e||{}),this},this.get=function(e){if(n.enabled)return n.list[e]},this.set=function(e,t){return n.enabled&&(n.list[e]=t),this},this.resolve=function(e){return Promise.resolve(this.get(e))},this.remove=function(e){delete n.list[e]},this.exist=function(e){return k(n.list,e)}}var R=[{symbol:"-",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(e){return"')\n/**".concat(e,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(e){return"')\n".concat(e.trim(),"\n").concat(this.BUFFER,"('")}}];function T(e){if(!1===m(this,T))return new T(e);var n={};this.configure=function(e){n.withObject=e.withObject,n.rmWhitespace=e.rmWhitespace,n.token=e.token,n.vars=e.vars,n.globalHelpers=e.globalHelpers,n.matches=[],n.formats=[],n.slurp={match:"[ \\t]*",start:[n.token.start,"_"],end:["_",n.token.end]},R.forEach((function(e){n.matches.push(n.token.start.concat(e.symbol).concat(n.token.regex).concat(n.token.end)),n.formats.push(e.format.bind(n.vars))})),n.regex=new RegExp(n.matches.join("|").concat("|$"),"g"),n.slurpStart=new RegExp([n.slurp.match,n.slurp.start.join("")].join(""),"gm"),n.slurpEnd=new RegExp([n.slurp.end.join(""),n.slurp.match].join(""),"gm")},this.compile=function(e,t){var r=n.vars,i=r.SCOPE,o=r.SAFE,u=r.BUFFER,c=r.COMPONENT,a=n.globalHelpers;e=String(e),n.rmWhitespace&&(e=e.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),e=e.replace(n.slurpStart,n.token.start).replace(n.slurpEnd,n.token.end);var l,s,f,h="".concat(u,"('");l=n.regex,s=function(t,r,i){h+=v(e.slice(r,i)),t.forEach((function(e,t){e&&(h+=n.formats[t](e))}))},f=0,e.replace(l,(function(){var e=[].slice.call(arguments,0,-1),n=e.pop(),t=e.shift();return s(e,f,n),f=n+t.length,t})),h="try{".concat(h+="');","}catch(e){console.info(e)}"),n.withObject&&(h="with(".concat(i,"){").concat(h,"}")),h="".concat(u,".start();").concat(h,"return ").concat(u,".end();"),h+="\n//# sourceURL=".concat(t);var p=null,b=[i,c,u,o].concat(a);try{(p=Function.apply(null,b.concat(h))).source="(function(".concat(b.join(","),"){\n").concat(h,"\n})")}catch(e){throw e.filename=t,e.source=h,e}return p},this.configure(e)}function $(e,n,t){if(!1===m(this,$))return new $(e,n,t);if(!1===m(n,P))throw new TypeError("cache is not instance of Cache");if(!1===m(t,T))throw new TypeError("compiler is not instance of Compiler");var i={},o=function(e){return i.resolver(i.path,e)};this.configure=function(e){i.path=e.path,i.cache=e.cache,r(e.resolver)&&(i.resolver=e.resolver)},this.get=function(e){return n.exist(e)?n.resolve(e):o(e).then((function(i){return function(e,t){return n.set(e,t),t}(e,function(e,n){return r(e)?e:t.compile(e,n)}(i,e))}))},this.configure(e)}function A(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var C=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],N=" ",U='"',M="/",H="<",L=">",W=function(e,n,t){var r=[],i=-1===C.indexOf(e),o=function(e,n,t){var r=[];return E(e,(function(e,t,i){var o=n(e,t,i);!1===u(o)&&r.push(o)})),r}(n,(function(e,n){if(null!=e)return[b(n),[U,b(e),U].join("")].join("=")})).join(N);return r.push([H,e,N,o,L].join("")),t&&r.push(t instanceof Array?t.join(""):t),i&&r.push([H,M,e,L].join("")),r.join("")};function J(e){return Promise.all(e||[]).then((function(e){return e.join("")}))}function _(){var e=[],n=[];function t(e){n.push(e)}return t.start=function(){n=[]},t.backup=function(){e.push(n.concat()),n=[]},t.restore=function(){var t=n.concat();return n=e.pop(),J(t)},t.error=function(e){throw e},t.end=function(){return J(n)},t}function q(e){if(!1===m(this,q))return new q(e);this.configure=function(e,n){var t,o=e.vars,u=o.BLOCKS,c=o.MACRO,a=o.EXTEND,l=o.LAYOUT,s=o.BUFFER,f=o.COMPONENT;function h(e){this[u]={},this[c]={},y(this,e||{})}this.create=function(e){return new h(e)},this.helpers=function(e){y(h.prototype,e||{})},h.prototype=y({},n||{}),Object.defineProperties(h.prototype,(A(t={},s,{value:_(),writable:!0,configurable:!1,enumerable:!1}),A(t,u,{value:{},writable:!0,configurable:!1,enumerable:!1}),A(t,c,{value:{},writable:!0,configurable:!1,enumerable:!1}),A(t,l,{value:!1,writable:!0,configurable:!1,enumerable:!1}),A(t,a,{value:!1,writable:!0,configurable:!1,enumerable:!1}),A(t,"getMacro",{value:function(){return this[c]},writable:!1,configurable:!1,enumerable:!1}),A(t,"getBuffer",{value:function(){return this[s]},writable:!1,configurable:!1,enumerable:!1}),A(t,"getComponent",{value:function(){var e=this;return f in e?function(){return e[f].apply(e,arguments)}:function(){console.log("%s function not defined",f)}},writable:!1,configurable:!1,enumerable:!1}),A(t,"getBlocks",{value:function(){return this[u]},writable:!1,configurable:!1,enumerable:!1}),A(t,"setExtend",{value:function(e){this[a]=e},writable:!1,configurable:!1,enumerable:!1}),A(t,"getExtend",{value:function(){return this[a]},writable:!1,configurable:!1,enumerable:!1}),A(t,"setLayout",{value:function(e){this[l]=e},writable:!1,configurable:!1,enumerable:!1}),A(t,"getLayout",{value:function(){return this[l]},writable:!1,configurable:!1,enumerable:!1}),A(t,"clone",{value:function(e){var n=[l,a,s];return!0===e&&n.push(u),x(this,n)},writable:!1,configurable:!1,enumerable:!1}),A(t,"extend",{value:function(e){this.setExtend(!0),this.setLayout(e)},writable:!1,configurable:!1,enumerable:!1}),A(t,"echo",{value:function(e){var n=this.getBuffer();[].slice.call(arguments).forEach(n)},writable:!1,configurable:!1,enumerable:!1}),A(t,"fn",{value:function(e){var n=this.getBuffer(),t=this;return function(){return n.backup(),r(e)&&e.apply(t,arguments),n.restore()}},writable:!1,configurable:!1,enumerable:!1}),A(t,"get",{value:function(e,n){var t=w(this,e,!0),r=t.shift(),i=t.pop();return k(r,i)?r[i]:n},writable:!1,configurable:!1,enumerable:!1}),A(t,"set",{value:function(e,n){var t=w(this,e,!1),r=t.shift(),i=t.pop();return this.getExtend()&&k(r,i)?r[i]:r[i]=n},writable:!1,configurable:!1,enumerable:!1}),A(t,"macro",{value:function(e,n){var t=this.getMacro(),r=this.fn(n),i=this;t[e]=function(){return i.echo(r.apply(void 0,arguments))}},writable:!1,configurable:!1,enumerable:!1}),A(t,"call",{value:function(e){var n=this.getMacro()[e],t=[].slice.call(arguments,1);if(r(n))return n.apply(n,t)},writable:!1,configurable:!1,enumerable:!1}),A(t,"block",{value:function(e,n){var t=this,r=this.getBlocks();if(r[e]=r[e]||[],r[e].push(this.fn(n)),!this.getExtend()){var i=Object.assign([],r[e]),o=function(){return i.shift()};this.echo(o()(function e(){var n=o();return n?function(){t.echo(n(e()))}:j}()))}},writable:!1,configurable:!1,enumerable:!1}),A(t,"include",{value:function(e,n,t){var r=!1===t?{}:this.clone(!0),i=y(r,n||{}),o=this.render(e,i);this.echo(o)},writable:!1,configurable:!1,enumerable:!1}),A(t,"use",{value:function(e,n){var t=this.require(e);this.echo(O(t,(function(e){var t=this.getMacro();E(e,(function(e,r){t[[n,r].join(".")]=e}))}),this))},writable:!1,configurable:!1,enumerable:!1}),A(t,"async",{value:function(e,n){this.echo(O(e,(function(e){return this.fn(n)(e)}),this))},writable:!1,configurable:!1,enumerable:!1}),A(t,"each",{value:function(e,n){i(e)&&(e=this.get(e,[])),E(e,n)},writable:!1,configurable:!1,enumerable:!1}),A(t,"element",{value:function(e,n,t){return W(e,n,t)},writable:!1,configurable:!1,enumerable:!1}),A(t,"el",{value:function(e,n,t){r(t)&&(t=this.fn(t)()),this.echo(O(t,(function(t){return this.element(e,n,t)}),this))},writable:!1,configurable:!1,enumerable:!1}),t))},this.configure(e)}var D={};var K=new function e(n){if(!1===m(this,e))return new e(n);var t={},i={};S(i,n||{});var o=new q(i),u=new T(i),c=new P,a=new $(i,c,u),l=function(e,n){var t=[n,n.getComponent(),n.getBuffer(),g];return i.globalHelpers.forEach((function(e){r(n[e])&&t.push(n[e].bind(n))})),a.get(e).then((function(e){return e.apply(n,t)}))},s=function e(n,t){var r=d(n,i.extension),u=o.create(t);return l(r,u).then((function(n){if(u.getExtend()){u.setExtend(!1);var t=u.getLayout(),r=u.clone();return e(t,r)}return n}))};return this.configure=function(e){return S(i,e=e||{}),o.configure(i,t),u.configure(i),c.configure(i),a.configure(i),i},this.render=function(e,n){return s(e,n)},this.helpers=function(e){o.helpers(y(t,e))},this.preload=function(e){return c.load(e||{})},this.create=function(n){return new e(n)},this.compile=function(e,n){return u.compile(e,n)},this.context=function(e){return o.create(e)},this.helpers({require:function(e){var n=d(e,i.extension),t=o.create({});return l(n,t).then((function(){return t.getMacro()}))},render:s}),this}({resolver:function(e,n){return new Promise((function(t,r){D.readFile(function(e,n){return(n=[e,n].join("/")).replace(/\/\//g,"/")}(e,n),(function(e,n){e?r(e):t(n.toString())}))}))}}),X=K.render,Y=K.context,z=K.compile,G=K.helpers,I=K.preload,Q=K.configure,V=K.create,Z=function(e){return function(t,u,c){r(u)&&(c=u,u={});var a=y({},(u=u||{}).settings),l=n(i,F.path,a.views),s=n(o,F.cache,a["view cache"]),f=y({},a["view options"]),h=D.relative(l,t);return f.path=l,f.cache=s,e.configure(f),e.render(h,u).then((function(e){c(null,e)})).catch((function(e){c(e)}))}}(K);e.__express=Z,e.compile=z,e.configure=Q,e.context=Y,e.create=V,e.helpers=G,e.preload=I,e.render=X}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ejs={})}(this,(function(e){"use strict";var t=function(){var e=[].slice.call(arguments),t=e.shift();return e.filter(t).pop()},n=function(e){return Array.isArray(e)},r=function(e){return"function"==typeof e},i=function(e){return"string"==typeof e},o=function(e){return"boolean"==typeof e},u=function(e){return void 0===e},c="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},l={"&":"&","<":"<",">":">",'"':""","'":"'"},s=function(e){return new RegExp(["[",Object.keys(e).join(""),"]"].join(""),"g")},f=s(l),h=s(a),p=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(f,(function(e){return l[e]}))},b=function(e,t){var n=e;return null==n?"":!0===t?p(n):n},v=function(e,t){return Boolean(e instanceof t)},g=function(e,t,n){for(var i=e,o=String(t).split("."),u=o.pop(),c=0;c<o.length;c++){var a=o[c];if(r(i.toJSON)&&(i=i.toJSON()),n&&!1===i.hasOwnProperty(a)){i={};break}i=i[a]=i[a]||{}}return r(i.toJSON)&&(i=i.toJSON()),[i,u]},m=function(e,t){var n=e.split(".").pop();return n!==t&&(e=[e,t].join(".")),e},d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return n.filter((function(e){return e})).reduce((function(e,t){return Object.assign(e,t)}),e)},w=function(){},y=function(e,t){var n;for(n in e)O(e,n)&&t(e[n],n,e)},j=function(e,t){return function(e,t){var n=e instanceof Array,r=n?[]:{};return y(e,(function(e,i,o){var c=t(e,i,o);!1===u(c)&&(n?r.push(c):r[i]=c)})),r}(e,(function(e,n){if(-1===t.indexOf(n))return e}))},E=function(e,t,n){return Promise.resolve(e).then(t.bind(n))},O=function(e,t){return e&&e.hasOwnProperty(t)},x={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:function(e,t){return Promise.resolve(["resolver is not defined",e,t].join(" "))},extension:"ejs",rmWhitespace:!0,withObject:!0,globalHelpers:[],vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},k=function(e,u){d(e,{path:t(i,x.path,e.path,u.path),export:t(i,x.export,e.export,u.export),resolver:t(r,x.resolver,e.resolver,u.resolver),extension:t(i,x.extension,e.extension,u.extension),withObject:t(o,x.withObject,e.withObject,u.withObject),rmWhitespace:t(o,x.rmWhitespace,e.rmWhitespace,u.rmWhitespace),cache:t(o,x.cache,e.cache,u.cache),token:d({},x.token,e.token,u.token),vars:d({},x.vars,e.vars,u.vars),globalHelpers:t(n,x.globalHelpers,e.globalHelpers,u.globalHelpers)})},F="undefined"!=typeof globalThis?globalThis:window||self;function S(e){if(!1===v(this,S))return new S;var t={enabled:!0,list:{}};this.configure=function(e){t.enabled=e.cache,!1===c&&this.load(F[e.export])},this.clear=function(){t.list={}},this.load=function(e){return t.enabled&&d(t.list,e||{}),this},this.get=function(e){if(t.enabled)return t.list[e]},this.set=function(e,n){return t.enabled&&(t.list[e]=n),this},this.resolve=function(e){return Promise.resolve(this.get(e))},this.remove=function(e){delete t.list[e]},this.exist=function(e){return O(t.list,e)}}var P=[{symbol:"-",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(e){return"')\n/**".concat(e,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(e){return"')\n".concat(e.trim(),"\n").concat(this.BUFFER,"('")}}];function B(e){if(!1===v(this,B))return new B(e);var t={};this.configure=function(e){t.withObject=e.withObject,t.rmWhitespace=e.rmWhitespace,t.token=e.token,t.vars=e.vars,t.globalHelpers=e.globalHelpers,t.matches=[],t.formats=[],t.slurp={match:"[ \\t]*",start:[t.token.start,"_"],end:["_",t.token.end]},P.forEach((function(e){t.matches.push(t.token.start.concat(e.symbol).concat(t.token.regex).concat(t.token.end)),t.formats.push(e.format.bind(t.vars))})),t.regex=new RegExp(t.matches.join("|").concat("|$"),"g"),t.slurpStart=new RegExp([t.slurp.match,t.slurp.start.join("")].join(""),"gm"),t.slurpEnd=new RegExp([t.slurp.end.join(""),t.slurp.match].join(""),"gm")},this.compile=function(e,n){var r=t.vars,i=r.SCOPE,o=r.SAFE,u=r.BUFFER,c=r.COMPONENT,l=t.globalHelpers;e=String(e),t.rmWhitespace&&(e=e.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),e=e.replace(t.slurpStart,t.token.start).replace(t.slurpEnd,t.token.end);var s,f,p,b="".concat(u,"('");s=t.regex,f=function(n,r,i){b+=(""+e.slice(r,i)).replace(h,(function(e){return"\\"+a[e]})),n.forEach((function(e,n){e&&(b+=t.formats[n](e))}))},p=0,e.replace(s,(function(){var e=[].slice.call(arguments,0,-1),t=e.pop(),n=e.shift();return f(e,p,t),p=t+n.length,n})),b="try{".concat(b+="');","}catch(e){return ").concat(u,".error(e)}"),t.withObject&&(b="with(".concat(i,"){").concat(b,"}")),b="".concat(u,".start();").concat(b,"return ").concat(u,".end();"),b+="\n//# sourceURL=".concat(n);var v=null,g=[i,c,u,o].concat(l);try{(v=Function.apply(null,g.concat(b))).source="(function(".concat(g.join(","),"){\n").concat(b,"\n})")}catch(e){throw e.filename=n,e.source=b,e}return v},this.configure(e)}function T(e,t,n){if(!1===v(this,T))return new T(e,t,n);if(!1===v(t,S))throw new TypeError("cache is not instance of Cache");if(!1===v(n,B))throw new TypeError("compiler is not instance of Compiler");var i={},o=function(e){return i.resolver(i.path,e)};this.configure=function(e){i.path=e.path,i.cache=e.cache,r(e.resolver)&&(i.resolver=e.resolver)},this.get=function(e){return t.exist(e)?t.resolve(e):o(e).then((function(i){return function(e,n){return t.set(e,n),n}(e,function(e,t){return r(e)?e:n.compile(e,t)}(i,e))}))},this.configure(e)}function R(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var N=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],$=" ",A='"',C="/",U="<",M=">",H=function(e,t,n){var r=[],i=-1===N.indexOf(e),o=function(e,t){var n=[];return y(e,(function(e,r,i){var o=t(e,r,i);!1===u(o)&&n.push(o)})),n}(t,(function(e,t){if(null!=e)return[p(t),[A,p(e),A].join("")].join("=")})).join($);return r.push([U,e,$,o,M].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([U,C,e,M].join("")),r.join("")};function L(e){this.code=1,this.name="TemplateError",this.message=e,Error.call(this)}function W(e){L.call(this),this.code=404,this.name="TemplateNotFound",this.message=e}function J(e){L.call(this),this.code=500,this.name="TemplateSyntaxError",this.message=e}function _(e){return Promise.all(e||[]).then((function(e){return e.join("")}))}function q(){var e=[],t=[];function n(e){t.push(e)}return n.start=function(){t=[]},n.backup=function(){e.push(t.concat()),t=[]},n.restore=function(){var n=t.concat();return t=e.pop(),_(n)},n.error=function(e){return t=e,Promise.reject(new J(t.message));var t},n.end=function(){return _(t)},n}function D(e){if(!1===v(this,D))return new D(e);this.configure=function(e,t){var n,o=e.vars,u=o.BLOCKS,c=o.MACRO,a=o.EXTEND,l=o.LAYOUT,s=o.BUFFER,f=o.COMPONENT;function h(e){this[u]={},this[c]={},d(this,e||{})}this.create=function(e){return new h(e)},this.helpers=function(e){d(h.prototype,e||{})},h.prototype=d({},t||{}),Object.defineProperties(h.prototype,(R(n={},s,{value:q(),writable:!0,configurable:!1,enumerable:!1}),R(n,u,{value:{},writable:!0,configurable:!1,enumerable:!1}),R(n,c,{value:{},writable:!0,configurable:!1,enumerable:!1}),R(n,l,{value:!1,writable:!0,configurable:!1,enumerable:!1}),R(n,a,{value:!1,writable:!0,configurable:!1,enumerable:!1}),R(n,"getMacro",{value:function(){return this[c]},writable:!1,configurable:!1,enumerable:!1}),R(n,"getBuffer",{value:function(){return this[s]},writable:!1,configurable:!1,enumerable:!1}),R(n,"getComponent",{value:function(){var e=this;return f in e?function(){return e[f].apply(e,arguments)}:function(){console.log("%s function not defined",f)}},writable:!1,configurable:!1,enumerable:!1}),R(n,"getBlocks",{value:function(){return this[u]},writable:!1,configurable:!1,enumerable:!1}),R(n,"setExtend",{value:function(e){this[a]=e},writable:!1,configurable:!1,enumerable:!1}),R(n,"getExtend",{value:function(){return this[a]},writable:!1,configurable:!1,enumerable:!1}),R(n,"setLayout",{value:function(e){this[l]=e},writable:!1,configurable:!1,enumerable:!1}),R(n,"getLayout",{value:function(){return this[l]},writable:!1,configurable:!1,enumerable:!1}),R(n,"clone",{value:function(e){var t=[l,a,s];return!0===e&&t.push(u),j(this,t)},writable:!1,configurable:!1,enumerable:!1}),R(n,"extend",{value:function(e){this.setExtend(!0),this.setLayout(e)},writable:!1,configurable:!1,enumerable:!1}),R(n,"echo",{value:function(e){var t=this.getBuffer();[].slice.call(arguments).forEach(t)},writable:!1,configurable:!1,enumerable:!1}),R(n,"fn",{value:function(e){var t=this.getBuffer(),n=this;return function(){return t.backup(),r(e)&&e.apply(n,arguments),t.restore()}},writable:!1,configurable:!1,enumerable:!1}),R(n,"get",{value:function(e,t){var n=g(this,e,!0),r=n.shift(),i=n.pop();return O(r,i)?r[i]:t},writable:!0,configurable:!0,enumerable:!1}),R(n,"set",{value:function(e,t){var n=g(this,e,!1),r=n.shift(),i=n.pop();return this.getExtend()&&O(r,i)?r[i]:r[i]=t},writable:!1,configurable:!1,enumerable:!1}),R(n,"macro",{value:function(e,t){var n=this.getMacro(),r=this.fn(t),i=this;n[e]=function(){return i.echo(r.apply(void 0,arguments))}},writable:!1,configurable:!1,enumerable:!1}),R(n,"call",{value:function(e){var t=this.getMacro()[e],n=[].slice.call(arguments,1);if(r(t))return t.apply(t,n)},writable:!1,configurable:!1,enumerable:!1}),R(n,"block",{value:function(e,t){var n=this,r=this.getBlocks();if(r[e]=r[e]||[],r[e].push(this.fn(t)),!this.getExtend()){var i=Object.assign([],r[e]),o=function(){return i.shift()};this.echo(o()(function e(){var t=o();return t?function(){n.echo(t(e()))}:w}()))}},writable:!1,configurable:!1,enumerable:!1}),R(n,"hasBlock",{value:function(e){return this.getBlocks().hasOwnProperty(e)},writable:!1,configurable:!1,enumerable:!1}),R(n,"include",{value:function(e,t,n){var r=!1===n?{}:this.clone(!0),i=d(r,t||{}),o=this.render(e,i);this.echo(o)},writable:!1,configurable:!1,enumerable:!1}),R(n,"use",{value:function(e,t){var n=this.require(e);this.echo(E(n,(function(e){var n=this.getMacro();y(e,(function(e,r){n[[t,r].join(".")]=e}))}),this))},writable:!1,configurable:!1,enumerable:!1}),R(n,"async",{value:function(e,t){this.echo(E(e,(function(e){return this.fn(t)(e)}),this))},writable:!1,configurable:!1,enumerable:!1}),R(n,"each",{value:function(e,t){i(e)&&(e=this.get(e,[])),y(e,t)},writable:!1,configurable:!1,enumerable:!1}),R(n,"element",{value:function(e,t,n){return H(e,t,n)},writable:!1,configurable:!1,enumerable:!1}),R(n,"el",{value:function(e,t,n){r(n)&&(n=this.fn(n)()),this.echo(E(n,(function(n){return this.element(e,t,n)}),this))},writable:!1,configurable:!1,enumerable:!1}),n))},this.configure(e)}Object.setPrototypeOf(W.prototype,Error.prototype),Object.setPrototypeOf(W.prototype,L.prototype),Object.setPrototypeOf(J.prototype,L.prototype);var K={};var X=new function e(t){if(!1===v(this,e))return new e(t);var n={},i={};k(i,t||{});var o=new D(i),u=new B(i),c=new S,a=new T(i,c,u),l=function(e,t){var n=i.globalHelpers,o=[t,t.getComponent(),t.getBuffer(),b].concat(n.filter((function(e){return r(t[e])})).map((function(e){return t[e].bind(t)})));return a.get(e).then((function(e){return e.apply(t,o)}))},s=function e(t,n){var r=m(t,i.extension),u=o.create(n);return l(r,u).then((function(t){if(u.getExtend()){u.setExtend(!1);var n=u.getLayout(),r=u.clone();return e(n,r)}return t}))};return this.configure=function(e){return k(i,e=e||{}),o.configure(i,n),u.configure(i),c.configure(i),a.configure(i),i},this.render=function(e,t){return s(e,t)},this.helpers=function(e){o.helpers(d(n,e))},this.preload=function(e){return c.load(e||{})},this.create=function(t){return new e(t)},this.compile=function(e,t){return u.compile(e,t)},this.context=function(e){return o.create(e)},this.helpers({require:function(e){var t=m(e,i.extension),n=o.create({});return l(t,n).then((function(){return n.getMacro()}))},render:s}),this}({resolver:function(e,t){return new Promise((function(n,r){K.readFile(function(e,t){return(t=[e,t].join("/")).replace(/\/\//g,"/")}(e,t),(function(e,t){e?r(new L(e)):n(t.toString())}))}))}}),Y=X.render,z=X.context,G=X.compile,I=X.helpers,Q=X.preload,V=X.configure,Z=X.create,ee=function(e){return function(n,u,c){r(u)&&(c=u,u={});var a=d({},(u=u||{}).settings),l=t(i,x.path,a.views),s=t(o,x.cache,a["view cache"]),f=d({},a["view options"]),h=K.relative(l,n);return f.path=l,f.cache=s,e.configure(f),e.render(h,u).then((function(e){c(null,e)})).catch((function(e){c(e)}))}}(X);e.__express=ee,e.compile=G,e.configure=V,e.context=z,e.create=Z,e.helpers=I,e.preload=Q,e.render=Y}));
|
package/dist/umd/worker.js
CHANGED
|
@@ -682,7 +682,7 @@
|
|
|
682
682
|
});
|
|
683
683
|
});
|
|
684
684
|
source += "');";
|
|
685
|
-
source = "try{".concat(source, "}catch(e){
|
|
685
|
+
source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
|
|
686
686
|
if (compiler.withObject) {
|
|
687
687
|
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
688
688
|
}
|
|
@@ -765,11 +765,36 @@
|
|
|
765
765
|
return result.join('');
|
|
766
766
|
};
|
|
767
767
|
|
|
768
|
+
function TemplateError(message) {
|
|
769
|
+
this.code = 1;
|
|
770
|
+
this.name = 'TemplateError';
|
|
771
|
+
this.message = message;
|
|
772
|
+
Error.call(this);
|
|
773
|
+
}
|
|
774
|
+
Object.setPrototypeOf(TemplateNotFound.prototype, Error.prototype);
|
|
775
|
+
function TemplateNotFound(message) {
|
|
776
|
+
TemplateError.call(this);
|
|
777
|
+
this.code = 404;
|
|
778
|
+
this.name = 'TemplateNotFound';
|
|
779
|
+
this.message = message;
|
|
780
|
+
}
|
|
781
|
+
Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
|
|
782
|
+
function TemplateSyntaxError(message) {
|
|
783
|
+
TemplateError.call(this);
|
|
784
|
+
this.code = 500;
|
|
785
|
+
this.name = 'TemplateSyntaxError';
|
|
786
|
+
this.message = message;
|
|
787
|
+
}
|
|
788
|
+
Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
|
|
789
|
+
|
|
768
790
|
function resolve(list) {
|
|
769
791
|
return Promise.all(list || []).then(function (list) {
|
|
770
792
|
return list.join('');
|
|
771
793
|
});
|
|
772
794
|
}
|
|
795
|
+
function reject(error) {
|
|
796
|
+
return Promise.reject(new TemplateSyntaxError(error.message));
|
|
797
|
+
}
|
|
773
798
|
function createBuffer() {
|
|
774
799
|
var store = [],
|
|
775
800
|
array = [];
|
|
@@ -789,7 +814,7 @@
|
|
|
789
814
|
return resolve(result);
|
|
790
815
|
};
|
|
791
816
|
buffer.error = function (e) {
|
|
792
|
-
|
|
817
|
+
return reject(e);
|
|
793
818
|
};
|
|
794
819
|
buffer.end = function () {
|
|
795
820
|
return resolve(array);
|
|
@@ -814,6 +839,11 @@
|
|
|
814
839
|
this.helpers = function (methods) {
|
|
815
840
|
extend(Scope.prototype, methods || {});
|
|
816
841
|
};
|
|
842
|
+
/**
|
|
843
|
+
* @name ContextScope
|
|
844
|
+
* @param data
|
|
845
|
+
* @constructor
|
|
846
|
+
*/
|
|
817
847
|
function Scope(data) {
|
|
818
848
|
this[BLOCKS] = {};
|
|
819
849
|
this[MACRO] = {};
|
|
@@ -959,8 +989,8 @@
|
|
|
959
989
|
var prop = path.pop();
|
|
960
990
|
return hasProp(result, prop) ? result[prop] : defaults;
|
|
961
991
|
},
|
|
962
|
-
writable:
|
|
963
|
-
configurable:
|
|
992
|
+
writable: true,
|
|
993
|
+
configurable: true,
|
|
964
994
|
enumerable: false
|
|
965
995
|
}), _defineProperty(_Object$definePropert, "set", {
|
|
966
996
|
value: function value(name, _value2) {
|
|
@@ -1025,6 +1055,13 @@
|
|
|
1025
1055
|
writable: false,
|
|
1026
1056
|
configurable: false,
|
|
1027
1057
|
enumerable: false
|
|
1058
|
+
}), _defineProperty(_Object$definePropert, "hasBlock", {
|
|
1059
|
+
value: function value(name) {
|
|
1060
|
+
return this.getBlocks().hasOwnProperty(name);
|
|
1061
|
+
},
|
|
1062
|
+
writable: false,
|
|
1063
|
+
configurable: false,
|
|
1064
|
+
enumerable: false
|
|
1028
1065
|
}), _defineProperty(_Object$definePropert, "include", {
|
|
1029
1066
|
value: function value(path, data, cx) {
|
|
1030
1067
|
var context = cx === false ? {} : this.clone(true);
|
|
@@ -1100,13 +1137,15 @@
|
|
|
1100
1137
|
var compiler = new Compiler(config);
|
|
1101
1138
|
var cache = new Cache();
|
|
1102
1139
|
var template = new Template(config, cache, compiler);
|
|
1103
|
-
var output = function output(path,
|
|
1104
|
-
var
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
})
|
|
1140
|
+
var output = function output(path, scope) {
|
|
1141
|
+
var globalHelpers = config.globalHelpers;
|
|
1142
|
+
var params = [scope, scope.getComponent(), scope.getBuffer(), safeValue].concat(globalHelpers.filter(function (name) {
|
|
1143
|
+
return isFunction(scope[name]);
|
|
1144
|
+
}).map(function (name) {
|
|
1145
|
+
return scope[name].bind(scope);
|
|
1146
|
+
}));
|
|
1108
1147
|
return template.get(path).then(function (callback) {
|
|
1109
|
-
return callback.apply(
|
|
1148
|
+
return callback.apply(scope, params);
|
|
1110
1149
|
});
|
|
1111
1150
|
};
|
|
1112
1151
|
var require = function require(name) {
|
|
@@ -1163,33 +1202,73 @@
|
|
|
1163
1202
|
return this;
|
|
1164
1203
|
}
|
|
1165
1204
|
|
|
1166
|
-
var
|
|
1205
|
+
var templateCache = {};
|
|
1167
1206
|
var ejs = new EJS({
|
|
1168
1207
|
cache: false,
|
|
1169
1208
|
withObject: false,
|
|
1170
1209
|
resolver: function resolver(path, name) {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1210
|
+
return new Promise(function (resolve, reject) {
|
|
1211
|
+
if (templateCache.hasOwnProperty(name)) {
|
|
1212
|
+
resolve(templateCache[name]);
|
|
1213
|
+
} else {
|
|
1214
|
+
reject(new TemplateNotFound("template ".concat(name, " not found")));
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1175
1217
|
}
|
|
1176
1218
|
});
|
|
1177
|
-
function
|
|
1178
|
-
|
|
1219
|
+
var getOrigin = function getOrigin(url, secure) {
|
|
1220
|
+
url = new URL(url);
|
|
1221
|
+
if (secure) url.protocol = 'https:';
|
|
1222
|
+
return url.origin;
|
|
1223
|
+
};
|
|
1224
|
+
function setTemplates(list) {
|
|
1225
|
+
Object.assign(templateCache, list || {});
|
|
1179
1226
|
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1227
|
+
|
|
1228
|
+
/**
|
|
1229
|
+
* @typedef {Object<string,any>} HonoContext
|
|
1230
|
+
* @property {function(*):Promise<Response>} html
|
|
1231
|
+
* @property {function(name:string,data:{}):Promise<string>} render
|
|
1232
|
+
* @property {function(name:string,data:{}):Promise<string>} ejs
|
|
1233
|
+
* @property {ContextScope} data
|
|
1234
|
+
*/
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
*
|
|
1238
|
+
* @param {Object<string,any>} options
|
|
1239
|
+
* @return {(function(c:Context, next): Promise<any>)|*}
|
|
1240
|
+
*/
|
|
1241
|
+
function setRenderer(_ref) {
|
|
1242
|
+
var _ref$secure = _ref.secure,
|
|
1243
|
+
secure = _ref$secure === void 0 ? true : _ref$secure,
|
|
1244
|
+
_ref$version = _ref.version,
|
|
1245
|
+
version = _ref$version === void 0 ? '1.0' : _ref$version;
|
|
1246
|
+
return /*#__PURE__*/function () {
|
|
1247
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(c, next) {
|
|
1248
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1249
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1250
|
+
case 0:
|
|
1251
|
+
c.data = context({});
|
|
1252
|
+
c.data.set('version', version);
|
|
1253
|
+
c.data.set('origin', getOrigin(c.req.url, secure));
|
|
1254
|
+
c.ejs = function (name, data) {
|
|
1255
|
+
return render(name, Object.assign({}, c.data, data));
|
|
1256
|
+
};
|
|
1257
|
+
c.render = function (name, data) {
|
|
1258
|
+
return c.html(c.ejs(name, data));
|
|
1259
|
+
};
|
|
1260
|
+
_context.next = 7;
|
|
1261
|
+
return next();
|
|
1262
|
+
case 7:
|
|
1263
|
+
case "end":
|
|
1264
|
+
return _context.stop();
|
|
1265
|
+
}
|
|
1266
|
+
}, _callee);
|
|
1267
|
+
}));
|
|
1268
|
+
return function (_x, _x2) {
|
|
1269
|
+
return _ref2.apply(this, arguments);
|
|
1270
|
+
};
|
|
1271
|
+
}();
|
|
1193
1272
|
}
|
|
1194
1273
|
var render = ejs.render,
|
|
1195
1274
|
context = ejs.context,
|
|
@@ -1206,6 +1285,7 @@
|
|
|
1206
1285
|
exports.helpers = helpers;
|
|
1207
1286
|
exports.preload = preload;
|
|
1208
1287
|
exports.render = render;
|
|
1209
|
-
exports.
|
|
1288
|
+
exports.setRenderer = setRenderer;
|
|
1289
|
+
exports.setTemplates = setTemplates;
|
|
1210
1290
|
|
|
1211
1291
|
}));
|