aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-03-18 15:52:43 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-03-18 15:52:43 -0700
commit71c9337f45f9c5461cbc6ddf6cab764ad0f82c3b (patch)
tree4e4a89ceca056d7ee4fcf329ecb56bbc0547d553 /actionpack/lib
parent523d0f3700f5bb68cdd3d549eaad63d8a88c2aef (diff)
downloadrails-71c9337f45f9c5461cbc6ddf6cab764ad0f82c3b.tar.gz
rails-71c9337f45f9c5461cbc6ddf6cab764ad0f82c3b.tar.bz2
rails-71c9337f45f9c5461cbc6ddf6cab764ad0f82c3b.zip
All tests pass without memoizing view_context
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb16
-rw-r--r--actionpack/lib/action_controller/caching/fragments.rb19
-rw-r--r--actionpack/lib/action_controller/metal/renderers.rb2
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/routing.rb5
-rw-r--r--actionpack/lib/action_view/base.rb2
-rw-r--r--actionpack/lib/action_view/helpers/cache_helper.rb22
6 files changed, 37 insertions, 29 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 16664098e5..eec7e520fa 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -32,7 +32,6 @@ module AbstractController
module Rendering
extend ActiveSupport::Concern
- include AbstractController::Assigns
include AbstractController::ViewPaths
# Overwrite process to setup I18n proxy.
@@ -53,7 +52,8 @@ module AbstractController
#
# Override this method in a module to change the default behavior.
def view_context
- @_view_context ||= ActionView::Base.for_controller(self)
+ klass = ActionView::Base.for_controller(self)
+ klass.new(lookup_context, view_assigns, self)
end
# Normalize arguments, options and then delegates render_to_body and
@@ -82,7 +82,6 @@ module AbstractController
# Find and renders a template based on the options given.
# :api: private
def _render_template(options) #:nodoc:
- _evaluate_assigns(view_context)
view_context.render(options)
end
@@ -105,6 +104,17 @@ module AbstractController
private
+ # This method should return a hash with assigns.
+ # You can overwrite this configuration per controller.
+ # :api: public
+ def view_assigns
+ hash = {}
+ variables = instance_variable_names
+ variables -= protected_instance_variables if respond_to?(:protected_instance_variables)
+ variables.each { |name| hash[name.to_s[1..-1]] = instance_variable_get(name) }
+ hash
+ end
+
# Normalize options by converting render "foo" to render :action => "foo" and
# render "foo/bar" to render :file => "foo/bar".
def _normalize_args(action=nil, options={})
diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb
index 8a10bdfe23..473a2fe214 100644
--- a/actionpack/lib/action_controller/caching/fragments.rb
+++ b/actionpack/lib/action_controller/caching/fragments.rb
@@ -34,25 +34,6 @@ module ActionController #:nodoc:
ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views)
end
- def fragment_for(name = {}, options = nil, &block) #:nodoc:
- if perform_caching
- if fragment_exist?(name, options)
- read_fragment(name, options)
- else
- # VIEW TODO: Make #capture usable outside of ERB
- # This dance is needed because Builder can't use capture
- buffer = view_context.output_buffer
- pos = buffer.length
- yield
- fragment = buffer.slice!(pos..-1)
- write_fragment(name, fragment, options)
- end
- else
- ret = yield
- ActiveSupport::SafeBuffer.new(ret) if ret.is_a?(String)
- end
- end
-
# Writes <tt>content</tt> to the location signified by <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats)
def write_fragment(key, content, options = nil)
return content unless cache_configured?
diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb
index 08325b468c..d906e1fb5b 100644
--- a/actionpack/lib/action_controller/metal/renderers.rb
+++ b/actionpack/lib/action_controller/metal/renderers.rb
@@ -87,7 +87,7 @@ module ActionController
end
add :update do |proc, options|
- _evaluate_assigns(view_context)
+ view_context = self.view_context
generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
self.content_type = Mime::JS
self.response_body = generator.to_s
diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
index eb28cd5107..de833bb3ca 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
@@ -154,15 +154,14 @@ module ActionDispatch
# TODO: Make this unnecessary
if @controller
@controller.singleton_class.send(:include, @router.url_helpers)
- @controller.class._helper_serial += 1
- @controller.view_context.singleton_class.send(:include, @router.url_helpers)
+ @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1
end
yield @router
ensure
@router = old_routes
if @controller
@controller = old_controller
- @controller.class._helper_serial += 1 if @controller
+ @controller.class._helper_serial = AbstractController::Helpers.next_serial + 1 if @controller
end
end
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 859c5c0863..b82c6a8203 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -250,8 +250,6 @@ module ActionView #:nodoc:
else
klass = self
end
-
- klass.new(controller.lookup_context, {}, controller)
end
def initialize(lookup_context = nil, assigns_for_first_render = {}, controller = nil, formats = nil) #:nodoc:
diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb
index f5c2127d3f..a904af56bb 100644
--- a/actionpack/lib/action_view/helpers/cache_helper.rb
+++ b/actionpack/lib/action_view/helpers/cache_helper.rb
@@ -32,9 +32,29 @@ module ActionView
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
- safe_concat controller.fragment_for(name, options, &block)
+ safe_concat fragment_for(name, options, &block)
nil
end
+
+ private
+ # TODO: Create an object that has caching read/write on it
+ def fragment_for(name = {}, options = nil, &block) #:nodoc:
+ if controller.perform_caching
+ if controller.fragment_exist?(name, options)
+ controller.read_fragment(name, options)
+ else
+ # VIEW TODO: Make #capture usable outside of ERB
+ # This dance is needed because Builder can't use capture
+ pos = output_buffer.length
+ yield
+ fragment = output_buffer.slice!(pos..-1)
+ controller.write_fragment(name, fragment, options)
+ end
+ else
+ ret = yield
+ ActiveSupport::SafeBuffer.new(ret) if ret.is_a?(String)
+ end
+ end
end
end
end