1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-03 00:47:46 +01:00
liquid/expression/context.go
2017-07-05 11:17:31 -04:00

29 lines
740 B
Go

package expression
// Context is the expression evaluation context. It maps variables names to values.
type Context interface {
ApplyFilter(string, valueFn, []valueFn) interface{}
Get(string) interface{}
Set(string, interface{})
}
type context struct {
Config
bindings map[string]interface{}
}
// NewContext makes a new expression evaluation context.
func NewContext(vars map[string]interface{}, s Config) Context {
return &context{s, vars}
}
// Get looks up a variable value in the expression context.
func (c *context) Get(name string) interface{} {
return ToLiquid(c.bindings[name])
}
// Set sets a variable value in the expression context.
func (c *context) Set(name string, value interface{}) {
c.bindings[name] = value
}