Skip to content

Engine: Delegate context-aware expressions to overridable engine methods#1421

Merged
marcoroth merged 1 commit intomainfrom
expression-block-delegation
Mar 18, 2026
Merged

Engine: Delegate context-aware expressions to overridable engine methods#1421
marcoroth merged 1 commit intomainfrom
expression-block-delegation

Conversation

@marcoroth
Copy link
Copy Markdown
Owner

@marcoroth marcoroth commented Mar 18, 2026

This pull request moves expression handling logic from the compiler into overridable engine methods, making Herb::Engine an easier drop-in replacement for Erubi::Engine.

Previously, the compiler bypassed the engine's add_expression method in two cases:

  1. Block expressions (<%= link_to do %>...<% end %>), the compiler called add_expression_block which dispatched directly to add_expression_block_result, skipping any subclass override of add_expression.

  2. Context-aware expressions (inside <script>, <style>, or attribute values), the compiler's add_context_aware_expression wrote directly to @engine.src, bypassing the engine entirely (see Engine: Quotes inside <script> elements get forcibly entity-escaped in ReActionView #1419)

This meant subclasses that overrode add_expression (the Erubi pattern used by ActionView) would not have their override apply to blocks or context-aware expressions, leading to incorrect compiled output.

So the idea of this pull request is to move the logic from the compiler into overridable engine methods so that subclasses (like ReActionView) get correct behavior by only overriding add_expression. The compiler becomes a thin dispatcher that routes tokens to the engine and no longer manipulates @engine.src directly.

Resolves #1419

Related marcoroth/reactionview#78
Related marcoroth/reactionview#80
Related marcoroth/reactionview#83

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 18, 2026

npx https://pkg.pr.new/@herb-tools/formatter@1421
npx https://pkg.pr.new/@herb-tools/language-server@1421
npx https://pkg.pr.new/@herb-tools/linter@1421

commit: c2d2bbf

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 18, 2026

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit c2d2bbf


✅ Preview deployment has been cleaned up.

@marcoroth marcoroth merged commit f037dbb into main Mar 18, 2026
32 checks passed
@marcoroth marcoroth deleted the expression-block-delegation branch March 18, 2026 13:48
@marcoroth marcoroth added this to the v1.0.0 milestone Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Engine: Quotes inside <script> elements get forcibly entity-escaped in ReActionView

1 participant