@memberjunction/templates 2.30.0 → 2.32.0
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
|
@@ -43,13 +43,29 @@ export declare class TemplateEngineServer extends TemplateEngineBase {
|
|
|
43
43
|
* @param data
|
|
44
44
|
*/
|
|
45
45
|
RenderTemplate(templateEntity: TemplateEntityExtended, templateContent: TemplateContentEntity, data: any, SkipValidation?: boolean): Promise<TemplateRenderResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Simple rendering utilty method. Use this to render any valid Nunjucks Template within the Nunjucks environment created by the Template Engine
|
|
48
|
+
* without having to use the stored metadata (Templates/Template Contents/Template Params/etc) within the MJ database. This is useful when you have
|
|
49
|
+
* a template that is stored elsewhere or dynamically created and you just want to render it with some data.
|
|
50
|
+
* @param templateText
|
|
51
|
+
* @param data
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
RenderTemplateSimple(templateText: string, data: any): Promise<TemplateRenderResult>;
|
|
46
55
|
/**
|
|
47
56
|
* This method is responsible for creating a new Nunjucks template, caching it, and returning it.
|
|
48
57
|
* If the templateContentId already had a template created, it will return that template from the cache.
|
|
49
|
-
* @param templateId
|
|
58
|
+
* @param templateId - must be provided if you want to cache the template, if not provided the template will not be cached
|
|
50
59
|
* @param templateText
|
|
60
|
+
* @param cacheTemplate - if true, the template will be cached, otherwise it will not be cached
|
|
61
|
+
*/
|
|
62
|
+
protected getNunjucksTemplate(templateContentId: string, templateText: string, cacheTemplate: boolean): any;
|
|
63
|
+
/**
|
|
64
|
+
* Simple utility method to create a new Nunjucks template object and bind it to our Nunjucks environment.
|
|
65
|
+
* @param templateText
|
|
66
|
+
* @returns
|
|
51
67
|
*/
|
|
52
|
-
protected
|
|
68
|
+
protected createNunjucksTemplate(templateText: string): any;
|
|
53
69
|
ClearTemplateCache(): void;
|
|
54
70
|
/**
|
|
55
71
|
* Promisifies the Nunjucks template rendering process.
|
|
@@ -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,EAAY,QAAQ,EAAuB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,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;IAED,OAAO,CAAC,uBAAuB,CAAkB;cACjC,iBAAiB,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBjE,aAAa,IAAI,IAAI;IAK5B,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,eAAe,CAAuB;IAE9C;;OAEG;IACH,OAAO,CAAC,cAAc,CAA4C;IAE3D,WAAW,CAAC,cAAc,EAAE,sBAAsB;IAKzD;;;;;OAKG;IACU,cAAc,CAAC,cAAc,EAAE,sBAAsB,EAAE,eAAe,EAAE,qBAAqB,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgD/K;;;;;;;OAOG;IACU,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoBjG;;;;;;OAMG;IACH,SAAS,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,GAAG;IAgB3G;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG;IAIpD,kBAAkB;IAIzB;;;;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
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.TemplateEngineServer = exports.TemplateEntityLoader = void 0;
|
|
27
|
+
const core_1 = require("@memberjunction/core");
|
|
27
28
|
const nunjucks = __importStar(require("nunjucks"));
|
|
28
29
|
const global_1 = require("@memberjunction/global");
|
|
29
30
|
const TemplateExtensionBase_1 = require("./extensions/TemplateExtensionBase");
|
|
@@ -139,7 +140,7 @@ class TemplateEngineServer extends templates_base_types_1.TemplateEngineBase {
|
|
|
139
140
|
};
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
|
-
const template = this.getNunjucksTemplate(templateContent.ID, templateContent.TemplateText);
|
|
143
|
+
const template = this.getNunjucksTemplate(templateContent.ID, templateContent.TemplateText, true);
|
|
143
144
|
const result = await this.renderTemplateAsync(template, data);
|
|
144
145
|
return {
|
|
145
146
|
Success: true,
|
|
@@ -155,19 +156,62 @@ class TemplateEngineServer extends templates_base_types_1.TemplateEngineBase {
|
|
|
155
156
|
};
|
|
156
157
|
}
|
|
157
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Simple rendering utilty method. Use this to render any valid Nunjucks Template within the Nunjucks environment created by the Template Engine
|
|
161
|
+
* without having to use the stored metadata (Templates/Template Contents/Template Params/etc) within the MJ database. This is useful when you have
|
|
162
|
+
* a template that is stored elsewhere or dynamically created and you just want to render it with some data.
|
|
163
|
+
* @param templateText
|
|
164
|
+
* @param data
|
|
165
|
+
* @returns
|
|
166
|
+
*/
|
|
167
|
+
async RenderTemplateSimple(templateText, data) {
|
|
168
|
+
try {
|
|
169
|
+
const template = this.createNunjucksTemplate(templateText);
|
|
170
|
+
const result = await this.renderTemplateAsync(template, data);
|
|
171
|
+
return {
|
|
172
|
+
Success: true,
|
|
173
|
+
Output: result,
|
|
174
|
+
Message: undefined
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
(0, core_1.LogError)(e);
|
|
179
|
+
return {
|
|
180
|
+
Success: false,
|
|
181
|
+
Output: null,
|
|
182
|
+
Message: e.message
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
158
186
|
/**
|
|
159
187
|
* This method is responsible for creating a new Nunjucks template, caching it, and returning it.
|
|
160
188
|
* If the templateContentId already had a template created, it will return that template from the cache.
|
|
161
|
-
* @param templateId
|
|
189
|
+
* @param templateId - must be provided if you want to cache the template, if not provided the template will not be cached
|
|
162
190
|
* @param templateText
|
|
191
|
+
* @param cacheTemplate - if true, the template will be cached, otherwise it will not be cached
|
|
163
192
|
*/
|
|
164
|
-
getNunjucksTemplate(templateContentId, templateText) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
193
|
+
getNunjucksTemplate(templateContentId, templateText, cacheTemplate) {
|
|
194
|
+
if (templateContentId && cacheTemplate) {
|
|
195
|
+
let template = this._templateCache.get(templateContentId);
|
|
196
|
+
if (!template) {
|
|
197
|
+
template = this.createNunjucksTemplate(templateText);
|
|
198
|
+
this._templateCache.set(templateContentId, template);
|
|
199
|
+
}
|
|
200
|
+
return template;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// we don't have a template ID which means this is a dyanmic template, and so we don't want to do
|
|
204
|
+
// anything with the cache, we just create a new nunjucks template and return it
|
|
205
|
+
return this.createNunjucksTemplate(templateText);
|
|
169
206
|
}
|
|
170
|
-
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Simple utility method to create a new Nunjucks template object and bind it to our Nunjucks environment.
|
|
210
|
+
* @param templateText
|
|
211
|
+
* @returns
|
|
212
|
+
*/
|
|
213
|
+
createNunjucksTemplate(templateText) {
|
|
214
|
+
return new nunjucks.Template(templateText, this._nunjucksEnv);
|
|
171
215
|
}
|
|
172
216
|
ClearTemplateCache() {
|
|
173
217
|
this._templateCache.clear();
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA+E;AAE/E,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,WAAW,CAAC,UAAkB,EAAE,QAAgC;QACnE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,IAAY,EAAE,QAAa;QACxC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,QAAQ,GAAG,IAAI,C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/templates",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.0",
|
|
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": "2.
|
|
22
|
-
"@memberjunction/templates-base-types": "2.
|
|
23
|
-
"@memberjunction/ai": "2.
|
|
24
|
-
"@memberjunction/aiengine": "2.
|
|
25
|
-
"@memberjunction/ai-groq": "2.
|
|
26
|
-
"@memberjunction/core-entities": "2.
|
|
27
|
-
"@memberjunction/global": "2.
|
|
21
|
+
"@memberjunction/core": "2.32.0",
|
|
22
|
+
"@memberjunction/templates-base-types": "2.32.0",
|
|
23
|
+
"@memberjunction/ai": "2.32.0",
|
|
24
|
+
"@memberjunction/aiengine": "2.32.0",
|
|
25
|
+
"@memberjunction/ai-groq": "2.32.0",
|
|
26
|
+
"@memberjunction/core-entities": "2.32.0",
|
|
27
|
+
"@memberjunction/global": "2.32.0",
|
|
28
28
|
"nunjucks": "3.2.4"
|
|
29
29
|
}
|
|
30
30
|
}
|