haml2html converts Haml templates to Rails ERB templates. It is built for Rails app migrations where rendered HTML equivalence matters more than preserving original source formatting.
gem install haml2htmlOr in a Gemfile:
gem "haml2html"haml2html app/views/posts/show.html.haml app/views/posts/show.html.erb
haml2html --stdin < app/views/posts/show.html.hamlThe CLI writes to stdout unless an output path is provided. Unsupported syntax is reported with file and line diagnostics and exits nonzero.
require "haml2html"
erb = Haml2html::Converter.new("%p= post.title\n", filename: "show.html.haml").renderHaml:
= form_with model: post do |form|
= form.text_field :titleERB:
<%= form_with model: post do |form| %>
<%= form.text_field :title %>
<% end %>Haml:
:ruby
if published
status = "Published"
else
status = "Draft"
end
%p= statusERB:
<%
if published
status = "Published"
else
status = "Draft"
end
%>
<p><%= status %></p>- Haml tags, nesting, static attributes, text, interpolation.
- Ruby output and control flow:
=,!=,- if,- each do, and similar blocks. - Public comments and silent comments.
:plain,:escaped,:javascript,:css,:erb, and:rubyfilters.- Dynamic Haml attributes through Rails
tag.attributes.
This is a migration tool, not a full source-preserving formatter. Output whitespace and quote style may differ from Haml output, while rendered HTML should remain equivalent for supported constructs. Unsupported filters or nodes fail with diagnostics instead of emitting known-wrong ERB.
Object references such as %div[user] are not converted yet.