From f341acdae3abfa97247736dde01f5e79c61de7d2 Mon Sep 17 00:00:00 2001 From: Andrew Rove Date: Sat, 1 Jun 2013 15:45:43 -0500 Subject: Move the write portion of fragment_for to its own method to allow for easier creation of custom cache methods. --- actionview/lib/action_view/helpers/cache_helper.rb | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index 8fc78ea7fb..2f2c8544ee 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -179,17 +179,21 @@ module ActionView 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) + write_fragment_for(name, options, &block) + end + end + + def write_fragment_for(name = {}, options = nil, &block) #: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 -- cgit v1.2.3 From f410c13bf8ec3a8fa3878d8acadb1f3d5a45032c Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 25 Jun 2013 20:51:02 -0300 Subject: Refactor cache fragment handling with read/write methods --- actionview/lib/action_view/helpers/cache_helper.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index 2f2c8544ee..2a38e5c446 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -176,14 +176,14 @@ 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 - write_fragment_for(name, options, &block) - end + 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 = nil, &block) #:nodoc: + 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 -- cgit v1.2.3