[Haml] Abstract away RAILS_ROOT.

Closes gh-48
This commit is contained in:
Nathan Weizenbaum 2009-11-04 19:01:39 -08:00
parent 0a11a29a4f
commit 285bf70701
6 changed files with 31 additions and 12 deletions

View File

@ -27,6 +27,12 @@
This is consistent with the behavior of multiple ids
when one is specified as a standard attribute.
### Edge Rails Compatibility
* Don't use `RAILS_ROOT` directly.
This no longer exists in Rails 3.0.
Instead abstract this out as `Haml::Util.rails_root`.
## [2.2.10](http://github.com/nex3/haml/commit/2.2.10)
* Fixed a bug where elements with dynamic attributes and no content

View File

@ -14,6 +14,12 @@
* Fixed `css2sass`'s generation of pseudo-classes so that they're backslash-escaped.
### Edge Rails Compatibility
* Don't use `RAILS_ROOT` directly.
This no longer exists in Rails 3.0.
Instead abstract this out as `Haml::Util.rails_root`.
## [2.2.10](http://github.com/nex3/haml/commit/2.2.10)
* Add support for attribute selectors with spaces around the `=`.

View File

@ -61,14 +61,14 @@ else
Haml::Template.try_enabling_xss_integration
end
if defined?(RAILS_ROOT)
if Haml::Util.rails_root
# Update init.rb to the current version
# if it's out of date.
#
# We can probably remove this as of v1.9,
# because the new init file is sufficiently flexible
# to not need updating.
rails_init_file = File.join(RAILS_ROOT, 'vendor', 'plugins', 'haml', 'init.rb')
rails_init_file = File.join(Haml::Util.rails_root, 'vendor', 'plugins', 'haml', 'init.rb')
haml_init_file = Haml::Util.scope('init.rb')
begin
if File.exists?(rails_init_file)
@ -79,7 +79,7 @@ if defined?(RAILS_ROOT)
warn <<END
HAML WARNING:
#{rails_init_file} is out of date and couldn't be automatically updated.
Please run `haml --rails #{File.expand_path(RAILS_ROOT)}' to update it.
Please run `haml --rails #{File.expand_path(Haml::Util.rails_root)}' to update it.
END
end
end

View File

@ -122,6 +122,19 @@ module Haml
end
end
## Cross Rails Version Compatibility
# Returns the root of the Rails application,
# if this is running in a Rails context.
# Returns `nil` if no such root is defined.
#
# @return [String, nil]
def rails_root
return Rails.root if defined?(Rails.root)
return RAILS_ROOT if defined?(RAILS_ROOT)
return nil
end
## Rails XSS Safety
# Whether or not ActionView's XSS protection is available and enabled,

View File

@ -1,9 +1,9 @@
unless defined?(Sass::RAILS_LOADED)
Sass::RAILS_LOADED = true
Sass::Plugin.options.merge!(:template_location => RAILS_ROOT + '/public/stylesheets/sass',
:css_location => RAILS_ROOT + '/public/stylesheets',
:cache_location => RAILS_ROOT + '/tmp/sass-cache',
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")

View File

@ -9,12 +9,6 @@ require 'sass'
Sass::RAILS_LOADED = true unless defined?(Sass::RAILS_LOADED)
# required because of Sass::Plugin
unless defined? RAILS_ROOT
RAILS_ROOT = '.'
MERB_ENV = RAILS_ENV = 'testing'
end
class Test::Unit::TestCase
def munge_filename(opts)
return if opts[:filename]