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

Compatibility with 1.9 *_methods methods which return symbols.

This commit is contained in:
Nathan Weizenbaum 2009-01-22 16:29:02 -08:00
parent d404d955e8
commit 8e1b40e31f
4 changed files with 15 additions and 5 deletions

View file

@ -17,7 +17,7 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
alias_method :render, :render_with_haml
# Rails >2.1
if instance_methods.include?('output_buffer')
if Haml::Util.has?(:instance_method, self, :output_buffer)
def output_buffer_with_haml
return haml_buffer.buffer if is_haml?
output_buffer_without_haml
@ -44,7 +44,7 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
# In Rails <=2.1, we've got to override considerable capturing infrastructure.
# In Rails >2.1, we can make do with only overriding #capture
# (which no longer behaves differently in helper contexts).
unless ActionView::Base.instance_methods.include?('output_buffer')
unless Haml::Util.has?(:instance_method, ActionView::Base, :output_buffer)
module CaptureHelper
def capture_with_haml(*args, &block)
# Rails' #capture helper will just return the value of the block

View file

@ -1,5 +1,15 @@
module Haml
module Util
class << self; include Haml::Util; end
RUBY_VERSION = ::RUBY_VERSION.split(".").map {|s| s.to_i}
def ruby1_8?
Haml::Util::RUBY_VERSION[0] == 1 && Haml::Util::RUBY_VERSION[1] < 9
end
def has?(attr, klass, method)
klass.send("#{attr}s").include?(ruby1_8? ? method.to_s : method.to_sym)
end
end
end

View file

@ -17,7 +17,7 @@ require File.dirname(__FILE__) + '/linked_rails'
action_view action_pack haml/template rbench].each {|dep| require(dep)}
def view
unless ActionView::Base.instance_methods.include? 'finder'
unless Haml::Util.has?(:instance_method, ActionView::Base, :finder)
return ActionView::Base.new(File.dirname(__FILE__), {})
end

View file

@ -38,7 +38,7 @@ class TemplateTest < Test::Unit::TestCase
def setup
vars = { 'article' => Article.new, 'foo' => 'value one' }
unless ActionView::Base.instance_methods.include? 'finder'
unless Haml::Util.has?(:instance_method, ActionView::Base, :finder)
@base = ActionView::Base.new(TEMPLATE_PATH, vars)
else
# Rails 2.1.0
@ -46,7 +46,7 @@ class TemplateTest < Test::Unit::TestCase
@base.finder.append_view_path(TEMPLATE_PATH)
end
if @base.private_methods.include?('evaluate_assigns')
if Haml::Util.has?(:private_method, @base, :evaluate_assigns)
@base.send(:evaluate_assigns)
else
# Rails 2.2