-
Notifications
You must be signed in to change notification settings - Fork 21
/
table_cell.go
69 lines (51 loc) · 1.03 KB
/
table_cell.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
package core
import (
"io"
)
type TableCell struct {
content Component
class, style string
noWrap bool
isHeader bool
}
func NewTableCell(content Component) *TableCell {
return &TableCell{
content: content,
}
}
func (c *TableCell) NoWrap() *TableCell {
c.noWrap = true
return c
}
func (c *TableCell) Class(class string) *TableCell {
c.class = class
return c
}
func (c *TableCell) Style(style string) *TableCell {
c.style = style
return c
}
func (c *TableCell) Header() *TableCell {
c.isHeader = true
return c
}
func (c *TableCell) WriteHTMLTo(w io.Writer) (int64, error) {
htmlTag := "td"
if c.isHeader {
htmlTag = "th"
}
n := appendSprintf(w, `<%s scope="col"`, htmlTag)
if c.class != "" {
n += appendSprintf(w, ` class="%s"`, c.class)
}
if c.noWrap {
n += appendString(w, ` nowrap="nowrap"`)
}
if c.style != "" {
n += appendSprintf(w, ` style="%s"`, c.style)
}
n += appendString(w, `>`)
n += appendComponent(w, c.content)
n += appendSprintf(w, `</%s>`, htmlTag)
return n, nil
}