diff --git a/lib/haml/template.rb b/lib/haml/template.rb index 1aa26a46..6455ada3 100644 --- a/lib/haml/template.rb +++ b/lib/haml/template.rb @@ -39,7 +39,7 @@ module Haml end end -if defined?(RAILS_ENV) && RAILS_ENV == "production" +if Haml::Util.rails_env == "production" Haml::Template.options[:ugly] = true end diff --git a/lib/haml/util.rb b/lib/haml/util.rb index 4cf37213..16b2f5b4 100644 --- a/lib/haml/util.rb +++ b/lib/haml/util.rb @@ -146,6 +146,17 @@ module Haml return nil end + # Returns the environment of the Rails application, + # if this is running in a Rails context. + # Returns `nil` if no such environment is defined. + # + # @return [String, nil] + def rails_env + return Rails.env.to_s if defined?(Rails.root) + return RAILS_ENV.to_s if defined?(RAILS_ENV) + return nil + end + # Returns an ActionView::Template* class. # In pre-3.0 versions of Rails, most of these classes # were of the form `ActionView::TemplateFoo`, diff --git a/lib/sass/plugin/rails.rb b/lib/sass/plugin/rails.rb index 8d4a5f40..0d2c6292 100644 --- a/lib/sass/plugin/rails.rb +++ b/lib/sass/plugin/rails.rb @@ -4,8 +4,8 @@ unless defined?(Sass::RAILS_LOADED) Sass::Plugin.options.merge!(:template_location => Haml::Util.rails_root + '/public/stylesheets/sass', :css_location => Haml::Util.rails_root + '/public/stylesheets', :cache_location => Haml::Util.rails_root + '/tmp/sass-cache', - :always_check => RAILS_ENV != "production", - :full_exception => RAILS_ENV != "production") + :always_check => Haml::Util.rails_env != "production", + :full_exception => Haml::Util.rails_env != "production") if defined?(ActionDispatch::Callbacks.to_prepare) # Rails >= 3.0.0