-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
view.ts
34 lines (30 loc) · 807 Bytes
/
view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { renderFile, contentType } from "../package.ts";
import { normalize } from "../package.ts";
import { getViewRenderConfig, RenderResult } from "../mod.ts";
/**
* Renders view with template with changed template render (default .ejs)
* @param templatePath
* @param model
* @param status
*/
export async function View(
templatePath: string,
model: Object,
status: number = 200,
): Promise<RenderResult> {
let body;
const headers = new Headers();
headers.set("content-type", contentType("text/html") as string);
const renderConfig = getViewRenderConfig();
// if renderConfig.type === dejs
body = await renderFile(
normalize(`${renderConfig.basePath}${templatePath}.ejs`),
model,
);
return {
body,
status,
headers,
__isRenderResult: true,
};
}