-
Notifications
You must be signed in to change notification settings - Fork 68
feat: add RemoveTag engine method #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a RemoveTag method to the Engine API, enabling dynamic removal of tag definitions from the engine configuration. This addresses the use case of disabling standard tags (like {% include %}) and getting parse-time errors instead of render-time errors when those tags are used.
Key changes:
- Added
RemoveTagmethod torender.Configthat uses Go'sdeletefunction to remove tags from the internal map - Exposed
RemoveTagthrough the publicEngineAPI with comprehensive documentation - Added test coverage verifying that removed tags cause parse/render errors
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| render/tags.go | Implements low-level RemoveTag method on Config that deletes tag from internal map |
| engine.go | Exposes public RemoveTag API with clear documentation about idempotent behavior |
| engine_examples_test.go | Adds test verifying custom tag removal causes errors on subsequent use |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| func TestRemoveTag(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.RemoveTag("echo") | ||
|
|
||
| _, err = engine.ParseAndRenderString(source, emptyBindings) | ||
| require.Error(t, err) | ||
| } |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test only verifies removing a custom tag (echo), but the PR description specifically mentions removing standard tags like {% include %} to get parse errors. Consider adding a test case that removes a standard tag to ensure this use case works as intended.
Example:
t.Run("RemoveStandardTag", func(t *testing.T) {
engine := NewEngine()
source := `{% if true %}test{% endif %}`
_, err := engine.ParseAndRenderString(source, emptyBindings)
require.NoError(t, err)
engine.RemoveTag("if")
_, err = engine.ParseAndRenderString(source, emptyBindings)
require.Error(t, err)
})| } | ||
|
|
||
| // RemoveTag removes a tag definition. | ||
| func (c *Config) RemoveTag(name string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider whether this should be RemoveTag or UnregisterTag. The first reads better in isolation; the second has better symmetry with RegisterTag.
This is just a question for you, not a requirement for me to accept the PR. I'm okay with either. Don't do both though! This ends up making it harder to work with client code.
| }) | ||
| } | ||
|
|
||
| func TestRemoveTag(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a test, this should go in engine_test.go. Or rename it to ExampleEngine_RemoveTag as a testable example.
osteele
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contribution! This looks solid. A couple of minor review comments are attached.
The aim of this PR is to add a function that allows to remove a defined tag. This is useful for my specific need as I need to disable a standard tag (
{% include %}) and still get aparseerror.Currently in order to disable a standard tag, you can:
This overrides the existing tag functionaly of
includeand will throw an error atrendertime. AddingRemoveTagallows to remove standard tags dinamically.Checklist
make testpasses.make lintpasses.