Permalink
Browse files

introduced Cell::Base#cache_configured? which is used now in every ca…

…che-dependent decider. RAILS_ENV is no longer inspected for caching, ActionController::Base.cache_configured? is the authorative switch now.

this was inspired by Michał Łomnicki [mlomnicki].

fixed the README, thanks to [le0pard] for patch.
  • Loading branch information...
1 parent f9f3eb2 commit ae56a1373e9fd363e0d055d374c8ef00d7f56a29 @apotonick apotonick committed Sep 30, 2009
Showing with 18 additions and 12 deletions.
  1. +3 −3 README.rdoc
  2. +4 −3 lib/cell/base.rb
  3. +1 −1 lib/cell/caching.rb
  4. +10 −5 test/caching_test.rb
View
@@ -39,7 +39,7 @@ The corresponding views are in <tt>app/cells/article/newest.html.erb</tt>:
<h2>Hot stuff!</h2>
<ul>
<% @articles.each do |article| %>
- <li><%= article.title</li>
+ <li><%= article.title %></li>
<% end %>
</ul>
@@ -63,8 +63,8 @@ where the rendered action view could be <tt>app/views/blog/top_page.html.erb</tt
<%= yield %>
- <div><%= render_cell(:article, :newest)</div>
- <div><%= render_cell(:article, :top_article)</div>
+ <div><%= render_cell(:article, :newest) %></div>
+ <div><%= render_cell(:article, :top_article) %></div>
The "top page" would consist of the controller action's content, and two additional
independent boxes with interesting content. These two boxes are <em>cells</em> and could
View
@@ -5,7 +5,7 @@ module Cell
# lightweight controller in the sense that it will assign variables and
# render a view. Cells can be rendered from other cells as well as from
# regular controllers and views (see ActionView::Base#render_cell and
- # ControllerMethods#render_cell_to_string)
+ # ControllerMethods#render_cell)
#
# == A render_cell() cycle
#
@@ -216,6 +216,8 @@ def class_from_cell_name(cell_name)
def state2view_cache
@state2view_cache ||= {}
end
+
+ def cache_configured?; ::ActionController::Base.cache_configured?; end
end
class_inheritable_array :view_paths, :instance_writer => false
@@ -351,7 +353,7 @@ def find_family_view_for_state(state, action_view)
### DISCUSS: ActionView::Base already caches results for #pick_template, so maybe
### we should just cache the family path for a state/format?
def find_family_view_for_state_with_caching(state, action_view)
- return find_family_view_for_state(state, action_view) unless rails_env == "production"
+ return find_family_view_for_state(state, action_view) unless self.class.cache_configured?
# in production mode:
key = "#{state}/#{action_view.template_format}"
@@ -393,6 +395,5 @@ def include_helpers_in_class(view_klass)
# View instance.
def ivars_to_ignore; ['@controller']; end
- def rails_env; RAILS_ENV; end
end
end
View
@@ -14,7 +14,7 @@ def self.included(base) #:nodoc:
# mixin Cell::Base#cache, setup vars and extend #render_state if caching's on.
extend ClassMethods
- return unless ActionController::Base.cache_configured?
+ return unless cache_configured?
alias_method_chain :render_state, :caching
end
View
@@ -189,15 +189,20 @@ def test_find_family_view_for_state_with_caching
# test environment: --------------------------------------
assert_equal({}, ACell.state2view_cache)
- ACell.new(@controller).render_state :existing_view
- # in development/test environment, no view name caching should happen:
+ a = ACell.new(@controller)
+ a.class.instance_eval do
+ def cache_configured?; false; end
+ end
+ a.render_state :existing_view
+ # in development/test environment, no view name caching should happen,
+ # if perform_caching is false.
assert_equal({}, ACell.state2view_cache)
# production environment: --------------------------------
a = ACell.new(@controller)
- a.instance_eval do
- def rails_env; "production"; end
- end
+ a.class.instance_eval do
+ def cache_configured?; true; end
+ end
a.render_state :existing_view
assert ACell.state2view_cache.has_key?("existing_view/html")
end

0 comments on commit ae56a13

Please sign in to comment.