-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstd.go
65 lines (48 loc) · 1.85 KB
/
std.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 easytpl
import (
"html/template"
"io"
)
// create an default instance
var std = NewRenderer()
// Reset the default instance
func Reset() { std = NewRenderer() }
// Revert the default instance, alias of Reset()
func Revert() { Reset() }
// Default get default instance
func Default() *Renderer { return std }
// AddFunc add template func
func AddFunc(name string, fn any) { std.AddFunc(name, fn) }
// AddFuncMap add template func map
func AddFuncMap(fm template.FuncMap) { std.AddFuncMap(fm) }
// LoadString load named template string.
func LoadString(tplName string, tplString string) { std.LoadString(tplName, tplString) }
// LoadStrings load multi named template strings
func LoadStrings(sMap map[string]string) { std.LoadStrings(sMap) }
// LoadFiles load custom template files.
func LoadFiles(files ...string) { std.LoadFiles(files...) }
// LoadByGlob load templates by glob pattern.
func LoadByGlob(pattern string, baseDirs ...string) { std.LoadByGlob(pattern, baseDirs...) }
// Initialize the default instance with config func
func Initialize(fns ...OptionFn) {
std.WithOptions(fns...).MustInit()
}
/*************************************************************
* render templates use default instance
*************************************************************/
// Render a template name/file with layout, write result to the Writer.
func Render(w io.Writer, tplName string, v any, layout ...string) error {
return std.Render(w, tplName, v, layout...)
}
// Execute render partial, will not render layout file
func Execute(w io.Writer, tplName string, v any) error {
return std.Execute(w, tplName, v)
}
// Partial is alias of the Execute()
func Partial(w io.Writer, tplName string, v any) error {
return std.Execute(w, tplName, v)
}
// String render a template string
func String(w io.Writer, tplStr string, v any) error {
return std.String(w, tplStr, v)
}