-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_markdown.go
114 lines (96 loc) · 2.47 KB
/
report_markdown.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
108
109
110
111
112
113
114
package drivercaps
import (
"bufio"
"html/template"
"io"
"log"
"os"
"time"
)
func renderMarkdown(results [][]string, test *DriverTest, tim time.Time) {
writeMarkdown(os.Stdout, results, test, tim)
}
func writeMarkdownFile(results [][]string, test *DriverTest, tim time.Time) {
// TODO(js) This is a bad code smell. We override the default headings from csv,
// both here and when dealing with ascii :/
header := []string{
"DDL Definition",
".Name",
".DBTypeName",
".Nullable",
".DecimalSize",
".Length",
".ScanType",
}
var res [][]string
res = append(res, header)
res = append(res, results[1:len(results)]...)
results = res
filename := localFilename(markdownFilename)
// log.Println("filename", filename)
f, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()
bufw := bufio.NewWriter(f)
writeMarkdown(bufw, results, test, tim)
bufw.Flush()
}
// func markdownFilename() string {
// wd, err := os.Getwd()
// if err != nil {
// log.Fatal(err)
// }
// return wd + "/README.md"
// }
func writeMarkdown(w io.Writer, results [][]string, test *DriverTest, tim time.Time) {
// TODO(js) Externalise this (markdown) template.
// "[]*" html escaped for markdown = []*
const tpl = `
# Driver sql.ColumnType Capability Report
- Package "{{.Package}}" ({{.Driver}})
- {{.Database}}
(Please scroll left/right to view full table contents)
<table>
<thead>
<tr>
{{range .Headings}}<th>{{ . }}</th>{{end}}
</tr>
</thead>
<tbody>{{range $row := .Rows}}
<tr>{{range $row}}
{{if and (ne . "-") (ne . "")}}<td nowrap><code>{{ . }}</code></td>{{end}}{{if eq . "-"}}<td>-</td>{{end}}{{if eq . ""}}<td/>{{end}}{{end}}
</tr>{{end}}
</tbody>
</table>
Report for [{{.Package}}](https://{{.URL}}) ({{.Driver}})<br/>
Test timestamp {{.Timestamp}}<br/>
Generated by [drivercaps](https://github.com/jimsmart/drivercaps)
`
t, err := template.New("webpage").Parse(tpl)
if err != nil {
log.Fatalf("template.Parse error %v", err)
}
data := struct {
Database string
URL string
Package string
Driver string
Headings []string
Rows [][]string
Timestamp string
}{
Database: test.Database,
URL: test.PkgURL,
Package: test.PkgName,
Driver: test.DrvName,
Headings: results[0],
Rows: results[1:len(results)],
Timestamp: tim.Format(time.RFC3339),
}
err = t.Execute(w, data)
if err != nil {
log.Fatalf("template.Execute error %v", err)
}
}