aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-08-31 03:44:00 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-08-31 03:48:09 +0100
commita59a3db1f3ae8c6aadaa8e1ce08b05f9ad677932 (patch)
treef54b4998a217ff4a0fc6d94fca9e3fd9d88dc694 /actionpack/lib
parent6183e55f714b436335dc843528be7525c342d922 (diff)
downloadrails-a59a3db1f3ae8c6aadaa8e1ce08b05f9ad677932.tar.gz
rails-a59a3db1f3ae8c6aadaa8e1ce08b05f9ad677932.tar.bz2
rails-a59a3db1f3ae8c6aadaa8e1ce08b05f9ad677932.zip
Move copying ivar logic from ActionController::Base to ActionView::Base
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/base.rb37
-rw-r--r--actionpack/lib/action_controller/layout.rb1
-rw-r--r--actionpack/lib/action_controller/rescue.rb3
-rw-r--r--actionpack/lib/action_controller/test_process.rb9
-rw-r--r--actionpack/lib/action_view/base.rb16
-rw-r--r--actionpack/lib/action_view/renderable.rb2
6 files changed, 23 insertions, 45 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 7dbc62980a..d12cc41cfa 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -260,10 +260,11 @@ module ActionController #:nodoc:
include StatusCodes
+ cattr_reader :protected_instance_variables
# Controller specific instance variables which will not be accessible inside views.
- @@protected_view_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
- @action_name @before_filter_chain_aborted @action_cache_path @_session @_cookies @_headers @_params
- @_flash @_response)
+ @@protected_instance_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
+ @action_name @before_filter_chain_aborted @action_cache_path @_session @_cookies @_headers @_params
+ @_flash @_response)
# Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
# and images to a dedicated asset server away from the main web server. Example:
@@ -393,10 +394,6 @@ module ActionController #:nodoc:
# directive. Values should always be specified as strings.
attr_internal :headers
- # Holds the hash of variables that are passed on to the template class to be made available to the view. This hash
- # is generated by taking a snapshot of all the instance variables in the current scope just before a template is rendered.
- attr_accessor :assigns
-
# Returns the name of the action this controller is processing.
attr_accessor :action_name
@@ -538,7 +535,6 @@ module ActionController #:nodoc:
assign_shortcuts(request, response)
initialize_current_url
assign_names
- forget_variables_added_to_assigns
log_processing
@@ -893,7 +889,6 @@ module ActionController #:nodoc:
render_for_file(template, options[:status], options[:locals] || {})
elsif inline = options[:inline]
- add_variables_to_assigns
render_for_text(@template.render(options), options[:status])
elsif action_name = options[:action]
@@ -911,12 +906,10 @@ module ActionController #:nodoc:
elsif options[:partial]
options[:partial] = default_template_name if options[:partial] == true
- add_variables_to_assigns
render_for_text(@template.render(options), options[:status])
elsif options[:update]
- add_variables_to_assigns
- @template.send! :evaluate_assigns
+ @template.send! :evaluate_assigns_and_ivars
generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block)
response.content_type = Mime::JS
@@ -937,7 +930,6 @@ module ActionController #:nodoc:
render(options, &block)
ensure
erase_render_results
- forget_variables_added_to_assigns
reset_variables_added_to_assigns
end
@@ -1123,7 +1115,6 @@ module ActionController #:nodoc:
private
def render_for_file(template_path, status = nil, locals = {}) #:nodoc:
- add_variables_to_assigns
logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
render_for_text(@template.render(:file => template_path, :locals => locals), status)
end
@@ -1160,7 +1151,6 @@ module ActionController #:nodoc:
@_session = @_response.session
@template = @_response.template
- @assigns = @_response.template.assigns
@_headers = @_response.headers
end
@@ -1224,27 +1214,10 @@ module ActionController #:nodoc:
hidden_actions
end
- def add_variables_to_assigns
- unless @variables_added
- add_instance_variables_to_assigns
- @variables_added = true
- end
- end
-
- def forget_variables_added_to_assigns
- @variables_added = nil
- end
-
def reset_variables_added_to_assigns
@template.instance_variable_set("@assigns_added", nil)
end
- def add_instance_variables_to_assigns
- (instance_variable_names - @@protected_view_variables).each do |var|
- @assigns[var[1..-1]] = instance_variable_get(var)
- end
- end
-
def request_origin
# this *needs* to be cached!
# otherwise you'd get different results if calling it more than once
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index fd743ced38..585bd03797 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -250,7 +250,6 @@ module ActionController #:nodoc:
content_for_layout = render_with_no_layout(options, extra_options, &block)
erase_render_results
- add_variables_to_assigns
@template.instance_variable_set("@content_for_layout", content_for_layout)
response.layout = layout
status = template_with_options ? options[:status] : nil
diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb
index a1a9d68a35..1492c4ec61 100644
--- a/actionpack/lib/action_controller/rescue.rb
+++ b/actionpack/lib/action_controller/rescue.rb
@@ -177,11 +177,8 @@ module ActionController #:nodoc:
# Render detailed diagnostics for unhandled exceptions rescued from
# a controller action.
def rescue_action_locally(exception)
- add_variables_to_assigns
@template.instance_variable_set("@exception", exception)
@template.instance_variable_set("@rescues_path", File.dirname(rescues_path("stub")))
- @template.send!(:assign_variables_from_controller)
-
@template.instance_variable_set("@contents", @template.render(:file => template_path_for_local_rescue(exception)))
response.content_type = Mime::HTML
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb
index a11fa7cd10..1d0254b522 100644
--- a/actionpack/lib/action_controller/test_process.rb
+++ b/actionpack/lib/action_controller/test_process.rb
@@ -3,6 +3,8 @@ require 'action_controller/test_case'
module ActionController #:nodoc:
class Base
+ attr_reader :assigns
+
# Process a test request called with a TestRequest object.
def self.process_test(request)
new.process_test(request)
@@ -14,7 +16,12 @@ module ActionController #:nodoc:
def process_with_test(*args)
returning process_without_test(*args) do
- add_variables_to_assigns
+ @assigns = {}
+ (instance_variable_names - @@protected_instance_variables).each do |var|
+ value = instance_variable_get(var)
+ @assigns[var[1..-1]] = value
+ response.template.assigns[var[1..-1]] = value if response
+ end
end
end
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index c65048bfa0..ce629d332a 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -343,18 +343,20 @@ module ActionView #:nodoc:
private
# Evaluate the local assigns and pushes them to the view.
- def evaluate_assigns
+ def evaluate_assigns_and_ivars
unless @assigns_added
- assign_variables_from_controller
+ @assigns.each { |key, value| instance_variable_set("@#{key}", value) }
+
+ if @controller
+ variables = @controller.instance_variables
+ variables -= @controller.protected_instance_variables if @controller.respond_to?(:protected_instance_variables)
+ variables.each {|name| instance_variable_set(name, @controller.instance_variable_get(name)) }
+ end
+
@assigns_added = true
end
end
- # Assigns instance variables from the controller to the view.
- def assign_variables_from_controller
- @assigns.each { |key, value| instance_variable_set("@#{key}", value) }
- end
-
def set_controller_content_type(content_type)
if controller.respond_to?(:response)
controller.response.content_type ||= content_type
diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb
index fa45edd436..5d950e336e 100644
--- a/actionpack/lib/action_view/renderable.rb
+++ b/actionpack/lib/action_view/renderable.rb
@@ -29,7 +29,7 @@ module ActionView
view._first_render ||= self
view._last_render = self
- view.send(:evaluate_assigns)
+ view.send(:evaluate_assigns_and_ivars)
view.send(:set_controller_content_type, mime_type) if respond_to?(:mime_type)
view.send(method_name(local_assigns), local_assigns) do |*names|