@kosatyi/ejs 0.0.15 → 0.0.17
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 +15 -32
- package/dist/ejs.js +15 -32
- package/dist/ejs.min.js +1 -1
- package/dist/ejs.mjs +21 -34
- package/ejs.d.ts +26 -0
- package/package.json +9 -7
- package/dist/build.js +0 -33
package/dist/ejs.cjs
CHANGED
|
@@ -16,7 +16,7 @@ defaults.cache = true;
|
|
|
16
16
|
defaults.path = 'views';
|
|
17
17
|
defaults.resolver = null;
|
|
18
18
|
defaults.extension = 'ejs';
|
|
19
|
-
defaults.withObject =
|
|
19
|
+
defaults.withObject = true;
|
|
20
20
|
defaults.vars = {
|
|
21
21
|
SCOPE: 'ejs',
|
|
22
22
|
EXTEND: '$$e',
|
|
@@ -261,7 +261,6 @@ var Compiler = function Compiler(config) {
|
|
|
261
261
|
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
262
262
|
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
263
263
|
} catch (e) {
|
|
264
|
-
console.log(e);
|
|
265
264
|
e.filename = path;
|
|
266
265
|
e.source = source;
|
|
267
266
|
throw e;
|
|
@@ -374,15 +373,6 @@ var Buffer = function Buffer() {
|
|
|
374
373
|
return buffer;
|
|
375
374
|
};
|
|
376
375
|
|
|
377
|
-
/**
|
|
378
|
-
* @memberOf global
|
|
379
|
-
* @class
|
|
380
|
-
* @alias ejs
|
|
381
|
-
* @param config
|
|
382
|
-
* @param methods
|
|
383
|
-
* @return {Scope}
|
|
384
|
-
*/
|
|
385
|
-
|
|
386
376
|
var configure = function configure(config, methods) {
|
|
387
377
|
var _config$vars = config.vars,
|
|
388
378
|
EXTEND = _config$vars.EXTEND,
|
|
@@ -390,12 +380,6 @@ var configure = function configure(config, methods) {
|
|
|
390
380
|
BLOCKS = _config$vars.BLOCKS,
|
|
391
381
|
BUFFER = _config$vars.BUFFER,
|
|
392
382
|
MACRO = _config$vars.MACRO;
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
*
|
|
396
|
-
* @param data
|
|
397
|
-
* @constructor
|
|
398
|
-
*/
|
|
399
383
|
function Scope() {
|
|
400
384
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
401
385
|
this.initBlocks();
|
|
@@ -575,23 +559,21 @@ var configure = function configure(config, methods) {
|
|
|
575
559
|
return this.fn(callback)(data);
|
|
576
560
|
}, this));
|
|
577
561
|
});
|
|
578
|
-
Scope.
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
if (isFunction(content)) {
|
|
582
|
-
content = this.fn(content)();
|
|
583
|
-
}
|
|
584
|
-
this.echo(resolve$1(content, function (content) {
|
|
585
|
-
return element(tag, attr, content);
|
|
586
|
-
}, this));
|
|
587
|
-
},
|
|
588
|
-
each: function each$1(object, callback) {
|
|
589
|
-
if (isString(object)) {
|
|
590
|
-
object = this.get(object, []);
|
|
591
|
-
}
|
|
592
|
-
each(object, callback);
|
|
562
|
+
Scope.method('el', function (tag, attr, content) {
|
|
563
|
+
if (isFunction(content)) {
|
|
564
|
+
content = this.fn(content)();
|
|
593
565
|
}
|
|
566
|
+
this.echo(resolve$1(content, function (content) {
|
|
567
|
+
return element(tag, attr, content);
|
|
568
|
+
}, this));
|
|
594
569
|
});
|
|
570
|
+
Scope.method('each', function (object, callback) {
|
|
571
|
+
if (isString(object)) {
|
|
572
|
+
object = this.get(object, []);
|
|
573
|
+
}
|
|
574
|
+
each(object, callback);
|
|
575
|
+
});
|
|
576
|
+
Scope.helpers(methods);
|
|
595
577
|
return Scope;
|
|
596
578
|
};
|
|
597
579
|
|
|
@@ -679,6 +661,7 @@ function init(options) {
|
|
|
679
661
|
config.path = typeProp(isString, defaults.path, options.path);
|
|
680
662
|
config.resolver = typeProp(isFunction, defaults.resolver, options.resolver);
|
|
681
663
|
config.extension = typeProp(isString, defaults.extension, options.extension);
|
|
664
|
+
config.withObject = typeProp(isBoolean, defaults.withObject, options.withObject);
|
|
682
665
|
config.token = extend({}, defaults.token, options.token);
|
|
683
666
|
config.vars = extend({}, defaults.vars, options.vars);
|
|
684
667
|
view.scope = configure(config, _helpers);
|
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 = true;
|
|
16
16
|
defaults.vars = {
|
|
17
17
|
SCOPE: 'ejs',
|
|
18
18
|
EXTEND: '$$e',
|
|
@@ -257,7 +257,6 @@
|
|
|
257
257
|
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
258
258
|
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
259
259
|
} catch (e) {
|
|
260
|
-
console.log(e);
|
|
261
260
|
e.filename = path;
|
|
262
261
|
e.source = source;
|
|
263
262
|
throw e;
|
|
@@ -370,15 +369,6 @@
|
|
|
370
369
|
return buffer;
|
|
371
370
|
};
|
|
372
371
|
|
|
373
|
-
/**
|
|
374
|
-
* @memberOf global
|
|
375
|
-
* @class
|
|
376
|
-
* @alias ejs
|
|
377
|
-
* @param config
|
|
378
|
-
* @param methods
|
|
379
|
-
* @return {Scope}
|
|
380
|
-
*/
|
|
381
|
-
|
|
382
372
|
var configure = function configure(config, methods) {
|
|
383
373
|
var _config$vars = config.vars,
|
|
384
374
|
EXTEND = _config$vars.EXTEND,
|
|
@@ -386,12 +376,6 @@
|
|
|
386
376
|
BLOCKS = _config$vars.BLOCKS,
|
|
387
377
|
BUFFER = _config$vars.BUFFER,
|
|
388
378
|
MACRO = _config$vars.MACRO;
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
*
|
|
392
|
-
* @param data
|
|
393
|
-
* @constructor
|
|
394
|
-
*/
|
|
395
379
|
function Scope() {
|
|
396
380
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
397
381
|
this.initBlocks();
|
|
@@ -571,23 +555,21 @@
|
|
|
571
555
|
return this.fn(callback)(data);
|
|
572
556
|
}, this));
|
|
573
557
|
});
|
|
574
|
-
Scope.
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
if (isFunction(content)) {
|
|
578
|
-
content = this.fn(content)();
|
|
579
|
-
}
|
|
580
|
-
this.echo(resolve$1(content, function (content) {
|
|
581
|
-
return element(tag, attr, content);
|
|
582
|
-
}, this));
|
|
583
|
-
},
|
|
584
|
-
each: function each$1(object, callback) {
|
|
585
|
-
if (isString(object)) {
|
|
586
|
-
object = this.get(object, []);
|
|
587
|
-
}
|
|
588
|
-
each(object, callback);
|
|
558
|
+
Scope.method('el', function (tag, attr, content) {
|
|
559
|
+
if (isFunction(content)) {
|
|
560
|
+
content = this.fn(content)();
|
|
589
561
|
}
|
|
562
|
+
this.echo(resolve$1(content, function (content) {
|
|
563
|
+
return element(tag, attr, content);
|
|
564
|
+
}, this));
|
|
590
565
|
});
|
|
566
|
+
Scope.method('each', function (object, callback) {
|
|
567
|
+
if (isString(object)) {
|
|
568
|
+
object = this.get(object, []);
|
|
569
|
+
}
|
|
570
|
+
each(object, callback);
|
|
571
|
+
});
|
|
572
|
+
Scope.helpers(methods);
|
|
591
573
|
return Scope;
|
|
592
574
|
};
|
|
593
575
|
|
|
@@ -675,6 +657,7 @@
|
|
|
675
657
|
config.path = typeProp(isString, defaults.path, options.path);
|
|
676
658
|
config.resolver = typeProp(isFunction, defaults.resolver, options.resolver);
|
|
677
659
|
config.extension = typeProp(isString, defaults.extension, options.extension);
|
|
660
|
+
config.withObject = typeProp(isBoolean, defaults.withObject, options.withObject);
|
|
678
661
|
config.token = extend({}, defaults.token, options.token);
|
|
679
662
|
config.vars = extend({}, defaults.vars, options.vars);
|
|
680
663
|
view.scope = configure(config, _helpers);
|
package/dist/ejs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).ejs=t()}(this,(function(){"use strict";var n={},t={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:"ejs",withObject:!
|
|
1
|
+
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).ejs=t()}(this,(function(){"use strict";var n={},t={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:"ejs",withObject:!0,vars:{SCOPE:"ejs",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},e=function(){var n=[].slice.call(arguments),t=n.shift();return n.filter(t).pop()},r=function(n){return"function"==typeof n},o=function(n){return"string"==typeof n},i=function(n){return"boolean"==typeof n},c=new Function("try {return this===global;}catch(e){return false;}"),u={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},a={"&":"&","<":"<",">":">",'"':""","'":"'"},f=function(n){return new RegExp(["[",Object.keys(n).join(""),"]"].join(""),"g")},s=f(a),h=f(u),l=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+n).replace(s,(function(n){return a[n]}))},p=function(n,t,e){return null==(e=n)?"":t?l(e):e},v=function(n,t){var e=n,r=t.split("."),o=r.pop();return r.forEach((function(n){e=e[n]=e[n]||{}})),[e,o]},d=function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var r=t.shift();return t.filter((function(n){return n})).reduce((function(n,t){return Object.assign(n,t)}),r)},m=function(){},g=function(n,t){var e;for(e in n)y(n,e)&&t(n[e],e,n)},b=function(n,t){return function(n,t,e){var r=n instanceof Array,o=r?[]:{};return g(n,(function(n,e,i){var c=t(n,e,i);void 0!==c&&(r?o.push(c):o[e]=c)})),o}(n,(function(n,e){if(-1===t.indexOf(e))return n}))},w=function(n,t,e){return Promise.resolve(n).then(t.bind(e))},y=function(n,t){return n&&n.hasOwnProperty(t)},x=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],j=" ",E='"',O="/",k="<",F=">";function B(n,t,e){var r=[],o=-1===x.indexOf(n),i=function(n,t,e){var r=[];return g(n,(function(n,e,o){var i=t(n,e,o);void 0!==i&&r.push(i)})),r}(t,(function(n,t){if(null!=n)return[l(t),[E,l(n),E].join("")].join("=")})).join(j);return r.push([k,n,j,i,F].join("")),e&&r.push(e instanceof Array?e.join(""):e),o&&r.push([k,O,n,F].join("")),r.join("")}var $=[{symbol:"-",format:function(n){return"'+\n".concat(this.SAFE,"(").concat(n,",1)+\n'")}},{symbol:"=",format:function(n){return"'+\n".concat(this.SAFE,"(").concat(n,")+\n'")}},{symbol:"#",format:function(n){return"'+\n/**".concat(n,"**/+\n'")}},{symbol:"",format:function(n){return"')\n".concat(n,"\n").concat(this.BUFFER,"('")}}],S=function(n){var t=n.withObject,e=n.token,r=n.vars,o=[],i=[],c={match:"[ \\t]*",start:[e.start,"_"],end:["_",e.end]};$.forEach((function(n){o.push(e.start.concat(n.symbol).concat(e.regex).concat(e.end)),i.push(n.format.bind(r))}));var a=new RegExp(o.join("|").concat("|$"),"g"),f=new RegExp([c.match,c.start].join(""),"gm"),s=new RegExp([c.end,c.match].join(""),"gm");return function(n,e){var o=r.SCOPE,l=r.SAFE,p=r.BUFFER;n=(n=n.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(f,c.start).replace(s,c.end);var v="".concat(p,"('");!function(n,t,e){var r=0;t.replace(n,(function(){var n=[].slice.call(arguments,0,-1),t=n.pop(),o=n.shift();return e(n,r,t),r=t+o.length,o}))}(a,n,(function(t,e,r){v+=(""+n.slice(e,r)).replace(h,(function(n){return"\\"+u[n]})),t.forEach((function(n,t){n&&(v+=i[t](n))}))})),v="try{".concat(v+="');","}catch(e){console.info(e)}"),t&&(v="with(".concat(o,"){").concat(v,"}")),v="".concat(p,".start();").concat(v,"return ").concat(p,".end();"),v+="\n//# sourceURL=".concat(e);var d=null;try{(d=new Function(o,p,l,v)).source="(function(".concat(o,",").concat(p,",").concat(l,"){\n").concat(v,"\n})")}catch(n){throw n.filename=e,n.source=v,n}return d}},A=function(n){return window.fetch(n).then((function(n){return n.text()}))},R=function(t){return new Promise((function(e,r){n.readFile(t,(function(n,t){n?r(n):e(t.toString())}))}))},L=function(t,e){return n.watch(".",{cwd:t}).on("change",(function(n){e.remove(n)})).on("error",(function(n){console.log("watcher error: "+n)}))},M=function(n,t,e){var o=n.path;n.token;var i=r(n.resolver)?n.resolver:c()?R:A,u=function(n){return i(function(n){return(n=[o,n].join("/")).replace(/\/\//g,"/")}(n))},a=function(n,e){return t.set(e,n),n};return n.watch&&c()&&L(o,t),function(n){if(t.exist(n))return t.resolve(n);var r=u(n).then((function(t){return a(e(t,n),n)}));return a(r,n)}},P=function(n){return Promise.all(n).then((function(n){return n.join("")}))},U=function(){var n=[],t=[];function e(n){t.push(n)}return e.start=function(){t=[]},e.backup=function(){n.push(t.concat()),t=[]},e.restore=function(){var e=t.concat();return t=n.pop(),P(e)},e.error=function(n){throw n},e.end=function(){return P(t)},e};var C,T,q,_,N,D=(T={},q={},_=function(n,t){var e=n.split(".").pop();return e!==t&&(n=[n,t].join(".")),n},N={element:B,output:function(n,t){return N.template(n).then((function(n){return n.call(t,t,t.getBuffer(),p)}))},render:function(n,t){var e=_(n,T.extension),r=new N.scope(t);return N.output(e,r).then((function(n){if(r.getExtend()){r.setExtend(!1);var t=r.getLayout(),e=r.clone();return N.render(t,e)}return n}))},require:function(n){var t=_(n,T.extension),e=new N.scope({});return N.output(t,e).then((function(){return e.getMacro()}))},helpers:function(n){d(q,n=n||{}),N.scope.helpers(n)},configure:function(n){return T.export=e(o,t.export,n.export),T.path=e(o,t.path,n.path),T.resolver=e(r,t.resolver,n.resolver),T.extension=e(o,t.extension,n.extension),T.withObject=e(i,t.withObject,n.withObject),T.token=d({},t.token,n.token),T.vars=d({},t.vars,n.vars),N.scope=function(n,t){var e=n.vars,i=e.EXTEND,c=e.LAYOUT,u=e.BLOCKS,a=e.BUFFER,f=e.MACRO;function s(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),d(this,n)}return s.helpers=function(n){d(s.prototype,n)},s.property=function(n,t){Object.defineProperty(s.prototype,n,t)},s.method=function(n,t){Object.defineProperty(s.prototype,n,{value:t,writable:!1,configurable:!1,enumerable:!1})},s.property(a,{value:U(),writable:!1,configurable:!1,enumerable:!1}),s.property(u,{value:{},writable:!0,configurable:!1,enumerable:!1}),s.property(f,{value:{},writable:!0,configurable:!1,enumerable:!1}),s.property(c,{value:!1,writable:!0,configurable:!1,enumerable:!1}),s.property(i,{value:!1,writable:!0,configurable:!1,enumerable:!1}),s.method("initBlocks",(function(){this[u]={}})),s.method("initMacro",(function(){this[f]={}})),s.method("getMacro",(function(){return this[f]})),s.method("getBuffer",(function(){return this[a]})),s.method("getBlocks",(function(){return this[u]})),s.method("setExtend",(function(n){this[i]=n})),s.method("getExtend",(function(){return this[i]})),s.method("setLayout",(function(n){this[c]=n})),s.method("getLayout",(function(){return this[c]})),s.method("clone",(function(n){var t=[c,i,a];return!0===n&&t.push(u),b(this,t)})),s.method("extend",(function(n){this.setExtend(!0),this.setLayout(n)})),s.method("echo",(function(){var n=this.getBuffer();[].slice.call(arguments).forEach((function(t){n(t)}))})),s.method("fn",(function(n){var t=this.getBuffer(),e=this;return function(){return t.backup(),r(n)&&n.apply(e,arguments),t.restore()}})),s.method("get",(function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();return y(r,o)?r[o]:t})),s.method("set",(function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();return this.getExtend()&&y(r,o)?r[o]:r[o]=t})),s.method("macro",(function(n,t){var e=this.getMacro(),r=this.fn(t),o=this;e[n]=function(){return o.echo(r.apply(void 0,arguments))}})),s.method("call",(function(n){var t=this.getMacro()[n],e=[].slice.call(arguments,1);if(r(t))return t.apply(t,e)})),s.method("block",(function(n,t){var e=this,r=this.getBlocks();if(r[n]=r[n]||[],r[n].push(this.fn(t)),!this.getExtend()){var o=Object.assign([],r[n]),i=function(){return o.shift()};this.echo(i()(function n(){var t=i();return t?function(){e.echo(t(n()))}:m}()))}})),s.method("include",(function(n,t,e){var r=!1===e?{}:this.clone(!0),o=d(r,t||{}),i=this.render(n,o);this.echo(i)})),s.method("use",(function(n,t){var e=this.require(n);this.echo(w(e,(function(n){var e=this.getMacro();g(n,(function(n,r){e[[t,r].join(".")]=n}))}),this))})),s.method("async",(function(n,t){this.echo(w(n,(function(n){return this.fn(t)(n)}),this))})),s.method("el",(function(n,t,e){r(e)&&(e=this.fn(e)()),this.echo(w(e,(function(e){return B(n,t,e)}),this))})),s.method("each",(function(n,t){o(n)&&(n=this.get(n,[])),g(n,t)})),s.helpers(t),s}(T,q),N.compile=S(T),N.wrapper=function(n){var t=n.export;return function(n){var e="(function(o){\n";return n.forEach((function(n){e+="o["+JSON.stringify(n.name)+"]="+String(n.content)+"\n"})),e+='})(window["'+t+'"] = window["'+t+'"] || {});\n'}}(T),N.cache=function(n){var t=n.export,e={};return{preload:function(){return!1===c()&&this.load(window[t]),this},exist:function(n){return y(e,n)},get:function(n){return e[n]},remove:function(n){delete e[n]},resolve:function(n){return Promise.resolve(this.get(n))},set:function(n,t){return e[n]=t,this},load:function(n){return d(e,n),this}}.preload()}(T),N.template=M(T,N.cache,N.compile),N},__express:function(c,u,a){r(u)&&(a=u,u={});var f=d({},(u=u||{}).settings),s=e(o,f.views,t.path),h=e(i,f["view cache"],t.cache),l=d({},f["view options"]),p=n.relative(s,c);return l.path=s,l.cache=h,N.configure(l),N.render(p,u).then((function(n){a(null,n)})).catch((function(n){a(n)}))}},N.configure(C||{}),N.helpers({require:function(n){return N.require(n,this)},render:function(n,t){return N.render(n,t)}}),N);return D}));
|
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 = true;
|
|
18
18
|
|
|
19
19
|
defaults.vars = {
|
|
20
20
|
SCOPE: 'ejs',
|
|
@@ -305,7 +305,6 @@ const Compiler = (config) => {
|
|
|
305
305
|
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
306
306
|
result.source = `(function(${SCOPE},${BUFFER},${SAFE}){\n${source}\n})`;
|
|
307
307
|
} catch (e) {
|
|
308
|
-
console.log(e);
|
|
309
308
|
e.filename = path;
|
|
310
309
|
e.source = source;
|
|
311
310
|
throw e
|
|
@@ -425,23 +424,8 @@ const Buffer = () => {
|
|
|
425
424
|
return buffer
|
|
426
425
|
};
|
|
427
426
|
|
|
428
|
-
/**
|
|
429
|
-
* @memberOf global
|
|
430
|
-
* @class
|
|
431
|
-
* @alias ejs
|
|
432
|
-
* @param config
|
|
433
|
-
* @param methods
|
|
434
|
-
* @return {Scope}
|
|
435
|
-
*/
|
|
436
|
-
|
|
437
427
|
const configure = (config, methods) => {
|
|
438
428
|
const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO } = config.vars;
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
*
|
|
442
|
-
* @param data
|
|
443
|
-
* @constructor
|
|
444
|
-
*/
|
|
445
429
|
function Scope(data = {}) {
|
|
446
430
|
this.initBlocks();
|
|
447
431
|
this.initMacro();
|
|
@@ -621,25 +605,23 @@ const configure = (config, methods) => {
|
|
|
621
605
|
}, this)
|
|
622
606
|
);
|
|
623
607
|
});
|
|
624
|
-
Scope.
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
if (isString(object)) {
|
|
638
|
-
object = this.get(object, []);
|
|
639
|
-
}
|
|
640
|
-
each(object, callback);
|
|
608
|
+
Scope.method('el',function(tag, attr, content){
|
|
609
|
+
if (isFunction(content)) {
|
|
610
|
+
content = this.fn(content)();
|
|
611
|
+
}
|
|
612
|
+
this.echo(
|
|
613
|
+
resolve$1(content, function(content) {
|
|
614
|
+
return element(tag, attr, content)
|
|
615
|
+
}, this)
|
|
616
|
+
);
|
|
617
|
+
});
|
|
618
|
+
Scope.method('each',function(object, callback){
|
|
619
|
+
if (isString(object)) {
|
|
620
|
+
object = this.get(object, []);
|
|
641
621
|
}
|
|
622
|
+
each(object, callback);
|
|
642
623
|
});
|
|
624
|
+
Scope.helpers(methods);
|
|
643
625
|
return Scope
|
|
644
626
|
};
|
|
645
627
|
|
|
@@ -735,6 +717,11 @@ function init(options) {
|
|
|
735
717
|
defaults.extension,
|
|
736
718
|
options.extension
|
|
737
719
|
);
|
|
720
|
+
config.withObject = typeProp(
|
|
721
|
+
isBoolean,
|
|
722
|
+
defaults.withObject,
|
|
723
|
+
options.withObject
|
|
724
|
+
);
|
|
738
725
|
config.token = extend({}, defaults.token, options.token);
|
|
739
726
|
config.vars = extend({}, defaults.vars, options.vars);
|
|
740
727
|
view.scope = configure(config, helpers);
|
package/ejs.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare namespace ejs {
|
|
2
|
+
// extend layout with blocks in current template file
|
|
3
|
+
function extend(layout: string);
|
|
4
|
+
// define block with custom **name** and callback
|
|
5
|
+
function block(name: string, callback );
|
|
6
|
+
// set property in current scope
|
|
7
|
+
function set(path: string, value: any);
|
|
8
|
+
// get property in current scope
|
|
9
|
+
function get(path: string, defaults: any );
|
|
10
|
+
// import macro from file **path** and set to current scope **name** property
|
|
11
|
+
function use(path: string, name: string);
|
|
12
|
+
// define macro function with custom **name**
|
|
13
|
+
function macro(name: string, callback );
|
|
14
|
+
// call macro function
|
|
15
|
+
function call(name: string, props?: object, callback?);
|
|
16
|
+
// asynchronous template execution
|
|
17
|
+
function async(promise: Promise<any>, callback?);
|
|
18
|
+
// asynchronous template execution
|
|
19
|
+
function fn(callback: Function);
|
|
20
|
+
// buffer output
|
|
21
|
+
function echo(...any);
|
|
22
|
+
// buffer output
|
|
23
|
+
function include();
|
|
24
|
+
// buffer output
|
|
25
|
+
function include();
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -2,20 +2,18 @@
|
|
|
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.17",
|
|
6
6
|
"main": "dist/ejs.cjs",
|
|
7
7
|
"module": "dist/ejs.mjs",
|
|
8
8
|
"browser": "dist/ejs.js",
|
|
9
9
|
"minified": "dist/ejs.min.js",
|
|
10
10
|
"author": "Stepan Kosatyi (https://kosatyi.com)",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"
|
|
13
|
-
"chokidar": "^3.5.3",
|
|
14
|
-
"glob": "^8.1.0",
|
|
15
|
-
"terser": "^5.16.1"
|
|
12
|
+
"chokidar": "^3.5.3"
|
|
16
13
|
},
|
|
17
14
|
"files": [
|
|
18
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"ejs.d.ts"
|
|
19
17
|
],
|
|
20
18
|
"scripts": {
|
|
21
19
|
"build": "rollup -c",
|
|
@@ -25,7 +23,11 @@
|
|
|
25
23
|
"postversion": "git push && git push --tags"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
|
-
"@kosatyi/rollup": "^0.0.1"
|
|
26
|
+
"@kosatyi/rollup": "^0.0.1",
|
|
27
|
+
"@babel/core": "^7.20.12",
|
|
28
|
+
"@babel/preset-env": "^7.20.2",
|
|
29
|
+
"glob": "^8.1.0",
|
|
30
|
+
"terser": "^5.16.1"
|
|
29
31
|
},
|
|
30
32
|
"directories": {
|
|
31
33
|
"test": "test"
|
package/dist/build.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const glob = require('glob');
|
|
8
|
-
const { minify } = require('terser');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const build = (ejs,source,target) => {
|
|
12
|
-
glob('**/*.{mjs,ejs}', { cwd: source }, function (er, list) {
|
|
13
|
-
const result = list.map(async (file) => {
|
|
14
|
-
const contents = fs.readFileSync(path.join('views', file)).toString();
|
|
15
|
-
const template = ejs.compile(contents, file);
|
|
16
|
-
const source = await minify(template.source, {
|
|
17
|
-
compress: {
|
|
18
|
-
dead_code: false,
|
|
19
|
-
side_effects: false,
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
name: file,
|
|
24
|
-
content: source.code,
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
Promise.all(result).then((files) => {
|
|
28
|
-
fs.writeFileSync(target, ejs.wrapper(files));
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
exports.build = build;
|