Fix CacheHelper#cache (closes #10733) [mindforge]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8614 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2008-01-10 00:47:08 +00:00
parent 4ad3721a17
commit f05b870ae0
1 changed files with 7 additions and 8 deletions

View File

@ -32,7 +32,7 @@ module ActionView
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
template_extension = first_render[/\.(\w+)$/, 1].to_sym
template_extension = find_template_extension_for(first_render)[/\.(\w+)$/, 1].to_sym
case template_extension
when :erb, :rhtml
@ -42,14 +42,13 @@ module ActionView
when :builder, :rxml
@controller.cache_rxml_fragment(block, name, options)
else
# do a last ditch effort for those brave souls using
# different template engines. This should give plugin
# writters a simple hook.
unless @controller.respond_to?("cache_#{template_extension}_fragment")
raise "fragment caching not supported for #{template_extension} files."
# Give template engine writers a hook to implement their own caching approach
if @controller.respond_to?("cache_#{template_extension}_fragment")
@controller.send!("cache_#{template_extension}_fragment", block, name, options)
else
# Let the ERb approach be the default one if the plugin doesn't specify it's own
@controller.cache_erb_fragment(block, name, options)
end
@controller.send!("cache_#{template_extension}_fragment", block, name, options)
end
end
end