Skip to content

Commit

Permalink
Merge pull request #104 from jam3sn/add-basic-liquid-engine
Browse files Browse the repository at this point in the history
Add a NewBasicEngine function
  • Loading branch information
danog authored Nov 6, 2024
2 parents fe7cf84 + 6d3633b commit f432a25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func NewEngine() *Engine {
return &e
}

// NewBasicEngine returns a new Engine without the standard filters or tags.
func NewBasicEngine() *Engine {
return &Engine{render.NewConfig()}
}

// RegisterBlock defines a block e.g. {% tag %}…{% endtag %}.
func (e *Engine) RegisterBlock(name string, td Renderer) {
e.cfg.AddBlock(name).Renderer(func(w io.Writer, ctx render.Context) error {
Expand Down
19 changes: 19 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ func TestEngine_ParseAndRenderString(t *testing.T) {
}
}

func TestBasicEngine_ParseAndRenderString(t *testing.T) {
engine := NewBasicEngine()

t.Run("1", func(t *testing.T) {
test := liquidTests[0]
out, err := engine.ParseAndRenderString(test.in, testBindings)
require.NoErrorf(t, err, test.in)
require.Equalf(t, test.expected, out, test.in)
})

for i, test := range liquidTests[1:] {
t.Run(strconv.Itoa(i+2), func(t *testing.T) {
out, err := engine.ParseAndRenderString(test.in, testBindings)
require.Errorf(t, err, test.in)
require.Equalf(t, "", out, test.in)
})
}
}

type capWriter struct {
bytes.Buffer
}
Expand Down

0 comments on commit f432a25

Please sign in to comment.