Skip to content

Commit d6e24f2

Browse files
committed
refactor(rendering): drop render options parameter 🍡
- Remove EngineRenderOptions type - Simplify Engine.render signature and include calls - Update ViewEngine render docs
1 parent a0b0c60 commit d6e24f2

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/interfaces/Render.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ export type DveStackFrame = { kind: 'if' | 'each'; node: AstNode; inElse: boolea
3131
/** Options for constructing rendering Engine. */
3232
export type EngineOptions = { viewsDir: string }
3333

34-
/** Render options override for Engine (matches ViewEngine render options). */
35-
export type EngineRenderOptions = { viewsDir?: string }
36-
37-
/** View engine for rendering templates (e.g. .dve); Engine implements this. */
34+
/**
35+
* View engine for templates
36+
* @description Renders DVE templates to HTML strings
37+
*/
3838
export interface ViewEngine {
39-
/** Render template at path with data; returns HTML string. */
40-
render(
41-
templatePath: string,
42-
data?: Record<string, unknown>,
43-
options?: EngineRenderOptions
44-
): Promise<string>
39+
/**
40+
* Render template to HTML
41+
* @description Renders DVE template with scope data
42+
* @param templatePath - Relative template path
43+
* @param data - Template scope data
44+
* @returns Rendered HTML string
45+
*/
46+
render(templatePath: string, data?: Record<string, unknown>): Promise<string>
4547
}

src/rendering/Engine.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,10 @@ export class Engine implements Types.ViewEngine {
3030
* @description Loads template and produces final HTML
3131
* @param templatePath - Relative template path
3232
* @param data - Template scope data
33-
* @param options - Render options override values
3433
* @returns Rendered HTML string
3534
* @throws {Error} When template path not discovered
3635
*/
37-
async render(
38-
templatePath: string,
39-
data: Record<string, unknown> = {},
40-
options?: Types.EngineRenderOptions
41-
): Promise<string> {
42-
const viewsDir = options?.viewsDir ?? this.defaultViewsDir
36+
async render(templatePath: string, data: Record<string, unknown> = {}): Promise<string> {
4337
if (this.discoveredPaths === null) {
4438
this.discoveredPaths = await Rendering.Discover.discoverPaths(this.defaultViewsDir)
4539
}
@@ -51,9 +45,9 @@ export class Engine implements Types.ViewEngine {
5145
if (!discoveredTemplatePaths.has(pathWithExt)) {
5246
throw new Error(`Template not found: ${templatePath}.`)
5347
}
54-
const absPath = EngineParts.Utils.join(viewsDir, pathWithExt)
48+
const absPath = EngineParts.Utils.join(this.defaultViewsDir, pathWithExt)
5549
const compiled = await this.compileTemplate(absPath)
56-
return await this.renderNodes(compiled.ast, data, viewsDir)
50+
return await this.renderNodes(compiled.ast, data, this.defaultViewsDir)
5751
}
5852

5953
/**
@@ -118,7 +112,7 @@ export class Engine implements Types.ViewEngine {
118112
continue
119113
}
120114
if (node.type === 'include') {
121-
outputHtml += await this.render(node.templatePath, data, { viewsDir })
115+
outputHtml += await this.render(node.templatePath, data)
122116
continue
123117
}
124118
if (node.type === 'if') {

0 commit comments

Comments
 (0)