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
|
// Complex.gsx
package testdata
import (
"fmt"
tui "github.com/grindlemire/go-tui"
)
// Unassigned block comment
// For package comment
// ItemList test
templ ItemList(items []string, selected int) {
<div direction={tui.Column} gap={1}>
// ItemList direction
for i, item := range items {
// ItemList for loop
if i == selected {
<div border={tui.BorderSingle}>
// ItemList border
<span>{fmt.Sprintf("> %s", /* ItemList item */ item)}</span>
</div>
} else {
// ItemList else
<span>{fmt.Sprintf(" %s", item)}</span>
}
}
</div>
}
// ItemList direction
// ItemList for loop
// ItemList border
/* ItemList item */
// ItemList else
/*
Counter
tests block comment
*/
templ Counter(count int, label string) {
countText := <span>{fmt.Sprintf("%d", count)}</span>
<div direction={tui.Column} gap={1} padding={1}>
<span class="font-bold">{label}</span>
{countText}
</div>
}
templ ConditionalContent(showHeader bool, showFooter bool) {
<div direction={tui.Column}>
if showHeader {
<span>Header</span>
}
<span>Main Content</span>
if showFooter {
<span>Footer</span>
} else {
<span>No Footer</span>
}
</div>
}
templ WithHelper(text string) {
shouldShowHeader := true
otherHelperFunction("test")
<div>
<span>{helperFunction(text)}</span>
if shouldShowHeader {
@ConditionalContent(true, false)
} else {
<span>False</span>
}
</div>
}
func helperFunction(s string) string {
return fmt.Sprintf("[%s]", s)
}
|