@kosatyi/ejs 0.0.28 → 0.0.30
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 +21 -20
- package/dist/ejs.js +21 -20
- package/dist/ejs.min.js +1 -1
- package/dist/ejs.mjs +38 -52
- package/package.json +2 -4
package/dist/ejs.cjs
CHANGED
|
@@ -17,7 +17,7 @@ defaults.cache = true;
|
|
|
17
17
|
defaults.path = 'views';
|
|
18
18
|
defaults.resolver = null;
|
|
19
19
|
defaults.extension = 'ejs';
|
|
20
|
-
defaults.withObject =
|
|
20
|
+
defaults.withObject = false;
|
|
21
21
|
defaults.vars = {
|
|
22
22
|
SCOPE: 'ejs',
|
|
23
23
|
EXTEND: '$$e',
|
|
@@ -294,8 +294,8 @@ var Compiler = /*#__PURE__*/function () {
|
|
|
294
294
|
_this.formats.push(item.format.bind(_this.vars));
|
|
295
295
|
});
|
|
296
296
|
this.regex = new RegExp(this.matches.join('|').concat('|$'), 'g');
|
|
297
|
-
this.slurpStart = new RegExp([this.slurp.match, this.slurp.start].join(''), 'gm');
|
|
298
|
-
this.slurpEnd = new RegExp([this.slurp.end, this.slurp.match].join(''), 'gm');
|
|
297
|
+
this.slurpStart = new RegExp([this.slurp.match, this.slurp.start.join('')].join(''), 'gm');
|
|
298
|
+
this.slurpEnd = new RegExp([this.slurp.end.join(''), this.slurp.match].join(''), 'gm');
|
|
299
299
|
}
|
|
300
300
|
}, {
|
|
301
301
|
key: "compile",
|
|
@@ -306,7 +306,7 @@ var Compiler = /*#__PURE__*/function () {
|
|
|
306
306
|
SAFE = _this$vars.SAFE,
|
|
307
307
|
BUFFER = _this$vars.BUFFER;
|
|
308
308
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
309
|
-
content = content.replace(this.slurpStart, this.
|
|
309
|
+
content = content.replace(this.slurpStart, this.token.start).replace(this.slurpEnd, this.token.end);
|
|
310
310
|
var source = "".concat(BUFFER, "('");
|
|
311
311
|
matchTokens(this.regex, content, function (params, index, offset) {
|
|
312
312
|
source += symbols(content.slice(index, offset));
|
|
@@ -470,7 +470,7 @@ var Context = /*#__PURE__*/function () {
|
|
|
470
470
|
}
|
|
471
471
|
_createClass(Context, [{
|
|
472
472
|
key: "configure",
|
|
473
|
-
value: function configure(config) {
|
|
473
|
+
value: function configure(config, methods) {
|
|
474
474
|
var _config$vars = config.vars,
|
|
475
475
|
EXTEND = _config$vars.EXTEND,
|
|
476
476
|
LAYOUT = _config$vars.LAYOUT,
|
|
@@ -489,9 +489,7 @@ var Context = /*#__PURE__*/function () {
|
|
|
489
489
|
this.initMacro();
|
|
490
490
|
extend(this, data);
|
|
491
491
|
}
|
|
492
|
-
Scope.
|
|
493
|
-
extend(Scope.prototype, methods);
|
|
494
|
-
};
|
|
492
|
+
Scope.prototype = extend({}, methods || {});
|
|
495
493
|
Scope.defineProp = Scope.method = function (name, value) {
|
|
496
494
|
var writable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
497
495
|
var configurable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
@@ -635,6 +633,9 @@ var Context = /*#__PURE__*/function () {
|
|
|
635
633
|
return this.fn(callback)(data);
|
|
636
634
|
}, this));
|
|
637
635
|
});
|
|
636
|
+
Scope.method('node', function (tag, attr, content) {
|
|
637
|
+
return element(tag, attr, content);
|
|
638
|
+
});
|
|
638
639
|
Scope.method('el', function (tag, attr, content) {
|
|
639
640
|
if (isFunction(content)) {
|
|
640
641
|
content = this.fn(content)();
|
|
@@ -708,13 +709,13 @@ var Cache = /*#__PURE__*/function () {
|
|
|
708
709
|
|
|
709
710
|
var configSchema = function configSchema(config, options) {
|
|
710
711
|
extend(config, {
|
|
711
|
-
"export": typeProp(isString, defaults["export"], options["export"]),
|
|
712
|
-
path: typeProp(isString, defaults.path, options.path),
|
|
713
|
-
resolver: typeProp(isFunction, defaults.resolver, options.resolver),
|
|
714
|
-
extension: typeProp(isString, defaults.extension, options.extension),
|
|
715
|
-
withObject: typeProp(isBoolean, defaults.withObject, options.withObject),
|
|
716
|
-
token: extend({}, defaults.token, options.token),
|
|
717
|
-
vars: extend({}, defaults.vars, options.vars)
|
|
712
|
+
"export": typeProp(isString, defaults["export"], config["export"], options["export"]),
|
|
713
|
+
path: typeProp(isString, defaults.path, config.path, options.path),
|
|
714
|
+
resolver: typeProp(isFunction, defaults.resolver, config.resolver, options.resolver),
|
|
715
|
+
extension: typeProp(isString, defaults.extension, config.extension, options.extension),
|
|
716
|
+
withObject: typeProp(isBoolean, defaults.withObject, config.withObject, options.withObject),
|
|
717
|
+
token: extend({}, defaults.token, config.token, options.token),
|
|
718
|
+
vars: extend({}, defaults.vars, config.vars, options.vars)
|
|
718
719
|
});
|
|
719
720
|
};
|
|
720
721
|
var init = function init(options) {
|
|
@@ -723,7 +724,7 @@ var init = function init(options) {
|
|
|
723
724
|
* @module ejs
|
|
724
725
|
*/
|
|
725
726
|
var config = {};
|
|
726
|
-
var
|
|
727
|
+
var scope = {};
|
|
727
728
|
configSchema(config, options || {});
|
|
728
729
|
var context = new Context(config);
|
|
729
730
|
var compiler = new Compiler(config);
|
|
@@ -732,7 +733,7 @@ var init = function init(options) {
|
|
|
732
733
|
var template = new Template(config, cache, compiler);
|
|
733
734
|
var configure = function configure(options) {
|
|
734
735
|
configSchema(config, options);
|
|
735
|
-
context.configure(config);
|
|
736
|
+
context.configure(config, scope);
|
|
736
737
|
compiler.configure(config);
|
|
737
738
|
bundler.configure(config);
|
|
738
739
|
cache.configure(config);
|
|
@@ -764,7 +765,7 @@ var init = function init(options) {
|
|
|
764
765
|
});
|
|
765
766
|
};
|
|
766
767
|
var helpers = function helpers(methods) {
|
|
767
|
-
context.helpers(extend(
|
|
768
|
+
context.helpers(extend(scope, methods || {}));
|
|
768
769
|
};
|
|
769
770
|
var __express = function __express(name, options, callback) {
|
|
770
771
|
if (isFunction(options)) {
|
|
@@ -773,8 +774,8 @@ var init = function init(options) {
|
|
|
773
774
|
}
|
|
774
775
|
options = options || {};
|
|
775
776
|
var settings = extend({}, options.settings);
|
|
776
|
-
var viewPath = typeProp(isString, settings['views']
|
|
777
|
-
var viewCache = typeProp(isBoolean, settings['view cache']
|
|
777
|
+
var viewPath = typeProp(isString, defaults.path, settings['views']);
|
|
778
|
+
var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
|
|
778
779
|
var viewOptions = extend({}, settings['view options']);
|
|
779
780
|
var filename = path__default["default"].relative(viewPath, name);
|
|
780
781
|
viewOptions.path = viewPath;
|
package/dist/ejs.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
defaults.path = 'views';
|
|
13
13
|
defaults.resolver = null;
|
|
14
14
|
defaults.extension = 'ejs';
|
|
15
|
-
defaults.withObject =
|
|
15
|
+
defaults.withObject = false;
|
|
16
16
|
defaults.vars = {
|
|
17
17
|
SCOPE: 'ejs',
|
|
18
18
|
EXTEND: '$$e',
|
|
@@ -289,8 +289,8 @@
|
|
|
289
289
|
_this.formats.push(item.format.bind(_this.vars));
|
|
290
290
|
});
|
|
291
291
|
this.regex = new RegExp(this.matches.join('|').concat('|$'), 'g');
|
|
292
|
-
this.slurpStart = new RegExp([this.slurp.match, this.slurp.start].join(''), 'gm');
|
|
293
|
-
this.slurpEnd = new RegExp([this.slurp.end, this.slurp.match].join(''), 'gm');
|
|
292
|
+
this.slurpStart = new RegExp([this.slurp.match, this.slurp.start.join('')].join(''), 'gm');
|
|
293
|
+
this.slurpEnd = new RegExp([this.slurp.end.join(''), this.slurp.match].join(''), 'gm');
|
|
294
294
|
}
|
|
295
295
|
}, {
|
|
296
296
|
key: "compile",
|
|
@@ -301,7 +301,7 @@
|
|
|
301
301
|
SAFE = _this$vars.SAFE,
|
|
302
302
|
BUFFER = _this$vars.BUFFER;
|
|
303
303
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
304
|
-
content = content.replace(this.slurpStart, this.
|
|
304
|
+
content = content.replace(this.slurpStart, this.token.start).replace(this.slurpEnd, this.token.end);
|
|
305
305
|
var source = "".concat(BUFFER, "('");
|
|
306
306
|
matchTokens(this.regex, content, function (params, index, offset) {
|
|
307
307
|
source += symbols(content.slice(index, offset));
|
|
@@ -465,7 +465,7 @@
|
|
|
465
465
|
}
|
|
466
466
|
_createClass(Context, [{
|
|
467
467
|
key: "configure",
|
|
468
|
-
value: function configure(config) {
|
|
468
|
+
value: function configure(config, methods) {
|
|
469
469
|
var _config$vars = config.vars,
|
|
470
470
|
EXTEND = _config$vars.EXTEND,
|
|
471
471
|
LAYOUT = _config$vars.LAYOUT,
|
|
@@ -484,9 +484,7 @@
|
|
|
484
484
|
this.initMacro();
|
|
485
485
|
extend(this, data);
|
|
486
486
|
}
|
|
487
|
-
Scope.
|
|
488
|
-
extend(Scope.prototype, methods);
|
|
489
|
-
};
|
|
487
|
+
Scope.prototype = extend({}, methods || {});
|
|
490
488
|
Scope.defineProp = Scope.method = function (name, value) {
|
|
491
489
|
var writable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
492
490
|
var configurable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
@@ -630,6 +628,9 @@
|
|
|
630
628
|
return this.fn(callback)(data);
|
|
631
629
|
}, this));
|
|
632
630
|
});
|
|
631
|
+
Scope.method('node', function (tag, attr, content) {
|
|
632
|
+
return element(tag, attr, content);
|
|
633
|
+
});
|
|
633
634
|
Scope.method('el', function (tag, attr, content) {
|
|
634
635
|
if (isFunction(content)) {
|
|
635
636
|
content = this.fn(content)();
|
|
@@ -703,13 +704,13 @@
|
|
|
703
704
|
|
|
704
705
|
var configSchema = function configSchema(config, options) {
|
|
705
706
|
extend(config, {
|
|
706
|
-
"export": typeProp(isString, defaults["export"], options["export"]),
|
|
707
|
-
path: typeProp(isString, defaults.path, options.path),
|
|
708
|
-
resolver: typeProp(isFunction, defaults.resolver, options.resolver),
|
|
709
|
-
extension: typeProp(isString, defaults.extension, options.extension),
|
|
710
|
-
withObject: typeProp(isBoolean, defaults.withObject, options.withObject),
|
|
711
|
-
token: extend({}, defaults.token, options.token),
|
|
712
|
-
vars: extend({}, defaults.vars, options.vars)
|
|
707
|
+
"export": typeProp(isString, defaults["export"], config["export"], options["export"]),
|
|
708
|
+
path: typeProp(isString, defaults.path, config.path, options.path),
|
|
709
|
+
resolver: typeProp(isFunction, defaults.resolver, config.resolver, options.resolver),
|
|
710
|
+
extension: typeProp(isString, defaults.extension, config.extension, options.extension),
|
|
711
|
+
withObject: typeProp(isBoolean, defaults.withObject, config.withObject, options.withObject),
|
|
712
|
+
token: extend({}, defaults.token, config.token, options.token),
|
|
713
|
+
vars: extend({}, defaults.vars, config.vars, options.vars)
|
|
713
714
|
});
|
|
714
715
|
};
|
|
715
716
|
var init = function init(options) {
|
|
@@ -718,7 +719,7 @@
|
|
|
718
719
|
* @module ejs
|
|
719
720
|
*/
|
|
720
721
|
var config = {};
|
|
721
|
-
var
|
|
722
|
+
var scope = {};
|
|
722
723
|
configSchema(config, options || {});
|
|
723
724
|
var context = new Context(config);
|
|
724
725
|
var compiler = new Compiler(config);
|
|
@@ -727,7 +728,7 @@
|
|
|
727
728
|
var template = new Template(config, cache, compiler);
|
|
728
729
|
var configure = function configure(options) {
|
|
729
730
|
configSchema(config, options);
|
|
730
|
-
context.configure(config);
|
|
731
|
+
context.configure(config, scope);
|
|
731
732
|
compiler.configure(config);
|
|
732
733
|
bundler.configure(config);
|
|
733
734
|
cache.configure(config);
|
|
@@ -759,7 +760,7 @@
|
|
|
759
760
|
});
|
|
760
761
|
};
|
|
761
762
|
var helpers = function helpers(methods) {
|
|
762
|
-
context.helpers(extend(
|
|
763
|
+
context.helpers(extend(scope, methods || {}));
|
|
763
764
|
};
|
|
764
765
|
var __express = function __express(name, options, callback) {
|
|
765
766
|
if (isFunction(options)) {
|
|
@@ -768,8 +769,8 @@
|
|
|
768
769
|
}
|
|
769
770
|
options = options || {};
|
|
770
771
|
var settings = extend({}, options.settings);
|
|
771
|
-
var viewPath = typeProp(isString, settings['views']
|
|
772
|
-
var viewCache = typeProp(isBoolean, settings['view cache']
|
|
772
|
+
var viewPath = typeProp(isString, defaults.path, settings['views']);
|
|
773
|
+
var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
|
|
773
774
|
var viewOptions = extend({}, settings['view options']);
|
|
774
775
|
var filename = path.relative(viewPath, name);
|
|
775
776
|
viewOptions.path = viewPath;
|
package/dist/ejs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).ejs={})}(this,(function(t){"use strict";var n={},e={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:"ejs",withObject:!0,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),n=t.shift();return t.filter(n).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"},f={"&":"&","<":"<",">":">",'"':""","'":"'"},h=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},l=h(f),p=h(a),v=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(l,(function(t){return f[t]}))},d=function(t,n,e){return null==(e=t)?"":n?v(e):e},g=function(t,n){var e=t,r=n.split("."),i=r.pop();return r.forEach((function(t){e=e[t]=e[t]||{}})),[e,i]},m=function(t,n){var e=t.split(".").pop();return e!==n&&(t=[t,n].join(".")),t},y=function(){for(var t=arguments.length,n=new Array(t),e=0;e<t;e++)n[e]=arguments[e];var r=n.shift();return n.filter((function(t){return t})).reduce((function(t,n){return Object.assign(t,n)}),r)},b=function(){},w=function(t,n){var e;for(e in t)E(t,e)&&n(t[e],e,t)},j=function(t,n){return function(t,n,e){var r=t instanceof Array,i=r?[]:{};return w(t,(function(t,e,o){var c=n(t,e,o);void 0!==c&&(r?i.push(c):i[e]=c)})),i}(t,(function(t,e){if(-1===n.indexOf(e))return t}))},x=function(t,n,e){return Promise.resolve(t).then(n.bind(e))},E=function(t,n){return t&&t.hasOwnProperty(n)},k=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],O=" ",F='"',P="/",S="<",B=">",R=function(t,n,e){var r=[],i=-1===k.indexOf(t),o=function(t,n,e){var r=[];return w(t,(function(t,e,i){var o=n(t,e,i);void 0!==o&&r.push(o)})),r}(n,(function(t,n){if(null!=t)return[v(n),[F,v(t),F].join("")].join("=")})).join(O);return r.push([S,t,O,o,B].join("")),e&&r.push(e instanceof Array?e.join(""):e),i&&r.push([S,P,t,B].join("")),r.join("")};function $(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function T(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,A(r.key),r)}}function U(t,n,e){return n&&T(t.prototype,n),e&&T(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function A(t){var n=function(t,n){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==typeof n?n:String(n)}var M=[{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(n){$(this,t),this.configure(n)}return U(t,[{key:"configure",value:function(t){var n=this;this.withObject=t.withObject,this.token=t.token,this.vars=t.vars,this.matches=[],this.formats=[],this.slurp={match:"[ \\t]*",start:[this.token.start,"_"],end:["_",this.token.end]},M.forEach((function(t){n.matches.push(n.token.start.concat(t.symbol).concat(n.token.regex).concat(n.token.end)),n.formats.push(t.format.bind(n.vars))})),this.regex=new RegExp(this.matches.join("|").concat("|$"),"g"),this.slurpStart=new RegExp([this.slurp.match,this.slurp.start].join(""),"gm"),this.slurpEnd=new RegExp([this.slurp.end,this.slurp.match].join(""),"gm")}},{key:"compile",value:function(t,n){var e=this,r=this.vars,i=r.SCOPE,o=r.SAFE,c=r.BUFFER;t=(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(this.slurpStart,this.slurp.start).replace(this.slurpEnd,this.slurp.end);var u,s,f,h="".concat(c,"('");u=this.regex,s=function(n,r,i){h+=(""+t.slice(r,i)).replace(p,(function(t){return"\\"+a[t]})),n.forEach((function(t,n){t&&(h+=e.formats[n](t))}))},f=0,t.replace(u,(function(){var t=[].slice.call(arguments,0,-1),n=t.pop(),e=t.shift();return s(t,f,n),f=n+e.length,e})),h="try{".concat(h+="');","}catch(e){console.info(e)}"),this.withObject&&(h="with(".concat(i,"){").concat(h,"}")),h="".concat(c,".start();").concat(h,"return ").concat(c,".end();"),h+="\n//# sourceURL=".concat(n);var l=null;try{(l=new Function(i,c,o,h)).source="(function(".concat(i,",").concat(c,",").concat(o,"){\n").concat(h,"\n})")}catch(t){throw t.filename=n,t.source=h,t}return l}}]),t}(),L=function(){function t(n){$(this,t),this.configure(n)}return U(t,[{key:"configure",value:function(t){this.namespace=t.export,this.useStrict=!1===t.withObject}},{key:"wrapper",value:function(t){var n="";return n+="(function(global,factory){",n+='typeof exports === "object" && typeof module !== "undefined" ?',n+="module.exports = factory():",n+='typeof define === "function" && define.amd ? define(factory):',n+='(global = typeof globalThis !== "undefined" ? globalThis:',n+='global || self,global["'+this.namespace+'"] = factory())',n+="})(this,(function(){",this.useStrict&&(n+="'use strict';\n"),n+="var list = {};\n",t.forEach((function(t){n+="list["+JSON.stringify(t.name)+"]="+String(t.content)+";\n"})),n+="return list;}));\n"}}]),t}(),C=function(t){return fetch(t).then((function(t){return t.text()}))},N=function(t){return new Promise((function(e,r){n.readFile(t,(function(t,n){t?r(t):e(n.toString())}))}))},q=function(){function t(n,e,r){$(this,t),this.cache=e,this.compiler=r,this.configure(n)}return U(t,[{key:"configure",value:function(t){this.path=t.path,this.resolver=i(t.resolver)?t.resolver:s()?N:C}},{key:"resolve",value:function(t){return this.resolver(function(t,n){return(n=[t,n].join("/")).replace(/\/\//g,"/")}(this.path,t))}},{key:"result",value:function(t,n){return this.cache.set(n,t),t}},{key:"get",value:function(t){var n=this;if(this.cache.exist(t))return this.cache.resolve(t);var e=this.resolve(t).then((function(e){return n.result(n.compiler.compile(e,t),t)}));return this.result(e,t)}}]),t}(),D=function(t){return Promise.all(t).then((function(t){return t.join("")}))},K=function(){function t(n){$(this,t),this.configure(n)}return U(t,[{key:"configure",value:function(t){var n=t.vars,e=n.EXTEND,r=n.LAYOUT,c=n.BLOCKS,u=n.BUFFER,s=n.MACRO;function a(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),y(this,t)}this.create=function(t){return new a(t)},this.helpers=function(t){y(a.prototype,t)},a.helpers=function(t){y(a.prototype,t)},a.defineProp=a.method=function(t,n){var e=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(a.prototype,t,{value:n,writable:e,configurable:r,enumerable:i})},a.defineProp(u,function(){var t=[],n=[];function e(t){n.push(t)}return e.start=function(){n=[]},e.backup=function(){t.push(n.concat()),n=[]},e.restore=function(){var e=n.concat();return n=t.pop(),D(e)},e.error=function(t){throw t},e.end=function(){return D(n)},e}()),a.defineProp(c,{},!0),a.defineProp(s,{},!0),a.defineProp(r,!1,!0),a.defineProp(e,!1,!0),a.method("initBlocks",(function(){this[c]={}})),a.method("initMacro",(function(){this[s]={}})),a.method("getMacro",(function(){return this[s]})),a.method("getBuffer",(function(){return this[u]})),a.method("getBlocks",(function(){return this[c]})),a.method("setExtend",(function(t){this[e]=t})),a.method("getExtend",(function(){return this[e]})),a.method("setLayout",(function(t){this[r]=t})),a.method("getLayout",(function(){return this[r]})),a.method("clone",(function(t){var n=[r,e,u];return!0===t&&n.push(c),j(this,n)})),a.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),a.method("echo",(function(){var t=this.getBuffer(),n=[].slice.call(arguments);n.forEach(t)})),a.method("fn",(function(t){var n=this.getBuffer(),e=this;return function(){return n.backup(),i(t)&&t.apply(e,arguments),n.restore()}})),a.method("get",(function(t,n){var e=g(this,t),r=e.shift(),i=e.pop();return E(r,i)?r[i]:n})),a.method("set",(function(t,n){var e=g(this,t),r=e.shift(),i=e.pop();return this.getExtend()&&E(r,i)?r[i]:r[i]=n})),a.method("macro",(function(t,n){var e=this.getMacro(),r=this.fn(n),i=this;e[t]=function(){return i.echo(r.apply(void 0,arguments))}})),a.method("call",(function(t){var n=this.getMacro(),e=n[t],r=[].slice.call(arguments,1);if(i(e))return e.apply(e,r)})),a.method("block",(function(t,n){var e=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(n)),!this.getExtend()){var i=Object.assign([],r[t]),o=function(){return i.shift()};this.echo(o()(function t(){var n=o();return n?function(){e.echo(n(t()))}:b}()))}})),a.method("include",(function(t,n,e){var r=!1===e?{}:this.clone(!0),i=y(r,n||{}),o=this.render(t,i);this.echo(o)})),a.method("use",(function(t,n){var e=this.require(t);this.echo(x(e,(function(t){var e=this.getMacro();w(t,(function(t,r){e[[n,r].join(".")]=t}))}),this))})),a.method("async",(function(t,n){this.echo(x(t,(function(t){return this.fn(n)(t)}),this))})),a.method("el",(function(t,n,e){i(e)&&(e=this.fn(e)()),this.echo(x(e,(function(e){return R(t,n,e)}),this))})),a.method("each",(function(t,n){o(t)&&(t=this.get(t,[])),w(t,n)}))}}]),t}(),X="undefined"!=typeof globalThis?globalThis:window||self,Y=function(){function t(n){var e,r,i;$(this,t),e=this,i={},(r=A(r="list"))in e?Object.defineProperty(e,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[r]=i,this.configure(n),!1===s()&&this.load(X[this.namespace])}return U(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 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,n){return this.list[t]=n,this}}]),t}(),J=function(t,n){y(t,{export:r(o,e.export,n.export),path:r(o,e.path,n.path),resolver:r(i,e.resolver,n.resolver),extension:r(o,e.extension,n.extension),withObject:r(c,e.withObject,n.withObject),token:y({},e.token,n.token),vars:y({},e.vars,n.vars)})},V=function t(u){var s={},a={};J(s,u||{});var f=new K(s),h=new _(s),l=new L(s),p=new Y(s),v=new q(s,p,h),g=function(t){J(s,t),f.configure(s),h.configure(s),l.configure(s),p.configure(s),v.configure(s)},b=function(t,n){return v.get(t).then((function(t){return t.call(n,n,n.getBuffer(),d)}))},w=function(t,n){var e=m(t,s.extension),r=f.create(n);return b(e,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var n=r.getLayout(),e=r.clone();return w(n,e)}return t}))},j=function(t){f.helpers(y(a,t||{}))};return j({require:function(t){return function(t){var n=m(t,s.extension),e=f.create({});return b(n,e).then((function(){return e.getMacro()}))}(t)},render:function(t,n){return w(t,n)}}),{render:w,helpers:j,configure:g,wrapper:function(t){return l.wrapper(t)},compile:function(t,n){return h.compile(t,n)},create:function(n){return t(n)},preload:function(t){return p.load(t)},__express:function(t,u,s){i(u)&&(s=u,u={});var a=y({},(u=u||{}).settings),f=r(o,a.views,e.path),h=r(c,a["view cache"],e.cache),l=y({},a["view options"]),p=n.relative(f,t);return l.path=f,l.cache=h,g(l),w(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,Q=V.compile,W=V.create,Z=V.preload,tt=V.__express;t.__express=tt,t.compile=Q,t.configure=H,t.create=W,t.element=R,t.helpers=G,t.preload=Z,t.render=z,t.safeValue=d,t.wrapper=I,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).ejs={})}(this,(function(t){"use strict";var n={},e={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:"ejs",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),n=t.shift();return t.filter(n).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"},f={"&":"&","<":"<",">":">",'"':""","'":"'"},h=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},l=h(f),p=h(a),v=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(l,(function(t){return f[t]}))},d=function(t,n,e){return null==(e=t)?"":n?v(e):e},m=function(t,n){var e=t,r=n.split("."),i=r.pop();return r.forEach((function(t){e=e[t]=e[t]||{}})),[e,i]},g=function(t,n){var e=t.split(".").pop();return e!==n&&(t=[t,n].join(".")),t},y=function(){for(var t=arguments.length,n=new Array(t),e=0;e<t;e++)n[e]=arguments[e];var r=n.shift();return n.filter((function(t){return t})).reduce((function(t,n){return Object.assign(t,n)}),r)},b=function(){},w=function(t,n){var e;for(e in t)k(t,e)&&n(t[e],e,t)},j=function(t,n){return function(t,n,e){var r=t instanceof Array,i=r?[]:{};return w(t,(function(t,e,o){var c=n(t,e,o);void 0!==c&&(r?i.push(c):i[e]=c)})),i}(t,(function(t,e){if(-1===n.indexOf(e))return t}))},x=function(t,n,e){return Promise.resolve(t).then(n.bind(e))},k=function(t,n){return t&&t.hasOwnProperty(n)},E=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],O=" ",F='"',P="/",S="<",B=">",R=function(t,n,e){var r=[],i=-1===E.indexOf(t),o=function(t,n,e){var r=[];return w(t,(function(t,e,i){var o=n(t,e,i);void 0!==o&&r.push(o)})),r}(n,(function(t,n){if(null!=t)return[v(n),[F,v(t),F].join("")].join("=")})).join(O);return r.push([S,t,O,o,B].join("")),e&&r.push(e instanceof Array?e.join(""):e),i&&r.push([S,P,t,B].join("")),r.join("")};function $(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function T(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,A(r.key),r)}}function U(t,n,e){return n&&T(t.prototype,n),e&&T(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function A(t){var n=function(t,n){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==typeof n?n:String(n)}var M=[{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(n){$(this,t),this.configure(n)}return U(t,[{key:"configure",value:function(t){var n=this;this.withObject=t.withObject,this.token=t.token,this.vars=t.vars,this.matches=[],this.formats=[],this.slurp={match:"[ \\t]*",start:[this.token.start,"_"],end:["_",this.token.end]},M.forEach((function(t){n.matches.push(n.token.start.concat(t.symbol).concat(n.token.regex).concat(n.token.end)),n.formats.push(t.format.bind(n.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:"compile",value:function(t,n){var e=this,r=this.vars,i=r.SCOPE,o=r.SAFE,c=r.BUFFER;t=(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(this.slurpStart,this.token.start).replace(this.slurpEnd,this.token.end);var u,s,f,h="".concat(c,"('");u=this.regex,s=function(n,r,i){h+=(""+t.slice(r,i)).replace(p,(function(t){return"\\"+a[t]})),n.forEach((function(t,n){t&&(h+=e.formats[n](t))}))},f=0,t.replace(u,(function(){var t=[].slice.call(arguments,0,-1),n=t.pop(),e=t.shift();return s(t,f,n),f=n+e.length,e})),h="try{".concat(h+="');","}catch(e){console.info(e)}"),this.withObject&&(h="with(".concat(i,"){").concat(h,"}")),h="".concat(c,".start();").concat(h,"return ").concat(c,".end();"),h+="\n//# sourceURL=".concat(n);var l=null;try{(l=new Function(i,c,o,h)).source="(function(".concat(i,",").concat(c,",").concat(o,"){\n").concat(h,"\n})")}catch(t){throw t.filename=n,t.source=h,t}return l}}]),t}(),L=function(){function t(n){$(this,t),this.configure(n)}return U(t,[{key:"configure",value:function(t){this.namespace=t.export,this.useStrict=!1===t.withObject}},{key:"wrapper",value:function(t){var n="";return n+="(function(global,factory){",n+='typeof exports === "object" && typeof module !== "undefined" ?',n+="module.exports = factory():",n+='typeof define === "function" && define.amd ? define(factory):',n+='(global = typeof globalThis !== "undefined" ? globalThis:',n+='global || self,global["'+this.namespace+'"] = factory())',n+="})(this,(function(){",this.useStrict&&(n+="'use strict';\n"),n+="var list = {};\n",t.forEach((function(t){n+="list["+JSON.stringify(t.name)+"]="+String(t.content)+";\n"})),n+="return list;}));\n"}}]),t}(),C=function(t){return fetch(t).then((function(t){return t.text()}))},N=function(t){return new Promise((function(e,r){n.readFile(t,(function(t,n){t?r(t):e(n.toString())}))}))},q=function(){function t(n,e,r){$(this,t),this.cache=e,this.compiler=r,this.configure(n)}return U(t,[{key:"configure",value:function(t){this.path=t.path,this.resolver=i(t.resolver)?t.resolver:s()?N:C}},{key:"resolve",value:function(t){return this.resolver(function(t,n){return(n=[t,n].join("/")).replace(/\/\//g,"/")}(this.path,t))}},{key:"result",value:function(t,n){return this.cache.set(n,t),t}},{key:"get",value:function(t){var n=this;if(this.cache.exist(t))return this.cache.resolve(t);var e=this.resolve(t).then((function(e){return n.result(n.compiler.compile(e,t),t)}));return this.result(e,t)}}]),t}(),D=function(t){return Promise.all(t).then((function(t){return t.join("")}))},K=function(){function t(n){$(this,t),this.configure(n)}return U(t,[{key:"configure",value:function(t,n){var e=t.vars,r=e.EXTEND,c=e.LAYOUT,u=e.BLOCKS,s=e.BUFFER,a=e.MACRO;function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),y(this,t)}this.create=function(t){return new f(t)},this.helpers=function(t){y(f.prototype,t)},f.prototype=y({},n||{}),f.defineProp=f.method=function(t,n){var e=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];Object.defineProperty(f.prototype,t,{value:n,writable:e,configurable:r,enumerable:i})},f.defineProp(s,function(){var t=[],n=[];function e(t){n.push(t)}return e.start=function(){n=[]},e.backup=function(){t.push(n.concat()),n=[]},e.restore=function(){var e=n.concat();return n=t.pop(),D(e)},e.error=function(t){throw t},e.end=function(){return D(n)},e}()),f.defineProp(u,{},!0),f.defineProp(a,{},!0),f.defineProp(c,!1,!0),f.defineProp(r,!1,!0),f.method("initBlocks",(function(){this[u]={}})),f.method("initMacro",(function(){this[a]={}})),f.method("getMacro",(function(){return this[a]})),f.method("getBuffer",(function(){return this[s]})),f.method("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 n=[c,r,s];return!0===t&&n.push(u),j(this,n)})),f.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),f.method("echo",(function(){var t=this.getBuffer(),n=[].slice.call(arguments);n.forEach(t)})),f.method("fn",(function(t){var n=this.getBuffer(),e=this;return function(){return n.backup(),i(t)&&t.apply(e,arguments),n.restore()}})),f.method("get",(function(t,n){var e=m(this,t),r=e.shift(),i=e.pop();return k(r,i)?r[i]:n})),f.method("set",(function(t,n){var e=m(this,t),r=e.shift(),i=e.pop();return this.getExtend()&&k(r,i)?r[i]:r[i]=n})),f.method("macro",(function(t,n){var e=this.getMacro(),r=this.fn(n),i=this;e[t]=function(){return i.echo(r.apply(void 0,arguments))}})),f.method("call",(function(t){var n=this.getMacro(),e=n[t],r=[].slice.call(arguments,1);if(i(e))return e.apply(e,r)})),f.method("block",(function(t,n){var e=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(n)),!this.getExtend()){var i=Object.assign([],r[t]),o=function(){return i.shift()};this.echo(o()(function t(){var n=o();return n?function(){e.echo(n(t()))}:b}()))}})),f.method("include",(function(t,n,e){var r=!1===e?{}:this.clone(!0),i=y(r,n||{}),o=this.render(t,i);this.echo(o)})),f.method("use",(function(t,n){var e=this.require(t);this.echo(x(e,(function(t){var e=this.getMacro();w(t,(function(t,r){e[[n,r].join(".")]=t}))}),this))})),f.method("async",(function(t,n){this.echo(x(t,(function(t){return this.fn(n)(t)}),this))})),f.method("node",(function(t,n,e){return R(t,n,e)})),f.method("el",(function(t,n,e){i(e)&&(e=this.fn(e)()),this.echo(x(e,(function(e){return R(t,n,e)}),this))})),f.method("each",(function(t,n){o(t)&&(t=this.get(t,[])),w(t,n)}))}}]),t}(),X="undefined"!=typeof globalThis?globalThis:window||self,Y=function(){function t(n){var e,r,i;$(this,t),e=this,i={},(r=A(r="list"))in e?Object.defineProperty(e,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[r]=i,this.configure(n),!1===s()&&this.load(X[this.namespace])}return U(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 k(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,n){return this.list[t]=n,this}}]),t}(),J=function(t,n){y(t,{export:r(o,e.export,t.export,n.export),path:r(o,e.path,t.path,n.path),resolver:r(i,e.resolver,t.resolver,n.resolver),extension:r(o,e.extension,t.extension,n.extension),withObject:r(c,e.withObject,t.withObject,n.withObject),token:y({},e.token,t.token,n.token),vars:y({},e.vars,t.vars,n.vars)})},V=function t(u){var s={},a={};J(s,u||{});var f=new K(s),h=new _(s),l=new L(s),p=new Y(s),v=new q(s,p,h),m=function(t){J(s,t),f.configure(s,a),h.configure(s),l.configure(s),p.configure(s),v.configure(s)},b=function(t,n){return v.get(t).then((function(t){return t.call(n,n,n.getBuffer(),d)}))},w=function(t,n){var e=g(t,s.extension),r=f.create(n);return b(e,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var n=r.getLayout(),e=r.clone();return w(n,e)}return t}))},j=function(t){f.helpers(y(a,t||{}))};return j({require:function(t){return function(t){var n=g(t,s.extension),e=f.create({});return b(n,e).then((function(){return e.getMacro()}))}(t)},render:function(t,n){return w(t,n)}}),{render:w,helpers:j,configure:m,wrapper:function(t){return l.wrapper(t)},compile:function(t,n){return h.compile(t,n)},create:function(n){return t(n)},preload:function(t){return p.load(t)},__express:function(t,u,s){i(u)&&(s=u,u={});var a=y({},(u=u||{}).settings),f=r(o,e.path,a.views),h=r(c,e.cache,a["view cache"]),l=y({},a["view options"]),p=n.relative(f,t);return l.path=f,l.cache=h,m(l),w(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,Q=V.compile,W=V.create,Z=V.preload,tt=V.__express;t.__express=tt,t.compile=Q,t.configure=H,t.create=W,t.element=R,t.helpers=G,t.preload=Z,t.render=z,t.safeValue=d,t.wrapper=I,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/ejs.mjs
CHANGED
|
@@ -14,7 +14,7 @@ defaults.resolver = null;
|
|
|
14
14
|
|
|
15
15
|
defaults.extension = 'ejs';
|
|
16
16
|
|
|
17
|
-
defaults.withObject =
|
|
17
|
+
defaults.withObject = false;
|
|
18
18
|
|
|
19
19
|
defaults.vars = {
|
|
20
20
|
SCOPE: 'ejs',
|
|
@@ -282,11 +282,11 @@ class Compiler {
|
|
|
282
282
|
});
|
|
283
283
|
this.regex = new RegExp(this.matches.join('|').concat('|$'), 'g');
|
|
284
284
|
this.slurpStart = new RegExp(
|
|
285
|
-
[this.slurp.match, this.slurp.start].join(''),
|
|
285
|
+
[this.slurp.match, this.slurp.start.join('')].join(''),
|
|
286
286
|
'gm'
|
|
287
287
|
);
|
|
288
288
|
this.slurpEnd = new RegExp(
|
|
289
|
-
[this.slurp.end, this.slurp.match].join(''),
|
|
289
|
+
[this.slurp.end.join(''), this.slurp.match].join(''),
|
|
290
290
|
'gm'
|
|
291
291
|
);
|
|
292
292
|
}
|
|
@@ -294,8 +294,8 @@ class Compiler {
|
|
|
294
294
|
const { SCOPE, SAFE, BUFFER } = this.vars;
|
|
295
295
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
296
296
|
content = content
|
|
297
|
-
.replace(this.slurpStart, this.
|
|
298
|
-
.replace(this.slurpEnd, this.
|
|
297
|
+
.replace(this.slurpStart, this.token.start)
|
|
298
|
+
.replace(this.slurpEnd, this.token.end);
|
|
299
299
|
let source = `${BUFFER}('`;
|
|
300
300
|
matchTokens(this.regex, content, (params, index, offset) => {
|
|
301
301
|
source += symbols(content.slice(index, offset));
|
|
@@ -441,26 +441,20 @@ class Context {
|
|
|
441
441
|
constructor(config) {
|
|
442
442
|
this.configure(config);
|
|
443
443
|
}
|
|
444
|
-
configure(config) {
|
|
444
|
+
configure(config, methods) {
|
|
445
445
|
const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO } = config.vars;
|
|
446
|
-
|
|
447
446
|
this.create = (data) => {
|
|
448
447
|
return new Scope(data)
|
|
449
448
|
};
|
|
450
|
-
|
|
451
449
|
this.helpers = (methods) => {
|
|
452
450
|
extend(Scope.prototype, methods);
|
|
453
451
|
};
|
|
454
|
-
|
|
455
452
|
function Scope(data = {}) {
|
|
456
453
|
this.initBlocks();
|
|
457
454
|
this.initMacro();
|
|
458
455
|
extend(this, data);
|
|
459
456
|
}
|
|
460
|
-
|
|
461
|
-
Scope.helpers = (methods) => {
|
|
462
|
-
extend(Scope.prototype, methods);
|
|
463
|
-
};
|
|
457
|
+
Scope.prototype = extend({}, methods || {});
|
|
464
458
|
Scope.defineProp = Scope.method = (
|
|
465
459
|
name,
|
|
466
460
|
value,
|
|
@@ -475,53 +469,38 @@ class Context {
|
|
|
475
469
|
enumerable,
|
|
476
470
|
});
|
|
477
471
|
};
|
|
478
|
-
|
|
479
472
|
Scope.defineProp(BUFFER, createBuffer());
|
|
480
|
-
|
|
481
473
|
Scope.defineProp(BLOCKS, {}, true);
|
|
482
|
-
|
|
483
474
|
Scope.defineProp(MACRO, {}, true);
|
|
484
|
-
|
|
485
475
|
Scope.defineProp(LAYOUT, false, true);
|
|
486
|
-
|
|
487
476
|
Scope.defineProp(EXTEND, false, true);
|
|
488
|
-
|
|
489
477
|
Scope.method('initBlocks', function () {
|
|
490
478
|
this[BLOCKS] = {};
|
|
491
479
|
});
|
|
492
|
-
|
|
493
480
|
Scope.method('initMacro', function () {
|
|
494
481
|
this[MACRO] = {};
|
|
495
482
|
});
|
|
496
|
-
|
|
497
483
|
Scope.method('getMacro', function () {
|
|
498
484
|
return this[MACRO]
|
|
499
485
|
});
|
|
500
|
-
|
|
501
486
|
Scope.method('getBuffer', function () {
|
|
502
487
|
return this[BUFFER]
|
|
503
488
|
});
|
|
504
|
-
|
|
505
489
|
Scope.method('getBlocks', function () {
|
|
506
490
|
return this[BLOCKS]
|
|
507
491
|
});
|
|
508
|
-
|
|
509
492
|
Scope.method('setExtend', function (value) {
|
|
510
493
|
this[EXTEND] = value;
|
|
511
494
|
});
|
|
512
|
-
|
|
513
495
|
Scope.method('getExtend', function () {
|
|
514
496
|
return this[EXTEND]
|
|
515
497
|
});
|
|
516
|
-
|
|
517
498
|
Scope.method('setLayout', function (layout) {
|
|
518
499
|
this[LAYOUT] = layout;
|
|
519
500
|
});
|
|
520
|
-
|
|
521
501
|
Scope.method('getLayout', function () {
|
|
522
502
|
return this[LAYOUT]
|
|
523
503
|
});
|
|
524
|
-
|
|
525
504
|
Scope.method('clone', function (exclude_blocks) {
|
|
526
505
|
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
527
506
|
if (exclude_blocks === true) {
|
|
@@ -529,18 +508,15 @@ class Context {
|
|
|
529
508
|
}
|
|
530
509
|
return omit(this, filter)
|
|
531
510
|
});
|
|
532
|
-
|
|
533
511
|
Scope.method('extend', function (layout) {
|
|
534
512
|
this.setExtend(true);
|
|
535
513
|
this.setLayout(layout);
|
|
536
514
|
});
|
|
537
|
-
|
|
538
515
|
Scope.method('echo', function () {
|
|
539
516
|
const buffer = this.getBuffer();
|
|
540
517
|
const params = [].slice.call(arguments);
|
|
541
518
|
params.forEach(buffer);
|
|
542
519
|
});
|
|
543
|
-
|
|
544
520
|
Scope.method('fn', function (callback) {
|
|
545
521
|
const buffer = this.getBuffer();
|
|
546
522
|
const context = this;
|
|
@@ -558,7 +534,6 @@ class Context {
|
|
|
558
534
|
const prop = path.pop();
|
|
559
535
|
return hasProp(result, prop) ? result[prop] : defaults
|
|
560
536
|
});
|
|
561
|
-
|
|
562
537
|
Scope.method('set', function (name, value) {
|
|
563
538
|
const path = getPath(this, name);
|
|
564
539
|
const result = path.shift();
|
|
@@ -568,7 +543,6 @@ class Context {
|
|
|
568
543
|
}
|
|
569
544
|
return (result[prop] = value)
|
|
570
545
|
});
|
|
571
|
-
|
|
572
546
|
Scope.method('macro', function (name, callback) {
|
|
573
547
|
const list = this.getMacro();
|
|
574
548
|
const macro = this.fn(callback);
|
|
@@ -577,7 +551,6 @@ class Context {
|
|
|
577
551
|
return context.echo(macro.apply(undefined, arguments))
|
|
578
552
|
};
|
|
579
553
|
});
|
|
580
|
-
|
|
581
554
|
Scope.method('call', function (name) {
|
|
582
555
|
const list = this.getMacro();
|
|
583
556
|
const macro = list[name];
|
|
@@ -586,7 +559,6 @@ class Context {
|
|
|
586
559
|
return macro.apply(macro, params)
|
|
587
560
|
}
|
|
588
561
|
});
|
|
589
|
-
|
|
590
562
|
Scope.method('block', function (name, callback) {
|
|
591
563
|
const blocks = this.getBlocks();
|
|
592
564
|
blocks[name] = blocks[name] || [];
|
|
@@ -608,14 +580,12 @@ class Context {
|
|
|
608
580
|
};
|
|
609
581
|
this.echo(current()(next()));
|
|
610
582
|
});
|
|
611
|
-
|
|
612
583
|
Scope.method('include', function (path, data, cx) {
|
|
613
584
|
const context = cx === false ? {} : this.clone(true);
|
|
614
585
|
const params = extend(context, data || {});
|
|
615
586
|
const promise = this.render(path, params);
|
|
616
587
|
this.echo(promise);
|
|
617
588
|
});
|
|
618
|
-
|
|
619
589
|
Scope.method('use', function (path, namespace) {
|
|
620
590
|
const promise = this.require(path);
|
|
621
591
|
this.echo(
|
|
@@ -631,7 +601,6 @@ class Context {
|
|
|
631
601
|
)
|
|
632
602
|
);
|
|
633
603
|
});
|
|
634
|
-
|
|
635
604
|
Scope.method('async', function (promise, callback) {
|
|
636
605
|
this.echo(
|
|
637
606
|
resolve$1(
|
|
@@ -643,7 +612,9 @@ class Context {
|
|
|
643
612
|
)
|
|
644
613
|
);
|
|
645
614
|
});
|
|
646
|
-
|
|
615
|
+
Scope.method('node', function (tag, attr, content) {
|
|
616
|
+
return element(tag, attr, content)
|
|
617
|
+
});
|
|
647
618
|
Scope.method('el', function (tag, attr, content) {
|
|
648
619
|
if (isFunction(content)) {
|
|
649
620
|
content = this.fn(content)();
|
|
@@ -658,7 +629,6 @@ class Context {
|
|
|
658
629
|
)
|
|
659
630
|
);
|
|
660
631
|
});
|
|
661
|
-
|
|
662
632
|
Scope.method('each', function (object, callback) {
|
|
663
633
|
if (isString(object)) {
|
|
664
634
|
object = this.get(object, []);
|
|
@@ -706,17 +676,33 @@ class Cache {
|
|
|
706
676
|
|
|
707
677
|
const configSchema = (config, options) => {
|
|
708
678
|
extend(config, {
|
|
709
|
-
export: typeProp(
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
679
|
+
export: typeProp(
|
|
680
|
+
isString,
|
|
681
|
+
defaults.export,
|
|
682
|
+
config.export,
|
|
683
|
+
options.export
|
|
684
|
+
),
|
|
685
|
+
path: typeProp(isString, defaults.path, config.path, options.path),
|
|
686
|
+
resolver: typeProp(
|
|
687
|
+
isFunction,
|
|
688
|
+
defaults.resolver,
|
|
689
|
+
config.resolver,
|
|
690
|
+
options.resolver
|
|
691
|
+
),
|
|
692
|
+
extension: typeProp(
|
|
693
|
+
isString,
|
|
694
|
+
defaults.extension,
|
|
695
|
+
config.extension,
|
|
696
|
+
options.extension
|
|
697
|
+
),
|
|
713
698
|
withObject: typeProp(
|
|
714
699
|
isBoolean,
|
|
715
700
|
defaults.withObject,
|
|
701
|
+
config.withObject,
|
|
716
702
|
options.withObject
|
|
717
703
|
),
|
|
718
|
-
token: extend({}, defaults.token, options.token),
|
|
719
|
-
vars: extend({}, defaults.vars, options.vars),
|
|
704
|
+
token: extend({}, defaults.token, config.token, options.token),
|
|
705
|
+
vars: extend({}, defaults.vars, config.vars, options.vars),
|
|
720
706
|
});
|
|
721
707
|
};
|
|
722
708
|
|
|
@@ -726,7 +712,7 @@ const init = (options) => {
|
|
|
726
712
|
* @module ejs
|
|
727
713
|
*/
|
|
728
714
|
const config = {};
|
|
729
|
-
const
|
|
715
|
+
const scope = {};
|
|
730
716
|
|
|
731
717
|
configSchema(config, options || {});
|
|
732
718
|
|
|
@@ -738,7 +724,7 @@ const init = (options) => {
|
|
|
738
724
|
|
|
739
725
|
const configure = (options) => {
|
|
740
726
|
configSchema(config, options);
|
|
741
|
-
context.configure(config);
|
|
727
|
+
context.configure(config, scope);
|
|
742
728
|
compiler.configure(config);
|
|
743
729
|
bundler.configure(config);
|
|
744
730
|
cache.configure(config);
|
|
@@ -774,7 +760,7 @@ const init = (options) => {
|
|
|
774
760
|
};
|
|
775
761
|
|
|
776
762
|
const helpers = (methods) => {
|
|
777
|
-
context.helpers(extend(
|
|
763
|
+
context.helpers(extend(scope, methods || {}));
|
|
778
764
|
};
|
|
779
765
|
|
|
780
766
|
const __express = (name, options, callback) => {
|
|
@@ -784,11 +770,11 @@ const init = (options) => {
|
|
|
784
770
|
}
|
|
785
771
|
options = options || {};
|
|
786
772
|
const settings = extend({}, options.settings);
|
|
787
|
-
const viewPath = typeProp(isString, settings['views']
|
|
773
|
+
const viewPath = typeProp(isString, defaults.path, settings['views']);
|
|
788
774
|
const viewCache = typeProp(
|
|
789
775
|
isBoolean,
|
|
790
|
-
|
|
791
|
-
|
|
776
|
+
defaults.cache,
|
|
777
|
+
settings['view cache']
|
|
792
778
|
);
|
|
793
779
|
const viewOptions = extend({}, settings['view options']);
|
|
794
780
|
const filename = path.relative(viewPath, name);
|
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.30",
|
|
6
6
|
"main": "dist/ejs.cjs",
|
|
7
7
|
"module": "dist/ejs.mjs",
|
|
8
8
|
"browser": "dist/ejs.js",
|
|
@@ -26,9 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@kosatyi/rollup": "^0.0.1",
|
|
28
28
|
"@babel/core": "^7.20.12",
|
|
29
|
-
"@babel/preset-env": "^7.20.2"
|
|
30
|
-
"glob": "^8.1.0",
|
|
31
|
-
"terser": "^5.16.1"
|
|
29
|
+
"@babel/preset-env": "^7.20.2"
|
|
32
30
|
},
|
|
33
31
|
"directories": {
|
|
34
32
|
"test": "test"
|