diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-06-25 20:52:12 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-06-25 20:52:12 -0300 |
commit | 32dd37b65a07286d046ea529b28df86446498a54 (patch) | |
tree | 8bad915e21a7d0b3b32896a9803d0c56d2586cdf /actionview/lib/action_view/helpers/cache_helper.rb | |
parent | 840c552047a660d0a66883fb9c0cb144d5e728fb (diff) | |
parent | f410c13bf8ec3a8fa3878d8acadb1f3d5a45032c (diff) | |
download | rails-32dd37b65a07286d046ea529b28df86446498a54.tar.gz rails-32dd37b65a07286d046ea529b28df86446498a54.tar.bz2 rails-32dd37b65a07286d046ea529b28df86446498a54.zip |
Merge branch 'cache-fragment-refactor'
Closes #10819
Diffstat (limited to 'actionview/lib/action_view/helpers/cache_helper.rb')
-rw-r--r-- | actionview/lib/action_view/helpers/cache_helper.rb | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index 8fc78ea7fb..2a38e5c446 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -176,20 +176,24 @@ module ActionView # TODO: Create an object that has caching read/write on it def fragment_for(name = {}, options = nil, &block) #:nodoc: - if fragment = controller.read_fragment(name, options) - fragment - else - # VIEW TODO: Make #capture usable outside of ERB - # This dance is needed because Builder can't use capture - pos = output_buffer.length - yield - 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 - controller.write_fragment(name, fragment, options) + read_fragment_for(name, options) || write_fragment_for(name, options, &block) + end + + def read_fragment_for(name, options) #:nodoc: + controller.read_fragment(name, options) + end + + def write_fragment_for(name, options) #:nodoc: + # VIEW TODO: Make #capture usable outside of ERB + # This dance is needed because Builder can't use capture + pos = output_buffer.length + yield + 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 + controller.write_fragment(name, fragment, options) end end end |