-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtml.go
More file actions
52 lines (46 loc) · 867 Bytes
/
html.go
File metadata and controls
52 lines (46 loc) · 867 Bytes
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
package main
import (
"io"
"golang.org/x/exp/slices"
)
func html(w io.Writer, tables Tables, section int) error {
t, err := newTemplate(htmlTemplate)
if err != nil {
return err
}
slices.SortFunc(tables, func(a, b Table) bool {
return a.Name < b.Name
})
return t.Execute(w, struct {
Tables Tables
Section int
}{
Tables: tables,
Section: section,
})
}
var htmlTemplate = `
{{range $i, $t := .Tables }}
<h{{$.Section}}>{{$t.Name}}</h{{$.Section}}>
<table>
<thead>
<tr>
<th>Column</th>
<th>Type</th>
<th>Default</th>
<th>Refers</th>
</tr>
</thead>
<tbody>
{{range $j, $c := $t.Columns }}
<tr>
<td>{{$c.Name}}{{if $c.PrimaryKey}} (pk){{end}}</td>
<td>{{$c.Type}}</td>
<td>{{$c.Default}}{{if not $c.NotNull}} (nullable){{end}}</td>
<td>{{- fk $t $c -}}</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
`