aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/new_base
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/new_base')
-rw-r--r--actionpack/lib/action_controller/new_base/base.rb173
-rw-r--r--actionpack/lib/action_controller/new_base/compatibility.rb139
-rw-r--r--actionpack/lib/action_controller/new_base/conditional_get.rb133
-rw-r--r--actionpack/lib/action_controller/new_base/helpers.rb178
-rw-r--r--actionpack/lib/action_controller/new_base/hide_actions.rb35
-rw-r--r--actionpack/lib/action_controller/new_base/http.rb100
-rw-r--r--actionpack/lib/action_controller/new_base/layouts.rb195
-rw-r--r--actionpack/lib/action_controller/new_base/rack_convenience.rb33
-rw-r--r--actionpack/lib/action_controller/new_base/redirector.rb19
-rw-r--r--actionpack/lib/action_controller/new_base/render_options.rb103
-rw-r--r--actionpack/lib/action_controller/new_base/renderer.rb78
-rw-r--r--actionpack/lib/action_controller/new_base/rescuable.rb52
-rw-r--r--actionpack/lib/action_controller/new_base/session.rb15
-rw-r--r--actionpack/lib/action_controller/new_base/testing.rb39
-rw-r--r--actionpack/lib/action_controller/new_base/url_for.rb49
15 files changed, 0 insertions, 1341 deletions
diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb
deleted file mode 100644
index e8fc153578..0000000000
--- a/actionpack/lib/action_controller/new_base/base.rb
+++ /dev/null
@@ -1,173 +0,0 @@
-module ActionController
- class Base < Http
- abstract!
-
- include AbstractController::Benchmarker
- include AbstractController::Callbacks
- include AbstractController::Logger
-
- include ActionController::Helpers
- include ActionController::HideActions
- include ActionController::UrlFor
- include ActionController::Redirector
- include ActionController::Renderer
- include ActionController::Renderers::All
- include ActionController::Layouts
- include ActionController::ConditionalGet
- include ActionController::RackConvenience
-
- # Legacy modules
- include SessionManagement
- include ActionDispatch::StatusCodes
- include ActionController::Caching
- include ActionController::MimeResponds
-
- # Rails 2.x compatibility
- include ActionController::Rails2Compatibility
-
- include ActionController::Cookies
- include ActionController::Session
- include ActionController::Flash
- include ActionController::Verification
- include ActionController::RequestForgeryProtection
- include ActionController::Streaming
- include ActionController::HttpAuthentication::Basic::ControllerMethods
- include ActionController::HttpAuthentication::Digest::ControllerMethods
- include ActionController::FilterParameterLogging
- include ActionController::Translation
-
- # TODO: Extract into its own module
- # This should be moved together with other normalizing behavior
- module ImplicitRender
- def send_action(*)
- ret = super
- default_render unless performed?
- ret
- end
-
- def default_render
- render
- end
-
- def method_for_action(action_name)
- super || begin
- if view_paths.find_by_parts?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path)
- "default_render"
- end
- end
- end
- end
-
- include ImplicitRender
-
- include ActionController::Rescue
-
- def self.inherited(klass)
- ::ActionController::Base.subclasses << klass.to_s
- super
- end
-
- def self.subclasses
- @subclasses ||= []
- end
-
- def self.app_loaded!
- @subclasses.each do |subclass|
- subclass.constantize._write_layout_method
- end
- end
-
- def _normalize_options(action = nil, options = {}, &blk)
- if action.is_a?(Hash)
- options, action = action, nil
- elsif action.is_a?(String) || action.is_a?(Symbol)
- key = case action = action.to_s
- when %r{^/} then :file
- when %r{/} then :template
- else :action
- end
- options.merge! key => action
- elsif action
- options.merge! :partial => action
- end
-
- if options.key?(:action) && options[:action].to_s.index("/")
- options[:template] = options.delete(:action)
- end
-
- if options[:status]
- options[:status] = interpret_status(options[:status]).to_i
- end
-
- options[:update] = blk if block_given?
- options
- end
-
- def render(action = nil, options = {}, &blk)
- options = _normalize_options(action, options, &blk)
- super(options)
- end
-
- def render_to_string(action = nil, options = {}, &blk)
- options = _normalize_options(action, options, &blk)
- super(options)
- end
-
- # Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
- #
- # * <tt>Hash</tt> - The URL will be generated by calling url_for with the +options+.
- # * <tt>Record</tt> - The URL will be generated by calling url_for with the +options+, which will reference a named URL for that record.
- # * <tt>String</tt> starting with <tt>protocol://</tt> (like <tt>http://</tt>) - Is passed straight through as the target for redirection.
- # * <tt>String</tt> not containing a protocol - The current protocol and host is prepended to the string.
- # * <tt>:back</tt> - Back to the page that issued the request. Useful for forms that are triggered from multiple places.
- # Short-hand for <tt>redirect_to(request.env["HTTP_REFERER"])</tt>
- #
- # Examples:
- # redirect_to :action => "show", :id => 5
- # redirect_to post
- # redirect_to "http://www.rubyonrails.org"
- # redirect_to "/images/screenshot.jpg"
- # redirect_to articles_url
- # redirect_to :back
- #
- # The redirection happens as a "302 Moved" header unless otherwise specified.
- #
- # Examples:
- # redirect_to post_url(@post), :status=>:found
- # redirect_to :action=>'atom', :status=>:moved_permanently
- # redirect_to post_url(@post), :status=>301
- # redirect_to :action=>'atom', :status=>302
- #
- # When using <tt>redirect_to :back</tt>, if there is no referrer,
- # RedirectBackError will be raised. You may specify some fallback
- # behavior for this case by rescuing RedirectBackError.
- def redirect_to(options = {}, response_status = {}) #:doc:
- raise ActionControllerError.new("Cannot redirect to nil!") if options.nil?
-
- status = if options.is_a?(Hash) && options.key?(:status)
- interpret_status(options.delete(:status))
- elsif response_status.key?(:status)
- interpret_status(response_status[:status])
- else
- 302
- end
-
- url = case options
- # The scheme name consist of a letter followed by any combination of
- # letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
- # characters; and is terminated by a colon (":").
- when %r{^\w[\w\d+.-]*:.*}
- options
- when String
- request.protocol + request.host_with_port + options
- when :back
- raise RedirectBackError unless refer = request.headers["Referer"]
- refer
- else
- url_for(options)
- end
-
- super(url, status)
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/compatibility.rb b/actionpack/lib/action_controller/new_base/compatibility.rb
deleted file mode 100644
index 29ba43a879..0000000000
--- a/actionpack/lib/action_controller/new_base/compatibility.rb
+++ /dev/null
@@ -1,139 +0,0 @@
-module ActionController
- module Rails2Compatibility
- extend ActiveSupport::Concern
-
- class ::ActionController::ActionControllerError < StandardError #:nodoc:
- end
-
- # Temporary hax
- included do
- ::ActionController::UnknownAction = ::AbstractController::ActionNotFound
- ::ActionController::DoubleRenderError = ::AbstractController::DoubleRenderError
-
- cattr_accessor :session_options
- self.session_options = {}
-
- cattr_accessor :allow_concurrency
- self.allow_concurrency = false
-
- cattr_accessor :param_parsers
- self.param_parsers = { Mime::MULTIPART_FORM => :multipart_form,
- Mime::URL_ENCODED_FORM => :url_encoded_form,
- Mime::XML => :xml_simple,
- Mime::JSON => :json }
-
- cattr_accessor :relative_url_root
- self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
-
- cattr_accessor :default_charset
- self.default_charset = "utf-8"
-
- # 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
- @action_name @before_filter_chain_aborted @action_cache_path @_headers @_params
- @_flash @_response)
-
- # Indicates whether or not optimise the generated named
- # route helper methods
- cattr_accessor :optimise_named_routes
- self.optimise_named_routes = true
-
- cattr_accessor :resources_path_names
- self.resources_path_names = { :new => 'new', :edit => 'edit' }
-
- # Controls the resource action separator
- cattr_accessor :resource_action_separator
- self.resource_action_separator = "/"
-
- cattr_accessor :use_accept_header
- self.use_accept_header = true
-
- 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
-
- # 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
-
- cattr_accessor :ip_spoofing_check
- self.ip_spoofing_check = true
- end
-
- # For old tests
- def initialize_template_class(*) end
- def assign_shortcuts(*) end
-
- # TODO: Remove this after we flip
- def template
- @template ||= _action_view
- end
-
- def process_action(*)
- template
- super
- end
-
- module ClassMethods
- def consider_all_requests_local
- end
-
- def rescue_action(env)
- raise env["action_dispatch.rescue.exception"]
- end
-
- # Defines the storage option for cached fragments
- def cache_store=(store_option)
- @@cache_store = ActiveSupport::Cache.lookup_store(store_option)
- end
- end
-
- def render_to_body(options)
- if options.is_a?(Hash) && options.key?(:template)
- options[:template].sub!(/^\//, '')
- end
-
- options[:text] = nil if options[:nothing] == true
-
- body = super
- body = [' '] if body.blank?
- body
- end
-
- 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")
- end
-
- def _find_by_parts(name, details)
- details[:prefix] = nil if name =~ /\blayouts/
- super
- end
-
- def performed?
- response_body
- end
-
- # ==== 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
- _action_view.view_paths
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/conditional_get.rb b/actionpack/lib/action_controller/new_base/conditional_get.rb
deleted file mode 100644
index d287ec4994..0000000000
--- a/actionpack/lib/action_controller/new_base/conditional_get.rb
+++ /dev/null
@@ -1,133 +0,0 @@
-module ActionController
- module ConditionalGet
- extend ActiveSupport::Concern
-
- include RackConvenience
-
- # Sets the etag, last_modified, or both on the response and renders a
- # "304 Not Modified" response if the request is already fresh.
- #
- # Parameters:
- # * <tt>:etag</tt>
- # * <tt>:last_modified</tt>
- # * <tt>:public</tt> By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches).
- #
- # Example:
- #
- # def show
- # @article = Article.find(params[:id])
- # fresh_when(:etag => @article, :last_modified => @article.created_at.utc, :public => true)
- # end
- #
- # This will render the show template if the request isn't sending a matching etag or
- # If-Modified-Since header and just a "304 Not Modified" response if there's a match.
- #
- def fresh_when(options)
- options.assert_valid_keys(:etag, :last_modified, :public)
-
- response.etag = options[:etag] if options[:etag]
- response.last_modified = options[:last_modified] if options[:last_modified]
-
- if options[:public]
- cache_control = response.headers["Cache-Control"].split(",").map {|k| k.strip }
- cache_control.delete("private")
- cache_control.delete("no-cache")
- cache_control << "public"
- response.headers["Cache-Control"] = cache_control.join(', ')
- end
-
- if request.fresh?(response)
- head :not_modified
- end
- end
-
- # Return a response that has no content (merely headers). The options
- # argument is interpreted to be a hash of header names and values.
- # This allows you to easily return a response that consists only of
- # significant headers:
- #
- # head :created, :location => person_path(@person)
- #
- # It can also be used to return exceptional conditions:
- #
- # return head(:method_not_allowed) unless request.post?
- # return head(:bad_request) unless valid_request?
- # render
- def head(*args)
- if args.length > 2
- raise ArgumentError, "too many arguments to head"
- elsif args.empty?
- raise ArgumentError, "too few arguments to head"
- end
- options = args.extract_options!
- status = args.shift || options.delete(:status) || :ok
-
- options.each do |key, value|
- headers[key.to_s.dasherize.split(/-/).map { |v| v.capitalize }.join("-")] = value.to_s
- end
-
- render :nothing => true, :status => status
- end
-
- # Sets the etag and/or last_modified on the response and checks it against
- # the client request. If the request doesn't match the options provided, the
- # request is considered stale and should be generated from scratch. Otherwise,
- # it's fresh and we don't need to generate anything and a reply of "304 Not Modified" is sent.
- #
- # Parameters:
- # * <tt>:etag</tt>
- # * <tt>:last_modified</tt>
- # * <tt>:public</tt> By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches).
- #
- # Example:
- #
- # def show
- # @article = Article.find(params[:id])
- #
- # if stale?(:etag => @article, :last_modified => @article.created_at.utc)
- # @statistics = @article.really_expensive_call
- # respond_to do |format|
- # # all the supported formats
- # end
- # end
- # end
- def stale?(options)
- fresh_when(options)
- !request.fresh?(response)
- end
-
- # Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a "private" instruction, so that
- # intermediate caches shouldn't cache the response.
- #
- # Examples:
- # expires_in 20.minutes
- # expires_in 3.hours, :public => true
- # expires in 3.hours, 'max-stale' => 5.hours, :public => true
- #
- # This method will overwrite an existing Cache-Control header.
- # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.
- def expires_in(seconds, options = {}) #:doc:
- cache_control = response.headers["Cache-Control"].split(",").map {|k| k.strip }
-
- cache_control << "max-age=#{seconds}"
- cache_control.delete("no-cache")
- if options[:public]
- cache_control.delete("private")
- cache_control << "public"
- else
- cache_control << "private"
- end
-
- # This allows for additional headers to be passed through like 'max-stale' => 5.hours
- cache_control += options.symbolize_keys.reject{|k,v| k == :public || k == :private }.map{ |k,v| v == true ? k.to_s : "#{k.to_s}=#{v.to_s}"}
-
- response.headers["Cache-Control"] = cache_control.join(', ')
- end
-
- # Sets a HTTP 1.1 Cache-Control header of "no-cache" so no caching should occur by the browser or
- # intermediate caches (like caching proxy servers).
- def expires_now #:doc:
- response.headers["Cache-Control"] = "no-cache"
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/helpers.rb b/actionpack/lib/action_controller/new_base/helpers.rb
deleted file mode 100644
index 2fa5ea6519..0000000000
--- a/actionpack/lib/action_controller/new_base/helpers.rb
+++ /dev/null
@@ -1,178 +0,0 @@
-require 'active_support/core_ext/load_error'
-require 'active_support/core_ext/name_error'
-require 'active_support/dependencies'
-
-module ActionController
- # The Rails framework provides a large number of helpers for working with +assets+, +dates+, +forms+,
- # +numbers+ and model objects, to name a few. These helpers are available to all templates
- # by default.
- #
- # In addition to using the standard template helpers provided in the Rails framework, creating custom helpers to
- # extract complicated logic or reusable functionality is strongly encouraged. By default, the controller will
- # include a helper whose name matches that of the controller, e.g., <tt>MyController</tt> will automatically
- # include <tt>MyHelper</tt>.
- #
- # Additional helpers can be specified using the +helper+ class method in <tt>ActionController::Base</tt> or any
- # controller which inherits from it.
- #
- # ==== Examples
- # The +to_s+ method from the Time class can be wrapped in a helper method to display a custom message if
- # the Time object is blank:
- #
- # module FormattedTimeHelper
- # def format_time(time, format=:long, blank_message="&nbsp;")
- # time.blank? ? blank_message : time.to_s(format)
- # end
- # end
- #
- # FormattedTimeHelper can now be included in a controller, using the +helper+ class method:
- #
- # class EventsController < ActionController::Base
- # helper FormattedTimeHelper
- # def index
- # @events = Event.find(:all)
- # end
- # end
- #
- # Then, in any view rendered by <tt>EventController</tt>, the <tt>format_time</tt> method can be called:
- #
- # <% @events.each do |event| -%>
- # <p>
- # <% format_time(event.time, :short, "N/A") %> | <%= event.name %>
- # </p>
- # <% end -%>
- #
- # Finally, assuming we have two event instances, one which has a time and one which does not,
- # the output might look like this:
- #
- # 23 Aug 11:30 | Carolina Railhawks Soccer Match
- # N/A | Carolina Railhaws Training Workshop
- #
- module Helpers
- extend ActiveSupport::Concern
-
- include AbstractController::Helpers
-
- included do
- # Set the default directory for helpers
- extlib_inheritable_accessor(:helpers_dir) do
- defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/app/helpers" : "app/helpers"
- end
- end
-
- module ClassMethods
- def inherited(klass)
- klass.class_eval { default_helper_module! unless name.blank? }
- super
- end
-
- # The +helper+ class method can take a series of helper module names, a block, or both.
- #
- # ==== Parameters
- # *args<Array[Module, Symbol, String, :all]>
- # block<Block>:: A block defining helper methods
- #
- # ==== Examples
- # When the argument is a string or symbol, the method will provide the "_helper" suffix, require the file
- # and include the module in the template class. The second form illustrates how to include custom helpers
- # when working with namespaced controllers, or other cases where the file containing the helper definition is not
- # in one of Rails' standard load paths:
- # helper :foo # => requires 'foo_helper' and includes FooHelper
- # helper 'resources/foo' # => requires 'resources/foo_helper' and includes Resources::FooHelper
- #
- # When the argument is a module it will be included directly in the template class.
- # helper FooHelper # => includes FooHelper
- #
- # When the argument is the symbol <tt>:all</tt>, the controller will include all helpers beneath
- # <tt>ActionController::Base.helpers_dir</tt> (defaults to <tt>app/helpers/**/*.rb</tt> under RAILS_ROOT).
- # helper :all
- #
- # Additionally, the +helper+ class method can receive and evaluate a block, making the methods defined available
- # to the template.
- # # One line
- # helper { def hello() "Hello, world!" end }
- # # Multi-line
- # helper do
- # def foo(bar)
- # "#{bar} is the very best"
- # end
- # end
- #
- # Finally, all the above styles can be mixed together, and the +helper+ method can be invoked with a mix of
- # +symbols+, +strings+, +modules+ and blocks.
- # helper(:three, BlindHelper) { def mice() 'mice' end }
- #
- def helper(*args, &block)
- super(*_modules_for_helpers(args), &block)
- end
-
- # Declares helper accessors for controller attributes. For example, the
- # following adds new +name+ and <tt>name=</tt> instance methods to a
- # controller and makes them available to the view:
- # helper_attr :name
- # attr_accessor :name
- #
- # ==== Parameters
- # *attrs<Array[String, Symbol]>:: Names of attributes to be converted
- # into helpers.
- def helper_attr(*attrs)
- attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") }
- end
-
- # Provides a proxy to access helpers methods from outside the view.
- def helpers
- @helper_proxy ||= ActionView::Base.new.extend(_helpers)
- end
-
- private
- # Returns a list of modules, normalized from the acceptable kinds of
- # helpers with the following behavior:
- # String or Symbol:: :FooBar or "FooBar" becomes "foo_bar_helper",
- # and "foo_bar_helper.rb" is loaded using require_dependency.
- # :all:: Loads all modules in the #helpers_dir
- # Module:: No further processing
- #
- # After loading the appropriate files, the corresponding modules
- # are returned.
- #
- # ==== Parameters
- # args<Array[String, Symbol, Module, all]>:: A list of helpers
- #
- # ==== Returns
- # Array[Module]:: A normalized list of modules for the list of
- # helpers provided.
- def _modules_for_helpers(args)
- args.flatten.map! do |arg|
- case arg
- when :all
- _modules_for_helpers all_application_helpers
- when String, Symbol
- file_name = "#{arg.to_s.underscore}_helper"
- require_dependency(file_name, "Missing helper file helpers/%s.rb")
- file_name.camelize.constantize
- when Module
- arg
- else
- raise ArgumentError, "helper must be a String, Symbol, or Module"
- end
- end
- end
-
- def default_helper_module!
- module_name = name.sub(/Controller$/, '')
- module_path = module_name.underscore
- helper module_path
- rescue MissingSourceFile => e
- raise e unless e.is_missing? "#{module_path}_helper"
- rescue NameError => e
- raise e unless e.missing_name? "#{module_name}Helper"
- end
-
- # Extract helper names from files in app/helpers/**/*.rb
- def all_application_helpers
- extract = /^#{Regexp.quote(helpers_dir)}\/?(.*)_helper.rb$/
- Dir["#{helpers_dir}/**/*_helper.rb"].map { |file| file.sub extract, '\1' }
- end
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/hide_actions.rb b/actionpack/lib/action_controller/new_base/hide_actions.rb
deleted file mode 100644
index af68c772b1..0000000000
--- a/actionpack/lib/action_controller/new_base/hide_actions.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-module ActionController
- # ActionController::HideActions adds the ability to prevent public methods on a controller
- # to be called as actions.
- module HideActions
- extend ActiveSupport::Concern
-
- included do
- extlib_inheritable_accessor(:hidden_actions) { Set.new }
- end
-
- private
-
- # Overrides AbstractController::Base#action_method? to return false if the
- # action name is in the list of hidden actions.
- def action_method?(action_name)
- !hidden_actions.include?(action_name) && super
- end
-
- module ClassMethods
- # Sets all of the actions passed in as hidden actions.
- #
- # ==== Parameters
- # *args<#to_s>:: A list of actions
- def hide_action(*args)
- hidden_actions.merge(args.map! {|a| a.to_s })
- end
-
- # Overrides AbstractController::Base#action_methods to remove any methods
- # that are listed as hidden methods.
- def action_methods
- @action_methods ||= Set.new(super.reject {|name| hidden_actions.include?(name)})
- end
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb
deleted file mode 100644
index 2e73561f93..0000000000
--- a/actionpack/lib/action_controller/new_base/http.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-require 'action_controller/abstract'
-require 'active_support/core_ext/module/delegation'
-
-module ActionController
- # ActionController::Http provides a way to get a valid Rack application from a controller.
- #
- # In AbstractController, dispatching is triggered directly by calling #process on a new controller.
- # ActionController::Http provides an #action method that returns a valid Rack application for a
- # given action. Other rack builders, such as Rack::Builder, Rack::URLMap, and the Rails router,
- # can dispatch directly to the action returned by FooController.action(:index).
- class Http < AbstractController::Base
- abstract!
-
- # :api: public
- attr_internal :params, :env
-
- # Returns the last part of the controller's name, underscored, without the ending
- # "Controller". For instance, MyApp::MyPostsController would return "my_posts" for
- # controller_name
- #
- # ==== Returns
- # String
- def self.controller_name
- @controller_name ||= controller_path.split("/").last
- end
-
- # Delegates to the class' #controller_name
- def controller_name
- self.class.controller_name
- end
-
- # Returns the full controller name, underscored, without the ending Controller.
- # For instance, MyApp::MyPostsController would return "my_app/my_posts" for
- # controller_name.
- #
- # ==== Returns
- # String
- def self.controller_path
- @controller_path ||= self.name.sub(/Controller$/, '').underscore
- end
-
- # Delegates to the class' #controller_path
- def controller_path
- self.class.controller_path
- end
-
- # The details below can be overridden to support a specific
- # Request and Response object. The default ActionController::Base
- # implementation includes RackConvenience, which makes a request
- # and response object available. You might wish to control the
- # environment and response manually for performance reasons.
-
- attr_internal :status, :headers, :content_type
-
- def initialize(*)
- @_headers = {}
- super
- end
-
- # Basic implementations for content_type=, location=, and headers are
- # provided to reduce the dependency on the RackConvenience module
- # in Renderer and Redirector.
-
- def content_type=(type)
- headers["Content-Type"] = type.to_s
- end
-
- def location=(url)
- headers["Location"] = url
- end
-
- # :api: private
- def call(name, env)
- @_env = env
- process(name)
- to_rack
- end
-
- # :api: private
- def to_rack
- [status, headers, response_body]
- end
-
- # Return a rack endpoint for the given action. Memoize the endpoint, so
- # multiple calls into MyController.action will return the same object
- # for the same action.
- #
- # ==== Parameters
- # action<#to_s>:: An action name
- #
- # ==== Returns
- # Proc:: A rack application
- def self.action(name)
- @actions ||= {}
- @actions[name.to_s] ||= proc do |env|
- new.call(name, env)
- end
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb
deleted file mode 100644
index ace4b148c9..0000000000
--- a/actionpack/lib/action_controller/new_base/layouts.rb
+++ /dev/null
@@ -1,195 +0,0 @@
-module ActionController
- # Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in
- # repeated setups. The inclusion pattern has pages that look like this:
- #
- # <%= render "shared/header" %>
- # Hello World
- # <%= render "shared/footer" %>
- #
- # This approach is a decent way of keeping common structures isolated from the changing content, but it's verbose
- # and if you ever want to change the structure of these two includes, you'll have to change all the templates.
- #
- # With layouts, you can flip it around and have the common structure know where to insert changing content. This means
- # that the header and footer are only mentioned in one place, like this:
- #
- # // The header part of this layout
- # <%= yield %>
- # // The footer part of this layout
- #
- # And then you have content pages that look like this:
- #
- # hello world
- #
- # At rendering time, the content page is computed and then inserted in the layout, like this:
- #
- # // The header part of this layout
- # hello world
- # // The footer part of this layout
- #
- # NOTE: The old notation for rendering the view from a layout was to expose the magic <tt>@content_for_layout</tt> instance
- # variable. The preferred notation now is to use <tt>yield</tt>, as documented above.
- #
- # == Accessing shared variables
- #
- # Layouts have access to variables specified in the content pages and vice versa. This allows you to have layouts with
- # references that won't materialize before rendering time:
- #
- # <h1><%= @page_title %></h1>
- # <%= yield %>
- #
- # ...and content pages that fulfill these references _at_ rendering time:
- #
- # <% @page_title = "Welcome" %>
- # Off-world colonies offers you a chance to start a new life
- #
- # The result after rendering is:
- #
- # <h1>Welcome</h1>
- # Off-world colonies offers you a chance to start a new life
- #
- # == Layout assignment
- #
- # You can either specify a layout declaratively (using the #layout class method) or give
- # it the same name as your controller, and place it in <tt>app/views/layouts</tt>.
- # If a subclass does not have a layout specified, it inherits its layout using normal Ruby inheritance.
- #
- # For instance, if you have PostsController and a template named <tt>app/views/layouts/posts.html.erb</tt>,
- # that template will be used for all actions in PostsController and controllers inheriting
- # from PostsController.
- #
- # If you use a module, for instance Weblog::PostsController, you will need a template named
- # <tt>app/views/layouts/weblog/posts.html.erb</tt>.
- #
- # Since all your controllers inherit from ApplicationController, they will use
- # <tt>app/views/layouts/application.html.erb</tt> if no other layout is specified
- # or provided.
- #
- # == Inheritance Examples
- #
- # class BankController < ActionController::Base
- # layout "bank_standard"
- #
- # class InformationController < BankController
- #
- # class TellerController < BankController
- # # teller.html.erb exists
- #
- # class TillController < TellerController
- #
- # class VaultController < BankController
- # layout :access_level_layout
- #
- # class EmployeeController < BankController
- # layout nil
- #
- # The InformationController uses "bank_standard" inherited from the BankController, the VaultController overwrites
- # and picks the layout dynamically, and the EmployeeController doesn't want to use a layout at all.
- #
- # The TellerController uses +teller.html.erb+, and TillController inherits that layout and
- # uses it as well.
- #
- # == Types of layouts
- #
- # Layouts are basically just regular templates, but the name of this template needs not be specified statically. Sometimes
- # you want to alternate layouts depending on runtime information, such as whether someone is logged in or not. This can
- # be done either by specifying a method reference as a symbol or using an inline method (as a proc).
- #
- # The method reference is the preferred approach to variable layouts and is used like this:
- #
- # class WeblogController < ActionController::Base
- # layout :writers_and_readers
- #
- # def index
- # # fetching posts
- # end
- #
- # private
- # def writers_and_readers
- # logged_in? ? "writer_layout" : "reader_layout"
- # end
- #
- # Now when a new request for the index action is processed, the layout will vary depending on whether the person accessing
- # is logged in or not.
- #
- # If you want to use an inline method, such as a proc, do something like this:
- #
- # class WeblogController < ActionController::Base
- # layout proc{ |controller| controller.logged_in? ? "writer_layout" : "reader_layout" }
- #
- # Of course, the most common way of specifying a layout is still just as a plain template name:
- #
- # class WeblogController < ActionController::Base
- # layout "weblog_standard"
- #
- # If no directory is specified for the template name, the template will by default be looked for in <tt>app/views/layouts/</tt>.
- # Otherwise, it will be looked up relative to the template root.
- #
- # == Conditional layouts
- #
- # If you have a layout that by default is applied to all the actions of a controller, you still have the option of rendering
- # a given action or set of actions without a layout, or restricting a layout to only a single action or a set of actions. The
- # <tt>:only</tt> and <tt>:except</tt> options can be passed to the layout call. For example:
- #
- # class WeblogController < ActionController::Base
- # layout "weblog_standard", :except => :rss
- #
- # # ...
- #
- # end
- #
- # This will assign "weblog_standard" as the WeblogController's layout except for the +rss+ action, which will not wrap a layout
- # around the rendered view.
- #
- # Both the <tt>:only</tt> and <tt>:except</tt> condition can accept an arbitrary number of method references, so
- # #<tt>:except => [ :rss, :text_only ]</tt> is valid, as is <tt>:except => :rss</tt>.
- #
- # == Using a different layout in the action render call
- #
- # If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above.
- # Sometimes you'll have exceptions where one action wants to use a different layout than the rest of the controller.
- # You can do this by passing a <tt>:layout</tt> option to the <tt>render</tt> call. For example:
- #
- # class WeblogController < ActionController::Base
- # layout "weblog_standard"
- #
- # def help
- # render :action => "help", :layout => "help"
- # end
- # end
- #
- # This will render the help action with the "help" layout instead of the controller-wide "weblog_standard" layout.
- module Layouts
- extend ActiveSupport::Concern
-
- include ActionController::Renderer
- include AbstractController::Layouts
-
- module ClassMethods
- # If no layout is provided, look for a layout with this name.
- def _implied_layout_name
- controller_path
- end
- end
-
- private
- def _determine_template(options)
- super
-
- return if (options.key?(:text) || options.key?(:inline) || options.key?(:partial)) && !options.key?(:layout)
- layout = options.key?(:layout) ? options[:layout] : :none
- options[:_layout] = _layout_for_option(layout, options[:_template].details)
- end
-
- def _layout_for_option(name, details)
- case name
- when String then _layout_for_name(name, details)
- when true then _default_layout(details, true)
- when :none then _default_layout(details, false)
- when false, nil then nil
- else
- raise ArgumentError,
- "String, true, or false, expected for `layout'; you passed #{name.inspect}"
- end
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/rack_convenience.rb b/actionpack/lib/action_controller/new_base/rack_convenience.rb
deleted file mode 100644
index 805157b0e3..0000000000
--- a/actionpack/lib/action_controller/new_base/rack_convenience.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-module ActionController
- module RackConvenience
- extend ActiveSupport::Concern
-
- included do
- delegate :headers, :status=, :location=, :content_type=,
- :status, :location, :content_type, :to => "@_response"
- attr_internal :request, :response
- end
-
- def call(name, env)
- @_request = ActionDispatch::Request.new(env)
- @_response = ActionDispatch::Response.new
- @_response.request = request
- super
- end
-
- def params
- @_params ||= @_request.parameters
- end
-
- # :api: private
- def to_rack
- @_response.prepare!
- @_response.to_a
- end
-
- def response_body=(body)
- response.body = body if response
- super
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/redirector.rb b/actionpack/lib/action_controller/new_base/redirector.rb
deleted file mode 100644
index 20060b001f..0000000000
--- a/actionpack/lib/action_controller/new_base/redirector.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-module ActionController
- class RedirectBackError < AbstractController::Error #:nodoc:
- DEFAULT_MESSAGE = 'No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify request.env["HTTP_REFERER"].'
-
- def initialize(message = nil)
- super(message || DEFAULT_MESSAGE)
- end
- end
-
- module Redirector
- def redirect_to(url, status) #:doc:
- raise AbstractController::DoubleRenderError if response_body
- logger.info("Redirected to #{url}") if logger && logger.info?
- self.status = status
- self.location = url.gsub(/[\r\n]/, '')
- self.response_body = "<html><body>You are being <a href=\"#{CGI.escapeHTML(url)}\">redirected</a>.</body></html>"
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/render_options.rb b/actionpack/lib/action_controller/new_base/render_options.rb
deleted file mode 100644
index fc9a02626f..0000000000
--- a/actionpack/lib/action_controller/new_base/render_options.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-module ActionController
- module RenderOptions
- extend ActiveSupport::Concern
-
- included do
- extlib_inheritable_accessor :_renderers
- self._renderers = []
- end
-
- module ClassMethods
- def _write_render_options
- renderers = _renderers.map do |r|
- <<-RUBY_EVAL
- if options.key?(:#{r})
- _process_options(options)
- return _render_#{r}(options[:#{r}], options)
- end
- RUBY_EVAL
- end
-
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
- def _handle_render_options(options)
- #{renderers.join}
- end
- RUBY_EVAL
- end
-
- def _add_render_option(name)
- _renderers << name
- _write_render_options
- end
- end
-
- def render_to_body(options)
- _handle_render_options(options) || super
- end
- end
-
- module RenderOption #:nodoc:
- def self.extended(base)
- base.extend ActiveSupport::Concern
- base.send :include, ::ActionController::RenderOptions
-
- def base.register_renderer(name)
- included { _add_render_option(name) }
- end
- end
- end
-
- module Renderers
- module Json
- extend RenderOption
- register_renderer :json
-
- def _render_json(json, options)
- json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
- json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
- self.content_type ||= Mime::JSON
- self.response_body = json
- end
- end
-
- module Js
- extend RenderOption
- register_renderer :js
-
- def _render_js(js, options)
- self.content_type ||= Mime::JS
- self.response_body = js
- end
- end
-
- module Xml
- extend RenderOption
- register_renderer :xml
-
- def _render_xml(xml, options)
- self.content_type ||= Mime::XML
- self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml
- end
- end
-
- module RJS
- extend RenderOption
- register_renderer :update
-
- def _render_update(proc, options)
- generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(_action_view, &proc)
- self.content_type = Mime::JS
- self.response_body = generator.to_s
- end
- end
-
- module All
- extend ActiveSupport::Concern
-
- include ActionController::Renderers::Json
- include ActionController::Renderers::Js
- include ActionController::Renderers::Xml
- include ActionController::Renderers::RJS
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb
deleted file mode 100644
index 2fab501302..0000000000
--- a/actionpack/lib/action_controller/new_base/renderer.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-module ActionController
- module Renderer
- extend ActiveSupport::Concern
-
- include AbstractController::Renderer
-
- def process_action(*)
- self.formats = request.formats.map {|x| x.to_sym}
- super
- end
-
- def render(options)
- super
- options[:_template] ||= _action_view._partial
- self.content_type ||= begin
- mime = options[:_template].mime_type
- formats.include?(mime && mime.to_sym) || formats.include?(:all) ? mime : Mime::Type.lookup_by_extension(formats.first)
- end
- response_body
- end
-
- def render_to_body(options)
- _process_options(options)
-
- if options.key?(:partial)
- _render_partial(options[:partial], options)
- end
-
- super
- end
-
- private
- def _prefix
- controller_path
- end
-
- def _determine_template(options)
- if options.key?(:text)
- options[:_template] = ActionView::TextTemplate.new(options[:text], formats.first)
- elsif options.key?(:inline)
- handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb")
- template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
- options[:_template] = template
- elsif options.key?(:template)
- options[:_template_name] = options[:template]
- elsif options.key?(:file)
- options[:_template_name] = options[:file]
- elsif !options.key?(:partial)
- options[:_template_name] = (options[:action] || action_name).to_s
- options[:_prefix] = _prefix
- end
-
- super
- end
-
- def _render_partial(partial, options)
- case partial
- when true
- options[:_prefix] = _prefix
- when String
- options[:_prefix] = _prefix unless partial.index('/')
- options[:_template_name] = partial
- else
- options[:_partial_object] = true
- return
- end
-
- options[:_partial] = options[:object] || true
- end
-
- def _process_options(options)
- status, content_type, location = options.values_at(:status, :content_type, :location)
- self.status = status if status
- self.content_type = content_type if content_type
- self.headers["Location"] = url_for(location) if location
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/rescuable.rb b/actionpack/lib/action_controller/new_base/rescuable.rb
deleted file mode 100644
index 029e643d93..0000000000
--- a/actionpack/lib/action_controller/new_base/rescuable.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-module ActionController #:nodoc:
- # Actions that fail to perform as expected throw exceptions. These
- # exceptions can either be rescued for the public view (with a nice
- # user-friendly explanation) or for the developers view (with tons of
- # debugging information). The developers view is already implemented by
- # the Action Controller, but the public view should be tailored to your
- # specific application.
- #
- # The default behavior for public exceptions is to render a static html
- # file with the name of the error code thrown. If no such file exists, an
- # empty response is sent with the correct status code.
- #
- # You can override what constitutes a local request by overriding the
- # <tt>local_request?</tt> method in your own controller. Custom rescue
- # behavior is achieved by overriding the <tt>rescue_action_in_public</tt>
- # and <tt>rescue_action_locally</tt> methods.
- module Rescue
- extend ActiveSupport::Concern
-
- included do
- include ActiveSupport::Rescuable
- end
-
- module ClassMethods
- # This can be removed once we can move action(:_rescue_action) into middlewares.rb
- # Currently, it does controller.method(:rescue_action), which is hiding the implementation
- # difference between the old and new base.
- def rescue_action(env)
- action(:_rescue_action).call(env)
- end
- end
-
- attr_internal :rescued_exception
-
- private
- def method_for_action(action_name)
- return action_name if self.rescued_exception = request.env.delete("action_dispatch.rescue.exception")
- super
- end
-
- def _rescue_action
- rescue_with_handler(rescued_exception) || raise(rescued_exception)
- end
-
- def process_action(*)
- super
- rescue Exception => exception
- self.rescued_exception = exception
- _rescue_action
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/session.rb b/actionpack/lib/action_controller/new_base/session.rb
deleted file mode 100644
index bcedd6e1c7..0000000000
--- a/actionpack/lib/action_controller/new_base/session.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module ActionController
- module Session
- extend ActiveSupport::Concern
-
- include RackConvenience
-
- def session
- @_request.session
- end
-
- def reset_session
- @_request.reset_session
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/testing.rb b/actionpack/lib/action_controller/new_base/testing.rb
deleted file mode 100644
index a4a1116d9e..0000000000
--- a/actionpack/lib/action_controller/new_base/testing.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-module ActionController
- module Testing
- extend ActiveSupport::Concern
-
- include RackConvenience
-
- # OMG MEGA HAX
- def process_with_new_base_test(request, response)
- @_request = request
- @_response = response
- @_response.request = request
- ret = process(request.parameters[:action])
- @_response.body ||= self.response_body
- @_response.prepare!
- set_test_assigns
- ret
- end
-
- def set_test_assigns
- @assigns = {}
- (instance_variable_names - self.class.protected_instance_variables).each do |var|
- name, value = var[1..-1], instance_variable_get(var)
- @assigns[name] = value
- end
- end
-
- # TODO : Rewrite tests using controller.headers= to use Rack env
- def headers=(new_headers)
- @_response ||= ActionDispatch::Response.new
- @_response.headers.replace(new_headers)
- end
-
- module ClassMethods
- def before_filters
- _process_action_callbacks.find_all{|x| x.kind == :before}.map{|x| x.name}
- end
- end
- end
-end
diff --git a/actionpack/lib/action_controller/new_base/url_for.rb b/actionpack/lib/action_controller/new_base/url_for.rb
deleted file mode 100644
index 7119c14cd3..0000000000
--- a/actionpack/lib/action_controller/new_base/url_for.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-module ActionController
- module UrlFor
- extend ActiveSupport::Concern
-
- include RackConvenience
-
- def process_action(*)
- initialize_current_url
- super
- end
-
- def initialize_current_url
- @url = UrlRewriter.new(request, params.clone)
- end
-
- # Overwrite to implement a number of default options that all url_for-based methods will use. The default options should come in
- # the form of a hash, just like the one you would use for url_for directly. Example:
- #
- # def default_url_options(options)
- # { :project => @project.active? ? @project.url_name : "unknown" }
- # end
- #
- # As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
- # urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
- # by this method.
- def default_url_options(options = nil)
- end
-
- def rewrite_options(options) #:nodoc:
- if defaults = default_url_options(options)
- defaults.merge(options)
- else
- options
- end
- end
-
- def url_for(options = {})
- options ||= {}
- case options
- when String
- options
- when Hash
- @url.rewrite(rewrite_options(options))
- else
- polymorphic_url(options)
- end
- end
- end
-end