@memberjunction/templates 1.4.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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/template-engine.d.ts +6 -0
- package/dist/template-engine.d.ts.map +1 -0
- package/dist/template-engine.js +166 -0
- package/dist/template-engine.js.map +1 -0
- package/package.json +35 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-engine.d.ts","sourceRoot":"","sources":["../src/template-engine.ts"],"names":[],"mappings":"AAoCA,qBACa,qBAAqB;IAC9B,OAAO,CAAC,UAAU,CAAS;;IAKvB,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,GAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CAevE"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
36
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
37
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
38
|
+
};
|
|
39
|
+
import { Injectable, NgModule, Component } from '@angular/core';
|
|
40
|
+
import { isPlatformServer } from '@angular/common';
|
|
41
|
+
import { renderModule } from '@angular/platform-server';
|
|
42
|
+
import { ServerModule } from '@angular/platform-server';
|
|
43
|
+
let TemplateRootComponent = (() => {
|
|
44
|
+
let _classDecorators = [Component({
|
|
45
|
+
selector: 'app-template-root',
|
|
46
|
+
template: 'hola' // This will be dynamically populated
|
|
47
|
+
})];
|
|
48
|
+
let _classDescriptor;
|
|
49
|
+
let _classExtraInitializers = [];
|
|
50
|
+
let _classThis;
|
|
51
|
+
var TemplateRootComponent = _classThis = class {
|
|
52
|
+
constructor() {
|
|
53
|
+
this.context = {}; // Data passed to the template
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
__setFunctionName(_classThis, "TemplateRootComponent");
|
|
57
|
+
(() => {
|
|
58
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
59
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
60
|
+
TemplateRootComponent = _classThis = _classDescriptor.value;
|
|
61
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
62
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
63
|
+
})();
|
|
64
|
+
return TemplateRootComponent = _classThis;
|
|
65
|
+
})();
|
|
66
|
+
let TemplateRenderModule = (() => {
|
|
67
|
+
let _classDecorators = [NgModule({
|
|
68
|
+
imports: [ServerModule],
|
|
69
|
+
declarations: [TemplateRootComponent],
|
|
70
|
+
bootstrap: [TemplateRootComponent],
|
|
71
|
+
})];
|
|
72
|
+
let _classDescriptor;
|
|
73
|
+
let _classExtraInitializers = [];
|
|
74
|
+
let _classThis;
|
|
75
|
+
var TemplateRenderModule = _classThis = class {
|
|
76
|
+
};
|
|
77
|
+
__setFunctionName(_classThis, "TemplateRenderModule");
|
|
78
|
+
(() => {
|
|
79
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
80
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
81
|
+
TemplateRenderModule = _classThis = _classDescriptor.value;
|
|
82
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
83
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
84
|
+
})();
|
|
85
|
+
return TemplateRenderModule = _classThis;
|
|
86
|
+
})();
|
|
87
|
+
// Dynamically create a component with the provided template
|
|
88
|
+
let DynamicTemplateComponent = (() => {
|
|
89
|
+
let _classDecorators = [Component({
|
|
90
|
+
selector: 'app-dynamic-template',
|
|
91
|
+
template: ''
|
|
92
|
+
})];
|
|
93
|
+
let _classDescriptor;
|
|
94
|
+
let _classExtraInitializers = [];
|
|
95
|
+
let _classThis;
|
|
96
|
+
var DynamicTemplateComponent = _classThis = class {
|
|
97
|
+
constructor() {
|
|
98
|
+
this.context = {};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
__setFunctionName(_classThis, "DynamicTemplateComponent");
|
|
102
|
+
(() => {
|
|
103
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
104
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
105
|
+
DynamicTemplateComponent = _classThis = _classDescriptor.value;
|
|
106
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
107
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
108
|
+
})();
|
|
109
|
+
return DynamicTemplateComponent = _classThis;
|
|
110
|
+
})();
|
|
111
|
+
// Dynamically create a module to house the component
|
|
112
|
+
let DynamicTemplateModule = (() => {
|
|
113
|
+
let _classDecorators = [NgModule({
|
|
114
|
+
imports: [TemplateRenderModule],
|
|
115
|
+
declarations: [DynamicTemplateComponent]
|
|
116
|
+
})];
|
|
117
|
+
let _classDescriptor;
|
|
118
|
+
let _classExtraInitializers = [];
|
|
119
|
+
let _classThis;
|
|
120
|
+
var DynamicTemplateModule = _classThis = class {
|
|
121
|
+
};
|
|
122
|
+
__setFunctionName(_classThis, "DynamicTemplateModule");
|
|
123
|
+
(() => {
|
|
124
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
125
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
126
|
+
DynamicTemplateModule = _classThis = _classDescriptor.value;
|
|
127
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
128
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
129
|
+
})();
|
|
130
|
+
return DynamicTemplateModule = _classThis;
|
|
131
|
+
})();
|
|
132
|
+
let TemplateEngineService = (() => {
|
|
133
|
+
let _classDecorators = [Injectable({ providedIn: 'root' })];
|
|
134
|
+
let _classDescriptor;
|
|
135
|
+
let _classExtraInitializers = [];
|
|
136
|
+
let _classThis;
|
|
137
|
+
var TemplateEngineService = _classThis = class {
|
|
138
|
+
constructor() {
|
|
139
|
+
this.platformId = 'server'; // Directly set the platform ID
|
|
140
|
+
}
|
|
141
|
+
async render(templateHtml, context = {}) {
|
|
142
|
+
if (!isPlatformServer(this.platformId)) {
|
|
143
|
+
throw new Error('Template rendering must be done on the server.');
|
|
144
|
+
}
|
|
145
|
+
// Use Angular Universal's renderModule
|
|
146
|
+
const html = await renderModule(DynamicTemplateModule, {
|
|
147
|
+
document: `<app-template-root></app-template-root>`,
|
|
148
|
+
extraProviders: [
|
|
149
|
+
{ provide: TemplateRootComponent, useValue: { context } }
|
|
150
|
+
]
|
|
151
|
+
});
|
|
152
|
+
return html;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
__setFunctionName(_classThis, "TemplateEngineService");
|
|
156
|
+
(() => {
|
|
157
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
158
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
159
|
+
TemplateEngineService = _classThis = _classDescriptor.value;
|
|
160
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
161
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
162
|
+
})();
|
|
163
|
+
return TemplateEngineService = _classThis;
|
|
164
|
+
})();
|
|
165
|
+
export { TemplateEngineService };
|
|
166
|
+
//# sourceMappingURL=template-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-engine.js","sourceRoot":"","sources":["../src/template-engine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;IAMlD,qBAAqB;4BAJ1B,SAAS,CAAC;YACT,QAAQ,EAAE,mBAAmB;YAC7B,QAAQ,EAAE,MAAM,CAAC,qCAAqC;SACvD,CAAC;;;;;;YAEA,YAAO,GAAQ,EAAE,CAAC,CAAC,8BAA8B;QACnD,CAAC;;;;;QAFD,6KAEC;;;QAFK,uDAAqB;;;;IASrB,oBAAoB;4BALzB,QAAQ,C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
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@memberjunction/templates",
|
|
3
|
+
"version": "1.4.1",
|
|
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
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"/dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "ts-node-dev src/index.ts",
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"ts-node-dev": "^2.0.0",
|
|
21
|
+
"typescript": "^5.3.3",
|
|
22
|
+
"@types/node": "^20.1.7"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@memberjunction/core": "~1.4.1",
|
|
26
|
+
"@memberjunction/core-entities": "~1.4.1",
|
|
27
|
+
"@memberjunction/global": "~1.4.1",
|
|
28
|
+
"@memberjunction/data-context": "~1.4.1",
|
|
29
|
+
"@angular/core": "~17.2.2",
|
|
30
|
+
"@angular/common": "~17.2.2",
|
|
31
|
+
"@angular/compiler": "~17.2.2",
|
|
32
|
+
"@angular/platform-server": "~17.2.2",
|
|
33
|
+
"@angular/platform-browser-dynamic": "~17.2.2"
|
|
34
|
+
}
|
|
35
|
+
}
|