Permalink
Browse files

Renamed Base2 to Base and don't require old action_controller for new…

… Base
  • Loading branch information...
1 parent b1d34b3 commit e046f36824fcc164c284a13524c6b4153010a4e1 Yehuda Katz + Carl Lerche committed May 2, 2009
@@ -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
-
- # :api: public
- def self.controller_name
- @controller_name ||= controller_path.split("/").last
- end
+ use AbstractController::Callbacks
+ use AbstractController::Helpers
+ use AbstractController::Logger
- # :api: public
- def controller_name() self.class.controller_name end
-
- # :api: public
- def self.controller_path
- @controller_path ||= self.name.sub(/Controller$/, '').underscore
- end
+ use ActionController::HideActions
+ use ActionController::UrlFor
+ use ActionController::Renderer
+ use ActionController::Layouts
+
+ # Legacy modules
+ include SessionManagement
- # :api: public
- def controller_path() self.class.controller_path end
+ # Rails 2.x compatibility
+ use ActionController::Rails2Compatibility
- # :api: private
- def self.internal_methods
- ActionController::Http.public_instance_methods(true)
+ def self.inherited(klass)
+ ::ActionController::Base.subclasses << klass.to_s
+ super
end
- # :api: private
- def self.action_names() action_methods end
+ def self.subclasses
+ @subclasses ||= []
+ end
- # :api: private
- def action_names() action_methods end
+ def self.app_loaded!
+ @subclasses.each do |subclass|
+ subclass.constantize._write_layout_method
+ end
+ end
- # :api: plugin
- def self.call(env)
- controller = new
- controller.call(env).to_rack
+ 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 call(env)
- @_request = ActionDispatch::Request.new(env)
- @_response = ActionDispatch::Response.new
- process(@_request.parameters[:action])
- @_response.body = response_body
- @_response.prepare!
- self
+ def render_to_body(options = {})
+ options = {:template => options} if options.is_a?(String)
+ super
end
- # :api: private
- def to_rack
- @_response.to_a
+ 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!(/^\//, '')
@@ -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 @@ def klass
else
@klass.to_s.constantize
end
- rescue NameError
- @klass
end
def active?
@@ -7,10 +7,7 @@
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 @@
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 @@
# 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 @@ class TestDirectResponseModTwice < SimpleRouteCase
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 @@ class TestSetOnRender < SimpleRouteCase
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 @@ class TestImpliedController < SimpleRouteCase
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 @@
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 @@ class TestCustomLayout < SimpleRouteCase
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 @@ class TestLayoutNil < SimpleRouteCase
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 @@ class TestTemplateRenderWithCustomLayout < SimpleRouteCase
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 @@ class TestBlankRender < SimpleRouteCase
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 @@ class TestTextRenderWithLayoutNil < SimpleRouteCase
end
end
-ActionController::Base2.app_loaded!
+ActionController::Base.app_loaded!
Oops, something went wrong.

0 comments on commit e046f36

Please sign in to comment.