mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Renamed Base2 to Base and don't require old action_controller for new Base
This commit is contained in:
parent
b1d34b3aa4
commit
e046f36824
13 changed files with 159 additions and 143 deletions
|
@ -1,9 +1,22 @@
|
||||||
module ActionController
|
module ActionController
|
||||||
|
autoload :Base, "action_controller/new_base/base"
|
||||||
autoload :HideActions, "action_controller/new_base/hide_actions"
|
autoload :HideActions, "action_controller/new_base/hide_actions"
|
||||||
autoload :Http, "action_controller/new_base/base"
|
autoload :Http, "action_controller/new_base/http"
|
||||||
autoload :Layouts, "action_controller/new_base/layouts"
|
autoload :Layouts, "action_controller/new_base/layouts"
|
||||||
autoload :Rails2Compatibility, "action_controller/new_base/compatibility"
|
autoload :Rails2Compatibility, "action_controller/new_base/compatibility"
|
||||||
autoload :Renderer, "action_controller/new_base/renderer"
|
autoload :Renderer, "action_controller/new_base/renderer"
|
||||||
autoload :Testing, "action_controller/new_base/testing"
|
autoload :Testing, "action_controller/new_base/testing"
|
||||||
autoload :UrlFor, "action_controller/new_base/url_for"
|
autoload :UrlFor, "action_controller/new_base/url_for"
|
||||||
end
|
|
||||||
|
# Ported modules
|
||||||
|
# require 'action_controller/routing'
|
||||||
|
autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
|
||||||
|
autoload :PolymorphicRoutes, 'action_controller/routing/generation/polymorphic_routes'
|
||||||
|
autoload :Resources, 'action_controller/routing/resources'
|
||||||
|
autoload :SessionManagement, 'action_controller/base/session_management'
|
||||||
|
|
||||||
|
require 'action_controller/routing'
|
||||||
|
end
|
||||||
|
|
||||||
|
require 'action_dispatch'
|
||||||
|
require 'action_view'
|
|
@ -1,59 +1,60 @@
|
||||||
module ActionController
|
module ActionController
|
||||||
class Http < AbstractController::Base
|
class Base < Http
|
||||||
abstract!
|
abstract!
|
||||||
|
|
||||||
# :api: public
|
use AbstractController::Callbacks
|
||||||
attr_internal :request, :response, :params
|
use AbstractController::Helpers
|
||||||
|
use AbstractController::Logger
|
||||||
|
|
||||||
# :api: public
|
use ActionController::HideActions
|
||||||
def self.controller_name
|
use ActionController::UrlFor
|
||||||
@controller_name ||= controller_path.split("/").last
|
use ActionController::Renderer
|
||||||
end
|
use ActionController::Layouts
|
||||||
|
|
||||||
# :api: public
|
# Legacy modules
|
||||||
def controller_name() self.class.controller_name end
|
include SessionManagement
|
||||||
|
|
||||||
# :api: public
|
# Rails 2.x compatibility
|
||||||
def self.controller_path
|
use ActionController::Rails2Compatibility
|
||||||
@controller_path ||= self.name.sub(/Controller$/, '').underscore
|
|
||||||
|
def self.inherited(klass)
|
||||||
|
::ActionController::Base.subclasses << klass.to_s
|
||||||
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
# :api: public
|
def self.subclasses
|
||||||
def controller_path() self.class.controller_path end
|
@subclasses ||= []
|
||||||
|
|
||||||
# :api: private
|
|
||||||
def self.internal_methods
|
|
||||||
ActionController::Http.public_instance_methods(true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# :api: private
|
def self.app_loaded!
|
||||||
def self.action_names() action_methods end
|
@subclasses.each do |subclass|
|
||||||
|
subclass.constantize._write_layout_method
|
||||||
# :api: private
|
end
|
||||||
def action_names() action_methods end
|
|
||||||
|
|
||||||
# :api: plugin
|
|
||||||
def self.call(env)
|
|
||||||
controller = new
|
|
||||||
controller.call(env).to_rack
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# :api: private
|
def render(action = action_name, options = {})
|
||||||
def call(env)
|
if action.is_a?(Hash)
|
||||||
@_request = ActionDispatch::Request.new(env)
|
options, action = action, nil
|
||||||
@_response = ActionDispatch::Response.new
|
else
|
||||||
process(@_request.parameters[:action])
|
options.merge! :action => action
|
||||||
@_response.body = response_body
|
end
|
||||||
@_response.prepare!
|
|
||||||
self
|
super(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# :api: private
|
def render_to_body(options = {})
|
||||||
def to_rack
|
options = {:template => options} if options.is_a?(String)
|
||||||
@_response.to_a
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_action
|
||||||
|
ret = super
|
||||||
|
render if response_body.nil?
|
||||||
|
ret
|
||||||
|
end
|
||||||
|
|
||||||
|
def respond_to_action?(action_name)
|
||||||
|
super || view_paths.find_by_parts?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
class Base < Http
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,6 +1,27 @@
|
||||||
module ActionController
|
module ActionController
|
||||||
module Rails2Compatibility
|
module Rails2Compatibility
|
||||||
|
|
||||||
|
# Temporary hax
|
||||||
|
setup do
|
||||||
|
cattr_accessor :session_options
|
||||||
|
self.send(:class_variable_set, "@@session_options", {})
|
||||||
|
|
||||||
|
cattr_accessor :allow_concurrency
|
||||||
|
self.send(:class_variable_set, "@@allow_concurrency", false)
|
||||||
|
|
||||||
|
cattr_accessor :param_parsers
|
||||||
|
self.send(:class_variable_set, "@@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.send(:class_variable_set, "@@relative_url_root", ENV['RAILS_RELATIVE_URL_ROOT'])
|
||||||
|
|
||||||
|
cattr_accessor :default_charset
|
||||||
|
self.send(:class_variable_set, "@@default_charset", "utf-8")
|
||||||
|
end
|
||||||
|
|
||||||
def render_to_body(options)
|
def render_to_body(options)
|
||||||
if options.is_a?(Hash) && options.key?(:template)
|
if options.is_a?(Hash) && options.key?(:template)
|
||||||
options[:template].sub!(/^\//, '')
|
options[:template].sub!(/^\//, '')
|
||||||
|
|
56
actionpack/lib/action_controller/new_base/http.rb
Normal file
56
actionpack/lib/action_controller/new_base/http.rb
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
module ActionController
|
||||||
|
class Http < AbstractController::Base
|
||||||
|
abstract!
|
||||||
|
|
||||||
|
# :api: public
|
||||||
|
attr_internal :request, :response, :params
|
||||||
|
|
||||||
|
# :api: public
|
||||||
|
def self.controller_name
|
||||||
|
@controller_name ||= controller_path.split("/").last
|
||||||
|
end
|
||||||
|
|
||||||
|
# :api: public
|
||||||
|
def controller_name() self.class.controller_name end
|
||||||
|
|
||||||
|
# :api: public
|
||||||
|
def self.controller_path
|
||||||
|
@controller_path ||= self.name.sub(/Controller$/, '').underscore
|
||||||
|
end
|
||||||
|
|
||||||
|
# :api: public
|
||||||
|
def controller_path() self.class.controller_path end
|
||||||
|
|
||||||
|
# :api: private
|
||||||
|
def self.internal_methods
|
||||||
|
ActionController::Http.public_instance_methods(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
# :api: private
|
||||||
|
def self.action_names() action_methods end
|
||||||
|
|
||||||
|
# :api: private
|
||||||
|
def action_names() action_methods end
|
||||||
|
|
||||||
|
# :api: plugin
|
||||||
|
def self.call(env)
|
||||||
|
controller = new
|
||||||
|
controller.call(env).to_rack
|
||||||
|
end
|
||||||
|
|
||||||
|
# :api: private
|
||||||
|
def call(env)
|
||||||
|
@_request = ActionDispatch::Request.new(env)
|
||||||
|
@_response = ActionDispatch::Response.new
|
||||||
|
process(@_request.parameters[:action])
|
||||||
|
@_response.body = response_body
|
||||||
|
@_response.prepare!
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
# :api: private
|
||||||
|
def to_rack
|
||||||
|
@_response.to_a
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -34,8 +34,6 @@ module ActionDispatch
|
||||||
else
|
else
|
||||||
@klass.to_s.constantize
|
@klass.to_s.constantize
|
||||||
end
|
end
|
||||||
rescue NameError
|
|
||||||
@klass
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def active?
|
def active?
|
||||||
|
|
|
@ -7,10 +7,7 @@ require 'test/unit'
|
||||||
require 'active_support/core/all'
|
require 'active_support/core/all'
|
||||||
require 'active_support/test_case'
|
require 'active_support/test_case'
|
||||||
require 'action_controller/abstract'
|
require 'action_controller/abstract'
|
||||||
require 'action_controller/new_base/base'
|
require 'action_view'
|
||||||
require 'action_controller/new_base/renderer'
|
|
||||||
require 'action_controller'
|
|
||||||
require 'action_view/base'
|
|
||||||
require 'fixture_template'
|
require 'fixture_template'
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -19,10 +16,4 @@ begin
|
||||||
Debugger.start
|
Debugger.start
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
# Debugging disabled. `gem install ruby-debug` to enable.
|
# Debugging disabled. `gem install ruby-debug` to enable.
|
||||||
end
|
end
|
||||||
|
|
||||||
# require 'action_controller/abstract/base'
|
|
||||||
# require 'action_controller/abstract/renderer'
|
|
||||||
# require 'action_controller/abstract/layouts'
|
|
||||||
# require 'action_controller/abstract/callbacks'
|
|
||||||
# require 'action_controller/abstract/helpers'
|
|
|
@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||||
|
|
||||||
# Tests the controller dispatching happy path
|
# Tests the controller dispatching happy path
|
||||||
module Dispatching
|
module Dispatching
|
||||||
class SimpleController < ActionController::Base2
|
class SimpleController < ActionController::Base
|
||||||
def index
|
def index
|
||||||
render :text => "success"
|
render :text => "success"
|
||||||
end
|
end
|
||||||
|
@ -69,9 +69,9 @@ module Dispatching
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class EmptyController < ActionController::Base2 ; end
|
class EmptyController < ActionController::Base ; end
|
||||||
module Submodule
|
module Submodule
|
||||||
class ContainedEmptyController < ActionController::Base2 ; end
|
class ContainedEmptyController < ActionController::Base ; end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ControllerClassTests < Test::Unit::TestCase
|
class ControllerClassTests < Test::Unit::TestCase
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||||
|
|
||||||
module ContentType
|
module ContentType
|
||||||
class BaseController < ActionController::Base2
|
class BaseController < ActionController::Base
|
||||||
def index
|
def index
|
||||||
render :text => "Hello world!"
|
render :text => "Hello world!"
|
||||||
end
|
end
|
||||||
|
@ -40,7 +40,7 @@ module ContentType
|
||||||
assert_header "Content-Type", "application/rss+xml; charset=utf-8"
|
assert_header "Content-Type", "application/rss+xml; charset=utf-8"
|
||||||
end
|
end
|
||||||
|
|
||||||
class ImpliedController < ActionController::Base2
|
class ImpliedController < ActionController::Base
|
||||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||||
"content_type/implied/i_am_html_erb.html.erb" => "Hello world!",
|
"content_type/implied/i_am_html_erb.html.erb" => "Hello world!",
|
||||||
"content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>",
|
"content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>",
|
||||||
|
@ -81,7 +81,7 @@ module ContentType
|
||||||
end
|
end
|
||||||
|
|
||||||
module Charset
|
module Charset
|
||||||
class BaseController < ActionController::Base2
|
class BaseController < ActionController::Base
|
||||||
def set_on_response_obj
|
def set_on_response_obj
|
||||||
response.charset = "utf-16"
|
response.charset = "utf-16"
|
||||||
render :text => "Hello world!"
|
render :text => "Hello world!"
|
||||||
|
|
|
@ -3,7 +3,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||||
module RenderAction
|
module RenderAction
|
||||||
|
|
||||||
# This has no layout and it works
|
# This has no layout and it works
|
||||||
class BasicController < ActionController::Base2
|
class BasicController < ActionController::Base
|
||||||
|
|
||||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||||
"render_action/basic/hello_world.html.erb" => "Hello world!"
|
"render_action/basic/hello_world.html.erb" => "Hello world!"
|
||||||
|
@ -203,7 +203,7 @@ end
|
||||||
|
|
||||||
module RenderActionWithControllerLayout
|
module RenderActionWithControllerLayout
|
||||||
|
|
||||||
class BasicController < ActionController::Base2
|
class BasicController < ActionController::Base
|
||||||
self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
|
self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
|
||||||
"render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!",
|
"render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!",
|
||||||
"layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
|
"layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
|
||||||
|
@ -266,7 +266,7 @@ end
|
||||||
|
|
||||||
module RenderActionWithBothLayouts
|
module RenderActionWithBothLayouts
|
||||||
|
|
||||||
class BasicController < ActionController::Base2
|
class BasicController < ActionController::Base
|
||||||
self.view_paths = [ActionView::Template::FixturePath.new({
|
self.view_paths = [ActionView::Template::FixturePath.new({
|
||||||
"render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!",
|
"render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!",
|
||||||
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
|
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||||
|
|
||||||
module RenderTemplate
|
module RenderTemplate
|
||||||
class WithoutLayoutController < ActionController::Base2
|
class WithoutLayoutController < ActionController::Base
|
||||||
|
|
||||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||||
"test/basic.html.erb" => "Hello from basic.html.erb",
|
"test/basic.html.erb" => "Hello from basic.html.erb",
|
||||||
|
@ -129,7 +129,7 @@ module RenderTemplate
|
||||||
end
|
end
|
||||||
|
|
||||||
module Compatibility
|
module Compatibility
|
||||||
class WithoutLayoutController < ActionController::CompatibleBase2
|
class WithoutLayoutController < ActionController::Base
|
||||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||||
"test/basic.html.erb" => "Hello from basic.html.erb",
|
"test/basic.html.erb" => "Hello from basic.html.erb",
|
||||||
"shared.html.erb" => "Elastica"
|
"shared.html.erb" => "Elastica"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||||
|
|
||||||
module Render
|
module Render
|
||||||
class BlankRenderController < ActionController::Base2
|
class BlankRenderController < ActionController::Base
|
||||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||||
"render/blank_render/index.html.erb" => "Hello world!",
|
"render/blank_render/index.html.erb" => "Hello world!",
|
||||||
"render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>",
|
"render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>",
|
||||||
|
@ -36,7 +36,7 @@ module Render
|
||||||
assert_status 200
|
assert_status 200
|
||||||
end
|
end
|
||||||
|
|
||||||
class DoubleRenderController < ActionController::Base2
|
class DoubleRenderController < ActionController::Base
|
||||||
def index
|
def index
|
||||||
render :text => "hello"
|
render :text => "hello"
|
||||||
render :text => "world"
|
render :text => "world"
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base2
|
class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
module RenderText
|
module RenderText
|
||||||
class SimpleController < ActionController::Base2
|
class SimpleController < ActionController::Base
|
||||||
self.view_paths = [ActionView::Template::FixturePath.new]
|
self.view_paths = [ActionView::Template::FixturePath.new]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -146,4 +146,4 @@ module RenderText
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ActionController::Base2.app_loaded!
|
ActionController::Base.app_loaded!
|
|
@ -5,10 +5,7 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'active_support'
|
require 'active_support'
|
||||||
require 'active_support/test_case'
|
require 'active_support/test_case'
|
||||||
require 'action_controller/new_base/base'
|
require 'action_view'
|
||||||
require 'action_controller/new_base/renderer'
|
|
||||||
require 'action_controller'
|
|
||||||
require 'action_view/base'
|
|
||||||
require 'fixture_template'
|
require 'fixture_template'
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -34,67 +31,6 @@ module Rails
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module ActionController
|
|
||||||
class Base2 < Http
|
|
||||||
abstract!
|
|
||||||
|
|
||||||
use AbstractController::Callbacks
|
|
||||||
use AbstractController::Helpers
|
|
||||||
use AbstractController::Logger
|
|
||||||
|
|
||||||
use ActionController::HideActions
|
|
||||||
use ActionController::UrlFor
|
|
||||||
use ActionController::Renderer
|
|
||||||
use ActionController::Layouts
|
|
||||||
|
|
||||||
def self.inherited(klass)
|
|
||||||
::ActionController::Base2.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 render(action = action_name, options = {})
|
|
||||||
if action.is_a?(Hash)
|
|
||||||
options, action = action, nil
|
|
||||||
else
|
|
||||||
options.merge! :action => action
|
|
||||||
end
|
|
||||||
|
|
||||||
super(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_to_body(options = {})
|
|
||||||
options = {:template => options} if options.is_a?(String)
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def process_action
|
|
||||||
ret = super
|
|
||||||
render if response_body.nil?
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
def respond_to_action?(action_name)
|
|
||||||
super || view_paths.find_by_parts?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class CompatibleBase2 < Base2
|
|
||||||
abstract!
|
|
||||||
|
|
||||||
use ActionController::Rails2Compatibility
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Temporary base class
|
# Temporary base class
|
||||||
class Rack::TestCase < ActiveSupport::TestCase
|
class Rack::TestCase < ActiveSupport::TestCase
|
||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
|
@ -103,7 +39,7 @@ class Rack::TestCase < ActiveSupport::TestCase
|
||||||
ActionController::Base.session_options[:key] = "abc"
|
ActionController::Base.session_options[:key] = "abc"
|
||||||
ActionController::Base.session_options[:secret] = ("*" * 30)
|
ActionController::Base.session_options[:secret] = ("*" * 30)
|
||||||
|
|
||||||
controllers = ActionController::Base2.subclasses.map do |k|
|
controllers = ActionController::Base.subclasses.map do |k|
|
||||||
k.underscore.sub(/_controller$/, '')
|
k.underscore.sub(/_controller$/, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -171,7 +107,7 @@ class Rack::TestCase < ActiveSupport::TestCase
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class ::ApplicationController < ActionController::Base2
|
class ::ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
class SimpleRouteCase < Rack::TestCase
|
class SimpleRouteCase < Rack::TestCase
|
||||||
|
|
Loading…
Reference in a new issue