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

[Haml] Make ActionPack version detection a little more flexible.

This commit is contained in:
Nathan Weizenbaum 2010-06-08 16:39:32 -07:00
parent 59c58f052c
commit 7e298cfc79
3 changed files with 11 additions and 31 deletions

View file

@ -291,42 +291,22 @@ module Haml
#
# @return [Boolean]
def ap_geq_3?
# The ActionPack module is always loaded automatically in Rails >= 3
return false unless defined?(ActionPack) && defined?(ActionPack::VERSION)
version =
if defined?(ActionPack::VERSION::MAJOR)
ActionPack::VERSION::MAJOR
else
# Rails 1.2
ActionPack::VERSION::Major
end
version >= 3
ap_geq?("3.0.0.beta1")
end
# Returns whether this environment is using ActionPack
# version 3.0.0.beta.3 or greater.
# of a version greater than or equal to that specified.
#
# @param version [String] The string version number to check against.
# Should be greater than or equal to Rails 3,
# because otherwise ActionPack::VERSION isn't autoloaded
# @return [Boolean]
def ap_geq_3_beta_3?
def ap_geq?(version)
# The ActionPack module is always loaded automatically in Rails >= 3
return false unless defined?(ActionPack) && defined?(ActionPack::VERSION)
return false unless defined?(ActionPack) && defined?(ActionPack::VERSION) &&
defined?(ActionPack::VERSION::STRING)
version =
if defined?(ActionPack::VERSION::MAJOR)
ActionPack::VERSION::MAJOR
else
# Rails 1.2
ActionPack::VERSION::Major
end
version >= 3 &&
((defined?(ActionPack::VERSION::TINY) &&
ActionPack::VERSION::TINY.is_a?(Fixnum) &&
ActionPack::VERSION::TINY >= 1) ||
(defined?(ActionPack::VERSION::BUILD) &&
ActionPack::VERSION::BUILD =~ /beta(\d+)/ &&
$1.to_i >= 3))
ActionPack::VERSION::STRING >= version
end
# Returns an ActionView::Template* class.

View file

@ -62,7 +62,7 @@ click
<input id="article_body" name="article[body]" size="30" type="text" value="World" />
</form>
</div>
- elsif Haml::Util.ap_geq_3_beta_3?
- elsif Haml::Util.ap_geq?("3.0.0.beta3")
%p
= form_tag ''
%div

View file

@ -65,7 +65,7 @@ class Test::Unit::TestCase
end
def form_for_calling_convention(name)
return "@#{name}, :as => :#{name}, :html => {:class => nil, :id => nil}" if Haml::Util.ap_geq_3_beta_3?
return "@#{name}, :as => :#{name}, :html => {:class => nil, :id => nil}" if Haml::Util.ap_geq?("3.0.0.beta3")
return ":#{name}, @#{name}"
end
end