forked from HapticX/happyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testjs2.nim
109 lines (96 loc) · 2.16 KB
/
testjs2.nim
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import
../src/happyx,
components/[hello_world, nested_component, component_for, component_with_slot]
var app = registerApp()
var t = initTag("div", @[], true)
echo t.onlyChildren
var d = t.Node
echo d.TagRef.onlyChildren
echo cast[TagRef](d).onlyChildren
var lazyTest = buildHtml:
lazy:
"Hello, world!"
lazy:
"Other lazy"
app.routes:
"/":
HelloWorld(counter = 1.0)
HelloWorld(counter = 2.0)
HelloWorld(counter = 4.0)
HelloWorld(counter = 8.0)
HelloWorld(counter = 16.0)
tagTextarea(style = "font-weight: 500; margin-bottom: 10px;"):
"Hello, world"
lazy:
"Hello, world!"
lazy:
"Other lazy"
{$lazyTest}
"/slots":
CompWithSlot:
"hello, world!"
CompWithSlot(counter = 100):
"Hello"
"/nested":
NestedComponent2
"/visit":
script(src="https://cdn.tailwindcss.com") # Tailwind CSS :D
tDiv(class="bg-gray-700 text-pink-400 px-8 py-24"):
"This page was visited"
button:
"Go to /visit"
@click:
echo "Clicked!"
route("/visit")
button:
"Go to /"
@click:
route("/")
button:
"Go to /calc"
@click:
route("/calc/5/%2b/5") # /calc5+5
"/calc/{left:int}/{op:string}/{right:int}":
h1:
"Result of {left} {op} {right}"
h2:
if op == "+":
{left + right}
else:
{left - right}
nim:
echo op
echo fmt"Hello from {path}!"
button:
"Go to /visit"
@click:
echo "Clicked!"
route("/visit")
"/shop":
echo "When statement list ends with buildHtml macro you can use Nim"
let someArg = 0
buildHtml:
"Like this"
for i in 0..10:
tButton(id="{i}", asd="123", class="rounded-full px-16 py-1 my-1 bg-gray-200 hover:bg-gray-300 transition-colors"):
{i}
@click:
echo i
ComponentFor(counter = 5)
{someArg}
"/asd":
tDiv(a = "1"):
b := "2"
@click:
echo 3
tDiv:
a := "1"
b := "2"
@click:
echo 3
notfound:
nim:
echo currentRoute
class := "myClass"
"Oops! Not found!"
app.start()