diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-20 17:26:14 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-20 17:26:14 +0000 |
commit | 7306675fe276a7586afa8526068e4698a6d360cf (patch) | |
tree | 23ca47cb953f71fef18779f6dc14ba939600dd72 | |
parent | 01ead94d0b11b00fb8726a868f5538c7a5a1af35 (diff) | |
download | rails-7306675fe276a7586afa8526068e4698a6d360cf.tar.gz rails-7306675fe276a7586afa8526068e4698a6d360cf.tar.bz2 rails-7306675fe276a7586afa8526068e4698a6d360cf.zip |
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
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/caching.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/cache_helper.rb | 2 |
3 files changed, 9 insertions, 7 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index bd76b3f61d..d046c11c2f 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -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] diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index cc80217bd6..21d9c69831 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -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 diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb index b44b436ef4..9353e5a694 100644 --- a/actionpack/lib/action_view/helpers/cache_helper.rb +++ b/actionpack/lib/action_view/helpers/cache_helper.rb @@ -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 |