@kosatyi/ejs 0.0.67 → 0.0.69
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/cjs/browser.js +845 -0
- package/dist/cjs/index.js +82 -78
- package/dist/esm/browser.js +946 -0
- package/dist/esm/index.js +130 -114
- package/dist/umd/browser.js +851 -0
- package/dist/umd/browser.min.js +1 -0
- package/dist/umd/index.js +84 -80
- package/dist/umd/index.min.js +1 -1
- package/package.json +8 -4
- package/types/global.d.ts +103 -0
- package/dist/templates.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).browser={})}(this,(function(e){"use strict";var n=function(){var e=[].slice.call(arguments),n=e.shift();return e.filter(n).pop()},t=function(e){return"function"==typeof e},r=function(e){return"string"==typeof e},i=function(e){return"boolean"==typeof e},o=function(e){return void 0===e},u="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),c=function(){return u},a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},s={"&":"&","<":"<",">":">",'"':""","'":"'"},l=function(e){return new RegExp(["[",Object.keys(e).join(""),"]"].join(""),"g")},f=l(s),h=l(a),p=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(f,(function(e){return s[e]}))},b=function(e){return(""+e).replace(h,(function(e){return"\\"+a[e]}))},v=function(e,n){var t=e;return null==t?"":!0===n?p(t):t},g=function(e,n){return Boolean(e instanceof n)},m=function(e,n,r){for(var i=e,o=String(n).split("."),u=o.pop(),c=0;c<o.length;c++){var a=o[c];if(t(i.toJSON)&&(i=i.toJSON()),r&&!1===i.hasOwnProperty(a)){i={};break}i=i[a]=i[a]||{}}return t(i.toJSON)&&(i=i.toJSON()),[i,u]},w=function(e,n){var t=e.split(".").pop();return t!==n&&(e=[e,n].join(".")),e},d=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];return t.filter((function(e){return e})).reduce((function(e,n){return Object.assign(e,n)}),e)},y=function(){},x=function(e,n){var t;for(t in e)O(e,t)&&n(e[t],t,e)},E=function(e,n){return function(e,n,t){var r=e instanceof Array,i=r?[]:{};return x(e,(function(e,t,u){var c=n(e,t,u);!1===o(c)&&(r?i.push(c):i[t]=c)})),i}(e,(function(e,t){if(-1===n.indexOf(t))return e}))},j=function(e,n,t){return Promise.resolve(e).then(n.bind(t))},O=function(e,n){return e&&e.hasOwnProperty(n)},k={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:function(e,n){return Promise.resolve(["resolver is not defined",e,n].join(" "))},extension:"ejs",rmWhitespace:!0,withObject:!0,vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},F=function(e,o){d(e,{path:n(r,k.path,e.path,o.path),export:n(r,k.export,e.export,o.export),resolver:n(t,k.resolver,e.resolver,o.resolver),extension:n(r,k.extension,e.extension,o.extension),withObject:n(i,k.withObject,e.withObject,o.withObject),rmWhitespace:n(i,k.rmWhitespace,e.rmWhitespace,o.rmWhitespace),cache:n(i,k.cache,e.cache,o.cache),token:d({},k.token,e.token,o.token),vars:d({},k.vars,e.vars,o.vars)})},S="undefined"!=typeof globalThis?globalThis:window||self;function B(e){if(!1===g(this,B))return new B;var n={enabled:!0,list:{}};this.configure=function(e){n.enabled=e.cache,!1===c()&&this.load(S[e.export])},this.clear=function(){n.list={}},this.load=function(e){return n.enabled&&d(n.list,e||{}),this},this.get=function(e){if(n.enabled)return n.list[e]},this.set=function(e,t){return n.enabled&&(n.list[e]=t),this},this.resolve=function(e){return Promise.resolve(this.get(e))},this.remove=function(e){delete n.list[e]},this.exist=function(e){return O(n.list,e)}}var P=[{symbol:"-",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(e){return"')\n/**".concat(e,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(e){return"')\n".concat(e.trim(),"\n").concat(this.BUFFER,"('")}}];function R(e){if(!1===g(this,R))return new R(e);var n={};this.configure=function(e){n.withObject=e.withObject,n.rmWhitespace=e.rmWhitespace,n.token=e.token,n.vars=e.vars,n.matches=[],n.formats=[],n.slurp={match:"[ \\t]*",start:[n.token.start,"_"],end:["_",n.token.end]},P.forEach((function(e){n.matches.push(n.token.start.concat(e.symbol).concat(n.token.regex).concat(n.token.end)),n.formats.push(e.format.bind(n.vars))})),n.regex=new RegExp(n.matches.join("|").concat("|$"),"g"),n.slurpStart=new RegExp([n.slurp.match,n.slurp.start.join("")].join(""),"gm"),n.slurpEnd=new RegExp([n.slurp.end.join(""),n.slurp.match].join(""),"gm")},this.compile=function(e,t){var r=n.vars,i=r.SCOPE,o=r.SAFE,u=r.BUFFER,c=r.COMPONENT;n.rmWhitespace&&(e=e.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),e=e.replace(n.slurpStart,n.token.start).replace(n.slurpEnd,n.token.end);var a,s,l,f="".concat(u,"('");a=n.regex,s=function(t,r,i){f+=b(e.slice(r,i)),t.forEach((function(e,t){e&&(f+=n.formats[t](e))}))},l=0,e.replace(a,(function(){var e=[].slice.call(arguments,0,-1),n=e.pop(),t=e.shift();return s(e,l,n),l=n+t.length,t})),f="try{".concat(f+="');","}catch(e){console.info(e)}"),n.withObject&&(f="with(".concat(i,"){").concat(f,"}")),f="".concat(u,".start();").concat(f,"return ").concat(u,".end();"),f+="\n//# sourceURL=".concat(t);var h=null;try{(h=new Function(i,c,u,o,f)).source="(function(".concat(i,",").concat(c,",").concat(u,",").concat(o,"){\n").concat(f,"\n})")}catch(e){throw e.filename=t,e.source=f,e}return h},this.configure(e)}function T(e,n,r){if(!1===g(this,T))return new T(e,n,r);if(!1===g(n,B))throw new TypeError("cache is not instance of Cache");if(!1===g(r,R))throw new TypeError("compiler is not instance of Compiler");var i={},o=function(e){return i.resolver(i.path,e)};this.configure=function(e){i.path=e.path,i.cache=e.cache,t(e.resolver)&&(i.resolver=e.resolver)},this.get=function(e){return n.exist(e)?n.resolve(e):o(e).then((function(i){return function(e,t){return n.set(e,t),t}(e,function(e,n){return t(e)?e:r.compile(e,n)}(i,e))}))},this.configure(e)}function $(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var C=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],N=" ",U='"',A="/",M="<",L=">",W=function(e,n,t){var r=[],i=-1===C.indexOf(e),u=function(e,n,t){var r=[];return x(e,(function(e,t,i){var u=n(e,t,i);!1===o(u)&&r.push(u)})),r}(n,(function(e,n){if(null!=e)return[p(n),[U,p(e),U].join("")].join("=")})).join(N);return r.push([M,e,N,u,L].join("")),t&&r.push(t instanceof Array?t.join(""):t),i&&r.push([M,A,e,L].join("")),r.join("")};function J(e){return Promise.all(e||[]).then((function(e){return e.join("")}))}function q(){var e=[],n=[];function t(e){n.push(e)}return t.start=function(){n=[]},t.backup=function(){e.push(n.concat()),n=[]},t.restore=function(){var t=n.concat();return n=e.pop(),J(t)},t.error=function(e){throw e},t.end=function(){return J(n)},t}function D(e){if(!1===g(this,D))return new D(e);this.configure=function(e,n){var i,o=e.vars,u=o.BLOCKS,c=o.MACRO,a=o.EXTEND,s=o.LAYOUT,l=o.BUFFER,f=o.COMPONENT;function h(e){this[u]={},this[c]={},d(this,e||{})}this.create=function(e){return new h(e)},this.helpers=function(e){d(h.prototype,e||{})},h.prototype=d({},n||{}),Object.defineProperties(h.prototype,($(i={},l,{value:q(),writable:!0,configurable:!1,enumerable:!1}),$(i,u,{value:{},writable:!0,configurable:!1,enumerable:!1}),$(i,c,{value:{},writable:!0,configurable:!1,enumerable:!1}),$(i,s,{value:!1,writable:!0,configurable:!1,enumerable:!1}),$(i,a,{value:!1,writable:!0,configurable:!1,enumerable:!1}),$(i,"getMacro",{value:function(){return this[c]},writable:!1,configurable:!1,enumerable:!1}),$(i,"getBuffer",{value:function(){return this[l]},writable:!1,configurable:!1,enumerable:!1}),$(i,"getComponent",{value:function(){var e=this;return f in e?function(){return e[f].apply(e,arguments)}:function(){console.log("%s function not defined",f)}},writable:!1,configurable:!1,enumerable:!1}),$(i,"getBlocks",{value:function(){return this[u]},writable:!1,configurable:!1,enumerable:!1}),$(i,"setExtend",{value:function(e){this[a]=e},writable:!1,configurable:!1,enumerable:!1}),$(i,"getExtend",{value:function(){return this[a]},writable:!1,configurable:!1,enumerable:!1}),$(i,"setLayout",{value:function(e){this[s]=e},writable:!1,configurable:!1,enumerable:!1}),$(i,"getLayout",{value:function(){return this[s]},writable:!1,configurable:!1,enumerable:!1}),$(i,"clone",{value:function(e){var n=[s,a,l];return!0===e&&n.push(u),E(this,n)},writable:!1,configurable:!1,enumerable:!1}),$(i,"extend",{value:function(e){this.setExtend(!0),this.setLayout(e)},writable:!1,configurable:!1,enumerable:!1}),$(i,"echo",{value:function(e){var n=this.getBuffer();[].slice.call(arguments).forEach(n)},writable:!1,configurable:!1,enumerable:!1}),$(i,"fn",{value:function(e){var n=this.getBuffer(),r=this;return function(){return n.backup(),t(e)&&e.apply(r,arguments),n.restore()}},writable:!1,configurable:!1,enumerable:!1}),$(i,"get",{value:function(e,n){var t=m(this,e,!0),r=t.shift(),i=t.pop();return O(r,i)?r[i]:n},writable:!1,configurable:!1,enumerable:!1}),$(i,"set",{value:function(e,n){var t=m(this,e,!1),r=t.shift(),i=t.pop();return this.getExtend()&&O(r,i)?r[i]:r[i]=n},writable:!1,configurable:!1,enumerable:!1}),$(i,"macro",{value:function(e,n){var t=this.getMacro(),r=this.fn(n),i=this;t[e]=function(){return i.echo(r.apply(void 0,arguments))}},writable:!1,configurable:!1,enumerable:!1}),$(i,"call",{value:function(e){var n=this.getMacro()[e],r=[].slice.call(arguments,1);if(t(n))return n.apply(n,r)},writable:!1,configurable:!1,enumerable:!1}),$(i,"block",{value:function(e,n){var t=this,r=this.getBlocks();if(r[e]=r[e]||[],r[e].push(this.fn(n)),!this.getExtend()){var i=Object.assign([],r[e]),o=function(){return i.shift()};this.echo(o()(function e(){var n=o();return n?function(){t.echo(n(e()))}:y}()))}},writable:!1,configurable:!1,enumerable:!1}),$(i,"include",{value:function(e,n,t){var r=!1===t?{}:this.clone(!0),i=d(r,n||{}),o=this.render(e,i);this.echo(o)},writable:!1,configurable:!1,enumerable:!1}),$(i,"use",{value:function(e,n){var t=this.require(e);this.echo(j(t,(function(e){var t=this.getMacro();x(e,(function(e,r){t[[n,r].join(".")]=e}))}),this))},writable:!1,configurable:!1,enumerable:!1}),$(i,"async",{value:function(e,n){this.echo(j(e,(function(e){return this.fn(n)(e)}),this))},writable:!1,configurable:!1,enumerable:!1}),$(i,"each",{value:function(e,n){r(e)&&(e=this.get(e,[])),x(e,n)},writable:!1,configurable:!1,enumerable:!1}),$(i,"element",{value:function(e,n,t){return W(e,n,t)}}),$(i,"el",{value:function(e,n,r){t(r)&&(r=this.fn(r)()),this.echo(j(r,(function(t){return this.element(e,n,t)}),this))},writable:!1,configurable:!1,enumerable:!1}),i))},this.configure(e)}var K=new function e(n){if(!1===g(this,e))return new e(n);var t={},r={};F(r,n||{});var i=new D(r),o=new R(r),u=new B,c=new T(r,u,o),a=function(e,n){return c.get(e).then((function(e){return e.call(n,n,n.getComponent(),n.getBuffer(),v)}))},s=function e(n,t){var o=w(n,r.extension),u=i.create(t);return a(o,u).then((function(n){if(u.getExtend()){u.setExtend(!1);var t=u.getLayout(),r=u.clone();return e(t,r)}return n}))};return this.configure=function(e){return F(r,e=e||{}),i.configure(r,t),o.configure(r),u.configure(r),c.configure(r),r},this.render=function(e,n){return s(e,n)},this.helpers=function(e){i.helpers(d(t,e))},this.preload=function(e){return u.load(e||{})},this.create=function(n){return new e(n)},this.compile=function(e,n){return o.compile(e,n)},this.context=function(e){return i.create(e)},this.helpers({require:function(e){var n=w(e,r.extension),t=i.create({});return a(n,t).then((function(){return t.getMacro()}))},render:s}),this}({resolver:function(e,n){return fetch(function(e,n){return(n=[e,n].join("/")).replace(/\/\//g,"/")}(e,n)).then((function(e){return e.text()}),(function(e){return String(e)}))}}),X=K.render,Y=K.context,_=K.compile,z=K.helpers,G=K.preload,H=K.configure,I=K.create;e.compile=_,e.configure=H,e.context=Y,e.create=I,e.helpers=z,e.preload=G,e.render=X}));
|
package/dist/umd/index.js
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ejs = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
var path = {};
|
|
8
|
-
|
|
9
7
|
var typeProp = function typeProp() {
|
|
10
8
|
var args = [].slice.call(arguments);
|
|
11
9
|
var callback = args.shift();
|
|
@@ -155,13 +153,20 @@
|
|
|
155
153
|
var hasProp = function hasProp(object, prop) {
|
|
156
154
|
return object && object.hasOwnProperty(prop);
|
|
157
155
|
};
|
|
156
|
+
var joinPath = function joinPath(path, template) {
|
|
157
|
+
template = [path, template].join('/');
|
|
158
|
+
template = template.replace(/\/\//g, '/');
|
|
159
|
+
return template;
|
|
160
|
+
};
|
|
158
161
|
|
|
159
162
|
var defaults = {};
|
|
160
163
|
defaults["export"] = 'ejsPrecompiled';
|
|
161
164
|
defaults.cache = true;
|
|
162
165
|
defaults.chokidar = null;
|
|
163
166
|
defaults.path = 'views';
|
|
164
|
-
defaults.resolver =
|
|
167
|
+
defaults.resolver = function (path, template) {
|
|
168
|
+
return Promise.resolve(['resolver is not defined', path, template].join(' '));
|
|
169
|
+
};
|
|
165
170
|
defaults.extension = 'ejs';
|
|
166
171
|
defaults.rmWhitespace = true;
|
|
167
172
|
defaults.withObject = true;
|
|
@@ -181,31 +186,6 @@
|
|
|
181
186
|
regex: '([\\s\\S]+?)'
|
|
182
187
|
};
|
|
183
188
|
|
|
184
|
-
var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
185
|
-
var space = ' ';
|
|
186
|
-
var quote = '"';
|
|
187
|
-
var equal = '=';
|
|
188
|
-
var slash = '/';
|
|
189
|
-
var lt = '<';
|
|
190
|
-
var gt = '>';
|
|
191
|
-
var element = function element(tag, attrs, content) {
|
|
192
|
-
var result = [];
|
|
193
|
-
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
194
|
-
var attributes = map(attrs, function (value, key) {
|
|
195
|
-
if (value !== null && value !== undefined) {
|
|
196
|
-
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
197
|
-
}
|
|
198
|
-
}).join(space);
|
|
199
|
-
result.push([lt, tag, space, attributes, gt].join(''));
|
|
200
|
-
if (content) {
|
|
201
|
-
result.push(content instanceof Array ? content.join('') : content);
|
|
202
|
-
}
|
|
203
|
-
if (hasClosedTag) {
|
|
204
|
-
result.push([lt, slash, tag, gt].join(''));
|
|
205
|
-
}
|
|
206
|
-
return result.join('');
|
|
207
|
-
};
|
|
208
|
-
|
|
209
189
|
var configSchema = function configSchema(config, options) {
|
|
210
190
|
extend(config, {
|
|
211
191
|
path: typeProp(isString, defaults.path, config.path, options.path),
|
|
@@ -359,30 +339,6 @@
|
|
|
359
339
|
this.configure(config);
|
|
360
340
|
}
|
|
361
341
|
|
|
362
|
-
var resolvePath = function resolvePath(path, template) {
|
|
363
|
-
template = [path, template].join('/');
|
|
364
|
-
template = template.replace(/\/\//g, '/');
|
|
365
|
-
return template;
|
|
366
|
-
};
|
|
367
|
-
var httpRequest = function httpRequest(path, template) {
|
|
368
|
-
return fetch(resolvePath(path, template)).then(function (response) {
|
|
369
|
-
return response.text();
|
|
370
|
-
});
|
|
371
|
-
};
|
|
372
|
-
var fileSystem = function fileSystem(path$1, template) {
|
|
373
|
-
return new Promise(function (resolve, reject) {
|
|
374
|
-
path.readFile(resolvePath(path$1, template), function (error, data) {
|
|
375
|
-
if (error) {
|
|
376
|
-
reject(error);
|
|
377
|
-
} else {
|
|
378
|
-
resolve(data.toString());
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
};
|
|
383
|
-
var fileResolver = function fileResolver(resolver) {
|
|
384
|
-
return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
|
|
385
|
-
};
|
|
386
342
|
function Template(config, cache, compiler) {
|
|
387
343
|
if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
|
|
388
344
|
if (instanceOf(cache, Cache) === false) throw new TypeError('cache is not instance of Cache');
|
|
@@ -405,15 +361,17 @@
|
|
|
405
361
|
this.configure = function (config) {
|
|
406
362
|
template.path = config.path;
|
|
407
363
|
template.cache = config.cache;
|
|
408
|
-
|
|
364
|
+
if (isFunction(config.resolver)) {
|
|
365
|
+
template.resolver = config.resolver;
|
|
366
|
+
}
|
|
409
367
|
};
|
|
410
368
|
this.get = function (template) {
|
|
411
369
|
if (cache.exist(template)) {
|
|
412
370
|
return cache.resolve(template);
|
|
413
371
|
}
|
|
414
|
-
return
|
|
372
|
+
return resolve(template).then(function (content) {
|
|
415
373
|
return result(template, compile(content, template));
|
|
416
|
-
})
|
|
374
|
+
});
|
|
417
375
|
};
|
|
418
376
|
this.configure(config);
|
|
419
377
|
}
|
|
@@ -447,6 +405,31 @@
|
|
|
447
405
|
return typeof key === "symbol" ? key : String(key);
|
|
448
406
|
}
|
|
449
407
|
|
|
408
|
+
var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
409
|
+
var space = ' ';
|
|
410
|
+
var quote = '"';
|
|
411
|
+
var equal = '=';
|
|
412
|
+
var slash = '/';
|
|
413
|
+
var lt = '<';
|
|
414
|
+
var gt = '>';
|
|
415
|
+
var element = function element(tag, attrs, content) {
|
|
416
|
+
var result = [];
|
|
417
|
+
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
418
|
+
var attributes = map(attrs, function (value, key) {
|
|
419
|
+
if (value !== null && value !== undefined) {
|
|
420
|
+
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
421
|
+
}
|
|
422
|
+
}).join(space);
|
|
423
|
+
result.push([lt, tag, space, attributes, gt].join(''));
|
|
424
|
+
if (content) {
|
|
425
|
+
result.push(content instanceof Array ? content.join('') : content);
|
|
426
|
+
}
|
|
427
|
+
if (hasClosedTag) {
|
|
428
|
+
result.push([lt, slash, tag, gt].join(''));
|
|
429
|
+
}
|
|
430
|
+
return result.join('');
|
|
431
|
+
};
|
|
432
|
+
|
|
450
433
|
function resolve(list) {
|
|
451
434
|
return Promise.all(list || []).then(function (list) {
|
|
452
435
|
return list.join('');
|
|
@@ -838,7 +821,51 @@
|
|
|
838
821
|
return this;
|
|
839
822
|
}
|
|
840
823
|
|
|
841
|
-
var
|
|
824
|
+
var fs = {};
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
*
|
|
828
|
+
* @param {EJS} ejs
|
|
829
|
+
* @return {function(*, *, *): Promise<String>}
|
|
830
|
+
*/
|
|
831
|
+
function expressRenderer(ejs) {
|
|
832
|
+
return function (name, options, callback) {
|
|
833
|
+
if (isFunction(options)) {
|
|
834
|
+
callback = options;
|
|
835
|
+
options = {};
|
|
836
|
+
}
|
|
837
|
+
options = options || {};
|
|
838
|
+
var settings = extend({}, options.settings);
|
|
839
|
+
var viewPath = typeProp(isString, defaults.path, settings['views']);
|
|
840
|
+
var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
|
|
841
|
+
var viewOptions = extend({}, settings['view options']);
|
|
842
|
+
var filename = fs.relative(viewPath, name);
|
|
843
|
+
viewOptions.path = viewPath;
|
|
844
|
+
viewOptions.cache = viewCache;
|
|
845
|
+
ejs.configure(viewOptions);
|
|
846
|
+
return ejs.render(filename, options).then(function (content) {
|
|
847
|
+
callback(null, content);
|
|
848
|
+
})["catch"](function (error) {
|
|
849
|
+
callback(error);
|
|
850
|
+
});
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
function readFile(path, template) {
|
|
855
|
+
return new Promise(function (resolve, reject) {
|
|
856
|
+
fs.readFile(joinPath(path, template), function (error, data) {
|
|
857
|
+
if (error) {
|
|
858
|
+
reject(error);
|
|
859
|
+
} else {
|
|
860
|
+
resolve(data.toString());
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
var ejs = new EJS({
|
|
867
|
+
resolver: readFile
|
|
868
|
+
});
|
|
842
869
|
var render = ejs.render,
|
|
843
870
|
context = ejs.context,
|
|
844
871
|
compile = ejs.compile,
|
|
@@ -846,38 +873,15 @@
|
|
|
846
873
|
preload = ejs.preload,
|
|
847
874
|
configure = ejs.configure,
|
|
848
875
|
create = ejs.create;
|
|
876
|
+
var __express = expressRenderer(ejs);
|
|
849
877
|
|
|
850
|
-
function __express(name, options, callback) {
|
|
851
|
-
if (isFunction(options)) {
|
|
852
|
-
callback = options;
|
|
853
|
-
options = {};
|
|
854
|
-
}
|
|
855
|
-
options = options || {};
|
|
856
|
-
var settings = extend({}, options.settings);
|
|
857
|
-
var viewPath = typeProp(isString, defaults.path, settings['views']);
|
|
858
|
-
var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
|
|
859
|
-
var viewOptions = extend({}, settings['view options']);
|
|
860
|
-
var filename = path.relative(viewPath, name);
|
|
861
|
-
viewOptions.path = viewPath;
|
|
862
|
-
viewOptions.cache = viewCache;
|
|
863
|
-
configure(viewOptions);
|
|
864
|
-
return render(filename, options).then(function (content) {
|
|
865
|
-
callback(null, content);
|
|
866
|
-
})["catch"](function (error) {
|
|
867
|
-
callback(error);
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
exports.EJS = EJS;
|
|
872
878
|
exports.__express = __express;
|
|
873
879
|
exports.compile = compile;
|
|
874
880
|
exports.configure = configure;
|
|
875
881
|
exports.context = context;
|
|
876
882
|
exports.create = create;
|
|
877
|
-
exports.element = element;
|
|
878
883
|
exports.helpers = helpers;
|
|
879
884
|
exports.preload = preload;
|
|
880
885
|
exports.render = render;
|
|
881
|
-
exports.safeValue = safeValue;
|
|
882
886
|
|
|
883
887
|
}));
|
package/dist/umd/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ejs={})}(this,(function(e){"use strict";var n={},t=function(){var e=[].slice.call(arguments),n=e.shift();return e.filter(n).pop()},r=function(e){return"function"==typeof e},i=function(e){return"string"==typeof e},o=function(e){return"boolean"==typeof e},u=function(e){return void 0===e},c="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a=function(){return c},l={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},s={"&":"&","<":"<",">":">",'"':""","'":"'"},f=function(e){return new RegExp(["[",Object.keys(e).join(""),"]"].join(""),"g")},h=f(s),p=f(l),b=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(h,(function(e){return s[e]}))},v=function(e){return(""+e).replace(p,(function(e){return"\\"+l[e]}))},g=function(e,n){var t=e;return null==t?"":!0===n?b(t):t},m=function(e,n){return Boolean(e instanceof n)},w=function(e,n,t){for(var i=e,o=String(n).split("."),u=o.pop(),c=0;c<o.length;c++){var a=o[c];if(r(i.toJSON)&&(i=i.toJSON()),t&&!1===i.hasOwnProperty(a)){i={};break}i=i[a]=i[a]||{}}return r(i.toJSON)&&(i=i.toJSON()),[i,u]},d=function(e,n){var t=e.split(".").pop();return t!==n&&(e=[e,n].join(".")),e},y=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];return t.filter((function(e){return e})).reduce((function(e,n){return Object.assign(e,n)}),e)},x=function(){},E=function(e,n){var t;for(t in e)k(e,t)&&n(e[t],t,e)},j=function(e,n){return function(e,n,t){var r=e instanceof Array,i=r?[]:{};return E(e,(function(e,t,o){var c=n(e,t,o);!1===u(c)&&(r?i.push(c):i[t]=c)})),i}(e,(function(e,t){if(-1===n.indexOf(t))return e}))},O=function(e,n,t){return Promise.resolve(e).then(n.bind(t))},k=function(e,n){return e&&e.hasOwnProperty(n)},F={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!0,vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},S=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],B=" ",P='"',R="/",T="<",$=">",C=function(e,n,t){var r=[],i=-1===S.indexOf(e),o=function(e,n,t){var r=[];return E(e,(function(e,t,i){var o=n(e,t,i);!1===u(o)&&r.push(o)})),r}(n,(function(e,n){if(null!=e)return[b(n),[P,b(e),P].join("")].join("=")})).join(B);return r.push([T,e,B,o,$].join("")),t&&r.push(t instanceof Array?t.join(""):t),i&&r.push([T,R,e,$].join("")),r.join("")},N=function(e,n){y(e,{path:t(i,F.path,e.path,n.path),export:t(i,F.export,e.export,n.export),resolver:t(r,F.resolver,e.resolver,n.resolver),extension:t(i,F.extension,e.extension,n.extension),withObject:t(o,F.withObject,e.withObject,n.withObject),rmWhitespace:t(o,F.rmWhitespace,e.rmWhitespace,n.rmWhitespace),cache:t(o,F.cache,e.cache,n.cache),token:y({},F.token,e.token,n.token),vars:y({},F.vars,e.vars,n.vars)})},U="undefined"!=typeof globalThis?globalThis:window||self;function A(e){if(!1===m(this,A))return new A;var n={enabled:!0,list:{}};this.configure=function(e){n.enabled=e.cache,!1===a()&&this.load(U[e.export])},this.clear=function(){n.list={}},this.load=function(e){return n.enabled&&y(n.list,e||{}),this},this.get=function(e){if(n.enabled)return n.list[e]},this.set=function(e,t){return n.enabled&&(n.list[e]=t),this},this.resolve=function(e){return Promise.resolve(this.get(e))},this.remove=function(e){delete n.list[e]},this.exist=function(e){return k(n.list,e)}}var M=[{symbol:"-",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(e){return"')\n/**".concat(e,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(e){return"')\n".concat(e.trim(),"\n").concat(this.BUFFER,"('")}}];function L(e){if(!1===m(this,L))return new L(e);var n={};this.configure=function(e){n.withObject=e.withObject,n.rmWhitespace=e.rmWhitespace,n.token=e.token,n.vars=e.vars,n.matches=[],n.formats=[],n.slurp={match:"[ \\t]*",start:[n.token.start,"_"],end:["_",n.token.end]},M.forEach((function(e){n.matches.push(n.token.start.concat(e.symbol).concat(n.token.regex).concat(n.token.end)),n.formats.push(e.format.bind(n.vars))})),n.regex=new RegExp(n.matches.join("|").concat("|$"),"g"),n.slurpStart=new RegExp([n.slurp.match,n.slurp.start.join("")].join(""),"gm"),n.slurpEnd=new RegExp([n.slurp.end.join(""),n.slurp.match].join(""),"gm")},this.compile=function(e,t){var r=n.vars,i=r.SCOPE,o=r.SAFE,u=r.BUFFER,c=r.COMPONENT;n.rmWhitespace&&(e=e.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),e=e.replace(n.slurpStart,n.token.start).replace(n.slurpEnd,n.token.end);var a,l,s,f="".concat(u,"('");a=n.regex,l=function(t,r,i){f+=v(e.slice(r,i)),t.forEach((function(e,t){e&&(f+=n.formats[t](e))}))},s=0,e.replace(a,(function(){var e=[].slice.call(arguments,0,-1),n=e.pop(),t=e.shift();return l(e,s,n),s=n+t.length,t})),f="try{".concat(f+="');","}catch(e){console.info(e)}"),n.withObject&&(f="with(".concat(i,"){").concat(f,"}")),f="".concat(u,".start();").concat(f,"return ").concat(u,".end();"),f+="\n//# sourceURL=".concat(t);var h=null;try{(h=new Function(i,c,u,o,f)).source="(function(".concat(i,",").concat(c,",").concat(u,",").concat(o,"){\n").concat(f,"\n})")}catch(e){throw e.filename=t,e.source=f,e}return h},this.configure(e)}var W=function(e,n){return n=(n=[e,n].join("/")).replace(/\/\//g,"/")},J=function(e,n){return fetch(W(e,n)).then((function(e){return e.text()}))},_=function(e,t){return new Promise((function(r,i){n.readFile(W(e,t),(function(e,n){e?i(e):r(n.toString())}))}))},q=function(e){return r(e)?e:a()?_:J};function D(e,n,t){if(!1===m(this,D))return new D(e,n,t);if(!1===m(n,A))throw new TypeError("cache is not instance of Cache");if(!1===m(t,L))throw new TypeError("compiler is not instance of Compiler");var i={},o=function(e,t){return n.set(e,t),t},u=function(e){return i.resolver(i.path,e)};this.configure=function(e){i.path=e.path,i.cache=e.cache,i.resolver=q(e.resolver)},this.get=function(e){return n.exist(e)?n.resolve(e):o(e,u(e).then((function(n){return o(e,function(e,n){return r(e)?e:t.compile(e,n)}(n,e))})))},this.configure(e)}function K(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function X(e){return Promise.all(e||[]).then((function(e){return e.join("")}))}function Y(){var e=[],n=[];function t(e){n.push(e)}return t.start=function(){n=[]},t.backup=function(){e.push(n.concat()),n=[]},t.restore=function(){var t=n.concat();return n=e.pop(),X(t)},t.error=function(e){throw e},t.end=function(){return X(n)},t}function V(e){if(!1===m(this,V))return new V(e);this.configure=function(e,n){var t,o=e.vars,u=o.BLOCKS,c=o.MACRO,a=o.EXTEND,l=o.LAYOUT,s=o.BUFFER,f=o.COMPONENT;function h(e){this[u]={},this[c]={},y(this,e||{})}this.create=function(e){return new h(e)},this.helpers=function(e){y(h.prototype,e||{})},h.prototype=y({},n||{}),Object.defineProperties(h.prototype,(K(t={},s,{value:Y(),writable:!0,configurable:!1,enumerable:!1}),K(t,u,{value:{},writable:!0,configurable:!1,enumerable:!1}),K(t,c,{value:{},writable:!0,configurable:!1,enumerable:!1}),K(t,l,{value:!1,writable:!0,configurable:!1,enumerable:!1}),K(t,a,{value:!1,writable:!0,configurable:!1,enumerable:!1}),K(t,"getMacro",{value:function(){return this[c]},writable:!1,configurable:!1,enumerable:!1}),K(t,"getBuffer",{value:function(){return this[s]},writable:!1,configurable:!1,enumerable:!1}),K(t,"getComponent",{value:function(){var e=this;return f in e?function(){return e[f].apply(e,arguments)}:function(){console.log("%s function not defined",f)}},writable:!1,configurable:!1,enumerable:!1}),K(t,"getBlocks",{value:function(){return this[u]},writable:!1,configurable:!1,enumerable:!1}),K(t,"setExtend",{value:function(e){this[a]=e},writable:!1,configurable:!1,enumerable:!1}),K(t,"getExtend",{value:function(){return this[a]},writable:!1,configurable:!1,enumerable:!1}),K(t,"setLayout",{value:function(e){this[l]=e},writable:!1,configurable:!1,enumerable:!1}),K(t,"getLayout",{value:function(){return this[l]},writable:!1,configurable:!1,enumerable:!1}),K(t,"clone",{value:function(e){var n=[l,a,s];return!0===e&&n.push(u),j(this,n)},writable:!1,configurable:!1,enumerable:!1}),K(t,"extend",{value:function(e){this.setExtend(!0),this.setLayout(e)},writable:!1,configurable:!1,enumerable:!1}),K(t,"echo",{value:function(e){var n=this.getBuffer();[].slice.call(arguments).forEach(n)},writable:!1,configurable:!1,enumerable:!1}),K(t,"fn",{value:function(e){var n=this.getBuffer(),t=this;return function(){return n.backup(),r(e)&&e.apply(t,arguments),n.restore()}},writable:!1,configurable:!1,enumerable:!1}),K(t,"get",{value:function(e,n){var t=w(this,e,!0),r=t.shift(),i=t.pop();return k(r,i)?r[i]:n},writable:!1,configurable:!1,enumerable:!1}),K(t,"set",{value:function(e,n){var t=w(this,e,!1),r=t.shift(),i=t.pop();return this.getExtend()&&k(r,i)?r[i]:r[i]=n},writable:!1,configurable:!1,enumerable:!1}),K(t,"macro",{value:function(e,n){var t=this.getMacro(),r=this.fn(n),i=this;t[e]=function(){return i.echo(r.apply(void 0,arguments))}},writable:!1,configurable:!1,enumerable:!1}),K(t,"call",{value:function(e){var n=this.getMacro()[e],t=[].slice.call(arguments,1);if(r(n))return n.apply(n,t)},writable:!1,configurable:!1,enumerable:!1}),K(t,"block",{value:function(e,n){var t=this,r=this.getBlocks();if(r[e]=r[e]||[],r[e].push(this.fn(n)),!this.getExtend()){var i=Object.assign([],r[e]),o=function(){return i.shift()};this.echo(o()(function e(){var n=o();return n?function(){t.echo(n(e()))}:x}()))}},writable:!1,configurable:!1,enumerable:!1}),K(t,"include",{value:function(e,n,t){var r=!1===t?{}:this.clone(!0),i=y(r,n||{}),o=this.render(e,i);this.echo(o)},writable:!1,configurable:!1,enumerable:!1}),K(t,"use",{value:function(e,n){var t=this.require(e);this.echo(O(t,(function(e){var t=this.getMacro();E(e,(function(e,r){t[[n,r].join(".")]=e}))}),this))},writable:!1,configurable:!1,enumerable:!1}),K(t,"async",{value:function(e,n){this.echo(O(e,(function(e){return this.fn(n)(e)}),this))},writable:!1,configurable:!1,enumerable:!1}),K(t,"each",{value:function(e,n){i(e)&&(e=this.get(e,[])),E(e,n)},writable:!1,configurable:!1,enumerable:!1}),K(t,"element",{value:function(e,n,t){return C(e,n,t)}}),K(t,"el",{value:function(e,n,t){r(t)&&(t=this.fn(t)()),this.echo(O(t,(function(t){return this.element(e,n,t)}),this))},writable:!1,configurable:!1,enumerable:!1}),t))},this.configure(e)}function z(e){if(!1===m(this,z))return new z(e);var n={},t={};N(t,e||{});var r=new V(t),i=new L(t),o=new A,u=new D(t,o,i),c=function(e,n){return u.get(e).then((function(e){return e.call(n,n,n.getComponent(),n.getBuffer(),g)}))},a=function e(n,i){var o=d(n,t.extension),u=r.create(i);return c(o,u).then((function(n){if(u.getExtend()){u.setExtend(!1);var t=u.getLayout(),r=u.clone();return e(t,r)}return n}))};return this.configure=function(e){return N(t,e=e||{}),r.configure(t,n),i.configure(t),o.configure(t),u.configure(t),t},this.render=function(e,n){return a(e,n)},this.helpers=function(e){r.helpers(y(n,e))},this.preload=function(e){return o.load(e||{})},this.create=function(e){return new z(e)},this.compile=function(e,n){return i.compile(e,n)},this.context=function(e){return r.create(e)},this.helpers({require:function(e){var n=d(e,t.extension),i=r.create({});return c(n,i).then((function(){return i.getMacro()}))},render:a}),this}var G=new z,H=G.render,I=G.context,Q=G.compile,Z=G.helpers,ee=G.preload,ne=G.configure,te=G.create;e.EJS=z,e.__express=function(e,u,c){r(u)&&(c=u,u={});var a=y({},(u=u||{}).settings),l=t(i,F.path,a.views),s=t(o,F.cache,a["view cache"]),f=y({},a["view options"]),h=n.relative(l,e);return f.path=l,f.cache=s,ne(f),H(h,u).then((function(e){c(null,e)})).catch((function(e){c(e)}))},e.compile=Q,e.configure=ne,e.context=I,e.create=te,e.element=C,e.helpers=Z,e.preload=ee,e.render=H,e.safeValue=g}));
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ejs={})}(this,(function(e){"use strict";var n=function(){var e=[].slice.call(arguments),n=e.shift();return e.filter(n).pop()},t=function(e){return"function"==typeof e},r=function(e){return"string"==typeof e},i=function(e){return"boolean"==typeof e},o=function(e){return void 0===e},u="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),c=function(){return u},a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},s={"&":"&","<":"<",">":">",'"':""","'":"'"},l=function(e){return new RegExp(["[",Object.keys(e).join(""),"]"].join(""),"g")},f=l(s),h=l(a),p=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(f,(function(e){return s[e]}))},b=function(e){return(""+e).replace(h,(function(e){return"\\"+a[e]}))},v=function(e,n){var t=e;return null==t?"":!0===n?p(t):t},g=function(e,n){return Boolean(e instanceof n)},m=function(e,n,r){for(var i=e,o=String(n).split("."),u=o.pop(),c=0;c<o.length;c++){var a=o[c];if(t(i.toJSON)&&(i=i.toJSON()),r&&!1===i.hasOwnProperty(a)){i={};break}i=i[a]=i[a]||{}}return t(i.toJSON)&&(i=i.toJSON()),[i,u]},w=function(e,n){var t=e.split(".").pop();return t!==n&&(e=[e,n].join(".")),e},d=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];return t.filter((function(e){return e})).reduce((function(e,n){return Object.assign(e,n)}),e)},y=function(){},j=function(e,n){var t;for(t in e)O(e,t)&&n(e[t],t,e)},x=function(e,n){return function(e,n,t){var r=e instanceof Array,i=r?[]:{};return j(e,(function(e,t,u){var c=n(e,t,u);!1===o(c)&&(r?i.push(c):i[t]=c)})),i}(e,(function(e,t){if(-1===n.indexOf(t))return e}))},E=function(e,n,t){return Promise.resolve(e).then(n.bind(t))},O=function(e,n){return e&&e.hasOwnProperty(n)},k={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:function(e,n){return Promise.resolve(["resolver is not defined",e,n].join(" "))},extension:"ejs",rmWhitespace:!0,withObject:!0,vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},F=function(e,o){d(e,{path:n(r,k.path,e.path,o.path),export:n(r,k.export,e.export,o.export),resolver:n(t,k.resolver,e.resolver,o.resolver),extension:n(r,k.extension,e.extension,o.extension),withObject:n(i,k.withObject,e.withObject,o.withObject),rmWhitespace:n(i,k.rmWhitespace,e.rmWhitespace,o.rmWhitespace),cache:n(i,k.cache,e.cache,o.cache),token:d({},k.token,e.token,o.token),vars:d({},k.vars,e.vars,o.vars)})},S="undefined"!=typeof globalThis?globalThis:window||self;function B(e){if(!1===g(this,B))return new B;var n={enabled:!0,list:{}};this.configure=function(e){n.enabled=e.cache,!1===c()&&this.load(S[e.export])},this.clear=function(){n.list={}},this.load=function(e){return n.enabled&&d(n.list,e||{}),this},this.get=function(e){if(n.enabled)return n.list[e]},this.set=function(e,t){return n.enabled&&(n.list[e]=t),this},this.resolve=function(e){return Promise.resolve(this.get(e))},this.remove=function(e){delete n.list[e]},this.exist=function(e){return O(n.list,e)}}var P=[{symbol:"-",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(e){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(e,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(e){return"')\n/**".concat(e,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(e){return"')\n".concat(e.trim(),"\n").concat(this.BUFFER,"('")}}];function R(e){if(!1===g(this,R))return new R(e);var n={};this.configure=function(e){n.withObject=e.withObject,n.rmWhitespace=e.rmWhitespace,n.token=e.token,n.vars=e.vars,n.matches=[],n.formats=[],n.slurp={match:"[ \\t]*",start:[n.token.start,"_"],end:["_",n.token.end]},P.forEach((function(e){n.matches.push(n.token.start.concat(e.symbol).concat(n.token.regex).concat(n.token.end)),n.formats.push(e.format.bind(n.vars))})),n.regex=new RegExp(n.matches.join("|").concat("|$"),"g"),n.slurpStart=new RegExp([n.slurp.match,n.slurp.start.join("")].join(""),"gm"),n.slurpEnd=new RegExp([n.slurp.end.join(""),n.slurp.match].join(""),"gm")},this.compile=function(e,t){var r=n.vars,i=r.SCOPE,o=r.SAFE,u=r.BUFFER,c=r.COMPONENT;n.rmWhitespace&&(e=e.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),e=e.replace(n.slurpStart,n.token.start).replace(n.slurpEnd,n.token.end);var a,s,l,f="".concat(u,"('");a=n.regex,s=function(t,r,i){f+=b(e.slice(r,i)),t.forEach((function(e,t){e&&(f+=n.formats[t](e))}))},l=0,e.replace(a,(function(){var e=[].slice.call(arguments,0,-1),n=e.pop(),t=e.shift();return s(e,l,n),l=n+t.length,t})),f="try{".concat(f+="');","}catch(e){console.info(e)}"),n.withObject&&(f="with(".concat(i,"){").concat(f,"}")),f="".concat(u,".start();").concat(f,"return ").concat(u,".end();"),f+="\n//# sourceURL=".concat(t);var h=null;try{(h=new Function(i,c,u,o,f)).source="(function(".concat(i,",").concat(c,",").concat(u,",").concat(o,"){\n").concat(f,"\n})")}catch(e){throw e.filename=t,e.source=f,e}return h},this.configure(e)}function T(e,n,r){if(!1===g(this,T))return new T(e,n,r);if(!1===g(n,B))throw new TypeError("cache is not instance of Cache");if(!1===g(r,R))throw new TypeError("compiler is not instance of Compiler");var i={},o=function(e){return i.resolver(i.path,e)};this.configure=function(e){i.path=e.path,i.cache=e.cache,t(e.resolver)&&(i.resolver=e.resolver)},this.get=function(e){return n.exist(e)?n.resolve(e):o(e).then((function(i){return function(e,t){return n.set(e,t),t}(e,function(e,n){return t(e)?e:r.compile(e,n)}(i,e))}))},this.configure(e)}function $(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var C=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],N=" ",U='"',A="/",M="<",L=">",W=function(e,n,t){var r=[],i=-1===C.indexOf(e),u=function(e,n,t){var r=[];return j(e,(function(e,t,i){var u=n(e,t,i);!1===o(u)&&r.push(u)})),r}(n,(function(e,n){if(null!=e)return[p(n),[U,p(e),U].join("")].join("=")})).join(N);return r.push([M,e,N,u,L].join("")),t&&r.push(t instanceof Array?t.join(""):t),i&&r.push([M,A,e,L].join("")),r.join("")};function J(e){return Promise.all(e||[]).then((function(e){return e.join("")}))}function _(){var e=[],n=[];function t(e){n.push(e)}return t.start=function(){n=[]},t.backup=function(){e.push(n.concat()),n=[]},t.restore=function(){var t=n.concat();return n=e.pop(),J(t)},t.error=function(e){throw e},t.end=function(){return J(n)},t}function q(e){if(!1===g(this,q))return new q(e);this.configure=function(e,n){var i,o=e.vars,u=o.BLOCKS,c=o.MACRO,a=o.EXTEND,s=o.LAYOUT,l=o.BUFFER,f=o.COMPONENT;function h(e){this[u]={},this[c]={},d(this,e||{})}this.create=function(e){return new h(e)},this.helpers=function(e){d(h.prototype,e||{})},h.prototype=d({},n||{}),Object.defineProperties(h.prototype,($(i={},l,{value:_(),writable:!0,configurable:!1,enumerable:!1}),$(i,u,{value:{},writable:!0,configurable:!1,enumerable:!1}),$(i,c,{value:{},writable:!0,configurable:!1,enumerable:!1}),$(i,s,{value:!1,writable:!0,configurable:!1,enumerable:!1}),$(i,a,{value:!1,writable:!0,configurable:!1,enumerable:!1}),$(i,"getMacro",{value:function(){return this[c]},writable:!1,configurable:!1,enumerable:!1}),$(i,"getBuffer",{value:function(){return this[l]},writable:!1,configurable:!1,enumerable:!1}),$(i,"getComponent",{value:function(){var e=this;return f in e?function(){return e[f].apply(e,arguments)}:function(){console.log("%s function not defined",f)}},writable:!1,configurable:!1,enumerable:!1}),$(i,"getBlocks",{value:function(){return this[u]},writable:!1,configurable:!1,enumerable:!1}),$(i,"setExtend",{value:function(e){this[a]=e},writable:!1,configurable:!1,enumerable:!1}),$(i,"getExtend",{value:function(){return this[a]},writable:!1,configurable:!1,enumerable:!1}),$(i,"setLayout",{value:function(e){this[s]=e},writable:!1,configurable:!1,enumerable:!1}),$(i,"getLayout",{value:function(){return this[s]},writable:!1,configurable:!1,enumerable:!1}),$(i,"clone",{value:function(e){var n=[s,a,l];return!0===e&&n.push(u),x(this,n)},writable:!1,configurable:!1,enumerable:!1}),$(i,"extend",{value:function(e){this.setExtend(!0),this.setLayout(e)},writable:!1,configurable:!1,enumerable:!1}),$(i,"echo",{value:function(e){var n=this.getBuffer();[].slice.call(arguments).forEach(n)},writable:!1,configurable:!1,enumerable:!1}),$(i,"fn",{value:function(e){var n=this.getBuffer(),r=this;return function(){return n.backup(),t(e)&&e.apply(r,arguments),n.restore()}},writable:!1,configurable:!1,enumerable:!1}),$(i,"get",{value:function(e,n){var t=m(this,e,!0),r=t.shift(),i=t.pop();return O(r,i)?r[i]:n},writable:!1,configurable:!1,enumerable:!1}),$(i,"set",{value:function(e,n){var t=m(this,e,!1),r=t.shift(),i=t.pop();return this.getExtend()&&O(r,i)?r[i]:r[i]=n},writable:!1,configurable:!1,enumerable:!1}),$(i,"macro",{value:function(e,n){var t=this.getMacro(),r=this.fn(n),i=this;t[e]=function(){return i.echo(r.apply(void 0,arguments))}},writable:!1,configurable:!1,enumerable:!1}),$(i,"call",{value:function(e){var n=this.getMacro()[e],r=[].slice.call(arguments,1);if(t(n))return n.apply(n,r)},writable:!1,configurable:!1,enumerable:!1}),$(i,"block",{value:function(e,n){var t=this,r=this.getBlocks();if(r[e]=r[e]||[],r[e].push(this.fn(n)),!this.getExtend()){var i=Object.assign([],r[e]),o=function(){return i.shift()};this.echo(o()(function e(){var n=o();return n?function(){t.echo(n(e()))}:y}()))}},writable:!1,configurable:!1,enumerable:!1}),$(i,"include",{value:function(e,n,t){var r=!1===t?{}:this.clone(!0),i=d(r,n||{}),o=this.render(e,i);this.echo(o)},writable:!1,configurable:!1,enumerable:!1}),$(i,"use",{value:function(e,n){var t=this.require(e);this.echo(E(t,(function(e){var t=this.getMacro();j(e,(function(e,r){t[[n,r].join(".")]=e}))}),this))},writable:!1,configurable:!1,enumerable:!1}),$(i,"async",{value:function(e,n){this.echo(E(e,(function(e){return this.fn(n)(e)}),this))},writable:!1,configurable:!1,enumerable:!1}),$(i,"each",{value:function(e,n){r(e)&&(e=this.get(e,[])),j(e,n)},writable:!1,configurable:!1,enumerable:!1}),$(i,"element",{value:function(e,n,t){return W(e,n,t)}}),$(i,"el",{value:function(e,n,r){t(r)&&(r=this.fn(r)()),this.echo(E(r,(function(t){return this.element(e,n,t)}),this))},writable:!1,configurable:!1,enumerable:!1}),i))},this.configure(e)}var D={};var K=new function e(n){if(!1===g(this,e))return new e(n);var t={},r={};F(r,n||{});var i=new q(r),o=new R(r),u=new B,c=new T(r,u,o),a=function(e,n){return c.get(e).then((function(e){return e.call(n,n,n.getComponent(),n.getBuffer(),v)}))},s=function e(n,t){var o=w(n,r.extension),u=i.create(t);return a(o,u).then((function(n){if(u.getExtend()){u.setExtend(!1);var t=u.getLayout(),r=u.clone();return e(t,r)}return n}))};return this.configure=function(e){return F(r,e=e||{}),i.configure(r,t),o.configure(r),u.configure(r),c.configure(r),r},this.render=function(e,n){return s(e,n)},this.helpers=function(e){i.helpers(d(t,e))},this.preload=function(e){return u.load(e||{})},this.create=function(n){return new e(n)},this.compile=function(e,n){return o.compile(e,n)},this.context=function(e){return i.create(e)},this.helpers({require:function(e){var n=w(e,r.extension),t=i.create({});return a(n,t).then((function(){return t.getMacro()}))},render:s}),this}({resolver:function(e,n){return new Promise((function(t,r){D.readFile(function(e,n){return(n=[e,n].join("/")).replace(/\/\//g,"/")}(e,n),(function(e,n){e?r(e):t(n.toString())}))}))}}),X=K.render,Y=K.context,z=K.compile,G=K.helpers,H=K.preload,I=K.configure,Q=K.create,V=function(e){return function(o,u,c){t(u)&&(c=u,u={});var a=d({},(u=u||{}).settings),s=n(r,k.path,a.views),l=n(i,k.cache,a["view cache"]),f=d({},a["view options"]),h=D.relative(s,o);return f.path=s,f.cache=l,e.configure(f),e.render(h,u).then((function(e){c(null,e)})).catch((function(e){c(e)}))}}(K);e.__express=V,e.compile=z,e.configure=I,e.context=Y,e.create=Q,e.helpers=G,e.preload=H,e.render=X}));
|
package/package.json
CHANGED
|
@@ -3,17 +3,21 @@
|
|
|
3
3
|
"description": "EJS Templates",
|
|
4
4
|
"homepage": "https://github.com/kosatyi/ejs",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.69",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.js",
|
|
9
|
-
"browser": "dist/umd/
|
|
10
|
-
"minified": "dist/umd/
|
|
9
|
+
"browser": "dist/umd/browser.js",
|
|
10
|
+
"minified": "dist/umd/browser.min.js",
|
|
11
11
|
"author": "Stepan Kosatyi (https://kosatyi.com)",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"import": "./dist/esm/index.js",
|
|
15
15
|
"require": "./dist/cjs/index.js"
|
|
16
16
|
},
|
|
17
|
+
"./browser": {
|
|
18
|
+
"import": "./dist/esm/browser.js",
|
|
19
|
+
"require": "./dist/cjs/browser.js"
|
|
20
|
+
},
|
|
17
21
|
"./element": {
|
|
18
22
|
"import": "./dist/esm/element.js",
|
|
19
23
|
"require": "./dist/cjs/element.js"
|
|
@@ -21,7 +25,7 @@
|
|
|
21
25
|
},
|
|
22
26
|
"files": [
|
|
23
27
|
"dist",
|
|
24
|
-
"
|
|
28
|
+
"types"
|
|
25
29
|
],
|
|
26
30
|
"scripts": {
|
|
27
31
|
"build": "rollup -c",
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
export namespace ejs {
|
|
3
|
+
/**
|
|
4
|
+
* extend layout with blocks in current template file
|
|
5
|
+
* @param layout
|
|
6
|
+
*/
|
|
7
|
+
function extend(layout: string): any
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* define block with custom **name** and callback
|
|
11
|
+
* @param name
|
|
12
|
+
* @param [callback]
|
|
13
|
+
*/
|
|
14
|
+
function block(name: string, callback?: Function): any
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* set property in current scope
|
|
18
|
+
* @param path
|
|
19
|
+
* @param value
|
|
20
|
+
*/
|
|
21
|
+
function set(path: string, value: any): any
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* get property in current scope
|
|
25
|
+
* @param path
|
|
26
|
+
* @param defaults
|
|
27
|
+
*/
|
|
28
|
+
function get(path: string, defaults?: any): any
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* import macro from file **path** and set to current scope **name** property
|
|
32
|
+
* @param path
|
|
33
|
+
* @param name
|
|
34
|
+
*/
|
|
35
|
+
function use(path: string, name: string): any
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* define macro function with custom **name**
|
|
39
|
+
* @param name
|
|
40
|
+
* @param callback
|
|
41
|
+
*/
|
|
42
|
+
function macro(name: string, callback: any): any
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* call macro function
|
|
46
|
+
* @param name
|
|
47
|
+
* @param props
|
|
48
|
+
* @param callback
|
|
49
|
+
*/
|
|
50
|
+
function call(name: string, props?: object, callback?: any): any
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* asynchronous template execution
|
|
54
|
+
* @param promise
|
|
55
|
+
* @param callback
|
|
56
|
+
*/
|
|
57
|
+
function async(promise: Promise<any>, callback?: any): any
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* asynchronous template execution
|
|
61
|
+
* @param callback
|
|
62
|
+
*/
|
|
63
|
+
function fn(callback: Function): any
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param {string} tag
|
|
68
|
+
* @param {object} attrs
|
|
69
|
+
* @param {function} content
|
|
70
|
+
*/
|
|
71
|
+
function el(tag: string, attrs?: object, content?: any): any
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* buffer output
|
|
75
|
+
* @param args
|
|
76
|
+
*/
|
|
77
|
+
function echo(...args: any[]): any
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* append rendered template from file
|
|
81
|
+
* @param path
|
|
82
|
+
* @param data
|
|
83
|
+
* @param cx
|
|
84
|
+
*/
|
|
85
|
+
function include(path: string, data?: object, cx?: boolean): any
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
*
|
|
89
|
+
* @param value
|
|
90
|
+
* @param callback
|
|
91
|
+
*/
|
|
92
|
+
function each(value: any, callback: Function): any
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* define block with custom **name** and callback
|
|
96
|
+
* @param {string} name
|
|
97
|
+
* @param {object} [props]
|
|
98
|
+
*/
|
|
99
|
+
function ui(name: string, props?: object): any
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export = global
|
package/dist/templates.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}!function(e,o){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e="undefined"!=typeof globalThis?globalThis:e||self).ejsPrecompiled=o()}(this,(function(){return{}}));
|