@kosatyi/ejs 0.0.34 → 0.0.36
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 +35 -20
- package/dist/ejs.js +35 -20
- package/dist/ejs.min.js +1 -1
- package/dist/ejs.mjs +83 -24
- package/global.d.ts +19 -14
- package/package.json +3 -2
package/dist/ejs.cjs
CHANGED
|
@@ -22,6 +22,7 @@ defaults.rmWhitespace = true;
|
|
|
22
22
|
defaults.withObject = false;
|
|
23
23
|
defaults.vars = {
|
|
24
24
|
SCOPE: 'ejs',
|
|
25
|
+
COMPONENT: 'ui',
|
|
25
26
|
EXTEND: '$$e',
|
|
26
27
|
BUFFER: '$$a',
|
|
27
28
|
LAYOUT: '$$l',
|
|
@@ -49,6 +50,9 @@ var isString = function isString(v) {
|
|
|
49
50
|
var isBoolean = function isBoolean(v) {
|
|
50
51
|
return typeof v === 'boolean';
|
|
51
52
|
};
|
|
53
|
+
var isUndefined = function isUndefined(v) {
|
|
54
|
+
return typeof v === 'undefined';
|
|
55
|
+
};
|
|
52
56
|
|
|
53
57
|
var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
54
58
|
var isNode = function isNode() {
|
|
@@ -129,7 +133,7 @@ var map = function map(object, callback, context) {
|
|
|
129
133
|
var result = [];
|
|
130
134
|
each(object, function (value, key, object) {
|
|
131
135
|
var item = callback(value, key, object);
|
|
132
|
-
if (item
|
|
136
|
+
if (isUndefined(item) === false) {
|
|
133
137
|
result.push(item);
|
|
134
138
|
}
|
|
135
139
|
});
|
|
@@ -140,7 +144,7 @@ var filter = function filter(object, callback, context) {
|
|
|
140
144
|
var result = isArray ? [] : {};
|
|
141
145
|
each(object, function (value, key, object) {
|
|
142
146
|
var item = callback(value, key, object);
|
|
143
|
-
if (item
|
|
147
|
+
if (isUndefined(item) === false) {
|
|
144
148
|
if (isArray) {
|
|
145
149
|
result.push(item);
|
|
146
150
|
} else {
|
|
@@ -312,7 +316,8 @@ var Compiler = /*#__PURE__*/function () {
|
|
|
312
316
|
var _this$vars = this.vars,
|
|
313
317
|
SCOPE = _this$vars.SCOPE,
|
|
314
318
|
SAFE = _this$vars.SAFE,
|
|
315
|
-
BUFFER = _this$vars.BUFFER
|
|
319
|
+
BUFFER = _this$vars.BUFFER,
|
|
320
|
+
COMPONENT = _this$vars.COMPONENT;
|
|
316
321
|
if (this.rmWhitespace) {
|
|
317
322
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
318
323
|
}
|
|
@@ -335,8 +340,8 @@ var Compiler = /*#__PURE__*/function () {
|
|
|
335
340
|
source += "\n//# sourceURL=".concat(path);
|
|
336
341
|
var result = null;
|
|
337
342
|
try {
|
|
338
|
-
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
339
|
-
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
343
|
+
result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
|
|
344
|
+
result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
340
345
|
} catch (e) {
|
|
341
346
|
e.filename = path;
|
|
342
347
|
e.source = source;
|
|
@@ -482,7 +487,8 @@ var Context = /*#__PURE__*/function () {
|
|
|
482
487
|
LAYOUT = _config$vars.LAYOUT,
|
|
483
488
|
BLOCKS = _config$vars.BLOCKS,
|
|
484
489
|
BUFFER = _config$vars.BUFFER,
|
|
485
|
-
MACRO = _config$vars.MACRO
|
|
490
|
+
MACRO = _config$vars.MACRO,
|
|
491
|
+
COMPONENT = _config$vars.COMPONENT;
|
|
486
492
|
this.create = function (data) {
|
|
487
493
|
return new Scope(data);
|
|
488
494
|
};
|
|
@@ -496,22 +502,26 @@ var Context = /*#__PURE__*/function () {
|
|
|
496
502
|
extend(this, data);
|
|
497
503
|
}
|
|
498
504
|
Scope.prototype = extend({}, methods || {});
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
505
|
+
/**
|
|
506
|
+
* @param {string} name
|
|
507
|
+
* @param {*} value
|
|
508
|
+
* @param {boolean} [writable]
|
|
509
|
+
* @param {boolean} [configurable]
|
|
510
|
+
* @param {boolean} [enumerable]
|
|
511
|
+
*/
|
|
512
|
+
Scope.define = Scope.method = function (name, value, writable, configurable, enumerable) {
|
|
513
|
+
return Object.defineProperty(Scope.prototype, name, {
|
|
504
514
|
value: value,
|
|
505
|
-
writable: writable,
|
|
506
|
-
configurable: configurable,
|
|
507
|
-
enumerable: enumerable
|
|
515
|
+
writable: writable || false,
|
|
516
|
+
configurable: configurable || false,
|
|
517
|
+
enumerable: enumerable || false
|
|
508
518
|
});
|
|
509
519
|
};
|
|
510
|
-
Scope.
|
|
511
|
-
Scope.
|
|
512
|
-
Scope.
|
|
513
|
-
Scope.
|
|
514
|
-
Scope.
|
|
520
|
+
Scope.define(BUFFER, createBuffer());
|
|
521
|
+
Scope.define(BLOCKS, {}, true);
|
|
522
|
+
Scope.define(MACRO, {}, true);
|
|
523
|
+
Scope.define(LAYOUT, false, true);
|
|
524
|
+
Scope.define(EXTEND, false, true);
|
|
515
525
|
Scope.method('initBlocks', function () {
|
|
516
526
|
this[BLOCKS] = {};
|
|
517
527
|
});
|
|
@@ -524,6 +534,11 @@ var Context = /*#__PURE__*/function () {
|
|
|
524
534
|
Scope.method('getBuffer', function () {
|
|
525
535
|
return this[BUFFER];
|
|
526
536
|
});
|
|
537
|
+
Scope.method('getComponent', function () {
|
|
538
|
+
return this[COMPONENT] || function () {
|
|
539
|
+
console.log('%s function not defined', COMPONENT);
|
|
540
|
+
};
|
|
541
|
+
});
|
|
527
542
|
Scope.method('getBlocks', function () {
|
|
528
543
|
return this[BLOCKS];
|
|
529
544
|
});
|
|
@@ -747,7 +762,7 @@ var init = function init(options) {
|
|
|
747
762
|
};
|
|
748
763
|
var output = function output(path, scope) {
|
|
749
764
|
return template.get(path).then(function (callback) {
|
|
750
|
-
return callback.call(scope, scope, scope.getBuffer(), safeValue);
|
|
765
|
+
return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
|
|
751
766
|
});
|
|
752
767
|
};
|
|
753
768
|
var _require = function require(name) {
|
package/dist/ejs.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
defaults.withObject = false;
|
|
17
17
|
defaults.vars = {
|
|
18
18
|
SCOPE: 'ejs',
|
|
19
|
+
COMPONENT: 'ui',
|
|
19
20
|
EXTEND: '$$e',
|
|
20
21
|
BUFFER: '$$a',
|
|
21
22
|
LAYOUT: '$$l',
|
|
@@ -43,6 +44,9 @@
|
|
|
43
44
|
var isBoolean = function isBoolean(v) {
|
|
44
45
|
return typeof v === 'boolean';
|
|
45
46
|
};
|
|
47
|
+
var isUndefined = function isUndefined(v) {
|
|
48
|
+
return typeof v === 'undefined';
|
|
49
|
+
};
|
|
46
50
|
|
|
47
51
|
var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
48
52
|
var isNode = function isNode() {
|
|
@@ -123,7 +127,7 @@
|
|
|
123
127
|
var result = [];
|
|
124
128
|
each(object, function (value, key, object) {
|
|
125
129
|
var item = callback(value, key, object);
|
|
126
|
-
if (item
|
|
130
|
+
if (isUndefined(item) === false) {
|
|
127
131
|
result.push(item);
|
|
128
132
|
}
|
|
129
133
|
});
|
|
@@ -134,7 +138,7 @@
|
|
|
134
138
|
var result = isArray ? [] : {};
|
|
135
139
|
each(object, function (value, key, object) {
|
|
136
140
|
var item = callback(value, key, object);
|
|
137
|
-
if (item
|
|
141
|
+
if (isUndefined(item) === false) {
|
|
138
142
|
if (isArray) {
|
|
139
143
|
result.push(item);
|
|
140
144
|
} else {
|
|
@@ -306,7 +310,8 @@
|
|
|
306
310
|
var _this$vars = this.vars,
|
|
307
311
|
SCOPE = _this$vars.SCOPE,
|
|
308
312
|
SAFE = _this$vars.SAFE,
|
|
309
|
-
BUFFER = _this$vars.BUFFER
|
|
313
|
+
BUFFER = _this$vars.BUFFER,
|
|
314
|
+
COMPONENT = _this$vars.COMPONENT;
|
|
310
315
|
if (this.rmWhitespace) {
|
|
311
316
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
312
317
|
}
|
|
@@ -329,8 +334,8 @@
|
|
|
329
334
|
source += "\n//# sourceURL=".concat(path);
|
|
330
335
|
var result = null;
|
|
331
336
|
try {
|
|
332
|
-
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
333
|
-
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
337
|
+
result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
|
|
338
|
+
result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
334
339
|
} catch (e) {
|
|
335
340
|
e.filename = path;
|
|
336
341
|
e.source = source;
|
|
@@ -476,7 +481,8 @@
|
|
|
476
481
|
LAYOUT = _config$vars.LAYOUT,
|
|
477
482
|
BLOCKS = _config$vars.BLOCKS,
|
|
478
483
|
BUFFER = _config$vars.BUFFER,
|
|
479
|
-
MACRO = _config$vars.MACRO
|
|
484
|
+
MACRO = _config$vars.MACRO,
|
|
485
|
+
COMPONENT = _config$vars.COMPONENT;
|
|
480
486
|
this.create = function (data) {
|
|
481
487
|
return new Scope(data);
|
|
482
488
|
};
|
|
@@ -490,22 +496,26 @@
|
|
|
490
496
|
extend(this, data);
|
|
491
497
|
}
|
|
492
498
|
Scope.prototype = extend({}, methods || {});
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
499
|
+
/**
|
|
500
|
+
* @param {string} name
|
|
501
|
+
* @param {*} value
|
|
502
|
+
* @param {boolean} [writable]
|
|
503
|
+
* @param {boolean} [configurable]
|
|
504
|
+
* @param {boolean} [enumerable]
|
|
505
|
+
*/
|
|
506
|
+
Scope.define = Scope.method = function (name, value, writable, configurable, enumerable) {
|
|
507
|
+
return Object.defineProperty(Scope.prototype, name, {
|
|
498
508
|
value: value,
|
|
499
|
-
writable: writable,
|
|
500
|
-
configurable: configurable,
|
|
501
|
-
enumerable: enumerable
|
|
509
|
+
writable: writable || false,
|
|
510
|
+
configurable: configurable || false,
|
|
511
|
+
enumerable: enumerable || false
|
|
502
512
|
});
|
|
503
513
|
};
|
|
504
|
-
Scope.
|
|
505
|
-
Scope.
|
|
506
|
-
Scope.
|
|
507
|
-
Scope.
|
|
508
|
-
Scope.
|
|
514
|
+
Scope.define(BUFFER, createBuffer());
|
|
515
|
+
Scope.define(BLOCKS, {}, true);
|
|
516
|
+
Scope.define(MACRO, {}, true);
|
|
517
|
+
Scope.define(LAYOUT, false, true);
|
|
518
|
+
Scope.define(EXTEND, false, true);
|
|
509
519
|
Scope.method('initBlocks', function () {
|
|
510
520
|
this[BLOCKS] = {};
|
|
511
521
|
});
|
|
@@ -518,6 +528,11 @@
|
|
|
518
528
|
Scope.method('getBuffer', function () {
|
|
519
529
|
return this[BUFFER];
|
|
520
530
|
});
|
|
531
|
+
Scope.method('getComponent', function () {
|
|
532
|
+
return this[COMPONENT] || function () {
|
|
533
|
+
console.log('%s function not defined', COMPONENT);
|
|
534
|
+
};
|
|
535
|
+
});
|
|
521
536
|
Scope.method('getBlocks', function () {
|
|
522
537
|
return this[BLOCKS];
|
|
523
538
|
});
|
|
@@ -741,7 +756,7 @@
|
|
|
741
756
|
};
|
|
742
757
|
var output = function output(path, scope) {
|
|
743
758
|
return template.get(path).then(function (callback) {
|
|
744
|
-
return callback.call(scope, scope, scope.getBuffer(), safeValue);
|
|
759
|
+
return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
|
|
745
760
|
});
|
|
746
761
|
};
|
|
747
762
|
var _require = function require(name) {
|
package/dist/ejs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ejs={})}(this,(function(t){"use strict";var e={},n={export:"ejsPrecompiled",cache:!0,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!1,vars:{SCOPE:"ejs",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},r=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},i=function(t){return"function"==typeof t},o=function(t){return"string"==typeof t},c=function(t){return"boolean"==typeof t},u="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),s=function(){return u},a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},h={"&":"&","<":"<",">":">",'"':""","'":"'"},f=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},l=f(h),p=f(a),v=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(l,(function(t){return h[t]}))},d=function(t,e,n){return null==(n=t)?"":e?v(n):n},m=function(t,e){var n=t,r=e.split("."),i=r.pop();return r.forEach((function(t){n=n[t]=n[t]||{}})),[n,i]},g=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},y=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),r)},b=function(){},w=function(t,e){var n;for(n in t)x(t,n)&&e(t[n],n,t)},j=function(t,e){return function(t,e,n){var r=t instanceof Array,i=r?[]:{};return w(t,(function(t,n,o){var c=e(t,n,o);void 0!==c&&(r?i.push(c):i[n]=c)})),i}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},k=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},x=function(t,e){return t&&t.hasOwnProperty(e)},E=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],O=" ",F='"',P="/",B="<",R=">",S=function(t,e,n){var r=[],i=-1===E.indexOf(t),o=function(t,e,n){var r=[];return w(t,(function(t,n,i){var o=e(t,n,i);void 0!==o&&r.push(o)})),r}(e,(function(t,e){if(null!=t)return[v(e),[F,v(t),F].join("")].join("=")})).join(O);return r.push([B,t,O,o,R].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([B,P,t,R].join("")),r.join("")};function $(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function U(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,M(r.key),r)}}function A(t,e,n){return e&&U(t.prototype,e),n&&U(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function M(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var T=[{symbol:"-",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(t){return"')\n/**".concat(t,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(t){return"')\n".concat(t.trim(),"\n").concat(this.BUFFER,"('")}}],_=function(){function t(e){$(this,t),this.configure(e)}return A(t,[{key:"configure",value:function(t){var e=this;this.withObject=t.withObject,this.rmWhitespace=t.rmWhitespace,this.token=t.token,this.vars=t.vars,this.matches=[],this.formats=[],this.slurp={match:"[ \\t]*",start:[this.token.start,"_"],end:["_",this.token.end]},T.forEach((function(t){e.matches.push(e.token.start.concat(t.symbol).concat(e.token.regex).concat(e.token.end)),e.formats.push(t.format.bind(e.vars))})),this.regex=new RegExp(this.matches.join("|").concat("|$"),"g"),this.slurpStart=new RegExp([this.slurp.match,this.slurp.start.join("")].join(""),"gm"),this.slurpEnd=new RegExp([this.slurp.end.join(""),this.slurp.match].join(""),"gm")}},{key:"truncate",value:function(t){return t&&t.replace(/^(?:\r\n|\r|\n)/,"")}},{key:"compile",value:function(t,e){var n=this,r=this.vars,i=r.SCOPE,o=r.SAFE,c=r.BUFFER;this.rmWhitespace&&(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=t.replace(this.slurpStart,this.token.start).replace(this.slurpEnd,this.token.end);var u,s,h,f="".concat(c,"('");u=this.regex,s=function(e,r,i){f+=(""+t.slice(r,i)).replace(p,(function(t){return"\\"+a[t]})),e.forEach((function(t,e){t&&(f+=n.formats[e](t))}))},h=0,t.replace(u,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return s(t,h,e),h=e+n.length,n})),f="try{".concat(f+="');","}catch(e){console.info(e)}"),this.withObject&&(f="with(".concat(i,"){").concat(f,"}")),f="".concat(c,".start();").concat(f,"return ").concat(c,".end();"),f+="\n//# sourceURL=".concat(e);var l=null;try{(l=new Function(i,c,o,f)).source="(function(".concat(i,",").concat(c,",").concat(o,"){\n").concat(f,"\n})")}catch(t){throw t.filename=e,t.source=f,t}return l}}]),t}(),L=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},W=function(t,e){return fetch(L(t,e)).then((function(t){return t.text()}))},C=function(t,n){return new Promise((function(r,i){e.readFile(L(t,n),(function(t,e){t?i(t):r(e.toString())}))}))},q=function(){function t(e,n,r){$(this,t),this.cache=n,this.watcher=null,this.compiler=r,this.configure(e)}return A(t,[{key:"configure",value:function(t){var n,r,o;this.path=t.path,this.resolver=i(t.resolver)?t.resolver:s()?C:W,(n=this.watcher)&&n.unwatch("."),t.watch&&s()&&(this.watcher=(r=this.cache,o=this.path,e.watch(".",{cwd:r}).on("change",(function(t){o.remove(t)})).on("error",(function(t){console.log("watcher error: "+t)}))))}},{key:"resolve",value:function(t){return this.resolver(this.path,t)}},{key:"result",value:function(t,e){return this.cache.set(t,e),e}},{key:"compile",value:function(t,e){return i(t)?t:this.compiler.compile(t,e)}},{key:"get",value:function(t){var e=this;if(this.cache.exist(t))return this.cache.resolve(t);var n=this.resolve(t).then((function(n){return e.result(t,e.compile(n,t))}));return this.result(t,n)}}]),t}(),N=function(t){return Promise.all(t).then((function(t){return t.join("")}))},D=function(){function t(e){$(this,t),this.configure(e)}return A(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,c=n.LAYOUT,u=n.BLOCKS,s=n.BUFFER,a=n.MACRO;function h(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),y(this,t)}this.create=function(t){return new h(t)},this.helpers=function(t){y(h.prototype,t)},h.prototype=y({},e||{}),h.defineProp=h.method=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];Object.defineProperty(h.prototype,t,{value:e,writable:n,configurable:r,enumerable:i})},h.defineProp(s,function(){var t=[],e=[];function n(t){e.push(t)}return n.start=function(){e=[]},n.backup=function(){t.push(e.concat()),e=[]},n.restore=function(){var n=e.concat();return e=t.pop(),N(n)},n.error=function(t){throw t},n.end=function(){return N(e)},n}()),h.defineProp(u,{},!0),h.defineProp(a,{},!0),h.defineProp(c,!1,!0),h.defineProp(r,!1,!0),h.method("initBlocks",(function(){this[u]={}})),h.method("initMacro",(function(){this[a]={}})),h.method("getMacro",(function(){return this[a]})),h.method("getBuffer",(function(){return this[s]})),h.method("getBlocks",(function(){return this[u]})),h.method("setExtend",(function(t){this[r]=t})),h.method("getExtend",(function(){return this[r]})),h.method("setLayout",(function(t){this[c]=t})),h.method("getLayout",(function(){return this[c]})),h.method("clone",(function(t){var e=[c,r,s];return!0===t&&e.push(u),j(this,e)})),h.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),h.method("echo",(function(){var t=this.getBuffer(),e=[].slice.call(arguments);e.forEach(t)})),h.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),i(t)&&t.apply(n,arguments),e.restore()}})),h.method("get",(function(t,e){var n=m(this,t),r=n.shift(),i=n.pop();return x(r,i)?r[i]:e})),h.method("set",(function(t,e){var n=m(this,t),r=n.shift(),i=n.pop();return this.getExtend()&&x(r,i)?r[i]:r[i]=e})),h.method("macro",(function(t,e){var n=this.getMacro(),r=this.fn(e),i=this;n[t]=function(){return i.echo(r.apply(void 0,arguments))}})),h.method("call",(function(t){var e=this.getMacro(),n=e[t],r=[].slice.call(arguments,1);if(i(n))return n.apply(n,r)})),h.method("block",(function(t,e){var n=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(e)),!this.getExtend()){var i=Object.assign([],r[t]),o=function(){return i.shift()};this.echo(o()(function t(){var e=o();return e?function(){n.echo(e(t()))}:b}()))}})),h.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),i=y(r,e||{}),o=this.render(t,i);this.echo(o)})),h.method("use",(function(t,e){var n=this.require(t);this.echo(k(n,(function(t){var n=this.getMacro();w(t,(function(t,r){n[[e,r].join(".")]=t}))}),this))})),h.method("async",(function(t,e){this.echo(k(t,(function(t){return this.fn(e)(t)}),this))})),h.method("node",(function(t,e,n){return S(t,e,n)})),h.method("el",(function(t,e,n){i(n)&&(n=this.fn(n)()),this.echo(k(n,(function(n){return S(t,e,n)}),this))})),h.method("each",(function(t,e){o(t)&&(t=this.get(t,[])),w(t,e)}))}}]),t}(),K="undefined"!=typeof globalThis?globalThis:window||self,X=function(){function t(e){var n,r,i;$(this,t),n=this,i={},(r=M(r="list"))in n?Object.defineProperty(n,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[r]=i,this.configure(e),!1===s()&&this.load(K[this.namespace])}return A(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return y(this.list,t),this}},{key:"exist",value:function(t){return x(this.list,t)}},{key:"get",value:function(t){return this.list[t]}},{key:"remove",value:function(t){delete this.list[t]}},{key:"resolve",value:function(t){return Promise.resolve(this.get(t))}},{key:"set",value:function(t,e){return this.list[t]=e,this}}]),t}(),Y=function(t,e){y(t,{export:r(o,n.export,t.export,e.export),path:r(o,n.path,t.path,e.path),resolver:r(i,n.resolver,t.resolver,e.resolver),extension:r(o,n.extension,t.extension,e.extension),withObject:r(c,n.withObject,t.withObject,e.withObject),rmWhitespace:r(c,n.rmWhitespace,t.rmWhitespace,e.rmWhitespace),token:y({},n.token,t.token,e.token),vars:y({},n.vars,t.vars,e.vars)})},V=function t(u){var s={},a={};Y(s,u||{});var h=new D(s),f=new _(s),l=new X(s),p=new q(s,l,f),v=function(t){return Y(s,t),h.configure(s,a),f.configure(s),l.configure(s),p.configure(s),s},m=function(t,e){return p.get(t).then((function(t){return t.call(e,e,e.getBuffer(),d)}))},b=function(t,e){var n=g(t,s.extension),r=h.create(e);return m(n,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),n=r.clone();return b(e,n)}return t}))},w=function(t){h.helpers(y(a,t||{}))};return w({require:function(t){return function(t){var e=g(t,s.extension),n=h.create({});return m(e,n).then((function(){return n.getMacro()}))}(t)},render:function(t,e){return b(t,e)}}),{render:b,helpers:w,configure:v,compile:function(t,e){return f.compile(t,e)},create:function(e){return t(e)},preload:function(t){return l.load(t)},__express:function(t,u,s){i(u)&&(s=u,u={});var a=y({},(u=u||{}).settings),h=r(o,n.path,a.views),f=r(c,n.cache,a["view cache"]),l=y({},a["view options"]),p=e.relative(h,t);return l.path=h,l.cache=f,v(l),b(p,u).then((function(t){s(null,t)})).catch((function(t){s(t)}))}}}({}),z=V.render,G=V.helpers,H=V.configure,I=V.wrapper,J=V.compile,Q=V.create,Z=V.preload,tt=V.__express;t.__express=tt,t.compile=J,t.configure=H,t.create=Q,t.element=S,t.helpers=G,t.preload=Z,t.render=z,t.safeValue=d,t.wrapper=I,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ejs={})}(this,(function(t){"use strict";var e={},n={export:"ejsPrecompiled",cache:!0,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!1,vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},r=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},i=function(t){return"function"==typeof t},o=function(t){return"string"==typeof t},c=function(t){return"boolean"==typeof t},u=function(t){return void 0===t},s="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a=function(){return s},h={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},f={"&":"&","<":"<",">":">",'"':""","'":"'"},l=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},p=l(f),v=l(h),d=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(p,(function(t){return f[t]}))},m=function(t,e,n){return null==(n=t)?"":e?d(n):n},g=function(t,e){var n=t,r=e.split("."),i=r.pop();return r.forEach((function(t){n=n[t]=n[t]||{}})),[n,i]},y=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},b=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),r)},w=function(){},j=function(t,e){var n;for(n in t)E(t,n)&&e(t[n],n,t)},k=function(t,e){return function(t,e,n){var r=t instanceof Array,i=r?[]:{};return j(t,(function(t,n,o){var c=e(t,n,o);!1===u(c)&&(r?i.push(c):i[n]=c)})),i}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},x=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},E=function(t,e){return t&&t.hasOwnProperty(e)},O=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],F=" ",B='"',P="/",R="<",S=">",$=function(t,e,n){var r=[],i=-1===O.indexOf(t),o=function(t,e,n){var r=[];return j(t,(function(t,n,i){var o=e(t,n,i);!1===u(o)&&r.push(o)})),r}(e,(function(t,e){if(null!=t)return[d(e),[B,d(t),B].join("")].join("=")})).join(F);return r.push([R,t,F,o,S].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([R,P,t,S].join("")),r.join("")};function M(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function T(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,U(r.key),r)}}function C(t,e,n){return e&&T(t.prototype,e),n&&T(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function U(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var A=[{symbol:"-",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(t){return"')\n/**".concat(t,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(t){return"')\n".concat(t.trim(),"\n").concat(this.BUFFER,"('")}}],_=function(){function t(e){M(this,t),this.configure(e)}return C(t,[{key:"configure",value:function(t){var e=this;this.withObject=t.withObject,this.rmWhitespace=t.rmWhitespace,this.token=t.token,this.vars=t.vars,this.matches=[],this.formats=[],this.slurp={match:"[ \\t]*",start:[this.token.start,"_"],end:["_",this.token.end]},A.forEach((function(t){e.matches.push(e.token.start.concat(t.symbol).concat(e.token.regex).concat(e.token.end)),e.formats.push(t.format.bind(e.vars))})),this.regex=new RegExp(this.matches.join("|").concat("|$"),"g"),this.slurpStart=new RegExp([this.slurp.match,this.slurp.start.join("")].join(""),"gm"),this.slurpEnd=new RegExp([this.slurp.end.join(""),this.slurp.match].join(""),"gm")}},{key:"truncate",value:function(t){return t&&t.replace(/^(?:\r\n|\r|\n)/,"")}},{key:"compile",value:function(t,e){var n=this,r=this.vars,i=r.SCOPE,o=r.SAFE,c=r.BUFFER,u=r.COMPONENT;this.rmWhitespace&&(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=t.replace(this.slurpStart,this.token.start).replace(this.slurpEnd,this.token.end);var s,a,f,l="".concat(c,"('");s=this.regex,a=function(e,r,i){l+=(""+t.slice(r,i)).replace(v,(function(t){return"\\"+h[t]})),e.forEach((function(t,e){t&&(l+=n.formats[e](t))}))},f=0,t.replace(s,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return a(t,f,e),f=e+n.length,n})),l="try{".concat(l+="');","}catch(e){console.info(e)}"),this.withObject&&(l="with(".concat(i,"){").concat(l,"}")),l="".concat(c,".start();").concat(l,"return ").concat(c,".end();"),l+="\n//# sourceURL=".concat(e);var p=null;try{(p=new Function(i,u,c,o,l)).source="(function(".concat(i,",").concat(u,",").concat(c,",").concat(o,"){\n").concat(l,"\n})")}catch(t){throw t.filename=e,t.source=l,t}return p}}]),t}(),L=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},N=function(t,e){return fetch(L(t,e)).then((function(t){return t.text()}))},W=function(t,n){return new Promise((function(r,i){e.readFile(L(t,n),(function(t,e){t?i(t):r(e.toString())}))}))},q=function(){function t(e,n,r){M(this,t),this.cache=n,this.watcher=null,this.compiler=r,this.configure(e)}return C(t,[{key:"configure",value:function(t){var n,r,o;this.path=t.path,this.resolver=i(t.resolver)?t.resolver:a()?W:N,(n=this.watcher)&&n.unwatch("."),t.watch&&a()&&(this.watcher=(r=this.cache,o=this.path,e.watch(".",{cwd:r}).on("change",(function(t){o.remove(t)})).on("error",(function(t){console.log("watcher error: "+t)}))))}},{key:"resolve",value:function(t){return this.resolver(this.path,t)}},{key:"result",value:function(t,e){return this.cache.set(t,e),e}},{key:"compile",value:function(t,e){return i(t)?t:this.compiler.compile(t,e)}},{key:"get",value:function(t){var e=this;if(this.cache.exist(t))return this.cache.resolve(t);var n=this.resolve(t).then((function(n){return e.result(t,e.compile(n,t))}));return this.result(t,n)}}]),t}(),D=function(t){return Promise.all(t).then((function(t){return t.join("")}))},K=function(){function t(e){M(this,t),this.configure(e)}return C(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,c=n.LAYOUT,u=n.BLOCKS,s=n.BUFFER,a=n.MACRO,h=n.COMPONENT;function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),b(this,t)}this.create=function(t){return new f(t)},this.helpers=function(t){b(f.prototype,t)},f.prototype=b({},e||{}),f.define=f.method=function(t,e,n,r,i){return Object.defineProperty(f.prototype,t,{value:e,writable:n||!1,configurable:r||!1,enumerable:i||!1})},f.define(s,function(){var t=[],e=[];function n(t){e.push(t)}return n.start=function(){e=[]},n.backup=function(){t.push(e.concat()),e=[]},n.restore=function(){var n=e.concat();return e=t.pop(),D(n)},n.error=function(t){throw t},n.end=function(){return D(e)},n}()),f.define(u,{},!0),f.define(a,{},!0),f.define(c,!1,!0),f.define(r,!1,!0),f.method("initBlocks",(function(){this[u]={}})),f.method("initMacro",(function(){this[a]={}})),f.method("getMacro",(function(){return this[a]})),f.method("getBuffer",(function(){return this[s]})),f.method("getComponent",(function(){return this[h]||function(){console.log("%s function not defined",h)}})),f.method("getBlocks",(function(){return this[u]})),f.method("setExtend",(function(t){this[r]=t})),f.method("getExtend",(function(){return this[r]})),f.method("setLayout",(function(t){this[c]=t})),f.method("getLayout",(function(){return this[c]})),f.method("clone",(function(t){var e=[c,r,s];return!0===t&&e.push(u),k(this,e)})),f.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),f.method("echo",(function(){var t=this.getBuffer(),e=[].slice.call(arguments);e.forEach(t)})),f.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),i(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=g(this,t),r=n.shift(),i=n.pop();return E(r,i)?r[i]:e})),f.method("set",(function(t,e){var n=g(this,t),r=n.shift(),i=n.pop();return this.getExtend()&&E(r,i)?r[i]:r[i]=e})),f.method("macro",(function(t,e){var n=this.getMacro(),r=this.fn(e),i=this;n[t]=function(){return i.echo(r.apply(void 0,arguments))}})),f.method("call",(function(t){var e=this.getMacro(),n=e[t],r=[].slice.call(arguments,1);if(i(n))return n.apply(n,r)})),f.method("block",(function(t,e){var n=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(e)),!this.getExtend()){var i=Object.assign([],r[t]),o=function(){return i.shift()};this.echo(o()(function t(){var e=o();return e?function(){n.echo(e(t()))}:w}()))}})),f.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),i=b(r,e||{}),o=this.render(t,i);this.echo(o)})),f.method("use",(function(t,e){var n=this.require(t);this.echo(x(n,(function(t){var n=this.getMacro();j(t,(function(t,r){n[[e,r].join(".")]=t}))}),this))})),f.method("async",(function(t,e){this.echo(x(t,(function(t){return this.fn(e)(t)}),this))})),f.method("node",(function(t,e,n){return $(t,e,n)})),f.method("el",(function(t,e,n){i(n)&&(n=this.fn(n)()),this.echo(x(n,(function(n){return $(t,e,n)}),this))})),f.method("each",(function(t,e){o(t)&&(t=this.get(t,[])),j(t,e)}))}}]),t}(),X="undefined"!=typeof globalThis?globalThis:window||self,Y=function(){function t(e){var n,r,i;M(this,t),n=this,i={},(r=U(r="list"))in n?Object.defineProperty(n,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[r]=i,this.configure(e),!1===a()&&this.load(X[this.namespace])}return C(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return b(this.list,t),this}},{key:"exist",value:function(t){return E(this.list,t)}},{key:"get",value:function(t){return this.list[t]}},{key:"remove",value:function(t){delete this.list[t]}},{key:"resolve",value:function(t){return Promise.resolve(this.get(t))}},{key:"set",value:function(t,e){return this.list[t]=e,this}}]),t}(),V=function(t,e){b(t,{export:r(o,n.export,t.export,e.export),path:r(o,n.path,t.path,e.path),resolver:r(i,n.resolver,t.resolver,e.resolver),extension:r(o,n.extension,t.extension,e.extension),withObject:r(c,n.withObject,t.withObject,e.withObject),rmWhitespace:r(c,n.rmWhitespace,t.rmWhitespace,e.rmWhitespace),token:b({},n.token,t.token,e.token),vars:b({},n.vars,t.vars,e.vars)})},z=function t(u){var s={},a={};V(s,u||{});var h=new K(s),f=new _(s),l=new Y(s),p=new q(s,l,f),v=function(t){return V(s,t),h.configure(s,a),f.configure(s),l.configure(s),p.configure(s),s},d=function(t,e){return p.get(t).then((function(t){return t.call(e,e,e.getComponent(),e.getBuffer(),m)}))},g=function(t,e){var n=y(t,s.extension),r=h.create(e);return d(n,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),n=r.clone();return g(e,n)}return t}))},w=function(t){h.helpers(b(a,t||{}))};return w({require:function(t){return function(t){var e=y(t,s.extension),n=h.create({});return d(e,n).then((function(){return n.getMacro()}))}(t)},render:function(t,e){return g(t,e)}}),{render:g,helpers:w,configure:v,compile:function(t,e){return f.compile(t,e)},create:function(e){return t(e)},preload:function(t){return l.load(t)},__express:function(t,u,s){i(u)&&(s=u,u={});var a=b({},(u=u||{}).settings),h=r(o,n.path,a.views),f=r(c,n.cache,a["view cache"]),l=b({},a["view options"]),p=e.relative(h,t);return l.path=h,l.cache=f,v(l),g(p,u).then((function(t){s(null,t)})).catch((function(t){s(t)}))}}}({}),G=z.render,H=z.helpers,I=z.configure,J=z.wrapper,Q=z.compile,Z=z.create,tt=z.preload,et=z.__express;t.__express=et,t.compile=Q,t.configure=I,t.create=Z,t.element=$,t.helpers=H,t.preload=tt,t.render=G,t.safeValue=m,t.wrapper=J,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/ejs.mjs
CHANGED
|
@@ -20,6 +20,7 @@ defaults.withObject = false;
|
|
|
20
20
|
|
|
21
21
|
defaults.vars = {
|
|
22
22
|
SCOPE: 'ejs',
|
|
23
|
+
COMPONENT: 'ui',
|
|
23
24
|
EXTEND: '$$e',
|
|
24
25
|
BUFFER: '$$a',
|
|
25
26
|
LAYOUT: '$$l',
|
|
@@ -42,8 +43,12 @@ const typeProp = function () {
|
|
|
42
43
|
const isFunction = (v) => typeof v === 'function';
|
|
43
44
|
const isString = (v) => typeof v === 'string';
|
|
44
45
|
const isBoolean = (v) => typeof v === 'boolean';
|
|
46
|
+
const isUndefined = (v) => typeof v === 'undefined';
|
|
45
47
|
|
|
46
|
-
const isNodeEnv =
|
|
48
|
+
const isNodeEnv =
|
|
49
|
+
Object.prototype.toString.call(
|
|
50
|
+
typeof process !== 'undefined' ? process : 0
|
|
51
|
+
) === '[object process]';
|
|
47
52
|
|
|
48
53
|
const isNode = () => isNodeEnv;
|
|
49
54
|
|
|
@@ -134,7 +139,7 @@ const map = (object, callback, context) => {
|
|
|
134
139
|
object,
|
|
135
140
|
(value, key, object) => {
|
|
136
141
|
let item = callback(value, key, object);
|
|
137
|
-
if (item
|
|
142
|
+
if (isUndefined(item) === false) {
|
|
138
143
|
result.push(item);
|
|
139
144
|
}
|
|
140
145
|
});
|
|
@@ -148,7 +153,7 @@ const filter = (object, callback, context) => {
|
|
|
148
153
|
object,
|
|
149
154
|
(value, key, object) => {
|
|
150
155
|
let item = callback(value, key, object);
|
|
151
|
-
if (item
|
|
156
|
+
if (isUndefined(item) === false) {
|
|
152
157
|
if (isArray) {
|
|
153
158
|
result.push(item);
|
|
154
159
|
} else {
|
|
@@ -167,7 +172,7 @@ const omit = (object, list) => {
|
|
|
167
172
|
})
|
|
168
173
|
};
|
|
169
174
|
|
|
170
|
-
const resolve$1 = (value,callback,context) =>
|
|
175
|
+
const resolve$1 = (value, callback, context) =>
|
|
171
176
|
Promise.resolve(value).then(callback.bind(context));
|
|
172
177
|
|
|
173
178
|
const hasProp = (object, prop) => {
|
|
@@ -262,6 +267,7 @@ class Compiler {
|
|
|
262
267
|
constructor(config) {
|
|
263
268
|
this.configure(config);
|
|
264
269
|
}
|
|
270
|
+
|
|
265
271
|
configure(config) {
|
|
266
272
|
this.withObject = config.withObject;
|
|
267
273
|
this.rmWhitespace = config.rmWhitespace;
|
|
@@ -293,11 +299,13 @@ class Compiler {
|
|
|
293
299
|
'gm'
|
|
294
300
|
);
|
|
295
301
|
}
|
|
302
|
+
|
|
296
303
|
truncate(value) {
|
|
297
304
|
return value && value.replace(/^(?:\r\n|\r|\n)/, '')
|
|
298
305
|
}
|
|
306
|
+
|
|
299
307
|
compile(content, path) {
|
|
300
|
-
const { SCOPE, SAFE, BUFFER } = this.vars;
|
|
308
|
+
const { SCOPE, SAFE, BUFFER, COMPONENT } = this.vars;
|
|
301
309
|
if (this.rmWhitespace) {
|
|
302
310
|
content = content
|
|
303
311
|
.replace(/[\r\n]+/g, '\n')
|
|
@@ -324,8 +332,8 @@ class Compiler {
|
|
|
324
332
|
source += `\n//# sourceURL=${path}`;
|
|
325
333
|
let result = null;
|
|
326
334
|
try {
|
|
327
|
-
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
328
|
-
result.source = `(function(${SCOPE},${BUFFER},${SAFE}){\n${source}\n})`;
|
|
335
|
+
result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
|
|
336
|
+
result.source = `(function(${SCOPE},${COMPONENT},${BUFFER},${SAFE}){\n${source}\n})`;
|
|
329
337
|
} catch (e) {
|
|
330
338
|
e.filename = path;
|
|
331
339
|
e.source = source;
|
|
@@ -456,7 +464,7 @@ class Context {
|
|
|
456
464
|
this.configure(config);
|
|
457
465
|
}
|
|
458
466
|
configure(config, methods) {
|
|
459
|
-
const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO } = config.vars;
|
|
467
|
+
const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO, COMPONENT } = config.vars;
|
|
460
468
|
this.create = (data) => {
|
|
461
469
|
return new Scope(data)
|
|
462
470
|
};
|
|
@@ -469,52 +477,83 @@ class Context {
|
|
|
469
477
|
extend(this, data);
|
|
470
478
|
}
|
|
471
479
|
Scope.prototype = extend({}, methods || {});
|
|
472
|
-
|
|
480
|
+
/**
|
|
481
|
+
* @param {string} name
|
|
482
|
+
* @param {*} value
|
|
483
|
+
* @param {boolean} [writable]
|
|
484
|
+
* @param {boolean} [configurable]
|
|
485
|
+
* @param {boolean} [enumerable]
|
|
486
|
+
*/
|
|
487
|
+
Scope.define = Scope.method = (
|
|
473
488
|
name,
|
|
474
489
|
value,
|
|
475
|
-
writable
|
|
476
|
-
configurable
|
|
477
|
-
enumerable
|
|
490
|
+
writable,
|
|
491
|
+
configurable,
|
|
492
|
+
enumerable
|
|
478
493
|
) => {
|
|
479
|
-
Object.defineProperty(Scope.prototype, name, {
|
|
480
|
-
value,
|
|
481
|
-
writable,
|
|
482
|
-
configurable,
|
|
483
|
-
enumerable,
|
|
484
|
-
})
|
|
494
|
+
return Object.defineProperty(Scope.prototype, name, {
|
|
495
|
+
value: value,
|
|
496
|
+
writable: writable || false,
|
|
497
|
+
configurable: configurable || false,
|
|
498
|
+
enumerable: enumerable || false,
|
|
499
|
+
})
|
|
485
500
|
};
|
|
486
|
-
|
|
487
|
-
Scope.
|
|
488
|
-
|
|
489
|
-
Scope.
|
|
490
|
-
|
|
501
|
+
|
|
502
|
+
Scope.define(BUFFER, createBuffer());
|
|
503
|
+
|
|
504
|
+
Scope.define(BLOCKS, {}, true);
|
|
505
|
+
|
|
506
|
+
Scope.define(MACRO, {}, true);
|
|
507
|
+
|
|
508
|
+
Scope.define(LAYOUT, false, true);
|
|
509
|
+
|
|
510
|
+
Scope.define(EXTEND, false, true);
|
|
511
|
+
|
|
491
512
|
Scope.method('initBlocks', function () {
|
|
492
513
|
this[BLOCKS] = {};
|
|
493
514
|
});
|
|
515
|
+
|
|
494
516
|
Scope.method('initMacro', function () {
|
|
495
517
|
this[MACRO] = {};
|
|
496
518
|
});
|
|
519
|
+
|
|
497
520
|
Scope.method('getMacro', function () {
|
|
498
521
|
return this[MACRO]
|
|
499
522
|
});
|
|
523
|
+
|
|
500
524
|
Scope.method('getBuffer', function () {
|
|
501
525
|
return this[BUFFER]
|
|
502
526
|
});
|
|
527
|
+
|
|
528
|
+
Scope.method('getComponent', function () {
|
|
529
|
+
return (
|
|
530
|
+
this[COMPONENT] ||
|
|
531
|
+
function () {
|
|
532
|
+
console.log('%s function not defined', COMPONENT);
|
|
533
|
+
}
|
|
534
|
+
)
|
|
535
|
+
});
|
|
536
|
+
|
|
503
537
|
Scope.method('getBlocks', function () {
|
|
504
538
|
return this[BLOCKS]
|
|
505
539
|
});
|
|
540
|
+
|
|
506
541
|
Scope.method('setExtend', function (value) {
|
|
507
542
|
this[EXTEND] = value;
|
|
508
543
|
});
|
|
544
|
+
|
|
509
545
|
Scope.method('getExtend', function () {
|
|
510
546
|
return this[EXTEND]
|
|
511
547
|
});
|
|
548
|
+
|
|
512
549
|
Scope.method('setLayout', function (layout) {
|
|
513
550
|
this[LAYOUT] = layout;
|
|
514
551
|
});
|
|
552
|
+
|
|
515
553
|
Scope.method('getLayout', function () {
|
|
516
554
|
return this[LAYOUT]
|
|
517
555
|
});
|
|
556
|
+
|
|
518
557
|
Scope.method('clone', function (exclude_blocks) {
|
|
519
558
|
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
520
559
|
if (exclude_blocks === true) {
|
|
@@ -522,15 +561,18 @@ class Context {
|
|
|
522
561
|
}
|
|
523
562
|
return omit(this, filter)
|
|
524
563
|
});
|
|
564
|
+
|
|
525
565
|
Scope.method('extend', function (layout) {
|
|
526
566
|
this.setExtend(true);
|
|
527
567
|
this.setLayout(layout);
|
|
528
568
|
});
|
|
569
|
+
|
|
529
570
|
Scope.method('echo', function () {
|
|
530
571
|
const buffer = this.getBuffer();
|
|
531
572
|
const params = [].slice.call(arguments);
|
|
532
573
|
params.forEach(buffer);
|
|
533
574
|
});
|
|
575
|
+
|
|
534
576
|
Scope.method('fn', function (callback) {
|
|
535
577
|
const buffer = this.getBuffer();
|
|
536
578
|
const context = this;
|
|
@@ -542,12 +584,14 @@ class Context {
|
|
|
542
584
|
return buffer.restore()
|
|
543
585
|
}
|
|
544
586
|
});
|
|
587
|
+
|
|
545
588
|
Scope.method('get', function (name, defaults) {
|
|
546
589
|
const path = getPath(this, name);
|
|
547
590
|
const result = path.shift();
|
|
548
591
|
const prop = path.pop();
|
|
549
592
|
return hasProp(result, prop) ? result[prop] : defaults
|
|
550
593
|
});
|
|
594
|
+
|
|
551
595
|
Scope.method('set', function (name, value) {
|
|
552
596
|
const path = getPath(this, name);
|
|
553
597
|
const result = path.shift();
|
|
@@ -557,6 +601,7 @@ class Context {
|
|
|
557
601
|
}
|
|
558
602
|
return (result[prop] = value)
|
|
559
603
|
});
|
|
604
|
+
|
|
560
605
|
Scope.method('macro', function (name, callback) {
|
|
561
606
|
const list = this.getMacro();
|
|
562
607
|
const macro = this.fn(callback);
|
|
@@ -565,6 +610,7 @@ class Context {
|
|
|
565
610
|
return context.echo(macro.apply(undefined, arguments))
|
|
566
611
|
};
|
|
567
612
|
});
|
|
613
|
+
|
|
568
614
|
Scope.method('call', function (name) {
|
|
569
615
|
const list = this.getMacro();
|
|
570
616
|
const macro = list[name];
|
|
@@ -573,6 +619,7 @@ class Context {
|
|
|
573
619
|
return macro.apply(macro, params)
|
|
574
620
|
}
|
|
575
621
|
});
|
|
622
|
+
|
|
576
623
|
Scope.method('block', function (name, callback) {
|
|
577
624
|
const blocks = this.getBlocks();
|
|
578
625
|
blocks[name] = blocks[name] || [];
|
|
@@ -594,12 +641,14 @@ class Context {
|
|
|
594
641
|
};
|
|
595
642
|
this.echo(current()(next()));
|
|
596
643
|
});
|
|
644
|
+
|
|
597
645
|
Scope.method('include', function (path, data, cx) {
|
|
598
646
|
const context = cx === false ? {} : this.clone(true);
|
|
599
647
|
const params = extend(context, data || {});
|
|
600
648
|
const promise = this.render(path, params);
|
|
601
649
|
this.echo(promise);
|
|
602
650
|
});
|
|
651
|
+
|
|
603
652
|
Scope.method('use', function (path, namespace) {
|
|
604
653
|
const promise = this.require(path);
|
|
605
654
|
this.echo(
|
|
@@ -615,6 +664,7 @@ class Context {
|
|
|
615
664
|
)
|
|
616
665
|
);
|
|
617
666
|
});
|
|
667
|
+
|
|
618
668
|
Scope.method('async', function (promise, callback) {
|
|
619
669
|
this.echo(
|
|
620
670
|
resolve$1(
|
|
@@ -626,9 +676,11 @@ class Context {
|
|
|
626
676
|
)
|
|
627
677
|
);
|
|
628
678
|
});
|
|
679
|
+
|
|
629
680
|
Scope.method('node', function (tag, attr, content) {
|
|
630
681
|
return element(tag, attr, content)
|
|
631
682
|
});
|
|
683
|
+
|
|
632
684
|
Scope.method('el', function (tag, attr, content) {
|
|
633
685
|
if (isFunction(content)) {
|
|
634
686
|
content = this.fn(content)();
|
|
@@ -643,6 +695,7 @@ class Context {
|
|
|
643
695
|
)
|
|
644
696
|
);
|
|
645
697
|
});
|
|
698
|
+
|
|
646
699
|
Scope.method('each', function (object, callback) {
|
|
647
700
|
if (isString(object)) {
|
|
648
701
|
object = this.get(object, []);
|
|
@@ -752,7 +805,13 @@ const init = (options) => {
|
|
|
752
805
|
|
|
753
806
|
const output = (path, scope) => {
|
|
754
807
|
return template.get(path).then(function (callback) {
|
|
755
|
-
return callback.call(
|
|
808
|
+
return callback.call(
|
|
809
|
+
scope,
|
|
810
|
+
scope,
|
|
811
|
+
scope.getComponent(),
|
|
812
|
+
scope.getBuffer(),
|
|
813
|
+
safeValue
|
|
814
|
+
)
|
|
756
815
|
})
|
|
757
816
|
};
|
|
758
817
|
|
package/global.d.ts
CHANGED
|
@@ -3,42 +3,42 @@ declare global {
|
|
|
3
3
|
* extend layout with blocks in current template file
|
|
4
4
|
* @param layout
|
|
5
5
|
*/
|
|
6
|
-
function extend(layout: string)
|
|
6
|
+
function extend(layout: string)
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* define block with custom **name** and callback
|
|
10
10
|
* @param name
|
|
11
11
|
* @param [callback]
|
|
12
12
|
*/
|
|
13
|
-
function block(name: string, callback?)
|
|
13
|
+
function block(name: string, callback?)
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* set property in current scope
|
|
17
17
|
* @param path
|
|
18
18
|
* @param value
|
|
19
19
|
*/
|
|
20
|
-
function set(path: string, value: any)
|
|
20
|
+
function set(path: string, value: any)
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* get property in current scope
|
|
24
24
|
* @param path
|
|
25
25
|
* @param defaults
|
|
26
26
|
*/
|
|
27
|
-
function get(path: string, defaults?: any)
|
|
27
|
+
function get(path: string, defaults?: any)
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* import macro from file **path** and set to current scope **name** property
|
|
31
31
|
* @param path
|
|
32
32
|
* @param name
|
|
33
33
|
*/
|
|
34
|
-
function use(path: string, name: string)
|
|
34
|
+
function use(path: string, name: string)
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* define macro function with custom **name**
|
|
38
38
|
* @param name
|
|
39
39
|
* @param callback
|
|
40
40
|
*/
|
|
41
|
-
function macro(name: string, callback)
|
|
41
|
+
function macro(name: string, callback)
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* call macro function
|
|
@@ -46,20 +46,20 @@ declare global {
|
|
|
46
46
|
* @param props
|
|
47
47
|
* @param callback
|
|
48
48
|
*/
|
|
49
|
-
function call(name: string, props?: object, callback?)
|
|
49
|
+
function call(name: string, props?: object, callback?)
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* asynchronous template execution
|
|
53
53
|
* @param promise
|
|
54
54
|
* @param callback
|
|
55
55
|
*/
|
|
56
|
-
function async(promise: Promise<any>, callback?)
|
|
56
|
+
function async(promise: Promise<any>, callback?)
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* asynchronous template execution
|
|
60
60
|
* @param callback
|
|
61
61
|
*/
|
|
62
|
-
function fn(callback: Function)
|
|
62
|
+
function fn(callback: Function)
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
*
|
|
@@ -67,13 +67,13 @@ declare global {
|
|
|
67
67
|
* @param {object} attrs
|
|
68
68
|
* @param {function} content
|
|
69
69
|
*/
|
|
70
|
-
function el(tag: string, attrs?: object, content?: any)
|
|
70
|
+
function el(tag: string, attrs?: object, content?: any)
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* buffer output
|
|
74
74
|
* @param any
|
|
75
75
|
*/
|
|
76
|
-
function echo(...any)
|
|
76
|
+
function echo(...any)
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* append rendered template from file
|
|
@@ -81,16 +81,21 @@ declare global {
|
|
|
81
81
|
* @param data
|
|
82
82
|
* @param cx
|
|
83
83
|
*/
|
|
84
|
-
function include(path: string, data?: object, cx?: boolean)
|
|
84
|
+
function include(path: string, data?: object, cx?: boolean)
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
*
|
|
88
88
|
* @param value
|
|
89
89
|
* @param callback
|
|
90
90
|
*/
|
|
91
|
-
function each(value:any,callback:Function)
|
|
91
|
+
function each(value: any, callback: Function)
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* define block with custom **name** and callback
|
|
95
|
+
* @param {string} name
|
|
96
|
+
* @param {object} [props]
|
|
97
|
+
*/
|
|
98
|
+
function ui(name: string, props?)
|
|
93
99
|
}
|
|
94
100
|
|
|
95
101
|
export = global
|
|
96
|
-
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@kosatyi/ejs",
|
|
3
3
|
"description": "EJS Templates",
|
|
4
4
|
"homepage": "https://github.com/kosatyi/ejs",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.36",
|
|
6
6
|
"main": "dist/ejs.cjs",
|
|
7
7
|
"module": "dist/ejs.mjs",
|
|
8
8
|
"browser": "dist/ejs.js",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@babel/core": "^7.20.12",
|
|
28
28
|
"@babel/preset-env": "^7.20.2",
|
|
29
|
-
"@kosatyi/ejs-bundle": "^1.0.
|
|
29
|
+
"@kosatyi/ejs-bundle": "^1.0.8",
|
|
30
|
+
"@kosatyi/ejs": "file:./",
|
|
30
31
|
"@kosatyi/rollup": "^0.0.1"
|
|
31
32
|
},
|
|
32
33
|
"license": "MIT",
|