Removed the need for passing the binding when using CacheHelper#cache

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@472 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-01-20 17:26:14 +00:00
parent 01ead94d0b
commit 7306675fe2
3 changed files with 9 additions and 7 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Removed the need for passing the binding when using CacheHelper#cache
* Added TestResponse#binary_content that'll return as a string the data sent through send_data/send_file for testing #500 [Alexey]
* Added @request.env['RAW_POST_DATA'] for people who need access to the data before Ruby's CGI has parsed it #505 [bitsweat]

View File

@ -193,7 +193,7 @@ module ActionController #:nodoc:
# parties. The caching is doing using the cache helper available in the Action View. A template with caching might look something like:
#
# <b>Hello <%= @name %></b>
# <% cache(binding) do %>
# <% cache do %>
# All the topics in the system:
# <%= render_collection_of_partials "topic", Topic.find_all %>
# <% end %>
@ -203,7 +203,7 @@ module ActionController #:nodoc:
# if you need to cache multiple fragments per action or if the action itself is cached using <tt>caches_action</tt>. So instead we should
# qualify the name of the action used with something like:
#
# <% cache(binding, :action => "list", :action_suffix => "all_topics") do %>
# <% cache(:action => "list", :action_suffix => "all_topics") do %>
#
# That would result in a name such as "/topics/list/all_topics", which wouldn't conflict with any action cache and neither with another
# fragment using a different suffix. Note that the URL doesn't have to really exist or be callable. We're just using the url_for system
@ -247,16 +247,16 @@ module ActionController #:nodoc:
end
# Called by CacheHelper#cache
def cache_erb_fragment(binding, name = {}, options = {})
unless perform_caching then yield; return end
def cache_erb_fragment(name = {}, options = {}, &block)
unless perform_caching then block.call; return end
buffer = eval("_erbout", binding)
buffer = eval("_erbout", block)
if cache = read_fragment(name, options)
buffer.concat(cache)
else
pos = buffer.length
yield
block.call
write_fragment(name, buffer[pos..-1], options)
end
end

View File

@ -2,7 +2,7 @@ module ActionView
module Helpers
# See ActionController::Caching::Fragments for usage instructions.
module CacheHelper
def cache(binding, name = {})
def cache(name = {})
@controller.cache_erb_fragment(binding, name) { yield }
end
end