Engine: Delegate context-aware expressions to overridable engine methods#1421
Merged
Engine: Delegate context-aware expressions to overridable engine methods#1421
Conversation
222355c to
c2d2bbf
Compare
commit: |
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
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.
This pull request moves expression handling logic from the compiler into overridable engine methods, making
Herb::Enginean easier drop-in replacement forErubi::Engine.Previously, the compiler bypassed the engine's
add_expressionmethod in two cases:Block expressions (
<%= link_to do %>...<% end %>), the compiler calledadd_expression_blockwhich dispatched directly toadd_expression_block_result, skipping any subclass override ofadd_expression.Context-aware expressions (inside
<script>,<style>, or attribute values), the compiler'sadd_context_aware_expressionwrote 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.srcdirectly.Resolves #1419
Related marcoroth/reactionview#78
Related marcoroth/reactionview#80
Related marcoroth/reactionview#83