mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Fix #capture when run with a block that returns a string.
Closes gh-387.
This commit is contained in:
parent
abfd8d1380
commit
10109d4eb1
3 changed files with 23 additions and 2 deletions
|
@ -3,6 +3,11 @@
|
|||
* Table of contents
|
||||
{:toc}
|
||||
|
||||
## 3.1.2 (Unreleased)
|
||||
|
||||
* If the ActionView `#capture` helper is used in a Haml template but without any Haml being run in the block,
|
||||
return the value of the block rather than the captured buffer.
|
||||
|
||||
## 3.1.1
|
||||
|
||||
* Update the vendored Sass to version 3.1.0.
|
||||
|
|
|
@ -51,7 +51,10 @@ module ActionView
|
|||
# We've got to do the same thing for compatibility.
|
||||
|
||||
if is_haml? && block_is_haml?(block)
|
||||
capture_haml(*args, &block)
|
||||
value = nil
|
||||
buffer = capture_haml(*args) { value = yield(*args) }
|
||||
return buffer unless buffer.empty?
|
||||
return value if value.is_a?(String)
|
||||
else
|
||||
capture_without_haml(*args, &block)
|
||||
end
|
||||
|
@ -85,7 +88,16 @@ module ActionView
|
|||
module CaptureHelper
|
||||
def capture_with_haml(*args, &block)
|
||||
if Haml::Helpers.block_is_haml?(block)
|
||||
str = capture_haml(*args, &block)
|
||||
value = nil
|
||||
buffer = capture_haml(*args) { value = yield(*args) }
|
||||
str =
|
||||
if !buffer.empty?
|
||||
buffer
|
||||
elsif value.is_a?(String)
|
||||
value
|
||||
else
|
||||
''
|
||||
end
|
||||
return ActionView::NonConcattingString.new(str) if defined?(ActionView::NonConcattingString)
|
||||
return str
|
||||
else
|
||||
|
|
|
@ -357,6 +357,10 @@ HAML
|
|||
assert_equal("1\n\n2\n\n3\n\n", render("- trc([1, 2, 3]) do |i|\n = i.inspect"))
|
||||
end
|
||||
|
||||
def test_capture_with_string_block
|
||||
assert_equal("foo\n", render("= capture { 'foo' }", :action_view))
|
||||
end
|
||||
|
||||
def test_find_and_preserve_with_block
|
||||
assert_equal("<pre>Foo
Bar</pre>\nFoo\nBar\n",
|
||||
render("= find_and_preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
|
||||
|
|
Loading…
Reference in a new issue