blob: 8ab1cb8de50968dc9443bf28b9e9b0aa36f6f733 (
plain) (
blame)
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
|
local page_wrapper = function(content)
return reluax.html_page(
<html>
<head>
<title>reluax</title>
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
</head>
<body>
{$ content $}
</body>
</html>
)
end
local route = function(path, method, body)
if path == "/" and method == "GET" then
return 200, page_wrapper(
<div>
<h1>reluax</h1>
<p>Click the button to get a random number.</p>
<button hx-post="/random" hx-swap="outerHTML">Random</button>
</div>
)
elseif path == "/random" and method == "POST" then
return 200, reluax.html(<h3>{$ math.random(1, 100) $}</h3>)
end
return 404, page_wrapper(
<div>
<h1>reluax</h1>
<p>404 Not Found</p>
</div>
)
end
return {
name = "htmx-example",
route = route
}
|