-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.templ
109 lines (93 loc) · 1.53 KB
/
test.templ
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
package main
import "path"
import "github.com/gosimple/slug"
const duck = false
const (
a = iota
b
c
)
// Can one tell apart function comments?
func test(foo string, bar int) bool {
print("foo\nbar\n")
return 42
}
var (
foo = bar
)
type Blah struct {
Foo int
}
func (b *Blah) Do() bool {
test("foo", 42)
foo, bar := bar
return true
}
func other() {
Blah.Do()
Blah.foo.Do(honk)
x = func(foo int, bar string) bool { return 5 }
}
css what() {
foo: bar;
baz: quux;
}
css foo() {
bar: zot;
quux: { what() };
}
// The header component
templ headerComponent(title string) {
<head>
<title
foo="bar"
baz="42"
test={ one() }
>
<foo></foo>
{ title(42, 1) }
</title>
<what></what>
<conditional
if true {
class="what"
test="42"
}
></conditional>
<test { attrs... }></test>
<embed
if false {
{ attrs... }
}
/>
@component(foo, bar)
</head>
}
// comment
func what(is string, this bool, magic int) {
}
templ contentComponent(title string, body templ.Component) {
<body>
<h1>{ title }</h1>
<div class="content">
@body
</div>
</body>
}
templ contentPage(title string, body templ.Component) {
<html>
@headerComponent(title)
@contentComponent(title, body)
</html>
}
templ indexPage(posts []Post) {
<html>
@headerComponent("My Blog")
<body>
<h1 foo="bar" baz="qux">My Blog</h1>
for _, post := range posts {
<div><a href={ templ.SafeURL(path.Join(post.Date.Format("2006/01/02"), slug.Make(post.Title), "/")) }>{ post.Title }</a></div>
}
</body>
</html>
}