aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/template/template.go
blob: 8b3fb73879945a9bdf23f584a675ec0c6ead34b2 (plain)
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
package template

import (
	_ "embed"
	html "html/template"
	"io"
	text "text/template"
)

type template interface {
	Execute(wr io.Writer, data interface{}) error
}

type Template struct {
	template
	useHtml bool
	dflt    string
}

//go:embed html.tpl
var defaultHtmlTpl string

//go:embed text.tpl
var defaultTextTpl string

var Html = Template{
	useHtml: true,
	dflt:    defaultHtmlTpl,
}

var Text = Template{
	useHtml: false,
	dflt:    defaultTextTpl,
}

func (tpl *Template) loadDefault() {
	if tpl.useHtml {
		tpl.template = html.Must(html.New("Html").Funcs(funcMap).Parse(tpl.dflt))
	} else {
		tpl.template = text.Must(text.New("Text").Funcs(funcMap).Parse(tpl.dflt))
	}
}

func init() {
	Html.loadDefault()
	Text.loadDefault()
}