This repository has been archived by the owner on May 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_html.go
executable file
·78 lines (66 loc) · 1.73 KB
/
generate_html.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
// "fmt"
"github.com/pieterclaerhout/go-html"
"github.com/pieterclaerhout/go-html/cmd/generate-html/components"
"github.com/pieterclaerhout/go-log"
)
func main() {
minimize := false
userProfile := &components.UserProfile{
Username: "pclaerhout",
AvatarURL: "https://en.gravatar.com/userimage/389631/32413201cb4a680e82ee7c4bdd30b795.jpeg",
}
log.Info(userProfile.HTML(minimize))
pageHeader := &components.PageHeader{
Title: "Title",
Subtitle: "Subtitle",
IconURL: "https://en.gravatar.com/userimage/389631/32413201cb4a680e82ee7c4bdd30b795.jpeg",
}
log.Info(pageHeader.HTML(minimize))
selectBox := components.MySelect().Options([]components.Option{
{"1", "label 1"},
{"2", "label 2"},
{"3", "label 3"},
}).Selected("2")
log.Info(selectBox.HTML(minimize))
// root := html.Blocks{
// // Option 1: directly add an element
// html.Doctype("html"),
// html.Html(nil,
// // Option 2: struct that implements Block interface (RenderHTML() Block)
// HeadBlock{html.Name("key").Content("super")},
// // Option 3: function that returns a Block
// BodyBlock("Hello, world! :) <br>"),
// ),
// }
// out, err := html.RenderString(root)
// if err != nil {
// fmt.Println("Error:", err)
// }
// fmt.Println(out)
// out, err = html.RenderMinifiedString(root)
// if err != nil {
// fmt.Println("Error:", err)
// }
// fmt.Println(out)
}
type HeadBlock struct {
html.Attributes
}
func (h HeadBlock) RenderHTML() html.Block {
return html.Head(nil,
html.Meta(h.Attributes),
)
}
func BodyBlock(in string) html.Block {
return html.Body(nil,
html.Main(html.Class("main-class\" href=\"/evil/link"),
html.H1(nil,
html.Text(in),
html.Br(),
html.UnsafeString(in),
),
),
)
}