Repository navigation
Add HAML support (.haml views and partials) - #2
Merged
Merged
Conversation
Introduce HamlParser, which walks the haml gem's own parse tree
(Haml::Parser, haml 5.2/6/7) and builds the same Nodes AST the ERB
front-end produces, so the Transformer, RubyUI mapping, RailsHelpers,
FormBuilder and LocalsDetector are reused unchanged. The haml gem is an
optional dependency, required lazily with a friendly error.
- RubyUIConverter.parse(source, format:) dispatches on :erb/:haml;
convert_string accepts format:, Template derives it from the extension
and FileWalker picks up **/*.{erb,haml}.
- Tags, =/!=/&=, control flow with flattened else/elsif/when, blocks,
interpolated text (unwrapping haml 5/6 escape wrappers), comments and
doctype. Dynamic attribute hashes are splatted for now.
- RubyLiteral splits Ruby string literals into text/code parts (Ripper).
- Fix: an unparenthesized form_with (model: @x do |form|) now activates
the form-builder mapping.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
HamlAttributes builds the attribute parts list from static attributes, html-style and hash attributes and object references: class values merge (strings into one string, expressions into a Phlex-flattened array), id values join with "_", false/nil drop, true is boolean, symbols become text, literal data:/aria: hashes expand to hyphenated attributes, [@obj] maps to dom_id/dom_class, and unsplittable hashes become a splat. String literals become static text so ComponentMap rules (Checkbox, Card) keep matching. Attribute expressions that are already self-delimited ([a, b], {...}, dom_id(user, :row)) are no longer wrapped in parentheses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- HAML text is routed through the ERB parser (#{x} -> <%= x %>), so
inline HTML becomes elements and interpolated helpers such as link_to
map like their ERB equivalents.
- Text next to rendered siblings gets a separating space (HAML's line
break), except around tags that remove outer whitespace.
- A / comment with nested content becomes comment do ... end
(Comment#children; locals inside it are detected); IE conditional
comments are left as a TODO.
- Filters: :javascript/:css -> script/style, :plain/:preserve, :escaped,
:erb (ERB parser), :ruby (statements); others become TODO comments.
- Fix: a same-line space between inline siblings is kept as Phlex
whitespace instead of being dropped (ERB too).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two templates generating the same .rb in one run (show.html.erb + show.html.haml, or a +variant) now report the later one as an error instead of skipping or overwriting the first. When the haml gem is not loadable, the CLI lists the affected files briefly and explains once how to add the gem. Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the ERB flow, add haml-rails, scaffold a Supplier with HAML views (--template-engine=haml, since tailwindcss-rails registers its own engine), convert them and render index/show/new/edit/create through the generated classes, including the spaced "|" separator between links. Co-Authored-By: Claude Opus 5.5 <[email protected]>
README (HAML templates section, compatibility, limitations, pipeline diagram), CHANGELOG, CLAUDE.md and the gemspec summary/description. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 13, 2026
Merged
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.
Summary
Adds conversion of
.hamlviews and partials, alongside.erb.convert app/viewspicks up both formats, andconvert_string(..., format: :haml)handles HAML strings.A new front-end,
HamlParser, walks the haml gem's own parse tree and builds the same AST the ERB front-end produces. So everything downstream applies to HAML unchanged: RubyUI element mapping,link_to/render, form-builder mapping, locals/ivars detection and--literal.hamlis an optional dependency. It is required lazily, only when a.hamlfile is converted. ERB-only users still have justthorat runtime, and haml 7 would otherwise also pullprism,templeandtiltinto every install. Apps with.hamlviews already have haml in their bundle. Supported: haml 5.2, 6.x and 7.x, which share the same parse tree shape. Without the gem,.erbfiles still convert and the CLI explains once how to add it.What's covered (one commit per phase)
.class#idshorthand,=/!=/&=,if/elsif/elseandcase/when(HAML nests these branches inside their opener), and blocks. Also interpolated text, where the escape wrappers that haml 5/6 add around each#{}are removed.classvalues merge andidvalues join with_.false/nilattributes are dropped andtruebecomes a boolean attribute. Literaldata:/aria:hashes expand to hyphenated attributes.[@obj]becomesdom_id/dom_class, and hashes that can't be split become a**splat. String values stay static, so RubyUI rules (Checkbox,Card) keep matching.#{x}→<%= x %>). Inline HTML becomes real elements, and#{link_to ...}becomesLink(...).%tag>is respected)./comment with nested content becomescomment do … end.:javascript,:css,:plain,:escaped,:erband:rubyare converted; other filters become TODO comments..rb(show.html.erb+show.html.haml, or a+variant) now report the second one as an error. The CLI explains a missing haml gem once.script/rails_e2e/run.shalso adds haml-rails, scaffolds aSupplierwith HAML views, converts them and renders index/show/new/edit/create. Passed locally on Rails 8.1 / Ruby 3.4; CI runs it across the full Rails × Ruby matrix.Changes that also affect ERB output
form_with model: @x do |form|now activates the form-builder mapping. Before, the model capture swalloweddo |form|.<em>a</em> <%= b %>) is now kept as Phlexwhitespaceinstead of being dropped. Line breaks between tags are still discarded.[a, b],{...},dom_id(user, :row)) are no longer wrapped in parentheses.Testing
Known limitations
Documented in the README:
{id: [a, b]}joins with a space in Phlex, but with_in HAML.[@obj]on a new record givesnew_user(HAML givesuser_new).Pre-existing and left for a separate PR: HTML entities in text (
©) come out escaped, in ERB as well.🤖 Generated with Claude Code