/
warnings.go
57 lines (45 loc) 路 964 Bytes
/
warnings.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
package gedcom
import (
"io"
"sort"
"github.com/elliotchance/gedcom/v39/html/core"
)
type Warnings []Warning
func (ws Warnings) Strings() (ss []string) {
for _, w := range ws {
ss = append(ss, w.String())
}
return
}
func (ws Warnings) WriteHTMLTo(w io.Writer) (int64, error) {
var data [][]string
for _, warning := range ws {
data = append(data, []string{
warning.Name(),
warning.Context().String(),
warning.String(),
})
}
sort.Slice(data, func(i, j int) bool {
a := data[i][1]
b := data[j][1]
return a < b
})
rows := []core.Component{
core.NewTableHead(
"#",
"Name",
"Context",
"Description",
),
}
for i, row := range data {
rows = append(rows, core.NewTableRow(
core.NewTableCell(core.NewNumber(i+1)),
core.NewTableCell(core.NewText(row[0])),
core.NewTableCell(core.NewText(row[1])),
core.NewTableCell(core.NewText(row[2])),
))
}
return core.NewTable("", rows...).WriteHTMLTo(w)
}