-
Notifications
You must be signed in to change notification settings - Fork 1
/
render.go
112 lines (89 loc) · 2.51 KB
/
render.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
package main
import (
"bytes"
"io"
"text/template"
"github.com/chop-dbhi/data-models-service/client"
"github.com/russross/blackfriday"
)
const (
htmlFlags = blackfriday.HTML_SKIP_HTML |
blackfriday.HTML_USE_SMARTYPANTS
extFlags = blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
blackfriday.EXTENSION_TABLES |
blackfriday.EXTENSION_AUTOLINK |
blackfriday.EXTENSION_STRIKETHROUGH |
blackfriday.EXTENSION_HEADER_IDS |
blackfriday.EXTENSION_FENCED_CODE
)
func loadTemplate(n string) *template.Template {
data, err := Asset(n)
if err != nil {
panic(err)
}
return template.Must(template.New("model").Parse(string(data)))
}
func renderMarkdown(w io.Writer, n string, v interface{}) {
t := loadTemplate(n)
t.Execute(w, v)
}
func renderHTML(w io.Writer, b []byte) {
// Render the final HTML page.
t := loadTemplate("assets/wrap.html")
s, _ := Asset("assets/style.css")
renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")
c := blackfriday.Markdown(b, renderer, extFlags)
data := map[string]string{
"Content": string(c),
"Style": string(s),
"GoogleAnalytics": googleAnalytics,
}
t.Execute(w, data)
}
func RenderModelsMarkdown(w io.Writer, v interface{}) {
renderMarkdown(w, "assets/models.md", v)
}
func RenderModelMarkdown(w io.Writer, v interface{}) {
renderMarkdown(w, "assets/models.md", v)
}
func RenderModelVersionMarkdown(w io.Writer, v interface{}) {
renderMarkdown(w, "assets/full.md", v)
}
func RenderModelCompareMarkdown(w io.Writer, m1 *client.Model, m2 *client.Model) {
DiffModels(w, m1, m2)
}
func RenderReposMarkdown(w io.Writer, v interface{}) {
renderMarkdown(w, "assets/repos.md", v)
}
func RenderIndexHTML(w io.Writer) {
b := bytes.Buffer{}
renderMarkdown(&b, "assets/index.md", map[string]interface{}{
"Version": progVersion,
})
renderHTML(w, b.Bytes())
}
func RenderModelsHTML(w io.Writer, v interface{}) {
b := bytes.Buffer{}
renderMarkdown(&b, "assets/models.md", v)
renderHTML(w, b.Bytes())
}
func RenderModelHTML(w io.Writer, v interface{}) {
b := bytes.Buffer{}
renderMarkdown(&b, "assets/models.md", v)
renderHTML(w, b.Bytes())
}
func RenderModelVersionHTML(w io.Writer, v interface{}) {
b := bytes.Buffer{}
renderMarkdown(&b, "assets/full.md", v)
renderHTML(w, b.Bytes())
}
func RenderModelCompareHTML(w io.Writer, m1 *client.Model, m2 *client.Model) {
b := bytes.Buffer{}
DiffModels(&b, m1, m2)
renderHTML(w, b.Bytes())
}
func RenderReposHTML(w io.Writer, v interface{}) {
b := bytes.Buffer{}
RenderReposMarkdown(&b, v)
renderHTML(w, b.Bytes())
}