1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 06:39:02 +01:00

Merge pull request #59 from carolynvs/expose-ast

Expose the template ast
This commit is contained in:
Oliver Steele 2022-02-11 16:35:02 +08:00 committed by GitHub
commit 2aa750df9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -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)

View File

@ -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 }}`))