-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.lua
executable file
·57 lines (52 loc) · 1.03 KB
/
example.lua
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
#!/usr/bin/env lua
local liluat = require("liluat")
local template = [[
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{= title}}</title>
</head>
<body>
<h1>Vegetables</h1>
<ul>
{{ -- write regular lua code in the template}}
{{for _,vegetable in ipairs(vegetables) do}}
<li><b>{{= vegetable}}</b></li>
{{end}}
</ul>
</body>
</html>
]]
-- values to render the template with
local values = {
title = "A fine selection of vegetables.",
vegetables = {
"carrot",
"cucumber",
"broccoli",
"tomato"
}
}
-- compile the template into lua code
local compiled_template = liluat.compile(template)
local rendered_template = liluat.render(compiled_template, values)
io.write(rendered_template)
--[[ output:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>A fine selection of vegetables.</title>
</head>
<body>
<h1>Vegetables</h1>
<ul>
<li><b>carrot</b></li>
<li><b>cucumber</b></li>
<li><b>broccoli</b></li>
<li><b>tomato</b></li>
</ul>
</body>
</html>
--]]