-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.go
52 lines (43 loc) · 863 Bytes
/
template.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
package svgsaurus
import (
"html/template"
)
var svgTemplate *template.Template
func init() {
var err error
svgTemplate, err = template.New("svg").Parse(svgTemplateString)
if err != nil {
panic(err)
}
}
var svgTemplateString = `
<svg xmlns="http://www.w3.org/2000/svg" height="{{.Height}}" viewBox="0 0 {{.Width}} {{.Height}}">
<style>
text {
font-family: {{.Font}}, sans-serif;
font-size: {{.Size}}px;
{{- if .Bold -}}
font-weight: bold;
{{- end}}
{{- if .Italic -}}
font-style: italic;
{{- end}}
{{- if .Underline -}}
text-decoration: underline;
{{- end}}
}
</style>
{{if .Background -}}
<rect
width="{{.Width}}"
height="{{.Height}}"
style="fill:#{{.Background}};"
/>
{{- end}}
<text
x="{{.X}}"
y="{{.Y}}"
fill="#{{.Color}}"
>[[Text]]</text>
</svg>
`