deno.land / x / lume@v2.1.4 / tests / core / engines.test.ts

engines.test.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { assertStrictEquals as equals } from "../../deps/assert.ts";import Site from "../../core/site.ts";
import type { Engine } from "../../core/renderer.ts";
Deno.test("Engines", async (t) => { const site = new Site();
const { formats, renderer } = site;
equals(formats.size, 0);
await t.step("Add a template engine", () => { site.loadPages( [".foo"], { engine: new class implements Engine { includes = ""; render( content: string, data: Record<string, unknown>, ): Promise<string> { return Promise.resolve(this.renderComponent(content, data)); } renderComponent( content: string, data: Record<string, unknown>, ): string { return content + data.foo; } addHelper() {} deleteCache() {} }(), }, );
equals(formats.size, 1); });
await t.step("Run the template engine", async () => { const result = await renderer.render("content", { foo: "bar" }, "foo.foo"); equals(result, "contentbar");
const result2 = await renderer.render( "content", { foo: "bar" }, "foo.not_found", ); equals(result2, "content"); });
await t.step("Add other template engine", () => { site.loadPages( [".upper"], { engine: new class implements Engine { includes = ""; render(content: string): Promise<string> { return Promise.resolve(this.renderComponent(content)); } renderComponent(content: string): string { return content.toUpperCase(); } addHelper() {} deleteCache() {} }(), }, );
equals(formats.size, 2); });
await t.step("Run the other template engine", async () => { const result = await renderer.render( "content", { foo: "bar" }, "foo.upper", ); equals(result, "CONTENT");
const result2 = await renderer.render( "content", { foo: "bar" }, "foo.not_found", ); equals(result2, "content"); });
await t.step("templateEngine variable", async () => { const result = await renderer.render("content", { foo: "bar", templateEngine: "foo", }, "foo.upper"); equals(result, "contentbar");
const result2 = await renderer.render("content", { foo: "bar", templateEngine: ["foo", "upper"], }, "foo.not_found"); equals(result2, "CONTENTBAR");
const result3 = await renderer.render("content", { foo: "bar", templateEngine: "upper,foo", }, "foo.not_found"); equals(result3, "CONTENTbar"); });
await t.step("Add a helper", () => { renderer.addHelper("quoted", (val: string) => `"${val}"`, { type: "filter", }); equals(renderer.helpers.has("quoted"), true); });});
lume

Version Info

Tagged at
7 months ago