@kosatyi/ejs 0.0.110 → 0.0.111
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 +295 -200
- package/dist/cjs/bundler.js +9 -1
- package/dist/cjs/element.js +1 -1
- package/dist/cjs/index.js +361 -277
- package/dist/cjs/worker.js +302 -224
- package/dist/esm/browser.js +77 -62
- package/dist/esm/bundler.js +9 -1
- package/dist/esm/index.js +195 -191
- package/dist/esm/worker.js +81 -83
- package/dist/umd/browser.js +832 -737
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/element.js +1 -1
- package/dist/umd/element.min.js +1 -1
- package/dist/umd/index.js +851 -767
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +302 -224
- package/dist/umd/worker.min.js +1 -1
- package/package.json +4 -4
- package/types/context.d.ts +19 -4
- package/types/ejs.d.ts +1 -1
- package/types/error.d.ts +5 -2
- package/types/worker.d.ts +0 -6
- package/dist/kosatyi-ejs-0.0.109.tgz +0 -0
- package/dist/umd/browser.js.map +0 -7
- package/dist/umd/browser.min.js.map +0 -7
package/dist/esm/worker.js
CHANGED
|
@@ -383,10 +383,10 @@ class EjsCompiler {
|
|
|
383
383
|
const result = Function.apply(null, params.concat(OUTPUT));
|
|
384
384
|
result.source = `(function(${params.join(',')}){\n${OUTPUT}\n});`;
|
|
385
385
|
return result
|
|
386
|
-
} catch (
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
386
|
+
} catch (e) {
|
|
387
|
+
e.filename = path;
|
|
388
|
+
e.source = OUTPUT;
|
|
389
|
+
error(0, e);
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
}
|
|
@@ -498,13 +498,11 @@ const element = (tag, attrs, content) => {
|
|
|
498
498
|
const resolve = (list) => {
|
|
499
499
|
return Promise.all(list || [])
|
|
500
500
|
.then((list) => list.join(''))
|
|
501
|
-
.catch((e) =>
|
|
502
|
-
return error(500, e)
|
|
503
|
-
})
|
|
501
|
+
.catch((e) => error(0, e))
|
|
504
502
|
};
|
|
505
503
|
|
|
506
504
|
const reject = (e) => {
|
|
507
|
-
return Promise.reject(error(
|
|
505
|
+
return Promise.reject(error(0, e))
|
|
508
506
|
};
|
|
509
507
|
|
|
510
508
|
const EjsBuffer = () => {
|
|
@@ -542,6 +540,7 @@ const EjsBuffer = () => {
|
|
|
542
540
|
const PARENT = Symbol('EjsContext.parentTemplate');
|
|
543
541
|
|
|
544
542
|
const createContext$1 = (config, methods) => {
|
|
543
|
+
const globals = config.globals || [];
|
|
545
544
|
const {
|
|
546
545
|
BLOCKS,
|
|
547
546
|
MACRO,
|
|
@@ -553,40 +552,41 @@ const createContext$1 = (config, methods) => {
|
|
|
553
552
|
COMPONENT,
|
|
554
553
|
ELEMENT,
|
|
555
554
|
} = config.vars;
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
555
|
+
class Context {
|
|
556
|
+
constructor(data) {
|
|
557
|
+
this[PARENT] = null;
|
|
558
|
+
this[BLOCKS] = {};
|
|
559
|
+
this[MACRO] = {};
|
|
560
|
+
Object.assign(
|
|
561
|
+
this,
|
|
562
|
+
omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]),
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
565
|
}
|
|
566
|
-
Object.
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
566
|
+
Object.defineProperties(Context.prototype, {
|
|
567
|
+
[BUFFER]: {
|
|
568
|
+
value: EjsBuffer(),
|
|
569
|
+
},
|
|
570
|
+
[BLOCKS]: {
|
|
571
|
+
value: {},
|
|
572
|
+
writable: true,
|
|
573
|
+
},
|
|
574
|
+
[MACRO]: {
|
|
575
|
+
value: {},
|
|
576
|
+
writable: true,
|
|
577
|
+
},
|
|
578
|
+
[LAYOUT]: {
|
|
579
|
+
value: false,
|
|
580
|
+
writable: true,
|
|
581
|
+
},
|
|
582
|
+
[EXTEND]: {
|
|
583
|
+
value: false,
|
|
584
|
+
writable: true,
|
|
585
|
+
},
|
|
586
|
+
[PARENT]: {
|
|
587
|
+
value: null,
|
|
588
|
+
writable: true,
|
|
589
|
+
},
|
|
590
590
|
setParentTemplate: {
|
|
591
591
|
value(value) {
|
|
592
592
|
this[PARENT] = value;
|
|
@@ -599,32 +599,34 @@ const createContext$1 = (config, methods) => {
|
|
|
599
599
|
},
|
|
600
600
|
},
|
|
601
601
|
useEscapeValue: {
|
|
602
|
-
|
|
602
|
+
value() {
|
|
603
|
+
return escapeValue
|
|
604
|
+
},
|
|
603
605
|
},
|
|
604
606
|
useComponent: {
|
|
605
|
-
|
|
607
|
+
value() {
|
|
606
608
|
if (isFunction(this[COMPONENT])) {
|
|
607
609
|
return this[COMPONENT].bind(this)
|
|
608
610
|
} else {
|
|
609
611
|
return function () {
|
|
610
|
-
|
|
612
|
+
error(2, `${COMPONENT} must be a function`);
|
|
611
613
|
}
|
|
612
614
|
}
|
|
613
615
|
},
|
|
614
616
|
},
|
|
615
617
|
useElement: {
|
|
616
|
-
|
|
618
|
+
value() {
|
|
617
619
|
if (isFunction(this[ELEMENT])) {
|
|
618
620
|
return this[ELEMENT].bind(this)
|
|
619
621
|
} else {
|
|
620
622
|
return () => {
|
|
621
|
-
|
|
623
|
+
error(2, `${ELEMENT} must be a function`);
|
|
622
624
|
}
|
|
623
625
|
}
|
|
624
626
|
},
|
|
625
627
|
},
|
|
626
628
|
useBuffer: {
|
|
627
|
-
|
|
629
|
+
value() {
|
|
628
630
|
return this[BUFFER]
|
|
629
631
|
},
|
|
630
632
|
},
|
|
@@ -677,17 +679,18 @@ const createContext$1 = (config, methods) => {
|
|
|
677
679
|
},
|
|
678
680
|
echo: {
|
|
679
681
|
value() {
|
|
680
|
-
return [].slice.call(arguments).forEach(this.useBuffer)
|
|
682
|
+
return [].slice.call(arguments).forEach(this.useBuffer())
|
|
681
683
|
},
|
|
682
684
|
},
|
|
683
685
|
fn: {
|
|
684
686
|
value(callback) {
|
|
687
|
+
const buffer = this.useBuffer();
|
|
685
688
|
const context = this;
|
|
686
689
|
return function () {
|
|
687
690
|
if (isFunction(callback)) {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
return
|
|
691
|
+
buffer.backup();
|
|
692
|
+
buffer(callback.apply(context, arguments));
|
|
693
|
+
return buffer.restore()
|
|
691
694
|
}
|
|
692
695
|
}
|
|
693
696
|
},
|
|
@@ -804,14 +807,22 @@ const createContext$1 = (config, methods) => {
|
|
|
804
807
|
value() {},
|
|
805
808
|
writable: true,
|
|
806
809
|
},
|
|
810
|
+
require: {
|
|
811
|
+
value() {},
|
|
812
|
+
writable: true,
|
|
813
|
+
},
|
|
814
|
+
render: {
|
|
815
|
+
value() {},
|
|
816
|
+
writable: true,
|
|
817
|
+
},
|
|
807
818
|
});
|
|
808
819
|
Object.entries(methods).forEach(([name, value]) => {
|
|
809
820
|
if (isFunction(value) && globals.includes(name)) {
|
|
810
|
-
value = value.bind(
|
|
821
|
+
value = value.bind(Context.prototype);
|
|
811
822
|
}
|
|
812
|
-
|
|
823
|
+
Context.prototype[name] = value;
|
|
813
824
|
});
|
|
814
|
-
return
|
|
825
|
+
return Context
|
|
815
826
|
};
|
|
816
827
|
|
|
817
828
|
class EjsContext {
|
|
@@ -849,6 +860,10 @@ class EjsInstance {
|
|
|
849
860
|
'compile',
|
|
850
861
|
'helpers',
|
|
851
862
|
]
|
|
863
|
+
/**
|
|
864
|
+
*
|
|
865
|
+
* @param {EjsConfig} options
|
|
866
|
+
*/
|
|
852
867
|
constructor(options = {}) {
|
|
853
868
|
bindContext(this, this.constructor.exports);
|
|
854
869
|
this.#methods = {};
|
|
@@ -911,10 +926,10 @@ class EjsInstance {
|
|
|
911
926
|
.then((callback) =>
|
|
912
927
|
callback.apply(data, [
|
|
913
928
|
data,
|
|
914
|
-
data.useComponent,
|
|
915
|
-
data.useElement,
|
|
916
|
-
data.useBuffer,
|
|
917
|
-
data.useEscapeValue,
|
|
929
|
+
data.useComponent(),
|
|
930
|
+
data.useElement(),
|
|
931
|
+
data.useBuffer(),
|
|
932
|
+
data.useEscapeValue(),
|
|
918
933
|
]),
|
|
919
934
|
)
|
|
920
935
|
}
|
|
@@ -936,9 +951,6 @@ class EjsInstance {
|
|
|
936
951
|
}
|
|
937
952
|
}
|
|
938
953
|
|
|
939
|
-
/**
|
|
940
|
-
* @type {{[p:string]:Function}}
|
|
941
|
-
*/
|
|
942
954
|
const templateCache = {};
|
|
943
955
|
|
|
944
956
|
const getOrigin = (url, secure) => {
|
|
@@ -947,37 +959,23 @@ const getOrigin = (url, secure) => {
|
|
|
947
959
|
return url.origin
|
|
948
960
|
};
|
|
949
961
|
|
|
962
|
+
const resolver = async (path, name, error) => {
|
|
963
|
+
if (isFunction(templateCache[name])) {
|
|
964
|
+
return templateCache[name]
|
|
965
|
+
}
|
|
966
|
+
error(1, `template ${name} not found`);
|
|
967
|
+
};
|
|
968
|
+
|
|
950
969
|
const { render, createContext, helpers, configure } = new EjsInstance({
|
|
951
970
|
cache: false,
|
|
952
971
|
strict: true,
|
|
953
|
-
|
|
954
|
-
if (isFunction(templateCache[name])) {
|
|
955
|
-
return templateCache[name]
|
|
956
|
-
}
|
|
957
|
-
error(404, `template ${name} not found`);
|
|
958
|
-
},
|
|
972
|
+
resolver,
|
|
959
973
|
});
|
|
960
974
|
|
|
961
|
-
/**
|
|
962
|
-
* @param {{[p:string],Function}} templates
|
|
963
|
-
*/
|
|
964
975
|
function useTemplates(templates = {}) {
|
|
965
976
|
Object.assign(templateCache, templates);
|
|
966
977
|
}
|
|
967
978
|
|
|
968
|
-
/**
|
|
969
|
-
* @typedef {{[p:string]:any}} HonoContext
|
|
970
|
-
* @property {function(*):Promise<Response>} html
|
|
971
|
-
* @property {function():Promise<Response>} notFound
|
|
972
|
-
* @property {function(methods:{}):void} helpers
|
|
973
|
-
* @property {function(name:string,data:{}):Promise<string>} render
|
|
974
|
-
* @property {function(name:string,data:{}):Promise<string>} ejs
|
|
975
|
-
* @property {EjsContext} data
|
|
976
|
-
*/
|
|
977
|
-
/**
|
|
978
|
-
* @param {RendererParams} options
|
|
979
|
-
* @return {(function(c:HonoContext, next): Promise<any>)|*}
|
|
980
|
-
*/
|
|
981
979
|
function useRenderer(options = {}) {
|
|
982
980
|
useTemplates(options.templates ?? {});
|
|
983
981
|
return async (c, next) => {
|