seratch's weblog in Japanese

About Scala, Java and Ruby programming in Japaense. If you need English information, go to http://blog.seratch.net/

Rails4 で ERB テンプレートを Haml に移行

したので、手順をメモ。Rails4 固有のアレはなさそうですが Rails4 でやったよというくらいです。

既存の erb ファイルを html2haml で変換して、古い erb ファイルを全部削除。

gem install html2haml
cd app/views
find . -name '*erb' | xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | bash
find . -name *.erb | xargs git rm -f
find . -name *.haml | xargs git add -v

Gemfile に haml-rails を追加。

gem 'haml-rails'

あとはテストが書いてあるはずなので bundle exec rspec spec して全部パスすれば大丈夫そうですね。