提交 9a020bd8 编写于 作者: L Lucas Mazza

Replace the flush parameter with a Hash.

上级 66b859bd
...@@ -134,7 +134,7 @@ def capture(*args) ...@@ -134,7 +134,7 @@ def capture(*args)
# #
# <%# Add some other content, or use a different template: %> # <%# Add some other content, or use a different template: %>
# #
# <% content_for :navigation, true do %> # <% content_for :navigation, flush: true do %>
# <li><%= link_to 'Login', :action => 'login' %></li> # <li><%= link_to 'Login', :action => 'login' %></li>
# <% end %> # <% end %>
# #
...@@ -148,14 +148,14 @@ def capture(*args) ...@@ -148,14 +148,14 @@ def capture(*args)
# #
# WARNING: content_for is ignored in caches. So you shouldn't use it # WARNING: content_for is ignored in caches. So you shouldn't use it
# for elements that will be fragment cached. # for elements that will be fragment cached.
def content_for(name, content = nil, flush = false, &block) def content_for(name, content = nil, options = {}, &block)
if content || block_given? if content || block_given?
if block_given? if block_given?
flush = content if content options = content if content
content = capture(&block) content = capture(&block)
end end
if content if content
flush ? @view_flow.set(name, content) : @view_flow.append(name, content) options[:flush] ? @view_flow.set(name, content) : @view_flow.append(name, content)
end end
nil nil
else else
......
...@@ -56,7 +56,7 @@ def test_content_for_with_multiple_calls ...@@ -56,7 +56,7 @@ def test_content_for_with_multiple_calls
def test_content_for_with_multiple_calls_and_flush def test_content_for_with_multiple_calls_and_flush
assert ! content_for?(:title) assert ! content_for?(:title)
content_for :title, 'foo' content_for :title, 'foo'
content_for :title, 'bar', true content_for :title, 'bar', flush: true
assert_equal 'bar', content_for(:title) assert_equal 'bar', content_for(:title)
end end
...@@ -75,7 +75,7 @@ def test_content_for_with_block_and_multiple_calls_with_flush ...@@ -75,7 +75,7 @@ def test_content_for_with_block_and_multiple_calls_with_flush
content_for :title do content_for :title do
'foo' 'foo'
end end
content_for :title, true do content_for :title, flush: true do
'bar' 'bar'
end end
assert_equal 'bar', content_for(:title) assert_equal 'bar', content_for(:title)
...@@ -86,7 +86,7 @@ def test_content_for_with_block_and_multiple_calls_with_flush_nil_content ...@@ -86,7 +86,7 @@ def test_content_for_with_block_and_multiple_calls_with_flush_nil_content
content_for :title do content_for :title do
'foo' 'foo'
end end
content_for :title, nil, true do content_for :title, nil, flush: true do
'bar' 'bar'
end end
assert_equal 'bar', content_for(:title) assert_equal 'bar', content_for(:title)
...@@ -97,7 +97,7 @@ def test_content_for_with_block_and_multiple_calls_without_flush ...@@ -97,7 +97,7 @@ def test_content_for_with_block_and_multiple_calls_without_flush
content_for :title do content_for :title do
'foo' 'foo'
end end
content_for :title, false do content_for :title, flush: false do
'bar' 'bar'
end end
assert_equal 'foobar', content_for(:title) assert_equal 'foobar', content_for(:title)
...@@ -117,11 +117,11 @@ def test_content_for_with_whitespace_block ...@@ -117,11 +117,11 @@ def test_content_for_with_whitespace_block
def test_content_for_with_whitespace_block_and_flush def test_content_for_with_whitespace_block_and_flush
assert ! content_for?(:title) assert ! content_for?(:title)
content_for :title, 'foo' content_for :title, 'foo'
content_for :title, true do content_for :title, flush: true do
output_buffer << " \n " output_buffer << " \n "
nil nil
end end
content_for :title, 'bar', true content_for :title, 'bar', flush: true
assert_equal 'bar', content_for(:title) assert_equal 'bar', content_for(:title)
end end
...@@ -131,9 +131,9 @@ def test_content_for_returns_nil_when_writing ...@@ -131,9 +131,9 @@ def test_content_for_returns_nil_when_writing
assert_equal nil, content_for(:title) { output_buffer << 'bar'; nil } assert_equal nil, content_for(:title) { output_buffer << 'bar'; nil }
assert_equal nil, content_for(:title) { output_buffer << " \n "; nil } assert_equal nil, content_for(:title) { output_buffer << " \n "; nil }
assert_equal 'foobar', content_for(:title) assert_equal 'foobar', content_for(:title)
assert_equal nil, content_for(:title, 'foo', true) assert_equal nil, content_for(:title, 'foo', flush: true)
assert_equal nil, content_for(:title, true) { output_buffer << 'bar'; nil } assert_equal nil, content_for(:title, flush: true) { output_buffer << 'bar'; nil }
assert_equal nil, content_for(:title, true) { output_buffer << " \n "; nil } assert_equal nil, content_for(:title, flush: true) { output_buffer << " \n "; nil }
assert_equal 'bar', content_for(:title) assert_equal 'bar', content_for(:title)
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册