1
0
mirror of https://github.com/danog/liquid.git synced 2025-01-23 08:11:23 +01:00
liquid/expressions/context.go

28 lines
667 B
Go
Raw Normal View History

2017-06-26 15:36:05 -04:00
package expressions
// Context is the expression evaluation context. It maps variables names to values.
type Context interface {
Get(string) interface{}
Set(string, interface{})
}
type context struct {
vars map[string]interface{}
copied bool
}
2017-06-27 13:36:38 -04:00
// NewContext makes a new expression evaluation context.
2017-06-26 15:36:05 -04:00
func NewContext(vars map[string]interface{}) Context {
return &context{vars, false}
}
2017-06-27 13:36:38 -04:00
// Get looks up a variable value in the expression context.
2017-06-26 15:36:05 -04:00
func (c *context) Get(name string) interface{} {
return c.vars[name]
}
2017-06-27 13:36:38 -04:00
// Set sets a variable value in the expression context.
2017-06-26 15:36:05 -04:00
func (c *context) Set(name string, value interface{}) {
c.vars[name] = value
}