@@ -176,20 +176,24 @@ def fragment_name_with_digest(name) #:nodoc:
176176
177177 # TODO: Create an object that has caching read/write on it
178178 def fragment_for ( name = { } , options = nil , &block ) #:nodoc:
179- if fragment = controller . read_fragment ( name , options )
180- fragment
181- else
182- # VIEW TODO: Make #capture usable outside of ERB
183- # This dance is needed because Builder can't use capture
184- pos = output_buffer . length
185- yield
186- output_safe = output_buffer . html_safe?
187- fragment = output_buffer . slice! ( pos ..-1 )
188- if output_safe
189- self . output_buffer = output_buffer . class . new ( output_buffer )
190- end
191- controller . write_fragment ( name , fragment , options )
179+ read_fragment_for ( name , options ) || write_fragment_for ( name , options , &block )
180+ end
181+
182+ def read_fragment_for ( name , options ) #:nodoc:
183+ controller . read_fragment ( name , options )
184+ end
185+
186+ def write_fragment_for ( name , options ) #:nodoc:
187+ # VIEW TODO: Make #capture usable outside of ERB
188+ # This dance is needed because Builder can't use capture
189+ pos = output_buffer . length
190+ yield
191+ output_safe = output_buffer . html_safe?
192+ fragment = output_buffer . slice! ( pos ..-1 )
193+ if output_safe
194+ self . output_buffer = output_buffer . class . new ( output_buffer )
192195 end
196+ controller . write_fragment ( name , fragment , options )
193197 end
194198 end
195199 end
0 commit comments