/
main.go
54 lines (46 loc) · 810 Bytes
/
main.go
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
package main
import (
"fmt"
"log"
h "github.com/RobinThrift/hkit"
)
func main() {
ctx := h.NewContext()
ctx.Set("Title", "From Context")
ctx.Set("Nested", "Value")
value, err := h.RenderWithContext(
ctx,
layout(compA()),
)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(value))
}
var compA = func() h.Component {
return h.Div(
nil,
compB(),
)
}
var compB = func() h.Component {
return func(ctx h.Context) h.Element {
return h.Div(
nil,
h.Span(
&h.SpanAttrs{
Class: "test",
},
h.Text(ctx.Get("Nested").(string)),
),
)
}
}
var layout = func(children ...h.Component) h.Component {
return func(ctx h.Context) h.Element {
return h.Html(nil,
h.Head(nil, h.Title(nil, h.Text(ctx.Get("Title").(string)))),
h.Body(nil, children...),
)
}
}