1
1
local xml_gen = require (" xml-generator" )
2
2
local xml = xml_gen .xml
3
-
3
+ local tw = xml_gen . namespace " tw "
4
4
math.randomseed (os.time ())
5
5
6
6
local header = xml_gen .component (function (args , kids )
7
7
return xml .head {
8
- xml .title { args .title } ;
8
+ xml .title ( args .title ) ;
9
9
xml .meta {
10
10
name = " viewport" ,
11
11
content = " width=device-width, initial-scale=1"
@@ -15,24 +15,35 @@ local header = xml_gen.component(function (args, kids)
15
15
}
16
16
end )
17
17
18
- local tw = xml_gen .namespace " tw"
18
+ local random_number = xml_gen .component (function (args )
19
+ return xml .p (math.random (args .min , args .max ))
20
+ end )
19
21
20
- local doc = xml .html {charset = " utf8" } {
21
- header {title = " Hello, World!" , css_framework = xml .link {rel = " stylesheet" , href = " ..." }} {
22
- xml .script {src = " index.lua" };
23
- xml .br ;
24
- };
25
-
26
- xml .body {
27
- xml .h1 {class = " text-center" } " Fritsite" ;
28
- xml .main {class = " container" } {
29
- xml .p " Hello, World!" ;
30
- xml .button {onclick = " say_hi()" } " Say Hi!" ;
31
- };
32
22
33
- tw .div {id = " test div" } " hello"
34
- };
35
- }
23
+ local yield = coroutine.yield
24
+ local doc = xml_gen .declare_generator (function ()
25
+ --- @diagnostic disable : undefined-global
26
+ return html {charset = " utf8" } {
27
+ header {title = " Hello, World!" , css_framework = link {rel = " stylesheet" , href = " ..." }};
28
+
29
+ body {
30
+ h1 {class = " text-center" } " Fritsite" ;
31
+ main {class = " container" } {
32
+ p " Hello, World!" ;
33
+ button {onclick = " say_hi()" } " Say Hi!" ;
34
+ };
35
+
36
+ function ()
37
+ for i = 1 , 10 do
38
+ yield (random_number {id = " rn-" .. i } {min = 1 , max = 100 })
39
+ end
40
+ end ;
41
+
42
+ tw .div {id = " test div" } " hello"
43
+ };
44
+ }
45
+ --- @diagnostic enable : undefined-global
46
+ end )
36
47
37
48
38
- print (doc )
49
+ print (doc () )
0 commit comments