Convert Haml to ERB

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

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.

Henning Koch Over 13 years ago