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

Merge branch 'stable'

Conflicts:

	lib/haml/util.rb
This commit is contained in:
Nathan Weizenbaum 2009-01-22 16:40:44 -08:00
commit 5a45acf113
5 changed files with 18 additions and 8 deletions

View file

@ -254,13 +254,13 @@ module Haml
# the local variable <tt>foo</tt> would be assigned to "<p>13</p>\n".
#
def capture_haml(*args, &block)
buffer = eval('_hamlout', block) rescue haml_buffer
buffer = eval('_hamlout', block.binding) rescue haml_buffer
with_haml_buffer(buffer) do
position = haml_buffer.buffer.length
block.call(*args)
captured = haml_buffer.buffer.slice!(position..-1)
captured = haml_buffer.buffer.slice!(position..-1).split(/^/)
min_tabs = nil
captured.each do |line|
@ -412,7 +412,7 @@ END
# Returns whether or not +block+ is defined directly in a Haml template.
def block_is_haml?(block)
eval('_hamlout', block)
eval('_hamlout', block.binding)
true
rescue
false

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

@ -5,6 +5,8 @@ module Haml
module Util
class << self; include Haml::Util; end
RUBY_VERSION = ::RUBY_VERSION.split(".").map {|s| s.to_i}
def to_hash(arr)
arr.compact.inject({}) {|h, (k, v)| h[k] = v; h}
end
@ -32,6 +34,14 @@ module Haml
end
end
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
class StaticConditionalContext
def initialize(set)
@set = set

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