8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsでtemplateをerb -> slim

Posted at

現行のRails製のプロジェクトでテンプレートエンジンにslimを使いたかったので、
erbからの変換手順をメモ。

group :development do
  gem 'erb2haml'
  gem 'haml2slim'
end

一時的に上記のgemを追加し、erb -> haml -> slimの順に変換する

# .erb => .haml(erbは残す)
$ rake haml:convert_erbs
# .haml => .slim(hamlは残す)
$ for i in `find app/views -name '*.haml'` ; do be haml2slim $i ${i%haml}slim ; done
# .erb .hamlファイル削除
$ for i in `find app/views -name '*.erb'` ; do rm $i ; done
$ for i in `find app/views -name '*.haml'` ; do rm $i ; done

変換完了後、変換用に加えたgemをGemfileから削除し、$ bundle clean
Railsでslimを使うため、Gemfileにgem 'slim-rails'を追加し$ bundle install

slimに関しては下記が参考になります。
slim/README.md at README_ja
HamlとSlimをMiddleman上で比較する

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?