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
|
||||
autoload :Base, "action_controller/new_base/base"
|
||||
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 :Rails2Compatibility, "action_controller/new_base/compatibility"
|
||||
autoload :Renderer, "action_controller/new_base/renderer"
|
||||
autoload :Testing, "action_controller/new_base/testing"
|
||||
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
|
||||
class Http < AbstractController::Base
|
||||
class Base < Http
|
||||
abstract!
|
||||
|
||||
# :api: public
|
||||
attr_internal :request, :response, :params
|
||||
use AbstractController::Callbacks
|
||||
use AbstractController::Helpers
|
||||
use AbstractController::Logger
|
||||
|
||||
# :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
|
||||
use ActionController::HideActions
|
||||
use ActionController::UrlFor
|
||||
use ActionController::Renderer
|
||||
use ActionController::Layouts
|
||||
|
||||
# Legacy modules
|
||||
include SessionManagement
|
||||
|
||||
# Rails 2.x compatibility
|
||||
use ActionController::Rails2Compatibility
|
||||
|
||||
def self.inherited(klass)
|
||||
::ActionController::Base.subclasses << klass.to_s
|
||||
super
|
||||
end
|
||||
|
||||
# :api: public
|
||||
def controller_path() self.class.controller_path end
|
||||
|
||||
# :api: private
|
||||
def self.internal_methods
|
||||
ActionController::Http.public_instance_methods(true)
|
||||
def self.subclasses
|
||||
@subclasses ||= []
|
||||
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
|
||||
def self.app_loaded!
|
||||
@subclasses.each do |subclass|
|
||||
subclass.constantize._write_layout_method
|
||||
end
|
||||
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
|
||||
def render(action = action_name, options = {})
|
||||
if action.is_a?(Hash)
|
||||
options, action = action, nil
|
||||
else
|
||||
options.merge! :action => action
|
||||
end
|
||||
|
||||
super(options)
|
||||
end
|
||||
|
||||
# :api: private
|
||||
def to_rack
|
||||
@_response.to_a
|
||||
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 Base < Http
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,27 @@
|
|||
module ActionController
|
||||
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)
|
||||
if options.is_a?(Hash) && options.key?(:template)
|
||||
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
|
||||
@klass.to_s.constantize
|
||||
end
|
||||
rescue NameError
|
||||
@klass
|
||||
end
|
||||
|
||||
def active?
|
||||
|
|
|
@ -7,10 +7,7 @@ require 'test/unit'
|
|||
require 'active_support/core/all'
|
||||
require 'active_support/test_case'
|
||||
require 'action_controller/abstract'
|
||||
require 'action_controller/new_base/base'
|
||||
require 'action_controller/new_base/renderer'
|
||||
require 'action_controller'
|
||||
require 'action_view/base'
|
||||
require 'action_view'
|
||||
require 'fixture_template'
|
||||
|
||||
begin
|
||||
|
@ -19,10 +16,4 @@ begin
|
|||
Debugger.start
|
||||
rescue LoadError
|
||||
# Debugging disabled. `gem install ruby-debug` to enable.
|
||||
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'
|
||||
end
|
|
@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
|||
|
||||
# Tests the controller dispatching happy path
|
||||
module Dispatching
|
||||
class SimpleController < ActionController::Base2
|
||||
class SimpleController < ActionController::Base
|
||||
def index
|
||||
render :text => "success"
|
||||
end
|
||||
|
@ -69,9 +69,9 @@ module Dispatching
|
|||
end
|
||||
end
|
||||
|
||||
class EmptyController < ActionController::Base2 ; end
|
||||
class EmptyController < ActionController::Base ; end
|
||||
module Submodule
|
||||
class ContainedEmptyController < ActionController::Base2 ; end
|
||||
class ContainedEmptyController < ActionController::Base ; end
|
||||
end
|
||||
|
||||
class ControllerClassTests < Test::Unit::TestCase
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||
|
||||
module ContentType
|
||||
class BaseController < ActionController::Base2
|
||||
class BaseController < ActionController::Base
|
||||
def index
|
||||
render :text => "Hello world!"
|
||||
end
|
||||
|
@ -40,7 +40,7 @@ module ContentType
|
|||
assert_header "Content-Type", "application/rss+xml; charset=utf-8"
|
||||
end
|
||||
|
||||
class ImpliedController < ActionController::Base2
|
||||
class ImpliedController < ActionController::Base
|
||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||
"content_type/implied/i_am_html_erb.html.erb" => "Hello world!",
|
||||
"content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>",
|
||||
|
@ -81,7 +81,7 @@ module ContentType
|
|||
end
|
||||
|
||||
module Charset
|
||||
class BaseController < ActionController::Base2
|
||||
class BaseController < ActionController::Base
|
||||
def set_on_response_obj
|
||||
response.charset = "utf-16"
|
||||
render :text => "Hello world!"
|
||||
|
|
|
@ -3,7 +3,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
|||
module RenderAction
|
||||
|
||||
# This has no layout and it works
|
||||
class BasicController < ActionController::Base2
|
||||
class BasicController < ActionController::Base
|
||||
|
||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||
"render_action/basic/hello_world.html.erb" => "Hello world!"
|
||||
|
@ -203,7 +203,7 @@ end
|
|||
|
||||
module RenderActionWithControllerLayout
|
||||
|
||||
class BasicController < ActionController::Base2
|
||||
class BasicController < ActionController::Base
|
||||
self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
|
||||
"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"
|
||||
|
@ -266,7 +266,7 @@ end
|
|||
|
||||
module RenderActionWithBothLayouts
|
||||
|
||||
class BasicController < ActionController::Base2
|
||||
class BasicController < ActionController::Base
|
||||
self.view_paths = [ActionView::Template::FixturePath.new({
|
||||
"render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!",
|
||||
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||
|
||||
module RenderTemplate
|
||||
class WithoutLayoutController < ActionController::Base2
|
||||
class WithoutLayoutController < ActionController::Base
|
||||
|
||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||
"test/basic.html.erb" => "Hello from basic.html.erb",
|
||||
|
@ -129,7 +129,7 @@ module RenderTemplate
|
|||
end
|
||||
|
||||
module Compatibility
|
||||
class WithoutLayoutController < ActionController::CompatibleBase2
|
||||
class WithoutLayoutController < ActionController::Base
|
||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||
"test/basic.html.erb" => "Hello from basic.html.erb",
|
||||
"shared.html.erb" => "Elastica"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||
|
||||
module Render
|
||||
class BlankRenderController < ActionController::Base2
|
||||
class BlankRenderController < ActionController::Base
|
||||
self.view_paths = [ActionView::Template::FixturePath.new(
|
||||
"render/blank_render/index.html.erb" => "Hello world!",
|
||||
"render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>",
|
||||
|
@ -36,7 +36,7 @@ module Render
|
|||
assert_status 200
|
||||
end
|
||||
|
||||
class DoubleRenderController < ActionController::Base2
|
||||
class DoubleRenderController < ActionController::Base
|
||||
def index
|
||||
render :text => "hello"
|
||||
render :text => "world"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
||||
|
||||
class ApplicationController < ActionController::Base2
|
||||
class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
module RenderText
|
||||
class SimpleController < ActionController::Base2
|
||||
class SimpleController < ActionController::Base
|
||||
self.view_paths = [ActionView::Template::FixturePath.new]
|
||||
|
||||
def index
|
||||
|
@ -146,4 +146,4 @@ module RenderText
|
|||
end
|
||||
end
|
||||
|
||||
ActionController::Base2.app_loaded!
|
||||
ActionController::Base.app_loaded!
|
|
@ -5,10 +5,7 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|||
require 'test/unit'
|
||||
require 'active_support'
|
||||
require 'active_support/test_case'
|
||||
require 'action_controller/new_base/base'
|
||||
require 'action_controller/new_base/renderer'
|
||||
require 'action_controller'
|
||||
require 'action_view/base'
|
||||
require 'action_view'
|
||||
require 'fixture_template'
|
||||
|
||||
begin
|
||||
|
@ -34,67 +31,6 @@ module Rails
|
|||
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
|
||||
class Rack::TestCase < ActiveSupport::TestCase
|
||||
include Rack::Test::Methods
|
||||
|
@ -103,7 +39,7 @@ class Rack::TestCase < ActiveSupport::TestCase
|
|||
ActionController::Base.session_options[:key] = "abc"
|
||||
ActionController::Base.session_options[:secret] = ("*" * 30)
|
||||
|
||||
controllers = ActionController::Base2.subclasses.map do |k|
|
||||
controllers = ActionController::Base.subclasses.map do |k|
|
||||
k.underscore.sub(/_controller$/, '')
|
||||
end
|
||||
|
||||
|
@ -171,7 +107,7 @@ class Rack::TestCase < ActiveSupport::TestCase
|
|||
|
||||
end
|
||||
|
||||
class ::ApplicationController < ActionController::Base2
|
||||
class ::ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
class SimpleRouteCase < Rack::TestCase
|
||||
|
|
Loading…
Reference in a new issue