Skip to content

Commit

Permalink
Merge pull request #66 from aisbergg/feat-context-env
Browse files Browse the repository at this point in the history
Expose the template lexical environment
  • Loading branch information
danog authored Aug 23, 2023
2 parents ddc76a5 + 9dd04d0 commit 3170e91
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions render/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

// Context provides the rendering context for a tag renderer.
type Context interface {
// Bindings returns the current lexical environment.
Bindings() map[string]interface{}
// Get retrieves the value of a variable from the current lexical environment.
Get(name string) interface{}
// Errorf creates a SourceError, that includes the source location.
Expand Down Expand Up @@ -104,6 +106,11 @@ func (c rendererContext) EvaluateString(source string) (out interface{}, err err
return expressions.EvaluateString(source, expressions.NewContext(c.ctx.bindings, c.ctx.config.Config.Config))
}

// Bindings returns the current lexical environment.
func (c rendererContext) Bindings() map[string]interface{} {
return c.ctx.bindings
}

// Get gets a variable value within an evaluation context.
func (c rendererContext) Get(name string) interface{} {
return c.ctx.bindings[name]
Expand Down

0 comments on commit 3170e91

Please sign in to comment.