Pretty much need this with every new Rails project I create if only to convert the application.html.erb to Haml (for no other reason than to appease my sense of order).
After creating a new Rails project, in the Gemfile:
#./Gemfile ⋮ gem 'haml' # you probably have already done this group :development do gem 'haml-rails' # you'll want this so all subsequent views are generated using Haml gem 'hpricot' end ⋮
Then create a new lib/tasks/erb2haml.rake Rake task:
#./lib/tasks/erb2haml.rake desc "Creates haml files for each of the erb files found under views (skips existing)" task :erb2haml do from_path = File.join(File.dirname(__FILE__), '..', '..', 'app', 'views') Dir["#{from_path}/**/*.erb"].each do |file| puts file # for each .erb file in the path, convert it & output to a .haml file output_file = file.gsub(/\.erb$/, '.haml') `bundle exec html2haml -ex #{file} #{output_file}` unless File.exist?(output_file) end end
Now don't forget that its not rake erb2html, its rake erb2haml!
Originally built this task for each project based on this post.