-
Notifications
You must be signed in to change notification settings - Fork 136
/
evaluation_ctx.go
43 lines (31 loc) · 970 Bytes
/
evaluation_ctx.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 texttemplate
import (
"fmt"
"github.com/k14s/ytt/pkg/template"
)
const (
EvaluationCtxDialectName template.EvaluationCtxDialectName = "text"
)
type EvaluationCtx struct{}
var _ template.EvaluationCtxDialect = EvaluationCtx{}
func (e EvaluationCtx) PrepareNode(
parentNode template.EvaluationNode, node template.EvaluationNode) error {
return nil
}
func (e EvaluationCtx) SetMapItemKey(node template.EvaluationNode, val interface{}) error {
return fmt.Errorf("unsupported operation")
}
func (e EvaluationCtx) Replace(
parentNodes []template.EvaluationNode, val interface{}) error {
return fmt.Errorf("unsupported operation")
}
func (e EvaluationCtx) ShouldWrapRootValue(nodeVal interface{}) bool {
_, root := nodeVal.(*NodeRoot)
return !root
}
func (e EvaluationCtx) WrapRootValue(val interface{}) interface{} {
if typedVal, ok := val.(*NodeRoot); ok {
return typedVal.AsString()
}
panic(fmt.Sprintf("Unexpected root value %T", val))
}