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]
|
# @return [Buffer]
|
||||||
attr_accessor :upper
|
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]
|
# @return [Boolean]
|
||||||
# @see #active?
|
# @see #active?
|
||||||
attr_writer :active
|
attr_writer :active
|
||||||
|
@ -218,6 +224,17 @@ RUBY
|
||||||
@real_tabs += 1 unless self_closing || nuke_inner_whitespace
|
@real_tabs += 1 unless self_closing || nuke_inner_whitespace
|
||||||
end
|
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.
|
# Merges two attribute hashes.
|
||||||
# This is the same as `to.merge!(from)`,
|
# This is the same as `to.merge!(from)`,
|
||||||
# except that it merges id and class attributes.
|
# except that it merges id and class attributes.
|
||||||
|
|
|
@ -302,6 +302,7 @@ module Haml
|
||||||
with_haml_buffer(buffer) do
|
with_haml_buffer(buffer) do
|
||||||
position = haml_buffer.buffer.length
|
position = haml_buffer.buffer.length
|
||||||
|
|
||||||
|
haml_buffer.capture_position = position
|
||||||
block.call(*args)
|
block.call(*args)
|
||||||
|
|
||||||
captured = haml_buffer.buffer.slice!(position..-1).split(/^/)
|
captured = haml_buffer.buffer.slice!(position..-1).split(/^/)
|
||||||
|
@ -317,6 +318,8 @@ module Haml
|
||||||
line[min_tabs..-1]
|
line[min_tabs..-1]
|
||||||
end.join
|
end.join
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
|
haml_buffer.capture_position = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# @deprecated This will be removed in version 2.4.
|
# @deprecated This will be removed in version 2.4.
|
||||||
|
|
|
@ -883,7 +883,7 @@ END
|
||||||
# or the merged text
|
# or the merged text
|
||||||
def rstrip_buffer!
|
def rstrip_buffer!
|
||||||
if @to_merge.empty?
|
if @to_merge.empty?
|
||||||
push_silent("_erbout.rstrip!", false)
|
push_silent("_hamlout.rstrip!", false)
|
||||||
@dont_tab_up_next_text = true
|
@dont_tab_up_next_text = true
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,8 @@ module Haml
|
||||||
# template is a template object in Rails >=2.1.0,
|
# template is a template object in Rails >=2.1.0,
|
||||||
# a source string previously
|
# a source string previously
|
||||||
if template.respond_to? :source
|
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
|
source = template.source
|
||||||
else
|
else
|
||||||
source = template
|
source = template
|
||||||
|
|
|
@ -14,6 +14,12 @@ class HelperTest < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
@base = ActionView::Base.new
|
@base = ActionView::Base.new
|
||||||
@base.controller = ActionController::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"))
|
@base.instance_variable_set('@post', Post.new("Foo bar\nbaz"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -61,7 +67,7 @@ class HelperTest < Test::Unit::TestCase
|
||||||
|
|
||||||
begin
|
begin
|
||||||
ActionView::Base.new.render(:inline => "<%= flatten('Foo\\nBar') %>")
|
ActionView::Base.new.render(:inline => "<%= flatten('Foo\\nBar') %>")
|
||||||
rescue NoMethodError
|
rescue NoMethodError, ActionView::TemplateError
|
||||||
proper_behavior = true
|
proper_behavior = true
|
||||||
end
|
end
|
||||||
assert(proper_behavior)
|
assert(proper_behavior)
|
||||||
|
@ -229,5 +235,20 @@ HAML
|
||||||
def test_random_class_includes_tag_helper
|
def test_random_class_includes_tag_helper
|
||||||
assert_equal "<p>some tag content</p>", ActsLikeTag.new.to_s
|
assert_equal "<p>some tag content</p>", ActsLikeTag.new.to_s
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,10 @@ class DummyController
|
||||||
def self.controller_path
|
def self.controller_path
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def controller_path
|
||||||
|
''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TemplateTest < Test::Unit::TestCase
|
class TemplateTest < Test::Unit::TestCase
|
||||||
|
|
Loading…
Reference in New Issue