Merged
Conversation
e8095a8 to
3f8eaeb
Compare
marcoroth
added a commit
to marcoroth/herb
that referenced
this pull request
Mar 18, 2026
This pull request updates `add_expression_block` in the `Herb::Engine` to delegate to `add_expression` instead of dispatching directly to block result methods. This makes `Herb::Engine` a true drop-in replacement for `Erubi::Engine` when subclassed. Previously, subclasses that overrode `add_expression` (like ActionView's Erubi handler does) would not have their override apply to block expressions, because `add_expression_block` bypassed `add_expression` entirely. This meant subclasses also had to override `add_expression_block` and `add_expression_block_end` to handle blocks correctly. This pattern led to bugs like unmatched closing parentheses. Now, `add_expression_block` sets an `expression_block?` flag and delegates to `add_expression`. The default `add_expression` checks this flag to route to the appropriate block result methods, preserving the correct `<< (code do ... end)` output for standalone usage. A new `@_expression_block_open_paren` flag tracks whether the opening method added a parenthesis, so `add_expression_block_end` knows whether to close with `)` or just emit `end` as regular code. When no methods are overridden, the default `add_expression` routes block expressions to the existing `add_expression_block_result` methods, preserving Herb's smart block handling with proper parenthesization. When a subclass overrides only `add_expression`, the same pattern ActionView uses with Erubi, block expressions now flow through that override automatically. The `expression_block?` predicate lets the subclass distinguish blocks from regular expressions without relying on a `BLOCK_EXPR` regex, since the parser already knows. When a subclass overrides `add_expression_block` directly, that override takes precedence and the delegation never happens. Related marcoroth/reactionview#83 Related marcoroth/reactionview#84
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://github.com/marcoroth/herb/releases/tag/v0.9.0
https://github.com/marcoroth/herb/releases/tag/v0.9.1
https://herb-tools.dev/blog/whats-new-in-herb-v0-9