From e2e98ef0b8a575712707e4297c5206e2ed7a7d90 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 3 Jan 2008 15:35:10 +0000 Subject: Made fragment caching in views work for rjs and builder as well (closes #6642) [zsombor] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8542 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/caching.rb | 32 ++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller/caching.rb') diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index e3e48f660b..024f633d7c 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -371,11 +371,10 @@ module ActionController #:nodoc: name.is_a?(Hash) ? url_for(name).split("://").last : name end - # Called by CacheHelper#cache - def cache_erb_fragment(block, name = {}, options = nil) + def fragment_for(block, name = {}, options = nil) #:nodoc: unless perform_caching then block.call; return end - buffer = eval(ActionView::Base.erb_variable, block.binding) + buffer = yield if cache = read_fragment(name, options) buffer.concat(cache) @@ -386,6 +385,33 @@ module ActionController #:nodoc: end end + # Called by CacheHelper#cache + def cache_rxml_fragment(block, name = {}, options = nil) #:nodoc: + fragment_for(block, name, options) do + eval('xml.target!', block.binding) + end + end + + # Called by CacheHelper#cache + def cache_rjs_fragment(block, name = {}, options = nil) #:nodoc: + fragment_for(block, name, options) do + begin + debug_mode, ActionView::Base.debug_rjs = ActionView::Base.debug_rjs, false + eval('page.to_s', block.binding) + ensure + ActionView::Base.debug_rjs = debug_mode + end + end + end + + # Called by CacheHelper#cache + def cache_erb_fragment(block, name = {}, options = nil) #:nodoc: + fragment_for(block, name, options) do + eval(ActionView::Base.erb_variable, block.binding) + end + end + + # Writes content to the location signified by name (see expire_fragment for acceptable formats) def write_fragment(name, content, options = nil) return unless perform_caching -- cgit v1.2.3