-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.go
65 lines (52 loc) · 901 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
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"html/template"
"io"
"strings"
)
const (
markdownTemplate = `
<div align="center">
<h1>{{toUpper .ProjectName}}</h1>
<a href="{{.Website}}">{{.Website}}</a>
</div>
### What is {{.ProjectName}}?
{{.Description}}
> #### Important Notice
> {{.Notice}}
### Usage:
- one
- two
- three
#
### Author
**{{.Author}} {{.Year}}**
`
)
// TemplateMD template
type TemplateMD struct {
ProjectName string
Website string
Description string
Notice string
Author string
Year string
}
// ParseOutput template
func ParseOutput(in TemplateMD, out io.Writer) error {
funcMap := template.FuncMap{
"toUpper": func(v string) string {
return strings.ToUpper(v)
},
}
t := template.New("tmpl").Funcs(funcMap)
t, err := t.Parse(markdownTemplate)
if err != nil {
return err
}
err = t.Execute(out, in)
if err != nil {
return err
}
return nil
}