2009-04-27 21:21:26 -04:00
|
|
|
module ActionController
|
|
|
|
module Rails2Compatibility
|
2009-05-28 12:35:36 -04:00
|
|
|
extend ActiveSupport::Concern
|
2009-05-21 05:50:34 -04:00
|
|
|
|
|
|
|
class ::ActionController::ActionControllerError < StandardError #:nodoc:
|
|
|
|
end
|
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
# Temporary hax
|
2009-05-11 20:07:05 -04:00
|
|
|
included do
|
2009-05-11 15:45:26 -04:00
|
|
|
::ActionController::UnknownAction = ::AbstractController::ActionNotFound
|
|
|
|
::ActionController::DoubleRenderError = ::AbstractController::DoubleRenderError
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
cattr_accessor :session_options
|
2009-05-12 19:21:34 -04:00
|
|
|
self.session_options = {}
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
cattr_accessor :allow_concurrency
|
2009-05-12 19:21:34 -04:00
|
|
|
self.allow_concurrency = false
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
cattr_accessor :relative_url_root
|
2009-05-12 19:21:34 -04:00
|
|
|
self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
|
2009-05-28 10:49:02 -04:00
|
|
|
|
Got overhead down from 127 to 85. All tests pass:
* Tentatively replaced HeaderHash with SimpleHeaderHash, which does not preserve
case but does handle converting Arrays to Strings in to_hash. This requires
further discussion.
* Moved default_charset to ActionDispatch::Response to avoid having to hop over
to ActionController. Ideally, this would be a constant on AD::Response, but
some tests expect to be able to change it dynamically and I didn't want to change
them yet.
* Completely override #initialize from Rack::Response. Previously, it was creating
a HeaderHash, and then we were creating an entirely new one. There is no way to
call super without incurring the overhead of creating a HeaderHash.
* Override #write from Rack::Response. Its implementation tracks Content-Length,
and doing so adds additional overhead that could be mooted if other middleware
changes the body. It is more efficiently done at the top-level server.
* Change sending_file to an instance_variable instead of header inspection. In
general, if a state is important, it should be set as a property of the response
not reconstructed later.
* Set the Etag to @body instead of .body. AS::Cache.expand_cache_key handles
Arrays fine, and it's more efficient to let it handle the body parts, since
it is not forced to create a joined String.
* If we detect the default cache control case, just set it, rather than setting
the constituent parts and then running the normal (expensive) code to generate
the string.
2009-08-10 11:40:41 -04:00
|
|
|
class << self
|
|
|
|
delegate :default_charset=, :to => "ActionDispatch::Response"
|
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-12 19:21:34 -04:00
|
|
|
# cattr_reader :protected_instance_variables
|
|
|
|
cattr_accessor :protected_instance_variables
|
|
|
|
self.protected_instance_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
|
2009-05-11 17:48:58 -04:00
|
|
|
@action_name @before_filter_chain_aborted @action_cache_path @_headers @_params
|
2009-05-12 19:21:34 -04:00
|
|
|
@_flash @_response)
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-12 19:21:34 -04:00
|
|
|
# Indicates whether or not optimise the generated named
|
|
|
|
# route helper methods
|
|
|
|
cattr_accessor :optimise_named_routes
|
|
|
|
self.optimise_named_routes = true
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-12 19:21:34 -04:00
|
|
|
cattr_accessor :resources_path_names
|
|
|
|
self.resources_path_names = { :new => 'new', :edit => 'edit' }
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-12 19:21:34 -04:00
|
|
|
# Controls the resource action separator
|
|
|
|
cattr_accessor :resource_action_separator
|
|
|
|
self.resource_action_separator = "/"
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-14 20:25:10 -04:00
|
|
|
cattr_accessor :use_accept_header
|
|
|
|
self.use_accept_header = true
|
2009-05-15 20:49:11 -04:00
|
|
|
|
|
|
|
cattr_accessor :page_cache_directory
|
|
|
|
self.page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""
|
|
|
|
|
|
|
|
cattr_reader :cache_store
|
|
|
|
|
|
|
|
cattr_accessor :consider_all_requests_local
|
|
|
|
self.consider_all_requests_local = true
|
2009-05-22 20:29:44 -04:00
|
|
|
|
|
|
|
# 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:
|
|
|
|
# ActionController::Base.asset_host = "http://assets.example.com"
|
|
|
|
cattr_accessor :asset_host
|
2009-05-26 18:03:09 -04:00
|
|
|
|
|
|
|
cattr_accessor :ip_spoofing_check
|
|
|
|
self.ip_spoofing_check = true
|
2009-08-09 11:56:18 -04:00
|
|
|
|
|
|
|
cattr_accessor :trusted_proxies
|
2009-05-11 17:48:58 -04:00
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-19 21:08:04 -04:00
|
|
|
# For old tests
|
|
|
|
def initialize_template_class(*) end
|
|
|
|
def assign_shortcuts(*) end
|
|
|
|
|
2009-05-20 18:33:08 -04:00
|
|
|
# TODO: Remove this after we flip
|
|
|
|
def template
|
2009-08-06 18:45:40 -04:00
|
|
|
@template ||= view_context
|
2009-05-26 15:06:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_action(*)
|
|
|
|
template
|
|
|
|
super
|
2009-05-20 18:33:08 -04:00
|
|
|
end
|
|
|
|
|
2009-05-11 17:48:58 -04:00
|
|
|
module ClassMethods
|
2009-05-28 10:49:02 -04:00
|
|
|
def consider_all_requests_local
|
|
|
|
end
|
|
|
|
|
2009-05-11 20:07:05 -04:00
|
|
|
def rescue_action(env)
|
|
|
|
raise env["action_dispatch.rescue.exception"]
|
|
|
|
end
|
2009-05-15 20:49:11 -04:00
|
|
|
|
|
|
|
# Defines the storage option for cached fragments
|
|
|
|
def cache_store=(store_option)
|
|
|
|
@@cache_store = ActiveSupport::Cache.lookup_store(store_option)
|
|
|
|
end
|
2009-05-01 20:27:44 -04:00
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-04-27 21:21:26 -04:00
|
|
|
def render_to_body(options)
|
|
|
|
if options.is_a?(Hash) && options.key?(:template)
|
|
|
|
options[:template].sub!(/^\//, '')
|
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-08-10 18:49:33 -04:00
|
|
|
options[:text] = nil if options.delete(:nothing) == true
|
|
|
|
options[:text] = " " if options.key?(:text) && options[:text].nil?
|
2009-05-11 15:04:43 -04:00
|
|
|
|
2009-08-10 18:49:33 -04:00
|
|
|
super || " "
|
2009-04-27 21:21:26 -04:00
|
|
|
end
|
2009-05-15 18:57:12 -04:00
|
|
|
|
|
|
|
def _handle_method_missing
|
|
|
|
method_missing(@_action_name.to_sym)
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_for_action(action_name)
|
|
|
|
super || (respond_to?(:method_missing) && "_handle_method_missing")
|
2009-05-28 10:49:02 -04:00
|
|
|
end
|
|
|
|
|
2009-07-11 23:39:45 -04:00
|
|
|
def _find_layout(name, details)
|
2009-06-09 19:46:42 -04:00
|
|
|
details[:prefix] = nil if name =~ /\blayouts/
|
|
|
|
super
|
2009-05-11 15:45:26 -04:00
|
|
|
end
|
2009-06-16 16:54:55 -04:00
|
|
|
|
|
|
|
# Move this into a "don't run in production" module
|
|
|
|
def _default_layout(details, require_layout = false)
|
|
|
|
super
|
|
|
|
rescue ActionView::MissingTemplate
|
2009-07-11 23:39:45 -04:00
|
|
|
_find_layout(_layout({}), {})
|
2009-06-17 15:36:15 -04:00
|
|
|
nil
|
2009-06-16 16:54:55 -04:00
|
|
|
end
|
2009-05-20 20:55:25 -04:00
|
|
|
|
|
|
|
def performed?
|
|
|
|
response_body
|
|
|
|
end
|
2009-05-26 15:14:50 -04:00
|
|
|
|
|
|
|
# ==== Request only view path switching ====
|
|
|
|
def append_view_path(path)
|
|
|
|
view_paths.push(*path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def prepend_view_path(path)
|
|
|
|
view_paths.unshift(*path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def view_paths
|
2009-08-06 18:45:40 -04:00
|
|
|
view_context.view_paths
|
2009-05-26 15:14:50 -04:00
|
|
|
end
|
2009-04-27 21:21:26 -04:00
|
|
|
end
|
2009-05-21 23:22:18 -04:00
|
|
|
end
|