Read more

Convert Haml to ERB

Henning Koch
August 25, 2010Software engineer at makandra GmbH

This is about converting Haml to ERB and not the other way round which you probably want!

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

This process can not be automated 100%, but you can still save time.

First do

script/plugin install http://github.com/cgoddard/haml2erb.git

Then in the console type

hamls = Dir["app/views/**/*.haml"] - ['app/views/layouts/screen.html.haml'];
hamls.each do |haml| 
  puts haml
  erb = haml.sub(/\.haml$/, '.erb')
  File.open(erb, 'w') do |file| 
    file.write Haml2Erb.convert(File.read(haml)) 
  end
end

After that you will need to look at every single .erb file and fix cases the plugin couldn't handle.

When you're done, delete all .haml files and also that plugin.

Posted by Henning Koch to makandra dev (2010-08-25 14:36)