Skip to content

Upgrade Herb to v0.9#84

Merged
marcoroth merged 1 commit intomainfrom
herb-v0.9.0
Mar 18, 2026
Merged

Upgrade Herb to v0.9#84
marcoroth merged 1 commit intomainfrom
herb-v0.9.0

Conversation

@marcoroth
Copy link
Copy Markdown
Owner

@marcoroth marcoroth commented Mar 15, 2026

@marcoroth marcoroth force-pushed the herb-v0.9.0 branch 2 times, most recently from e8095a8 to 3f8eaeb Compare March 15, 2026 14:26
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
@marcoroth marcoroth changed the title Upgrade Herb to v0.9.0 Upgrade Herb to v0.9 Mar 18, 2026
@marcoroth marcoroth merged commit 9141845 into main Mar 18, 2026
24 checks passed
@marcoroth marcoroth deleted the herb-v0.9.0 branch March 18, 2026 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant