-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_file.go
More file actions
41 lines (34 loc) · 973 Bytes
/
Copy pathtemplate_file.go
File metadata and controls
41 lines (34 loc) · 973 Bytes
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
// +build !bip
package bip
import (
"io"
"github.com/flosch/pongo2"
)
// FileTemplate ...
type FileTemplate struct {
fileName string
}
// Execute the template and returns the rendered template as a string.
func (t *FileTemplate) Execute(context Context) (string, error) {
tpl, err := pongo2.FromFile(t.fileName)
if err != nil {
return "", err
}
return tpl.Execute(pongo2.Context(context))
}
// ExecuteBytes the template and returns the rendered template as a []byte.
func (t *FileTemplate) ExecuteBytes(context Context) ([]byte, error) {
tpl, err := pongo2.FromFile(t.fileName)
if err != nil {
return nil, err
}
return tpl.ExecuteBytes(pongo2.Context(context))
}
// ExecuteWriter writes result that the template with the given context to writer.
func (t *FileTemplate) ExecuteWriter(context Context, w io.Writer) error {
tpl, err := pongo2.FromFile(t.fileName)
if err != nil {
return err
}
return tpl.ExecuteWriter(pongo2.Context(context), w)
}