Convert Haml to ERB

Updated . Posted . Visible to the public.

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
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-08-25 12:36)