1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Abstracted out Rails environment to Haml::Util to allow backwards compatability.

This commit is contained in:
Nathan Weizenbaum 2010-01-21 20:07:16 -08:00
parent cc8b27d930
commit 32f7eba94d
3 changed files with 14 additions and 3 deletions

View file

@ -39,7 +39,7 @@ module Haml
end end
end end
if defined?(RAILS_ENV) && RAILS_ENV == "production" if Haml::Util.rails_env == "production"
Haml::Template.options[:ugly] = true Haml::Template.options[:ugly] = true
end end

View file

@ -146,6 +146,17 @@ module Haml
return nil return nil
end 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. # Returns an ActionView::Template* class.
# In pre-3.0 versions of Rails, most of these classes # In pre-3.0 versions of Rails, most of these classes
# were of the form `ActionView::TemplateFoo`, # were of the form `ActionView::TemplateFoo`,

View file

@ -4,8 +4,8 @@ unless defined?(Sass::RAILS_LOADED)
Sass::Plugin.options.merge!(:template_location => Haml::Util.rails_root + '/public/stylesheets/sass', Sass::Plugin.options.merge!(:template_location => Haml::Util.rails_root + '/public/stylesheets/sass',
:css_location => Haml::Util.rails_root + '/public/stylesheets', :css_location => Haml::Util.rails_root + '/public/stylesheets',
:cache_location => Haml::Util.rails_root + '/tmp/sass-cache', :cache_location => Haml::Util.rails_root + '/tmp/sass-cache',
:always_check => RAILS_ENV != "production", :always_check => Haml::Util.rails_env != "production",
:full_exception => RAILS_ENV != "production") :full_exception => Haml::Util.rails_env != "production")
if defined?(ActionDispatch::Callbacks.to_prepare) if defined?(ActionDispatch::Callbacks.to_prepare)
# Rails >= 3.0.0 # Rails >= 3.0.0