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

nunjucks.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
import { assertSiteSnapshot, build, getSite } from "./utils.ts";import nunjucks from "../plugins/nunjucks.ts";
Deno.test("build a site with nunjucks", async (t) => { const site = getSite({ src: "nunjucks", location: new URL("https://example.com/blog"), });
site.use(nunjucks());
// Register an async filter site.filter( "returnAsync", (text) => new Promise((resolve) => setTimeout(() => resolve(`${text} (async)`), 10) ), true, );
// Register custom helpers site.helper( "upperCase", (text) => `<strong>${(text as string).toUpperCase()}</strong>`, { type: "tag" }, ); site.helper( "upperCaseBody", (text) => `<strong>${(text as string).toUpperCase()}</strong>`, { type: "tag", body: true }, ); site.helper( "upperCaseAsync", (text) => Promise.resolve(`<strong>${(text as string).toUpperCase()}</strong>`), { type: "tag", async: true }, ); site.helper( "upperCaseBodyAsync", (text) => Promise.resolve(`<strong>${(text as string).toUpperCase()}</strong>`), { type: "tag", body: true, async: true }, );
site.filter("fromPage", function (key) { return this?.data[key]; }); site.filter("fromPageAsync", function (key) { return Promise.resolve(this?.data[key]); }, true); site.helper( "fromPageTagAsync", function (key) { return Promise.resolve(`<strong>${this?.data[key]}</strong>`); }, { type: "tag", body: true, async: true }, );
await build(site); await assertSiteSnapshot(t, site);});
lume

Version Info

Tagged at
a month ago