-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.go
70 lines (60 loc) · 1.47 KB
/
panel.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
package bootstrapper
import (
"strings"
"github.com/grokify/mogo/html/htmlutil"
"golang.org/x/net/html/atom"
)
type Panel struct {
htmlutil.Element
}
func NewPanel() *Panel {
p := &Panel{}
p.Element.TagName = atom.Div.String()
err := p.Element.AddAttribute(htmlutil.AttributeClass, "panel")
if err != nil {
panic(err)
}
return p
}
func (p *Panel) Color(c string) error {
if IsColor(c) {
return p.Element.AddAttribute(htmlutil.AttributeClass, "panel-"+c)
}
return ErrColorUnknown
}
func (p *Panel) AddTitle(text string, escaped bool, tagName string) {
elText := &htmlutil.Text{
Text: text,
Escaped: escaped}
tagName = strings.TrimSpace(tagName)
if len(tagName) == 0 {
tagName = atom.H1.String()
}
elTitle := &htmlutil.Element{}
elTitle.TagName = tagName
err := elTitle.AddAttribute(htmlutil.AttributeClass, ClassPanelTitle)
if err != nil {
panic(err)
}
elTitle.AddInnerHTML(elText)
elHeading := &htmlutil.Element{}
elHeading.TagName = atom.Div.String()
err = elHeading.AddAttribute(htmlutil.AttributeClass, ClassPanelHeading)
if err != nil {
panic(err)
}
elHeading.AddInnerHTML(elTitle)
p.Element.AddInnerHTML(elHeading)
}
func (p *Panel) AddBody(text string, escaped bool) {
elBody := &htmlutil.Element{}
elBody.TagName = atom.Div.String()
err := elBody.AddAttribute(htmlutil.AttributeClass, ClassPanelBody)
if err != nil {
panic(err)
}
elBody.AddInnerHTML(&htmlutil.Text{
Text: text,
Escaped: escaped})
p.Element.AddInnerHTML(elBody)
}