Erb to Haml Rake Task

Love haml but have erb lurking in your code? I stumbled on this rake task looking up ways to get custom Devise views moved to haml to sit nicely w/ the rest of my code:

namespace :erb do
  namespace :to do
    task :haml do
      files = `find . -name *.html.erb`
      files.each_line do |file|
            file.strip!
            `bundle exec html2haml #{file} | cat > #{file.gsub(/\.erb$/, ".haml")}`
      end
    end
  end
end

So now its as easy as ‘rake erb:to:haml’.

Thanks to this post

Leave a Reply