Skip to content

fix(sinatra): render ERB views in erubi mode (newline fidelity) - #182

Merged
tannevaled merged 1 commit into
mainfrom
fix-sinatra-erubi-mode
Jul 6, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fix-sinatra-erubi-mode

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Problem

Sinatra 4.x maps :erb to Tilt::ErubiTemplate, so real Sinatra renders views through the erubi gem's Erubi::Engine, not classic MRI ERB. rbgo's Sinatra erb helper compiled through go-ruby-erb's default (classic ERB) mode, so a standalone <%= yield %> line dropped its trailing newline (classic trim <>) where erubi keeps it — the fidelity gap flagged in the Sinatra file-views work (#166).

Fix

Select go-ruby-erb's new erb.ModeErubi (byte-identical to Erubi::Engine, additive — go-ruby-erb PR #1) for the Sinatra view render only (internal/vm/sinatra_erb.go). The standalone require "erb" / classic-ERB binding (internal/vm/erb.go) stays in the default ModeERB, untouched.

Proof (through the rbgo binary)

The Sinatra+ERB webapp oracle (scripts/conformance/webapp) gains a layout whose <%= yield %> stands alone on its own line (route /l_standalone) — previously kept inline to dodge the classic-ERB gap. Under erubi that line keeps its trailing newline, producing a blank break between the wrapped view and the footer.

  • Golden regenerated from the real sinatra gem 4.2.1 + erubi 1.13.1 (matching the versions the existing golden was captured from); rbgo now reproduces it byte-for-byte.
  • Reverting the render to classic <> mode fails that request, confirming the fix is load-bearing.
  • Classic ERB conformance (TestERB*) unchanged; sinatra_erb.go holds 100% coverage.

Dependency

  • go-ruby-erb: v0.0.0-20260629074717 → v0.0.0-20260706152133 (adds ModeErubi)

🤖 Generated with Claude Code

Sinatra 4.x maps :erb to Tilt::ErubiTemplate, so real Sinatra renders
views through the erubi gem's Erubi::Engine, not classic MRI ERB. rbgo's
Sinatra `erb` helper compiled through go-ruby-erb's default (classic ERB)
mode, so a standalone `<%= yield %>` line dropped its trailing newline
(classic trim "<>") where erubi keeps it — the fidelity gap flagged in the
Sinatra file-views work (#166).

Select go-ruby-erb's new erb.ModeErubi (byte-identical to Erubi::Engine)
for the Sinatra view render only (internal/vm/sinatra_erb.go). The
standalone `require "erb"` / classic-ERB binding (internal/vm/erb.go)
stays in the default ModeERB, unchanged.

Prove it through the rbgo binary: the Sinatra+ERB webapp oracle gains a
layout whose `<%= yield %>` stands alone on its own line (previously kept
inline to dodge the classic-ERB gap). The golden was regenerated from the
real sinatra gem 4.2.1 + erubi 1.13.1; rbgo now reproduces it byte-for-byte.
Reverting to classic "<>" mode fails that request, confirming the fix is
load-bearing. Classic ERB conformance is unchanged; sinatra_erb.go holds
100% coverage.

- go-ruby-erb: v0.0.0-20260629074717 -> v0.0.0-20260706152133 (ModeErubi)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 2d9b1a7 into main Jul 6, 2026
9 checks passed
@tannevaled
tannevaled deleted the fix-sinatra-erubi-mode branch July 6, 2026 18:45
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