-
Notifications
You must be signed in to change notification settings - Fork 6
/
taghelpers.go
60 lines (52 loc) · 1.62 KB
/
taghelpers.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
package onthefly
import (
"strconv"
)
// SetMargin sets a margin given in em on a tag
func (tag *Tag) SetMargin(em int) {
value := strconv.Itoa(em) + "em"
tag.AddStyle("margin", value)
}
// SetRounded applies rounded corners to an HTML tag
func (tag *Tag) SetRounded(value string) {
tag.AddStyle("border-radius", value)
tag.AddStyle("-webkit-border-radius", value)
tag.AddStyle("-moz-border-radius", value)
}
// SetRoundedEm applies rounded corners to an HTML tag
// em is the roundedness, given as "em"
func (tag *Tag) SetRoundedEm(em int) {
value := strconv.Itoa(em) + "em"
tag.AddStyle("border-radius", value)
tag.AddStyle("-webkit-border-radius", value)
tag.AddStyle("-moz-border-radius", value)
}
// SetColor changes the forground and background color CSS styles
func (tag *Tag) SetColor(fgColor, bgColor string) {
tag.AddStyle("color", fgColor)
tag.AddStyle("background-color", bgColor)
}
// AddBox adds a <div> box
func (tag *Tag) AddBox(id string, rounded bool, em, text, fgColor, bgColor, leftPadding string) *Tag {
div := tag.AddNewTag("div")
div.AddAttrib("id", id)
div.AddContent(text)
if rounded {
div.SetRounded(em)
}
div.SetColor(fgColor, bgColor)
div.AddStyle("padding-left", leftPadding)
return div
}
// Add an <img> image
func (tag *Tag) AddImage(url string, width string) *Tag {
img := tag.AddNewTag("img")
img.AddAttrib("src", url)
img.AddStyle("width", width)
return img
}
// Repeat the background. repeat can be for instance "repeat-x"
func (tag *Tag) RepeatBackground(bgimageurl, repeat string) {
tag.AddStyle("background-image", "url('"+bgimageurl+"')")
tag.AddStyle("background-repeat", repeat)
}