-
Notifications
You must be signed in to change notification settings - Fork 3
/
compiled.go
43 lines (34 loc) · 1.01 KB
/
compiled.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
package parse
import (
"fmt"
"io"
)
// CompiledNode is a Node to represent
// a compiled template in the template nodes flow.
type CompiledNode struct {
NodeType
Pos
tr *Tree
Execute CompiledTemplateFunc
}
// Templater is the interface for text/html templates.
type Templater interface {
GetFuncs() map[string]interface{}
ExecuteTemplate(io.Writer, string, interface{}) error
}
// CompiledTemplateFunc is the signature of the func responsible to render a compiled template.
type CompiledTemplateFunc func(t Templater, w io.Writer, data interface{}) error
// NewCompiledNode makes a new instance of CompiledNode
func (t *Tree) NewCompiledNode(Execute CompiledTemplateFunc) *CompiledNode {
return &CompiledNode{tr: t, NodeType: NodeCompiledNode, Execute: Execute}
}
func (a *CompiledNode) String() string {
return fmt.Sprintf("{{compiled}}")
}
func (a *CompiledNode) tree() *Tree {
return a.tr
}
// Copy this Node to a new instance.
func (a *CompiledNode) Copy() Node {
return a.tr.NewCompiledNode(a.Execute)
}