2017-07-04 17:41:45 +02:00
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
2017-07-14 02:18:23 +02:00
|
|
|
"github.com/osteele/liquid/expressions"
|
2017-07-04 17:41:45 +02:00
|
|
|
)
|
|
|
|
|
2017-07-09 17:18:35 +02:00
|
|
|
// nodeContext provides the evaluation context for rendering the AST.
|
2017-07-09 17:49:24 +02:00
|
|
|
//
|
|
|
|
// This type has a clumsy name so that render.Context, in the public API, can
|
|
|
|
// have a clean name that doesn't stutter.
|
2017-07-04 17:41:45 +02:00
|
|
|
type nodeContext struct {
|
|
|
|
bindings map[string]interface{}
|
2017-07-04 22:48:38 +02:00
|
|
|
config Config
|
2017-07-04 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// newNodeContext creates a new evaluation context.
|
2017-07-07 11:41:37 +02:00
|
|
|
func newNodeContext(scope map[string]interface{}, c Config) nodeContext {
|
2017-07-04 17:41:45 +02:00
|
|
|
// The assign tag modifies the scope, so make a copy first.
|
|
|
|
// TODO this isn't really the right place for this.
|
|
|
|
vars := map[string]interface{}{}
|
|
|
|
for k, v := range scope {
|
|
|
|
vars[k] = v
|
|
|
|
}
|
2017-07-07 11:41:37 +02:00
|
|
|
return nodeContext{vars, c}
|
2017-07-04 17:41:45 +02:00
|
|
|
}
|
2017-07-19 16:26:11 +02:00
|
|
|
|
2017-07-04 17:41:45 +02:00
|
|
|
// Evaluate evaluates an expression within the template context.
|
2017-07-14 02:18:23 +02:00
|
|
|
func (c nodeContext) Evaluate(expr expressions.Expression) (out interface{}, err error) {
|
|
|
|
return expr.Evaluate(expressions.NewContext(c.bindings, c.config.Config.Config))
|
2017-07-04 17:41:45 +02:00
|
|
|
}
|