LoginSignup
0
0

More than 3 years have passed since last update.

hamlとは

Hamlとは、HTMLよりも簡単に書くためのビューテンプレートエンジンです。公式サイトによると「マークアップは美しくあるべき」という原則に基づいて開発されました。Hamlを使用することで、「綺麗に」、「読みやすく」、「生産的に」ビューを作成することができます。

gem 追記

Gemfile
  gem 'haml-rails'

bundle installを実行。

拡張子がerbのファイルをhamlに変換

ターミナルで下記のコマンドを実行すれば一括で変換できます。

ターミナル
$ rails haml:erb2haml

コマンドを実行すると途中で

ターミナル
Would you like to delete the original .erb files? (This is not recommended unless you are under version control.) (y/n)

アプリケーションの初期段階であるため、yを選択しましょう。すると、デフォルトで作成されたerbファイル(例えば、application.html.erbなど)がhamlに変換されていることが確認できると思います。

application.html.hamlを編集

application.html.haml
!!!
%html
  %head
    %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
    %title ChatSpace
    = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true
    = javascript_include_tag 'application', 'data-turbolinks-track' => true
    = csrf_meta_tags
  %body
    = yield

mailer.html.hamlを編集

mailer.html.haml
!!!
 %html
   %head
     %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
     :css
       /* Email styles need to be inline */
   %body
     = yield

mailer.text.hamlを編集

mailer.text.haml
= yield

:warning: mailer.html.hamlとmailer.text.hamlは不要なファイルである場合は、削除しましょう。

0
0
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
0
0