/
demo.ts
38 lines (33 loc) · 834 Bytes
/
demo.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
import { render } from 'html-template-lite'
const html = render(
/* html */ `
<div>Name: {name}</div>
<div>Rank: {rank}</div>
`,
{ name: "<b>o's</b>", rank: 42 },
)
console.log(html)
/*
<div>Name: <b>o's</b></div>
<div>Rank: 42</div>
*/
const listTemplate = /* html */ `<ul>
[items]
</ul>`
const itemTemplate = /* html */ ` <li><a href="{url}">{title}</a></li>`
const items = [
{ url: 'https://github.com', title: 'Github' },
{ url: 'https://gitlab.com', title: 'Gitlab' },
{ url: 'https://bitbucket.org', title: 'Bitbucket' },
]
const body = render(listTemplate, {
items: render(itemTemplate, items, '\n'),
})
console.log(body)
/*
<ul>
<li><a href="https://github.com">Github</a></li>
<li><a href="https://gitlab.com">Gitlab</a></li>
<li><a href="https://bitbucket.org">Bitbucket</a></li>
</ul>
*/