Skip to content
This repository

Replace the flush parameter with a Hash. #7150

Merged
merged 1 commit into from over 1 year ago

4 participants

Lucas Mazza Carlos Antonio da Silva Petteri Räty Rafael Mendonça França
Lucas Mazza

No description provided.

Rafael Mendonça França rafaelfranca merged commit d7856d3 into from
Rafael Mendonça França rafaelfranca closed this
Petteri Räty

flush to me doesn't seem like explanatory naming. flush on buffers means emptying the buffer to the stream so my first thought when reading such code would be that it has something to do with streaming. Why not call it replace instead?

//cc @rafaelfranca

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 24, 2012
Lucas Mazza Replace the flush parameter with a Hash. 9a020bd
This page is out of date. Refresh to see the latest.
8  actionpack/lib/action_view/helpers/capture_helper.rb
@@ -134,7 +134,7 @@ def capture(*args)
134 134
       #
135 135
       #   <%#  Add some other content, or use a different template: %>
136 136
       #
137  
-      #   <% content_for :navigation, true do %>
  137
+      #   <% content_for :navigation, flush: true do %>
138 138
       #     <li><%= link_to 'Login', :action => 'login' %></li>
139 139
       #   <% end %>
140 140
       #
@@ -148,14 +148,14 @@ def capture(*args)
148 148
       #
149 149
       # WARNING: content_for is ignored in caches. So you shouldn't use it
150 150
       # for elements that will be fragment cached.
151  
-      def content_for(name, content = nil, flush = false, &block)
  151
+      def content_for(name, content = nil, options = {}, &block)
152 152
         if content || block_given?
153 153
           if block_given?
154  
-            flush = content if content
  154
+            options = content if content
155 155
             content = capture(&block)
156 156
           end
157 157
           if content
158  
-            flush ? @view_flow.set(name, content) : @view_flow.append(name, content)
  158
+            options[:flush] ? @view_flow.set(name, content) : @view_flow.append(name, content)
159 159
           end
160 160
           nil
161 161
         else
18  actionpack/test/template/capture_helper_test.rb
@@ -56,7 +56,7 @@ def test_content_for_with_multiple_calls
56 56
   def test_content_for_with_multiple_calls_and_flush
57 57
     assert ! content_for?(:title)
58 58
     content_for :title, 'foo'
59  
-    content_for :title, 'bar', true
  59
+    content_for :title, 'bar', flush: true
60 60
     assert_equal 'bar', content_for(:title)
61 61
   end
62 62
 
@@ -75,7 +75,7 @@ def test_content_for_with_block_and_multiple_calls_with_flush
75 75
     content_for :title do
76 76
       'foo'
77 77
     end
78  
-    content_for :title, true do
  78
+    content_for :title, flush: true do
79 79
       'bar'
80 80
     end
81 81
     assert_equal 'bar', content_for(:title)
@@ -86,7 +86,7 @@ def test_content_for_with_block_and_multiple_calls_with_flush_nil_content
86 86
     content_for :title do
87 87
       'foo'
88 88
     end
89  
-    content_for :title, nil, true do
  89
+    content_for :title, nil, flush: true do
90 90
       'bar'
91 91
     end
92 92
     assert_equal 'bar', content_for(:title)
@@ -97,7 +97,7 @@ def test_content_for_with_block_and_multiple_calls_without_flush
97 97
     content_for :title do
98 98
       'foo'
99 99
     end
100  
-    content_for :title, false do
  100
+    content_for :title, flush: false do
101 101
       'bar'
102 102
     end
103 103
     assert_equal 'foobar', content_for(:title)
@@ -117,11 +117,11 @@ def test_content_for_with_whitespace_block
117 117
   def test_content_for_with_whitespace_block_and_flush
118 118
     assert ! content_for?(:title)
119 119
     content_for :title, 'foo'
120  
-    content_for :title, true do
  120
+    content_for :title, flush: true do
121 121
       output_buffer << "  \n  "
122 122
       nil
123 123
     end
124  
-    content_for :title, 'bar', true
  124
+    content_for :title, 'bar', flush: true
125 125
     assert_equal 'bar', content_for(:title)
126 126
   end
127 127
 
@@ -131,9 +131,9 @@ def test_content_for_returns_nil_when_writing
131 131
     assert_equal nil, content_for(:title) { output_buffer << 'bar'; nil }
132 132
     assert_equal nil, content_for(:title) { output_buffer << "  \n  "; nil }
133 133
     assert_equal 'foobar', content_for(:title)
134  
-    assert_equal nil, content_for(:title, 'foo', true)
135  
-    assert_equal nil, content_for(:title, true) { output_buffer << 'bar'; nil }
136  
-    assert_equal nil, content_for(:title, true) { output_buffer << "  \n  "; nil }
  134
+    assert_equal nil, content_for(:title, 'foo', flush: true)
  135
+    assert_equal nil, content_for(:title, flush: true) { output_buffer << 'bar'; nil }
  136
+    assert_equal nil, content_for(:title, flush: true) { output_buffer << "  \n  "; nil }
137 137
     assert_equal 'bar', content_for(:title)
138 138
   end
139 139
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.