aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller/rendering.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/abstract_controller/rendering.rb')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb72
1 files changed, 30 insertions, 42 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 306bd41e2d..ab2c532859 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -32,9 +32,13 @@ module AbstractController
module Rendering
extend ActiveSupport::Concern
-
include AbstractController::ViewPaths
+ included do
+ config_accessor :protected_instance_variables, :instance_reader => false
+ self.protected_instance_variables = []
+ end
+
# Overwrite process to setup I18n proxy.
def process(*) #:nodoc:
old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
@@ -46,46 +50,27 @@ module AbstractController
module ClassMethods
def view_context_class
@view_context_class ||= begin
- controller = self
- Class.new(ActionView::Base) do
- if controller.respond_to?(:_routes) && controller._routes
- include controller._routes.url_helpers
- include controller._routes.mounted_helpers
- end
-
- if controller.respond_to?(:_helpers)
- include controller._helpers
-
- # TODO: Fix RJS to not require this
- self.helpers = controller._helpers
- end
- end
+ routes = _routes if respond_to?(:_routes)
+ helpers = _helpers if respond_to?(:_helpers)
+ ActionView::Base.prepare(routes, helpers)
end
end
+ end
- def parent_prefixes
- @parent_prefixes ||= begin
- parent_controller = superclass
- prefixes = []
-
- until parent_controller.abstract?
- prefixes << parent_controller.controller_path
- parent_controller = parent_controller.superclass
- end
+ attr_internal_writer :view_context_class
- prefixes
- end
- end
+ # Explicitly define protected_instance_variables so it can be
+ # inherited and overwritten by other modules if needed.
+ def protected_instance_variables
+ config.protected_instance_variables
end
- attr_writer :view_context_class
-
def view_context_class
- @view_context_class || self.class.view_context_class
+ @_view_context_class || self.class.view_context_class
end
def initialize(*)
- @view_context_class = nil
+ @_view_context_class = nil
super
end
@@ -99,7 +84,12 @@ module AbstractController
#
# Override this method in a module to change the default behavior.
def view_context
- view_context_class.new(lookup_context, view_assigns, self)
+ view_context_class.new(view_renderer, view_assigns, self)
+ end
+
+ # Returns an object that is able to render templates.
+ def view_renderer
+ @_view_renderer ||= ActionView::Renderer.new(lookup_context)
end
# Normalize arguments, options and then delegates render_to_body and
@@ -127,26 +117,24 @@ module AbstractController
# Find and renders a template based on the options given.
# :api: private
def _render_template(options) #:nodoc:
- view_context.render(options)
- end
-
- # The prefixes used in render "foo" shortcuts.
- def _prefixes
- @_prefixes ||= begin
- parent_prefixes = self.class.parent_prefixes
- parent_prefixes.dup.unshift(controller_path)
- end
+ view_renderer.render(view_context, options)
end
private
+ DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
+ @_action_name @_response_body @_formats @_prefixes @_config
+ @_view_context_class @_view_renderer @_lookup_context
+ )
+
# 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 -= protected_instance_variables
+ variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
variables.each { |name| hash[name.to_s[1, name.length]] = instance_variable_get(name) }
hash
end