-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.go
44 lines (35 loc) · 1.26 KB
/
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
package main
import (
text "text/template"
"html/template"
"github.com/patrickalin/nest-client-go/assembly"
)
//GetTemplate retrieve a template
func GetTemplate(templateName string, templateLocation string, funcs map[string]interface{}, dev bool) *text.Template {
if dev {
t, err := text.New(templateName).Funcs(funcs).ParseFiles(templateLocation)
checkErr(err, funcName(), "Load template console", templateLocation)
return t
}
assetNest, err := assembly.Asset(templateLocation)
t, err := text.New(templateName).Funcs(funcs).Parse(string(assetNest[:]))
checkErr(err, funcName(), "Load template console", templateLocation)
return t
}
// GetHTMLTemplate "nest_header.html","tmpl/nest_header.html",map[string]interface{}{"T": config.translateFunc,}
func GetHTMLTemplate(templateName string, templatesLocation []string, funcs map[string]interface{}, dev bool) *template.Template {
t := template.New(templateName)
t.Funcs(funcs)
if dev {
tp, err := t.ParseFiles(templatesLocation...)
checkErr(err, funcName(), "ParseFiles", "")
return tp
}
for _, l := range templatesLocation {
asset, err := assembly.Asset(l)
checkErr(err, funcName(), "Assembly template", l)
t, err = t.Parse(string(asset[:]))
checkErr(err, funcName(), "Parse file", "")
}
return t
}