1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge branch 'cache-fragment-refactor'

Closes #10819
This commit is contained in:
Carlos Antonio da Silva 2013-06-25 20:52:12 -03:00
commit 32dd37b65a

View file

@ -176,20 +176,24 @@ module ActionView
# TODO: Create an object that has caching read/write on it # TODO: Create an object that has caching read/write on it
def fragment_for(name = {}, options = nil, &block) #:nodoc: def fragment_for(name = {}, options = nil, &block) #:nodoc:
if fragment = controller.read_fragment(name, options) read_fragment_for(name, options) || write_fragment_for(name, options, &block)
fragment end
else
# VIEW TODO: Make #capture usable outside of ERB def read_fragment_for(name, options) #:nodoc:
# This dance is needed because Builder can't use capture controller.read_fragment(name, options)
pos = output_buffer.length end
yield
output_safe = output_buffer.html_safe? def write_fragment_for(name, options) #:nodoc:
fragment = output_buffer.slice!(pos..-1) # VIEW TODO: Make #capture usable outside of ERB
if output_safe # This dance is needed because Builder can't use capture
self.output_buffer = output_buffer.class.new(output_buffer) pos = output_buffer.length
end yield
controller.write_fragment(name, fragment, options) output_safe = output_buffer.html_safe?
fragment = output_buffer.slice!(pos..-1)
if output_safe
self.output_buffer = output_buffer.class.new(output_buffer)
end end
controller.write_fragment(name, fragment, options)
end end
end end
end end