Merge branch 'stable'

Conflicts:
	lib/haml/precompiler.rb
This commit is contained in:
Nathan Weizenbaum 2009-06-03 13:21:37 -07:00
commit d442e1ee83
4 changed files with 34 additions and 1 deletions

View File

@ -19,6 +19,10 @@ module Haml
# It's nil at the top level (see #toplevel?).
attr_accessor :upper
# nil if there's no capture_haml block running,
# and the position at which it's beginning the capture if there is one.
attr_accessor :capture_position
# See #active?
attr_writer :active
@ -193,6 +197,17 @@ RUBY
@real_tabs += 1 unless self_closing || nuke_inner_whitespace
end
# Remove the whitespace from the right side of the buffer string.
# Doesn't do anything if we're at the beginning of a capture_haml block.
def rstrip!
if capture_position.nil?
buffer.rstrip!
return
end
buffer << buffer.slice!(capture_position..-1).rstrip
end
def self.merge_attrs(to, from)
if to['id'] && from['id']
to['id'] << '_' << from.delete('id')

View File

@ -275,6 +275,7 @@ module Haml
with_haml_buffer(buffer) do
position = haml_buffer.buffer.length
haml_buffer.capture_position = position
block.call(*args)
captured = haml_buffer.buffer.slice!(position..-1).split(/^/)
@ -290,6 +291,8 @@ module Haml
line[min_tabs..-1]
end.join
end
ensure
haml_buffer.capture_position = nil
end
def puts(*args) # :nodoc:

View File

@ -881,7 +881,7 @@ END
# or the merged text
def rstrip_buffer!
if @to_merge.empty?
push_silent("_erbout.rstrip!", false)
push_silent("_hamlout.rstrip!", false)
@dont_tab_up_next_text = true
return
end

View File

@ -235,5 +235,20 @@ HAML
def test_random_class_includes_tag_helper
assert_equal "<p>some tag content</p>", ActsLikeTag.new.to_s
end
def test_capture_with_nuke_outer
assert_equal "<div></div>\n*<div>hi there!</div>\n", render(<<HAML)
%div
= precede("*") do
%div> hi there!
HAML
assert_equal "<div></div>\n*<div>hi there!</div>\n", render(<<HAML)
%div
= precede("*") do
= " "
%div> hi there!
HAML
end
end