[Experiment] Herb as source of truth — engine-agnostic component export#357
Draft
djalmaaraujo wants to merge 4 commits intomainfrom
Draft
[Experiment] Herb as source of truth — engine-agnostic component export#357djalmaaraujo wants to merge 4 commits intomainfrom
djalmaaraujo wants to merge 4 commits intomainfrom
Conversation
added 4 commits
April 10, 2026 19:00
- HerbToPhlexVisitor: walks a Herb AST parsed from .html.erb templates
and emits Phlex DSL code. Handles HTML elements, ERB output/control-flow
tags, yield, tag_attributes() splat, and SVG block variable pattern.
- PhlexGenerator: convenience wrapper — template string in, Phlex class out.
- EngineUtils: engine-aware file selection (detects .html.erb presence).
- ComponentGenerator --engine flag:
phlex (default) copies a pre-generated Phlex class, no herb needed
erb/herb copies the plain Ruby class + .html.erb template
- PhlexTransformer: converts a plain ComponentBase class to a Phlex class
by text-transformation + inserting the visitor-generated view_template.
Design spec covers: Herb as sole source of truth, three-engine generator, ComponentBase architecture, docs single-source-of-truth approach (ERB tab / Phlex tab generated from one _docs.html.erb file), and the incremental migration strategy.
ComponentBase (lib/ruby_ui/component_base.rb): Plain Ruby mixin for all component classes. Provides TailwindMerge class merging, deep data-attribute merging, and attrs accessor. No Phlex dependency — usable standalone or with any rendering engine. Phlex Base (lib/ruby_ui/base.rb): Updated to use the same class-merging semantics as ComponentBase (array class values, deep merge). Generated Phlex classes that extend Base now behave identically to their plain Ruby source counterparts.
…+ Herb
Every component directory now has two source files:
component.rb — plain Ruby class (include ComponentBase, no Phlex)
component.html.erb — Herb/ERB template (HTML source of truth)
The Phlex class is no longer hand-written. It is generated at gem build
time by PhlexTransformer + HerbToPhlexVisitor and stored as a pre-built
artifact (component_phlex.rb) that the generator copies for --engine=phlex.
Component changes:
- class X < Base replaced by class X; include ComponentBase
- default_attrs unchanged (same Tailwind classes and Stimulus data attrs)
- view_template moved to .html.erb; templates use tag_attributes(attrs)
which the visitor converts to **attrs in the generated Phlex output
- _docs.rb replaced by _docs.html.erb (ERB usage examples)
- All tests rewritten to test plain Ruby class attrs directly
Components: accordion, alert, alert_dialog, aspect_ratio, avatar, badge,
breadcrumb, button, calendar, card, carousel, chart, checkbox, clipboard,
codeblock, collapsible, combobox, command, context_menu, dialog,
dropdown_menu, form, hover_card, input, link, masked_input, native_select,
pagination, popover, progress, radio_button, select, separator, sheet,
shortcut_key, sidebar, skeleton, switch, table, tabs, textarea,
theme_toggle, tooltip, typography (44 directories, 500+ files)
649 tests, 1266 assertions, 0 failures, 0 errors, lint clean.
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.
What this does
Replaces hand-written Phlex as the authoring format for components with Herb (HTML+ERB templates) as the single source of truth. Components are now authored once and exported to any rendering engine on demand.
Why
RubyUI components are currently Phlex-only. To use them with plain ERB, ViewComponent, or future rendering targets you'd have to rewrite the whole library. That's the core limitation this PR removes.
Herb gives us:
.html.erbby defaultArchitecture
Every component now has two source files:
The
--engineflag on the generator controls what consumers get:--engine=phlex(default)--engine=erb.html.erbtemplate--engine=herbbundle add herbThe Phlex output is generated, not hand-written.
HerbToPhlexVisitorwalks the Herb AST and emits Phlex DSL;PhlexTransformerwraps the result into a proper< Baseclass. The pre-generated_phlex.rbartifacts are committed so consumers don't need Herb installed.What changed
ComponentBasemodule — engine-agnostic TailwindMerge + deep attr mergeHerbToPhlexVisitor+PhlexGenerator— ERB template → Phlex DSLPhlexTransformer— plain Ruby class → Phlex class via text transformationEngineUtils— engine-aware file selection in the generator_docs.rb→_docs.html.erb— docs written in ERB, Phlex tab auto-generated by visitorPhlex::Baseto use ComponentBase-compatible class mergingTests
649 tests, 1266 assertions, 0 failures, 0 errors. StandardRB clean.
All 44 component docs pages confirmed returning 200 on the rubyui/web app after exporting with the default
--engine=phlex.