Merge branch 'master' into yard
Conflicts: lib/haml/buffer.rb
This commit is contained in:
commit
af1b2a9080
|
@ -26,6 +26,12 @@ module Haml
|
|||
# @return [Buffer]
|
||||
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.
|
||||
#
|
||||
# @return [Fixnum, nil]
|
||||
attr_accessor :capture_position
|
||||
|
||||
# @return [Boolean]
|
||||
# @see #active?
|
||||
attr_writer :active
|
||||
|
@ -218,6 +224,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
|
||||
|
||||
# Merges two attribute hashes.
|
||||
# This is the same as `to.merge!(from)`,
|
||||
# except that it merges id and class attributes.
|
||||
|
|
|
@ -302,6 +302,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(/^/)
|
||||
|
@ -317,6 +318,8 @@ module Haml
|
|||
line[min_tabs..-1]
|
||||
end.join
|
||||
end
|
||||
ensure
|
||||
haml_buffer.capture_position = nil
|
||||
end
|
||||
|
||||
# @deprecated This will be removed in version 2.4.
|
||||
|
|
|
@ -883,7 +883,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
|
||||
|
|
|
@ -11,7 +11,8 @@ module Haml
|
|||
# template is a template object in Rails >=2.1.0,
|
||||
# a source string previously
|
||||
if template.respond_to? :source
|
||||
options[:filename] = template.filename
|
||||
# Template has a generic identifier in Rails >=3.0.0
|
||||
options[:filename] = template.respond_to?(:identifier) ? template.identifier : template.filename
|
||||
source = template.source
|
||||
else
|
||||
source = template
|
||||
|
|
|
@ -14,6 +14,12 @@ class HelperTest < Test::Unit::TestCase
|
|||
def setup
|
||||
@base = ActionView::Base.new
|
||||
@base.controller = ActionController::Base.new
|
||||
|
||||
if defined?(ActionController::Response)
|
||||
# This is needed for >=3.0.0
|
||||
@base.controller.response = ActionController::Response.new
|
||||
end
|
||||
|
||||
@base.instance_variable_set('@post', Post.new("Foo bar\nbaz"))
|
||||
end
|
||||
|
||||
|
@ -61,7 +67,7 @@ class HelperTest < Test::Unit::TestCase
|
|||
|
||||
begin
|
||||
ActionView::Base.new.render(:inline => "<%= flatten('Foo\\nBar') %>")
|
||||
rescue NoMethodError
|
||||
rescue NoMethodError, ActionView::TemplateError
|
||||
proper_behavior = true
|
||||
end
|
||||
assert(proper_behavior)
|
||||
|
@ -229,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
|
||||
|
||||
|
|
|
@ -35,6 +35,10 @@ class DummyController
|
|||
def self.controller_path
|
||||
''
|
||||
end
|
||||
|
||||
def controller_path
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
class TemplateTest < Test::Unit::TestCase
|
||||
|
|
Loading…
Reference in New Issue