edgexpress 3.0.0 → 3.0.2

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.
Files changed (92) hide show
  1. package/eslint.config.cjs +6 -0
  2. package/examples/index.js +41 -0
  3. package/examples/views/components/layout/main.edge +26 -0
  4. package/examples/views/components/modal.edge +27 -0
  5. package/examples/views/home.edge +84 -0
  6. package/examples/views/partials/button.edge +1 -0
  7. package/examples/views/partials/home-footer.edge +49 -0
  8. package/examples/views/partials/home-header.edge +61 -0
  9. package/examples/views/welcome.edge +22 -0
  10. package/index.d.ts +7 -0
  11. package/package.json +12 -4
  12. package/src/cache_manager.d.ts +28 -0
  13. package/src/cache_manager.js +58 -0
  14. package/src/compiler.d.ts +73 -0
  15. package/src/compiler.js +319 -0
  16. package/src/component/props.d.ts +53 -0
  17. package/src/component/props.js +110 -0
  18. package/src/edge/globals.d.ts +5 -0
  19. package/src/edge/globals.js +95 -0
  20. package/src/edge/main.d.ts +192 -0
  21. package/src/edge/main.js +334 -0
  22. package/src/edge/renderer.d.ts +44 -0
  23. package/src/edge/renderer.js +85 -0
  24. package/src/edge/stacks.d.ts +22 -0
  25. package/src/edge/stacks.js +98 -0
  26. package/src/loader.d.ts +138 -0
  27. package/src/loader.js +347 -0
  28. package/src/migrate/globals.d.ts +1 -0
  29. package/src/migrate/globals.js +100 -0
  30. package/src/migrate/plugin.d.ts +2 -0
  31. package/src/migrate/plugin.js +58 -0
  32. package/src/migrate/props.d.ts +66 -0
  33. package/src/migrate/props.js +129 -0
  34. package/src/migrate/tags/layout.d.ts +6 -0
  35. package/src/migrate/tags/layout.js +25 -0
  36. package/src/migrate/tags/main.d.ts +4 -0
  37. package/src/migrate/tags/main.js +19 -0
  38. package/src/migrate/tags/section.d.ts +6 -0
  39. package/src/migrate/tags/section.js +23 -0
  40. package/src/migrate/tags/set.d.ts +26 -0
  41. package/src/migrate/tags/set.js +104 -0
  42. package/src/migrate/tags/super.d.ts +9 -0
  43. package/src/migrate/tags/super.js +31 -0
  44. package/src/plugins/supercharged.d.ts +4 -0
  45. package/src/plugins/supercharged.js +88 -0
  46. package/src/processor.d.ts +42 -0
  47. package/src/processor.js +86 -0
  48. package/src/tags/assign.d.ts +5 -0
  49. package/src/tags/assign.js +42 -0
  50. package/src/tags/component.d.ts +6 -0
  51. package/src/tags/component.js +299 -0
  52. package/src/tags/debugger.d.ts +5 -0
  53. package/src/tags/debugger.js +26 -0
  54. package/src/tags/each.d.ts +20 -0
  55. package/src/tags/each.js +185 -0
  56. package/src/tags/else.d.ts +2 -0
  57. package/src/tags/else.js +22 -0
  58. package/src/tags/else_if.d.ts +7 -0
  59. package/src/tags/else_if.js +39 -0
  60. package/src/tags/eval.d.ts +7 -0
  61. package/src/tags/eval.js +30 -0
  62. package/src/tags/if.d.ts +5 -0
  63. package/src/tags/if.js +45 -0
  64. package/src/tags/include.d.ts +27 -0
  65. package/src/tags/include.js +78 -0
  66. package/src/tags/include_if.d.ts +10 -0
  67. package/src/tags/include_if.js +61 -0
  68. package/src/tags/inject.d.ts +6 -0
  69. package/src/tags/inject.js +40 -0
  70. package/src/tags/let.d.ts +6 -0
  71. package/src/tags/let.js +69 -0
  72. package/src/tags/main.d.ts +18 -0
  73. package/src/tags/main.js +47 -0
  74. package/src/tags/new_error.d.ts +6 -0
  75. package/src/tags/new_error.js +47 -0
  76. package/src/tags/push_once_to.d.ts +13 -0
  77. package/src/tags/push_once_to.js +65 -0
  78. package/src/tags/push_to.d.ts +7 -0
  79. package/src/tags/push_to.js +62 -0
  80. package/src/tags/slot.d.ts +6 -0
  81. package/src/tags/slot.js +29 -0
  82. package/src/tags/stack.d.ts +5 -0
  83. package/src/tags/stack.js +38 -0
  84. package/src/tags/unless.d.ts +12 -0
  85. package/src/tags/unless.js +52 -0
  86. package/src/template.d.ts +127 -0
  87. package/src/template.js +203 -0
  88. package/src/types.d.ts +144 -0
  89. package/src/types.js +10 -0
  90. package/src/utils.d.ts +96 -0
  91. package/src/utils.js +297 -0
  92. package/tsconfig.json +16 -0
@@ -0,0 +1,192 @@
1
+ import { type Compiler } from '../compiler.js'
2
+ import { type Processor } from '../processor.js'
3
+ import { type EdgeRenderer } from './renderer.js'
4
+ import type {
5
+ PluginFn,
6
+ TagContract,
7
+ EdgeGlobals,
8
+ EdgeOptions,
9
+ LoaderTemplate,
10
+ LoaderContract,
11
+ } from '../types.js'
12
+ /**
13
+ * Exposes the API to render templates, register custom tags and globals
14
+ */
15
+ export declare class Edge {
16
+ #private
17
+ /**
18
+ * Create an instance of edge with given options
19
+ */
20
+ static create(options?: EdgeOptions): Edge
21
+ /**
22
+ * Reference to the registered processor handlers
23
+ */
24
+ processor: Processor
25
+ /**
26
+ * A flag to know if using compat mode
27
+ */
28
+ compat: boolean
29
+ /**
30
+ * The loader to load templates. A loader can read and return
31
+ * templates from anywhere. The default loader reads files
32
+ * from the disk
33
+ */
34
+ loader: LoaderContract
35
+ /**
36
+ * The underlying compiler in use
37
+ */
38
+ compiler: Compiler
39
+ /**
40
+ * The underlying compiler in use
41
+ */
42
+ asyncCompiler: Compiler
43
+ /**
44
+ * Globals are shared with all rendered templates
45
+ */
46
+ globals: EdgeGlobals
47
+ /**
48
+ * List of registered tags. Adding new tags will only impact
49
+ * this list
50
+ */
51
+ tags: {
52
+ [name: string]: TagContract
53
+ }
54
+ constructor(options?: EdgeOptions)
55
+ /**
56
+ * Re-configure an existing edge instance
57
+ */
58
+ configure(options: EdgeOptions): void
59
+ /**
60
+ * Register a plugin. Plugins are called only once just before
61
+ * a rendering a view.
62
+ *
63
+ * You can invoke a plugin multiple times by marking it as a
64
+ * recurring plugin
65
+ */
66
+ use<T extends any>(pluginFn: PluginFn<T>, options?: T): this
67
+ /**
68
+ * Mount named directory to use views. Later you can reference
69
+ * the views from a named disk as follows.
70
+ *
71
+ * ```
72
+ * edge.mount('admin', join(__dirname, 'admin'))
73
+ *
74
+ * edge.render('admin::filename')
75
+ * ```
76
+ */
77
+ mount(viewsDirectory: string | URL): this
78
+ mount(diskName: string, viewsDirectory: string | URL): this
79
+ /**
80
+ * Un Mount a disk from the loader.
81
+ *
82
+ * ```js
83
+ * edge.unmount('admin')
84
+ * ```
85
+ */
86
+ unmount(diskName: string): this
87
+ /**
88
+ * Add a new global to the edge globals. The globals are available
89
+ * to all the templates.
90
+ *
91
+ * ```js
92
+ * edge.global('username', 'virk')
93
+ * edge.global('time', () => new Date().getTime())
94
+ * ```
95
+ */
96
+ global(name: string, value: any): this
97
+ /**
98
+ * Add a new tag to the tags list.
99
+ *
100
+ * ```ts
101
+ * edge.registerTag('svg', {
102
+ * block: false,
103
+ * seekable: true,
104
+ *
105
+ * compile (parser, buffer, token) {
106
+ * const fileName = token.properties.jsArg.trim()
107
+ * buffer.writeRaw(fs.readFileSync(__dirname, 'assets', `${fileName}.svg`), 'utf-8')
108
+ * }
109
+ * })
110
+ * ```
111
+ */
112
+ registerTag(tag: TagContract): this
113
+ /**
114
+ * Register an in-memory template.
115
+ *
116
+ * ```ts
117
+ * edge.registerTemplate('button', {
118
+ * template: `<button class="{{ this.type || 'primary' }}">
119
+ * @!yield($slots.main())
120
+ * </button>`,
121
+ * })
122
+ * ```
123
+ *
124
+ * Later you can use this template
125
+ *
126
+ * ```edge
127
+ * @component('button', type = 'primary')
128
+ * Get started
129
+ * @endcomponent
130
+ * ```
131
+ */
132
+ registerTemplate(templatePath: string, contents: LoaderTemplate): this
133
+ /**
134
+ * Remove the template registered using the "registerTemplate" method
135
+ */
136
+ removeTemplate(templatePath: string): this
137
+ /**
138
+ * Get access to the underlying template renderer. Each render call
139
+ * to edge results in creating an isolated renderer instance.
140
+ */
141
+ onRender(callback: (renderer: EdgeRenderer) => void): this
142
+ /**
143
+ * Returns a new instance of edge. The instance
144
+ * can be used to define locals.
145
+ */
146
+ createRenderer(): EdgeRenderer
147
+ /**
148
+ * Render a template with optional state
149
+ *
150
+ * ```ts
151
+ * edge.render('welcome', { greeting: 'Hello world' })
152
+ * ```
153
+ */
154
+ render(templatePath: string, state?: Record<string, any>): Promise<string>
155
+ /**
156
+ * Render a template asynchronously with optional state
157
+ *
158
+ * ```ts
159
+ * edge.render('welcome', { greeting: 'Hello world' })
160
+ * ```
161
+ */
162
+ renderSync(templatePath: string, state?: Record<string, any>): string
163
+ /**
164
+ * Render a template with optional state
165
+ *
166
+ * ```ts
167
+ * edge.render('welcome', { greeting: 'Hello world' })
168
+ * ```
169
+ */
170
+ renderRaw(contents: string, state?: Record<string, any>, templatePath?: string): Promise<string>
171
+ /**
172
+ * Render a template asynchronously with optional state
173
+ *
174
+ * ```ts
175
+ * edge.render('welcome', { greeting: 'Hello world' })
176
+ * ```
177
+ */
178
+ renderRawSync(templatePath: string, state?: Record<string, any>): string
179
+ /**
180
+ * Share locals with the current view context.
181
+ *
182
+ * ```js
183
+ * const view = edge.createRenderer()
184
+ *
185
+ * // local state for the current render
186
+ * view.share({ foo: 'bar' })
187
+ *
188
+ * view.render('welcome')
189
+ * ```
190
+ */
191
+ share(data: Record<string, any>): EdgeRenderer
192
+ }
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.Edge = void 0;
45
+ const loader_js_1 = require("../loader.js");
46
+ const Tags = __importStar(require("../tags/main.js"));
47
+ const compiler_js_1 = require("../compiler.js");
48
+ const template_js_1 = require("../template.js");
49
+ const globals_js_1 = require("./globals.js");
50
+ const processor_js_1 = require("../processor.js");
51
+ const renderer_js_1 = require("./renderer.js");
52
+ const supercharged_js_1 = require("../plugins/supercharged.js");
53
+ /**
54
+ * Exposes the API to render templates, register custom tags and globals
55
+ */
56
+ class Edge {
57
+ /**
58
+ * Create an instance of edge with given options
59
+ */
60
+ static create(options = {}) {
61
+ return new Edge(options);
62
+ }
63
+ /**
64
+ * An array of bundled plugins
65
+ */
66
+ #bundledPlugins = [];
67
+ /**
68
+ * An array of registered plugins
69
+ */
70
+ #plugins = [];
71
+ /**
72
+ * Array of registered renderer hooks
73
+ */
74
+ #renderCallbacks = [];
75
+ /**
76
+ * Reference to the registered processor handlers
77
+ */
78
+ processor = new processor_js_1.Processor();
79
+ /**
80
+ * A flag to know if using compat mode
81
+ */
82
+ compat = false;
83
+ /**
84
+ * Globals are shared with all rendered templates
85
+ */
86
+ globals = { ...globals_js_1.edgeGlobals };
87
+ /**
88
+ * List of registered tags. Adding new tags will only impact
89
+ * this list
90
+ */
91
+ tags = {};
92
+ constructor(options = {}) {
93
+ this.configure(options);
94
+ /**
95
+ * Registering bundled set of tags
96
+ */
97
+ Object.keys(Tags).forEach((name) => {
98
+ this.registerTag(Tags[name]);
99
+ });
100
+ this.#bundledPlugins.push({
101
+ fn: supercharged_js_1.pluginSuperCharged,
102
+ executed: false,
103
+ options: { recurring: !options.cache },
104
+ });
105
+ }
106
+ /**
107
+ * Re-configure an existing edge instance
108
+ */
109
+ configure(options) {
110
+ if (options.loader) {
111
+ this.loader = options.loader;
112
+ }
113
+ else if (!this.loader) {
114
+ this.loader = new loader_js_1.Loader();
115
+ }
116
+ this.compiler = new compiler_js_1.Compiler(this.loader, this.tags, this.processor, {
117
+ cache: !!options.cache,
118
+ async: false,
119
+ });
120
+ this.asyncCompiler = new compiler_js_1.Compiler(this.loader, this.tags, this.processor, {
121
+ cache: !!options.cache,
122
+ async: true,
123
+ });
124
+ }
125
+ /**
126
+ * Execute plugins
127
+ */
128
+ #executePlugins() {
129
+ /**
130
+ * Running user-land plugins
131
+ */
132
+ this.#plugins
133
+ .filter(({ options, executed }) => {
134
+ if (options && options.recurring) {
135
+ return true;
136
+ }
137
+ return !executed;
138
+ })
139
+ .forEach((plugin) => {
140
+ plugin.fn(this, !plugin.executed, plugin.options);
141
+ plugin.executed = true;
142
+ });
143
+ /**
144
+ * Running bundled plugins after the user-land
145
+ * plugins
146
+ */
147
+ this.#bundledPlugins
148
+ .filter(({ options, executed }) => {
149
+ if (options && options.recurring) {
150
+ return true;
151
+ }
152
+ return !executed;
153
+ })
154
+ .forEach((plugin) => {
155
+ plugin.fn(this, !plugin.executed, plugin.options);
156
+ plugin.executed = true;
157
+ });
158
+ }
159
+ /**
160
+ * Register a plugin. Plugins are called only once just before
161
+ * a rendering a view.
162
+ *
163
+ * You can invoke a plugin multiple times by marking it as a
164
+ * recurring plugin
165
+ */
166
+ use(pluginFn, options) {
167
+ this.#plugins.push({
168
+ fn: pluginFn,
169
+ executed: false,
170
+ options,
171
+ });
172
+ return this;
173
+ }
174
+ mount(diskName, viewsDirectory) {
175
+ if (!viewsDirectory) {
176
+ viewsDirectory = diskName;
177
+ diskName = 'default';
178
+ }
179
+ this.loader.mount(diskName, viewsDirectory);
180
+ return this;
181
+ }
182
+ /**
183
+ * Un Mount a disk from the loader.
184
+ *
185
+ * ```js
186
+ * edge.unmount('admin')
187
+ * ```
188
+ */
189
+ unmount(diskName) {
190
+ this.loader.unmount(diskName);
191
+ return this;
192
+ }
193
+ /**
194
+ * Add a new global to the edge globals. The globals are available
195
+ * to all the templates.
196
+ *
197
+ * ```js
198
+ * edge.global('username', 'virk')
199
+ * edge.global('time', () => new Date().getTime())
200
+ * ```
201
+ */
202
+ global(name, value) {
203
+ this.globals[name] = value;
204
+ return this;
205
+ }
206
+ /**
207
+ * Add a new tag to the tags list.
208
+ *
209
+ * ```ts
210
+ * edge.registerTag('svg', {
211
+ * block: false,
212
+ * seekable: true,
213
+ *
214
+ * compile (parser, buffer, token) {
215
+ * const fileName = token.properties.jsArg.trim()
216
+ * buffer.writeRaw(fs.readFileSync(__dirname, 'assets', `${fileName}.svg`), 'utf-8')
217
+ * }
218
+ * })
219
+ * ```
220
+ */
221
+ registerTag(tag) {
222
+ if (typeof tag.boot === 'function') {
223
+ tag.boot(template_js_1.Template);
224
+ }
225
+ this.tags[tag.tagName] = tag;
226
+ return this;
227
+ }
228
+ /**
229
+ * Register an in-memory template.
230
+ *
231
+ * ```ts
232
+ * edge.registerTemplate('button', {
233
+ * template: `<button class="{{ this.type || 'primary' }}">
234
+ * @!yield($slots.main())
235
+ * </button>`,
236
+ * })
237
+ * ```
238
+ *
239
+ * Later you can use this template
240
+ *
241
+ * ```edge
242
+ * @component('button', type = 'primary')
243
+ * Get started
244
+ * @endcomponent
245
+ * ```
246
+ */
247
+ registerTemplate(templatePath, contents) {
248
+ this.loader.register(templatePath, contents);
249
+ return this;
250
+ }
251
+ /**
252
+ * Remove the template registered using the "registerTemplate" method
253
+ */
254
+ removeTemplate(templatePath) {
255
+ this.loader.remove(templatePath);
256
+ this.compiler.cacheManager.delete(templatePath);
257
+ this.asyncCompiler.cacheManager.delete(templatePath);
258
+ return this;
259
+ }
260
+ /**
261
+ * Get access to the underlying template renderer. Each render call
262
+ * to edge results in creating an isolated renderer instance.
263
+ */
264
+ onRender(callback) {
265
+ this.#renderCallbacks.push(callback);
266
+ return this;
267
+ }
268
+ /**
269
+ * Returns a new instance of edge. The instance
270
+ * can be used to define locals.
271
+ */
272
+ createRenderer() {
273
+ this.#executePlugins();
274
+ const renderer = new renderer_js_1.EdgeRenderer(this.compiler, this.asyncCompiler, this.processor, this.globals);
275
+ this.#renderCallbacks.forEach((callback) => callback(renderer));
276
+ return renderer;
277
+ }
278
+ /**
279
+ * Render a template with optional state
280
+ *
281
+ * ```ts
282
+ * edge.render('welcome', { greeting: 'Hello world' })
283
+ * ```
284
+ */
285
+ render(templatePath, state) {
286
+ return this.createRenderer().render(templatePath, state);
287
+ }
288
+ /**
289
+ * Render a template asynchronously with optional state
290
+ *
291
+ * ```ts
292
+ * edge.render('welcome', { greeting: 'Hello world' })
293
+ * ```
294
+ */
295
+ renderSync(templatePath, state) {
296
+ return this.createRenderer().renderSync(templatePath, state);
297
+ }
298
+ /**
299
+ * Render a template with optional state
300
+ *
301
+ * ```ts
302
+ * edge.render('welcome', { greeting: 'Hello world' })
303
+ * ```
304
+ */
305
+ renderRaw(contents, state, templatePath) {
306
+ return this.createRenderer().renderRaw(contents, state, templatePath);
307
+ }
308
+ /**
309
+ * Render a template asynchronously with optional state
310
+ *
311
+ * ```ts
312
+ * edge.render('welcome', { greeting: 'Hello world' })
313
+ * ```
314
+ */
315
+ renderRawSync(templatePath, state) {
316
+ return this.createRenderer().renderRawSync(templatePath, state);
317
+ }
318
+ /**
319
+ * Share locals with the current view context.
320
+ *
321
+ * ```js
322
+ * const view = edge.createRenderer()
323
+ *
324
+ * // local state for the current render
325
+ * view.share({ foo: 'bar' })
326
+ *
327
+ * view.render('welcome')
328
+ * ```
329
+ */
330
+ share(data) {
331
+ return this.createRenderer().share(data);
332
+ }
333
+ }
334
+ exports.Edge = Edge;
@@ -0,0 +1,44 @@
1
+ import { type Processor } from '../processor.js'
2
+ import type { Compiler } from '../compiler.js'
3
+ /**
4
+ * Renders a given template with it's shared state
5
+ */
6
+ export declare class EdgeRenderer {
7
+ #private
8
+ constructor(
9
+ compiler: Compiler,
10
+ asyncCompiler: Compiler,
11
+ processor: Processor,
12
+ globals: Record<string, any>
13
+ )
14
+ /**
15
+ * Clone renderer instance with shared data
16
+ */
17
+ clone(): EdgeRenderer
18
+ /**
19
+ * Share local variables with the template. They will overwrite the
20
+ * globals
21
+ */
22
+ share(data: Record<string, any>): this
23
+ /**
24
+ * Retrieves the local and global variables, used for testing things that
25
+ * share variables
26
+ */
27
+ getState(): Record<string, any>
28
+ /**
29
+ * Render the template
30
+ */
31
+ render(templatePath: string, state?: Record<string, any>): Promise<string>
32
+ /**
33
+ * Render the template
34
+ */
35
+ renderSync(templatePath: string, state?: Record<string, any>): string
36
+ /**
37
+ * Render the template from a raw string
38
+ */
39
+ renderRaw(contents: string, state?: Record<string, any>, templatePath?: string): Promise<string>
40
+ /**
41
+ * Render the template from a raw string
42
+ */
43
+ renderRawSync(contents: string, state?: Record<string, any>, templatePath?: string): string
44
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.EdgeRenderer = void 0;
15
+ const lodash_1 = __importDefault(require("@poppinss/utils/lodash"));
16
+ const template_js_1 = require("../template.js");
17
+ /**
18
+ * Renders a given template with it's shared state
19
+ */
20
+ class EdgeRenderer {
21
+ #compiler;
22
+ #processor;
23
+ #asyncCompiler;
24
+ /**
25
+ * Global state
26
+ */
27
+ #locals = {};
28
+ #globals;
29
+ constructor(compiler, asyncCompiler, processor, globals) {
30
+ this.#compiler = compiler;
31
+ this.#asyncCompiler = asyncCompiler;
32
+ this.#processor = processor;
33
+ this.#globals = globals;
34
+ }
35
+ /**
36
+ * Clone renderer instance with shared data
37
+ */
38
+ clone() {
39
+ const renderer = new EdgeRenderer(this.#compiler, this.#asyncCompiler, this.#processor, this.#globals);
40
+ return renderer.share(this.#locals);
41
+ }
42
+ /**
43
+ * Share local variables with the template. They will overwrite the
44
+ * globals
45
+ */
46
+ share(data) {
47
+ lodash_1.default.merge(this.#locals, data);
48
+ return this;
49
+ }
50
+ /**
51
+ * Retrieves the local and global variables, used for testing things that
52
+ * share variables
53
+ */
54
+ getState() {
55
+ return {
56
+ ...this.#globals,
57
+ ...this.#locals,
58
+ };
59
+ }
60
+ /**
61
+ * Render the template
62
+ */
63
+ async render(templatePath, state = {}) {
64
+ return new template_js_1.Template(this.#asyncCompiler, this.#globals, this.#locals, this.#processor).render(templatePath, state);
65
+ }
66
+ /**
67
+ * Render the template
68
+ */
69
+ renderSync(templatePath, state = {}) {
70
+ return new template_js_1.Template(this.#compiler, this.#globals, this.#locals, this.#processor).render(templatePath, state);
71
+ }
72
+ /**
73
+ * Render the template from a raw string
74
+ */
75
+ async renderRaw(contents, state = {}, templatePath) {
76
+ return new template_js_1.Template(this.#asyncCompiler, this.#globals, this.#locals, this.#processor).renderRaw(contents, state, templatePath);
77
+ }
78
+ /**
79
+ * Render the template from a raw string
80
+ */
81
+ renderRawSync(contents, state = {}, templatePath) {
82
+ return new template_js_1.Template(this.#compiler, this.#globals, this.#locals, this.#processor).renderRaw(contents, state, templatePath);
83
+ }
84
+ }
85
+ exports.EdgeRenderer = EdgeRenderer;
@@ -0,0 +1,22 @@
1
+ export default class Stacks {
2
+ #private
3
+ /**
4
+ * Create a new stack placeholder. Multiple calls to this method
5
+ * with the same name results in an exception.
6
+ */
7
+ create(name: string): string
8
+ /**
9
+ * Push content inside a given stack. Content can be pre-seeded
10
+ * without creating a stack
11
+ */
12
+ pushTo(name: string, contents: string): this
13
+ /**
14
+ * Push contents to a stack with a unique source id. A
15
+ * source can only push once to a given stack.
16
+ */
17
+ pushOnceTo(name: string, sourceId: string, contents: string): void
18
+ /**
19
+ * Fill placeholders with their actual content
20
+ */
21
+ fillPlaceholders(contents: string): string
22
+ }