Skip to content

Commit 32f7eba

Browse files
committed
Abstracted out Rails environment to Haml::Util to allow backwards compatability.
1 parent cc8b27d commit 32f7eba

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/haml/template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def precompiled_method_return_value_with_haml_xss
3939
end
4040
end
4141

42-
if defined?(RAILS_ENV) && RAILS_ENV == "production"
42+
if Haml::Util.rails_env == "production"
4343
Haml::Template.options[:ugly] = true
4444
end
4545

lib/haml/util.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ def rails_root
146146
return nil
147147
end
148148

149+
# Returns the environment of the Rails application,
150+
# if this is running in a Rails context.
151+
# Returns `nil` if no such environment is defined.
152+
#
153+
# @return [String, nil]
154+
def rails_env
155+
return Rails.env.to_s if defined?(Rails.root)
156+
return RAILS_ENV.to_s if defined?(RAILS_ENV)
157+
return nil
158+
end
159+
149160
# Returns an ActionView::Template* class.
150161
# In pre-3.0 versions of Rails, most of these classes
151162
# were of the form `ActionView::TemplateFoo`,

lib/sass/plugin/rails.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Sass::Plugin.options.merge!(:template_location => Haml::Util.rails_root + '/public/stylesheets/sass',
55
:css_location => Haml::Util.rails_root + '/public/stylesheets',
66
:cache_location => Haml::Util.rails_root + '/tmp/sass-cache',
7-
:always_check => RAILS_ENV != "production",
8-
:full_exception => RAILS_ENV != "production")
7+
:always_check => Haml::Util.rails_env != "production",
8+
:full_exception => Haml::Util.rails_env != "production")
99

1010
if defined?(ActionDispatch::Callbacks.to_prepare)
1111
# Rails >= 3.0.0

0 commit comments

Comments
 (0)