diff --git a/template.go b/template.go index 0628272..5e60a90 100644 --- a/template.go +++ b/template.go @@ -24,6 +24,12 @@ func newTemplate(cfg *render.Config, source []byte, path string, line int) (*Tem return &Template{root, cfg}, nil } +// GetRoot returns the root node of the abstract syntax tree (AST) representing +// the parsed template. +func (t *Template) GetRoot() render.Node { + return t.root +} + // Render executes the template with the specified variable bindings. func (t *Template) Render(vars Bindings) ([]byte, SourceError) { buf := new(bytes.Buffer) diff --git a/template_test.go b/template_test.go index 77e2633..d54f899 100644 --- a/template_test.go +++ b/template_test.go @@ -9,6 +9,12 @@ import ( "github.com/stretchr/testify/require" ) +func TestTemplate_GetRoot(t *testing.T) { + root := &render.SeqNode{} + tmpl := Template{root: root} + require.Same(t, root, tmpl.GetRoot()) +} + func TestTemplate_RenderString(t *testing.T) { engine := NewEngine() tpl, err := engine.ParseTemplate([]byte(`{{ "hello world" | capitalize }}`))