Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,11 @@ func (e *Engine) ParseTemplateAndCache(source []byte, path string, line int) (*T
func (e *Engine) SetAutoEscapeReplacer(replacer render.Replacer) {
e.cfg.SetAutoEscapeReplacer(replacer)
}

// UnregisterTag removes the named tag definition from the engine's configuration.
// After calling UnregisterTag the tag will no longer be recognized by subsequent
// parsing or rendering operations. The call is idempotent — unregistering a tag
// that is not registered is a no-op.
func (e *Engine) UnregisterTag(name string) {
e.cfg.UnregisterTag(name)
}
17 changes: 17 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"testing"

"github.com/osteele/liquid/render"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -183,3 +184,19 @@ func Test_template_store(t *testing.T) {
out, _ := engine.ParseAndRenderString(string(template), params)
require.Equal(t, "Message Text: filename from: template.liquid.", out)
}

func TestEngine_UnregisterTag(t *testing.T) {
engine := NewEngine()
engine.RegisterTag("echo", func(c render.Context) (string, error) {
return c.TagArgs(), nil
})
source := `{% echo hello world %}`

_, err := engine.ParseAndRenderString(source, emptyBindings)
require.NoError(t, err)

engine.UnregisterTag("echo")

_, err = engine.ParseAndRenderString(source, emptyBindings)
require.Error(t, err)
}
5 changes: 5 additions & 0 deletions render/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ func (c *Config) FindTagDefinition(name string) (TagCompiler, bool) {
td, ok := c.tags[name]
return td, ok
}

// UnregisterTag removes a tag definition.
func (c *Config) UnregisterTag(name string) {
delete(c.tags, name)
}