1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 06:34:45 +01:00
liquid/expressions/context.go
Oliver Steele e71bc95d5f Lint
2017-07-01 23:52:23 -04:00

45 lines
999 B
Go

package expressions
// Context is the expression evaluation context. It maps variables names to values.
type Context interface {
Get(string) interface{}
Set(string, interface{})
Filters() *filterDictionary
}
type context struct {
bindings map[string]interface{}
Settings
}
type Settings struct {
filters *filterDictionary
}
func NewSettings() Settings {
return Settings{newFilterDictionary()}
}
func (s Settings) AddFilter(name string, fn interface{}) {
s.filters.addFilter(name, fn)
}
// NewContext makes a new expression evaluation context.
func NewContext(vars map[string]interface{}, s Settings) Context {
return &context{vars, s}
}
func (c *context) Filters() *filterDictionary {
return c.filters
}
// Get looks up a variable value in the expression context.
func (c *context) Get(name string) interface{} {
return c.bindings[name]
}
// Set sets a variable value in the expression context.
func (c *context) Set(name string, value interface{}) {
c.bindings[name] = value
}