Changeset 8619
- Timestamp:
- 01/10/08 03:17:20 (8 months ago)
- Files:
-
- trunk/actionpack/lib/action_controller/caching/fragments.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/cache_helper.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/template_handler.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/template_handlers/builder.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/template_handlers/erb.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/template_handlers/rjs.rb (modified) (1 diff)
- trunk/actionpack/test/controller/caching_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/caching/fragments.rb
r8546 r8619 75 75 end 76 76 77 # Called by CacheHelper#cache78 def cache_rxml_fragment(block, name = {}, options = nil) #:nodoc:79 fragment_for(block, name, options) do80 eval('xml.target!', block.binding)81 end82 end83 84 # Called by CacheHelper#cache85 def cache_rjs_fragment(block, name = {}, options = nil) #:nodoc:86 fragment_for(block, name, options) do87 begin88 debug_mode, ActionView::Base.debug_rjs = ActionView::Base.debug_rjs, false89 eval('page.to_s', block.binding)90 ensure91 ActionView::Base.debug_rjs = debug_mode92 end93 end94 end95 96 # Called by CacheHelper#cache97 def cache_erb_fragment(block, name = {}, options = nil) #:nodoc:98 fragment_for(block, name, options) do99 eval(ActionView::Base.erb_variable, block.binding)100 end101 end102 103 77 # Writes <tt>content</tt> to the location signified by <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats) 104 78 def write_fragment(key, content, options = nil) trunk/actionpack/lib/action_view/helpers/cache_helper.rb
r8614 r8619 34 34 def cache(name = {}, options = nil, &block) 35 35 template_extension = find_template_extension_for(first_render)[/\.(\w+)$/, 1].to_sym 36 37 case template_extension 38 when :erb, :rhtml 39 @controller.cache_erb_fragment(block, name, options) 40 when :rjs 41 @controller.cache_rjs_fragment(block, name, options) 42 when :builder, :rxml 43 @controller.cache_rxml_fragment(block, name, options) 44 else 45 # Give template engine writers a hook to implement their own caching approach 46 if @controller.respond_to?("cache_#{template_extension}_fragment") 47 @controller.send!("cache_#{template_extension}_fragment", block, name, options) 48 else 49 # Let the ERb approach be the default one if the plugin doesn't specify it's own 50 @controller.cache_erb_fragment(block, name, options) 51 end 52 end 36 handler = Base.handler_for_extension(template_extension) 37 handler.new(@controller).cache_fragment(block, name, options) 53 38 end 54 39 end trunk/actionpack/lib/action_view/template_handler.rb
r8374 r8619 14 14 def compile(template) 15 15 end 16 17 # Called by CacheHelper#cache 18 def cache_fragment(block, name = {}, options = nil) 19 end 16 20 end 17 21 end trunk/actionpack/lib/action_view/template_handlers/builder.rb
r8374 r8619 15 15 "\nxml.target!\n" 16 16 end 17 18 def cache_fragment(block, name = {}, options = nil) 19 @view.fragment_for(block, name, options) do 20 eval('xml.target!', block.binding) 21 end 22 end 17 23 end 18 24 end trunk/actionpack/lib/action_view/template_handlers/erb.rb
r8578 r8619 26 26 ::ERB.new(template, nil, @view.erb_trim_mode).src 27 27 end 28 29 def cache_fragment(block, name = {}, options = nil) #:nodoc: 30 @view.fragment_for(block, name, options) do 31 eval(ActionView::Base.erb_variable, block.binding) 32 end 33 end 28 34 end 29 35 end trunk/actionpack/lib/action_view/template_handlers/rjs.rb
r8374 r8619 10 10 "update_page do |page|\n#{template}\nend" 11 11 end 12 13 def cache_fragment(block, name = {}, options = nil) #:nodoc: 14 @view.fragment_for(block, name, options) do 15 begin 16 debug_mode, ActionView::Base.debug_rjs = ActionView::Base.debug_rjs, false 17 eval('page.to_s', block.binding) 18 ensure 19 ActionView::Base.debug_rjs = debug_mode 20 end 21 end 22 end 12 23 end 13 24 end trunk/actionpack/test/controller/caching_test.rb
r8564 r8619 446 446 447 447 assert_equal( 'generated till now -> fragment content', 448 @controller.cache_erb_fragment(Proc.new{ }, 'expensive'))448 ActionView::TemplateHandlers::ERB.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) 449 449 end 450 450 … … 455 455 456 456 assert_equal( 'generated till now -> fragment content', 457 @controller.cache_rxml_fragment(Proc.new{ }, 'expensive'))457 ActionView::TemplateHandlers::Builder.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) 458 458 end 459 459 … … 463 463 464 464 assert_equal( 'generated till now -> fragment content', 465 @controller.cache_rjs_fragment(Proc.new{ }, 'expensive'))465 ActionView::TemplateHandlers::RJS.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) 466 466 end 467 467 … … 473 473 debug_mode, ActionView::Base.debug_rjs = ActionView::Base.debug_rjs, true 474 474 assert_equal( 'generated till now -> fragment content', 475 @controller.cache_rjs_fragment(Proc.new{ }, 'expensive'))475 ActionView::TemplateHandlers::RJS.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) 476 476 assert ActionView::Base.debug_rjs 477 477 ensure