LoginSignup
22

More than 5 years have passed since last update.

Rails+Hamlで設定すべきHamlオプションまとめ

Last updated at Posted at 2014-07-06

Rails+Hamlで開発を行なう場合、以下の2点の設定を検討すべきです。

config/initializers/haml.rb
Haml::Template.options[:attr_wrapper] = '"'  # タグの属性値を「"」で囲む(デフォルトは「'」)
Haml::Template.options[:ugly] = true         # インデント等の扱いを各環境下で統一する(後述)

uglyオプションについて

uglyは、ひとことでいうとHaml→HTML変換時のインデント等の扱いを定めるオプションです。
ドキュメントには以下のようにあります。

If set to true, Haml makes no attempt to properly indent or format the HTML output. This significantly improves rendering performance but makes viewing the source unpleasant.

Defaults to true in Rails production mode, and false everywhere else.

Railsのproduction環境ではugly: trueになるのですが、developmentではfalseです。
これは、production/development環境下でインデントの扱いが変わることを意味します。

なにが問題かというと、インデントの有無でデザイン上にスペースが表れたり表れなかったりします。
development上でSCSSでデザインしていても、productionに上げるとデザインが微妙に変わってしまいます。

なので、uglyオプションはdevelopment/production両方でtrueになるように設定することを検討した方がいいでしょう。

参考

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
22