@memberjunction/templates 1.5.3 → 1.6.1
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/TemplateEngine.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { UserInfo } from "@memberjunction/core";
|
|
2
|
+
import { TemplateContentEntity } from "@memberjunction/core-entities";
|
|
3
3
|
import * as nunjucks from 'nunjucks';
|
|
4
|
-
import { TemplateEntityExtended, TemplateRenderResult } from '@memberjunction/templates-base-types';
|
|
4
|
+
import { TemplateEntityExtended, TemplateRenderResult, TemplateEngineBase } from '@memberjunction/templates-base-types';
|
|
5
5
|
/**
|
|
6
6
|
* This class extends the nunjucks loader to allow adding templates directly to the loader
|
|
7
7
|
*/
|
|
@@ -24,32 +24,12 @@ export declare class TemplateEntityLoader extends nunjucks.Loader {
|
|
|
24
24
|
/**
|
|
25
25
|
* TemplateEngine is used for accessing template metadata/caching it, and rendering templates
|
|
26
26
|
*/
|
|
27
|
-
export declare class
|
|
28
|
-
|
|
29
|
-
* Returns the global instance of the class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of it, always use this method to get the instance.
|
|
30
|
-
*/
|
|
31
|
-
static get Instance(): TemplateEngine;
|
|
32
|
-
Config(forceRefresh?: boolean, contextUser?: UserInfo): Promise<void>;
|
|
27
|
+
export declare class TemplateEngineServer extends TemplateEngineBase {
|
|
28
|
+
static get Instance(): TemplateEngineServer;
|
|
33
29
|
protected AdditionalLoading(contextUser?: UserInfo): Promise<void>;
|
|
34
30
|
private _nunjucksEnv;
|
|
35
31
|
private _templateLoader;
|
|
36
|
-
private _Templates;
|
|
37
|
-
get Templates(): TemplateEntityExtended[];
|
|
38
|
-
private _TemplateContentTypes;
|
|
39
|
-
get TemplateContentTypes(): TemplateContentTypeEntity[];
|
|
40
|
-
private _TemplateCategories;
|
|
41
|
-
get TemplateCategories(): TemplateCategoryEntity[];
|
|
42
|
-
private _TemplateContents;
|
|
43
|
-
get TemplateContents(): TemplateContentEntity[];
|
|
44
|
-
private _TemplateParams;
|
|
45
|
-
get TemplateParams(): TemplateParamEntity[];
|
|
46
32
|
AddTemplate(templateEntity: TemplateEntityExtended): void;
|
|
47
|
-
/**
|
|
48
|
-
* Convenience method to find a template by name, case-insensitive
|
|
49
|
-
* @param templateName
|
|
50
|
-
* @returns
|
|
51
|
-
*/
|
|
52
|
-
FindTemplate(templateName: string): TemplateEntityExtended;
|
|
53
33
|
/**
|
|
54
34
|
* Renders a template with the given data.
|
|
55
35
|
* @param templateEntity the template object to render
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../src/TemplateEngine.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../src/TemplateEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAA0B,qBAAqB,EAAkD,MAAM,+BAA+B,CAAC;AAC9I,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AAEvH;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ,CAAC,MAAM;IAC9C,KAAK,EAAE,IAAI,CAAC;IAEnB,OAAO,CAAC,SAAS,CAAwD;IAEzE;;;;OAIG;IACI,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;IAIvE;;;;OAIG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG;CAW/C;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,kBAAkB;IACxD,WAAkB,QAAQ,IAAI,oBAAoB,CAEjD;cAEe,iBAAiB,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBxE,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,eAAe,CAAuB;IAGvC,WAAW,CAAC,cAAc,EAAE,sBAAsB;IAKzD;;;;;OAKG;IACU,cAAc,CAAC,cAAc,EAAE,sBAAsB,EAAE,eAAe,EAAE,qBAAqB,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoCrJ;;;;OAIG;cACa,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;CAW/F"}
|
package/dist/TemplateEngine.js
CHANGED
|
@@ -23,11 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const core_1 = require("@memberjunction/core");
|
|
26
|
+
exports.TemplateEngineServer = exports.TemplateEntityLoader = void 0;
|
|
28
27
|
const nunjucks = __importStar(require("nunjucks"));
|
|
29
28
|
const global_1 = require("@memberjunction/global");
|
|
30
29
|
const TemplateExtensionBase_1 = require("./extensions/TemplateExtensionBase");
|
|
30
|
+
const templates_base_types_1 = require("@memberjunction/templates-base-types");
|
|
31
31
|
/**
|
|
32
32
|
* This class extends the nunjucks loader to allow adding templates directly to the loader
|
|
33
33
|
*/
|
|
@@ -65,44 +65,12 @@ exports.TemplateEntityLoader = TemplateEntityLoader;
|
|
|
65
65
|
/**
|
|
66
66
|
* TemplateEngine is used for accessing template metadata/caching it, and rendering templates
|
|
67
67
|
*/
|
|
68
|
-
class
|
|
69
|
-
/**
|
|
70
|
-
* Returns the global instance of the class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of it, always use this method to get the instance.
|
|
71
|
-
*/
|
|
68
|
+
class TemplateEngineServer extends templates_base_types_1.TemplateEngineBase {
|
|
72
69
|
static get Instance() {
|
|
73
70
|
return super.getInstance();
|
|
74
71
|
}
|
|
75
|
-
async Config(forceRefresh, contextUser) {
|
|
76
|
-
const c = [
|
|
77
|
-
{
|
|
78
|
-
EntityName: 'Template Content Types',
|
|
79
|
-
PropertyName: '_TemplateContentTypes',
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
EntityName: 'Template Categories',
|
|
83
|
-
PropertyName: '_TemplateCategories'
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
EntityName: 'Templates',
|
|
87
|
-
PropertyName: '_Templates',
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
EntityName: 'Template Contents',
|
|
91
|
-
PropertyName: '_TemplateContents',
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
EntityName: 'Template Params',
|
|
95
|
-
PropertyName: '_TemplateParams',
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
await this.Load(c, forceRefresh, contextUser);
|
|
99
|
-
}
|
|
100
72
|
async AdditionalLoading(contextUser) {
|
|
101
|
-
|
|
102
|
-
this.Templates.forEach((t) => {
|
|
103
|
-
t.Content = this.TemplateContents.filter((tc) => tc.TemplateID === t.ID);
|
|
104
|
-
t.Params = this.TemplateParams.filter((tp) => tp.TemplateID === t.ID);
|
|
105
|
-
});
|
|
73
|
+
await super.AdditionalLoading(contextUser);
|
|
106
74
|
// do this after the templates are loaded and doing it inside AdditionalLoading() ensures it is done after the templates are loaded and
|
|
107
75
|
// only done once
|
|
108
76
|
this._templateLoader = new TemplateEntityLoader();
|
|
@@ -119,32 +87,9 @@ class TemplateEngine extends core_1.BaseEngine {
|
|
|
119
87
|
// this._nunjucksEnv.addExtension('AIPrompt', aiPromptExtension);
|
|
120
88
|
}
|
|
121
89
|
}
|
|
122
|
-
get Templates() {
|
|
123
|
-
return this._Templates;
|
|
124
|
-
}
|
|
125
|
-
get TemplateContentTypes() {
|
|
126
|
-
return this._TemplateContentTypes;
|
|
127
|
-
}
|
|
128
|
-
get TemplateCategories() {
|
|
129
|
-
return this._TemplateCategories;
|
|
130
|
-
}
|
|
131
|
-
get TemplateContents() {
|
|
132
|
-
return this._TemplateContents;
|
|
133
|
-
}
|
|
134
|
-
get TemplateParams() {
|
|
135
|
-
return this._TemplateParams;
|
|
136
|
-
}
|
|
137
90
|
AddTemplate(templateEntity) {
|
|
138
91
|
this._templateLoader.AddTemplate(templateEntity.ID, templateEntity);
|
|
139
92
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Convenience method to find a template by name, case-insensitive
|
|
142
|
-
* @param templateName
|
|
143
|
-
* @returns
|
|
144
|
-
*/
|
|
145
|
-
FindTemplate(templateName) {
|
|
146
|
-
return this.Templates.find((t) => t.Name.trim().toLowerCase() === templateName.trim().toLowerCase());
|
|
147
|
-
}
|
|
148
93
|
/**
|
|
149
94
|
* Renders a template with the given data.
|
|
150
95
|
* @param templateEntity the template object to render
|
|
@@ -202,5 +147,5 @@ class TemplateEngine extends core_1.BaseEngine {
|
|
|
202
147
|
});
|
|
203
148
|
}
|
|
204
149
|
}
|
|
205
|
-
exports.
|
|
150
|
+
exports.TemplateEngineServer = TemplateEngineServer;
|
|
206
151
|
//# sourceMappingURL=TemplateEngine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngine.js","sourceRoot":"","sources":["../src/TemplateEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"TemplateEngine.js","sourceRoot":"","sources":["../src/TemplateEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mDAAqC;AACrC,mDAAkD;AAClD,8EAA2E;AAC3E,+EAAuH;AAEvH;;GAEG;AACH,MAAa,oBAAqB,SAAQ,QAAQ,CAAC,MAAM;IAAzD;;QAGY,cAAS,GAAqD,EAAE,CAAC;IA2B7E,CAAC;IAzBG;;;;OAIG;IACI,WA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AAC,OAAO;aACrB,CAAC;QACN,CAAC;IACL,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,mBAAmB,CAAC,QAA2B,EAAE,IAAS;QACtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;gBAClC,IAAI,GAAG,EAAE,CAAC;oBACN,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACJ,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpB,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA7FD,oDA6FC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/templates",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "MemberJunction Templating Engine and Utilities - Used for any application that requires templating utility functionality. NOTE: this package does use Angular Universal for compilation but is not marked with the usual ng prefix because it is a server-side library and not used within Angular apps.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"typescript": "^5.4.5"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@memberjunction/core": "1.
|
|
22
|
-
"@memberjunction/templates-base-types": "1.
|
|
23
|
-
"@memberjunction/ai": "1.
|
|
24
|
-
"@memberjunction/aiengine": "1.
|
|
25
|
-
"@memberjunction/ai-groq": "1.
|
|
26
|
-
"@memberjunction/core-entities": "1.
|
|
27
|
-
"@memberjunction/global": "1.
|
|
21
|
+
"@memberjunction/core": "1.6.1",
|
|
22
|
+
"@memberjunction/templates-base-types": "1.6.1",
|
|
23
|
+
"@memberjunction/ai": "1.6.1",
|
|
24
|
+
"@memberjunction/aiengine": "1.6.1",
|
|
25
|
+
"@memberjunction/ai-groq": "1.6.1",
|
|
26
|
+
"@memberjunction/core-entities": "1.6.1",
|
|
27
|
+
"@memberjunction/global": "1.6.1",
|
|
28
28
|
"nunjucks": "3.2.4"
|
|
29
29
|
}
|
|
30
30
|
}
|