-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.go
107 lines (92 loc) · 1.87 KB
/
grid.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
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
package carbon
import "io"
type grid struct {
children []*column
attrs []Attr
condensed bool
narrow bool
fullWidth bool
noGutter bool
noGutterLeft bool
noGutterRight bool
padding bool
}
var _ Component = (*grid)(nil)
func Grid(c ...*column) *grid {
return &grid{
children: c,
attrs: nil,
condensed: false,
narrow: false,
fullWidth: false,
noGutter: false,
noGutterLeft: false,
noGutterRight: false,
padding: false,
}
}
func (g *grid) Attr(name string, value string) *grid {
g.attrs = append(g.attrs, Attr{name, value})
return g
}
func (g *grid) Condensed(condensed bool) *grid {
g.condensed = condensed
return g
}
func (g *grid) Narrow(narrow bool) *grid {
g.narrow = narrow
return g
}
func (g *grid) FullWidth(fullWidth bool) *grid {
g.fullWidth = fullWidth
return g
}
func (g *grid) NoGutter(noGutter bool) *grid {
g.noGutter = noGutter
return g
}
func (g *grid) NoGutterLeft(noGutterLeft bool) *grid {
g.noGutterLeft = noGutterLeft
return g
}
func (g *grid) NoGutterRight(noGutterRight bool) *grid {
g.noGutterRight = noGutterRight
return g
}
func (g *grid) Padding(padding bool) *grid {
g.padding = padding
return g
}
func (g *grid) Render(w io.Writer) {
w.Write([]byte(`<div class="bx--grid`))
if g.condensed {
w.Write([]byte(` bx--grid--condensed`))
}
if g.narrow {
w.Write([]byte(` bx--grid--narrow`))
}
if g.fullWidth {
w.Write([]byte(` bx--grid--full-width`))
}
if g.noGutter {
w.Write([]byte(` bx--no-gutter`))
}
if g.noGutterLeft {
w.Write([]byte(` bx--no-gutter--left`))
}
if g.noGutterRight {
w.Write([]byte(` bx--no-gutter--right`))
}
if g.padding {
w.Write([]byte(` bx--grid--padding`))
}
w.Write([]byte(`"`))
renderAttrs(w, g.attrs)
w.Write([]byte(`>`))
{
for _, child := range g.children {
child.Render(w)
}
}
w.Write([]byte("</div>"))
}