Skip to content

Commit

Permalink
Merge commit 'rails/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
miloops committed Aug 7, 2009
2 parents 945ef58 + bfe58ac commit 04abe53
Show file tree
Hide file tree
Showing 53 changed files with 241 additions and 406 deletions.
4 changes: 2 additions & 2 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def render_template(template, body)
@template = initialize_template_class(body)
layout = _pick_layout(layout, true) unless
ActionController::Base.exempt_from_layout.include?(template.handler)
@template._render_template_with_layout(template, layout, {})
@template._render_template(template, layout, {})
ensure
@current_template_content_type = nil
end
Expand All @@ -592,7 +592,7 @@ def render(opts)
!template || ActionController::Base.exempt_from_layout.include?(template.handler))

if template
@template._render_template_with_layout(template, layout, opts)
@template._render_template(template, layout, opts)
elsif inline = opts[:inline]
@template._render_inline(inline, layout, opts)
end
Expand Down
10 changes: 6 additions & 4 deletions actionmailer/test/mail_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,14 @@ def initialize
@info_contents, @debug_contents = "", ""
end

def info(str)
@info_contents << str
def info(str = nil, &blk)
@info_contents << str if str
@info_contents << blk.call if block_given?
end

def debug(str)
@debug_contents << str
def debug(str = nil, &blk)
@debug_contents << str if str
@debug_contents << blk.call if block_given?
end
end

Expand Down
8 changes: 3 additions & 5 deletions actionpack/examples/minimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ def index
OK = [200, {}, []]
MetalPostController = lambda { OK }

if ActionController.const_defined?(:Http)
class HttpPostController < ActionController::Http
def index
self.response_body = ''
end
class HttpPostController < ActionController::Metal
def index
self.response_body = ''
end
end

Expand Down
6 changes: 3 additions & 3 deletions actionpack/examples/very_simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require "action_controller"

class Kaigi < ActionController::Http
class Kaigi < ActionController::Metal
include AbstractController::Callbacks
include ActionController::RackConvenience
include ActionController::Renderer
Expand All @@ -13,7 +13,7 @@ class Kaigi < ActionController::Http
before_filter :set_name
append_view_path "views"

def _action_view
def view_context
self
end

Expand All @@ -23,7 +23,7 @@ def controller

DEFAULT_LAYOUT = Object.new.tap {|l| def l.render(*) yield end }

def _render_template_from_controller(template, layout = DEFAULT_LAYOUT, options = {}, partial = false)
def render_template(template, layout = DEFAULT_LAYOUT, options = {}, partial = false)
ret = template.render(self, {})
layout.render(self, {}) { ret }
end
Expand Down
16 changes: 16 additions & 0 deletions actionpack/lib/abstract_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "active_support/core_ext/module/attr_internal"
require "active_support/core_ext/module/delegation"

module AbstractController
autoload :Base, "abstract_controller/base"
autoload :Benchmarker, "abstract_controller/benchmarker"
autoload :Callbacks, "abstract_controller/callbacks"
autoload :Helpers, "abstract_controller/helpers"
autoload :Layouts, "abstract_controller/layouts"
autoload :Logger, "abstract_controller/logger"
autoload :Renderer, "abstract_controller/renderer"
# === Exceptions
autoload :ActionNotFound, "abstract_controller/exceptions"
autoload :DoubleRenderError, "abstract_controller/exceptions"
autoload :Error, "abstract_controller/exceptions"
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def descendants
# instance methods on that abstract class. Public instance methods of
# a controller would normally be considered action methods, so we
# are removing those methods on classes declared as abstract
# (ActionController::Http and ActionController::Base are defined
# (ActionController::Metal and ActionController::Base are defined
# as abstract)
def internal_methods
controller = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ def _layout(details)
end
end

def render_to_body(options = {})
response = super

if options.key?(:partial)
# This is a little bit messy. We need to explicitly handle partial
# layouts here since the core lookup logic is in the view, but
# we need to determine the layout based on the controller
if options.key?(:layout)
layout = _layout_for_option(options[:layout], options[:_template].details)
response = layout.render(view_context, options[:locals]) { response }
end
end

response
end

private
# This will be overwritten by _write_layout_method
def _layout(details) end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "action_controller/abstract/logger"
require "abstract_controller/logger"

module AbstractController
module Renderer
Expand All @@ -19,20 +19,20 @@ module Renderer
# The view class must have the following methods:
# View.for_controller[controller] Create a new ActionView instance for a
# controller
# View#_render_partial_from_controller[options]
# View#render_partial[options]
# - responsible for setting options[:_template]
# - Returns String with the rendered partial
# options<Hash>:: see _render_partial in ActionView::Base
# View#_render_template_from_controller[template, layout, options, partial]
# View#render_template[template, layout, options, partial]
# - Returns String with the rendered template
# template<ActionView::Template>:: The template to render
# layout<ActionView::Template>:: The layout to render around the template
# options<Hash>:: See _render_template_with_layout in ActionView::Base
# partial<Boolean>:: Whether or not the template to render is a partial
#
# Override this method in a to change the default behavior.
def _action_view
@_action_view ||= ActionView::Base.for_controller(self)
def view_context
@_view_context ||= ActionView::Base.for_controller(self)
end

# Mostly abstracts the fact that calling render twice is a DoubleRenderError.
Expand All @@ -54,8 +54,8 @@ def render(*args)
# :api: plugin
def render_to_body(options = {})
# TODO: Refactor so we can just use the normal template logic for this
if options[:_partial_object]
_action_view._render_partial_from_controller(options)
if options.key?(:partial)
view_context.render_partial(options)
else
_determine_template(options)
_render_template(options)
Expand All @@ -77,7 +77,7 @@ def render_to_string(options = {})
# _layout<ActionView::Template>:: The layout to wrap the template in (optional)
# _partial<TrueClass, FalseClass>:: Whether or not the template to be rendered is a partial
def _render_template(options)
_action_view._render_template_from_controller(options[:_template], options[:_layout], options, options[:_partial])
view_context.render_template(options)
end

# The list of view paths for this controller. See ActionView::ViewPathSet for
Expand Down
74 changes: 37 additions & 37 deletions actionpack/lib/action_controller.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
module ActionController
autoload :Base, "action_controller/base/base"
autoload :ConditionalGet, "action_controller/base/conditional_get"
autoload :HideActions, "action_controller/base/hide_actions"
autoload :Http, "action_controller/base/http"
autoload :Layouts, "action_controller/base/layouts"
autoload :RackConvenience, "action_controller/base/rack_convenience"
autoload :Rails2Compatibility, "action_controller/base/compatibility"
autoload :Redirector, "action_controller/base/redirector"
autoload :Renderer, "action_controller/base/renderer"
autoload :RenderOptions, "action_controller/base/render_options"
autoload :Renderers, "action_controller/base/render_options"
autoload :Rescue, "action_controller/base/rescuable"
autoload :Testing, "action_controller/base/testing"
autoload :UrlFor, "action_controller/base/url_for"
autoload :Session, "action_controller/base/session"
autoload :Helpers, "action_controller/base/helpers"
autoload :Base, "action_controller/base"
autoload :ConditionalGet, "action_controller/metal/conditional_get"
autoload :HideActions, "action_controller/metal/hide_actions"
autoload :Metal, "action_controller/metal"
autoload :Layouts, "action_controller/metal/layouts"
autoload :RackConvenience, "action_controller/metal/rack_convenience"
autoload :Rails2Compatibility, "action_controller/metal/compatibility"
autoload :Redirector, "action_controller/metal/redirector"
autoload :Renderer, "action_controller/metal/renderer"
autoload :RenderOptions, "action_controller/metal/render_options"
autoload :Renderers, "action_controller/metal/render_options"
autoload :Rescue, "action_controller/metal/rescuable"
autoload :Testing, "action_controller/metal/testing"
autoload :UrlFor, "action_controller/metal/url_for"
autoload :Session, "action_controller/metal/session"
autoload :Helpers, "action_controller/metal/helpers"

# Ported modules
# require 'action_controller/routing'
autoload :Caching, 'action_controller/caching'
autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
autoload :Integration, 'action_controller/testing/integration'
autoload :MimeResponds, 'action_controller/base/mime_responds'
autoload :MimeResponds, 'action_controller/metal/mime_responds'
autoload :PolymorphicRoutes, 'action_controller/routing/generation/polymorphic_routes'
autoload :RecordIdentifier, 'action_controller/record_identifier'
autoload :Resources, 'action_controller/routing/resources'
autoload :SessionManagement, 'action_controller/base/session_management'
autoload :SessionManagement, 'action_controller/metal/session_management'
autoload :TestCase, 'action_controller/testing/test_case'
autoload :TestProcess, 'action_controller/testing/process'
autoload :UrlRewriter, 'action_controller/routing/generation/url_rewriter'
autoload :UrlWriter, 'action_controller/routing/generation/url_rewriter'

autoload :Verification, 'action_controller/base/verification'
autoload :Flash, 'action_controller/base/flash'
autoload :RequestForgeryProtection, 'action_controller/base/request_forgery_protection'
autoload :Streaming, 'action_controller/base/streaming'
autoload :HttpAuthentication, 'action_controller/base/http_authentication'
autoload :FilterParameterLogging, 'action_controller/base/filter_parameter_logging'
autoload :Verification, 'action_controller/metal/verification'
autoload :Flash, 'action_controller/metal/flash'
autoload :RequestForgeryProtection, 'action_controller/metal/request_forgery_protection'
autoload :Streaming, 'action_controller/metal/streaming'
autoload :HttpAuthentication, 'action_controller/metal/http_authentication'
autoload :FilterParameterLogging, 'action_controller/metal/filter_parameter_logging'
autoload :Translation, 'action_controller/translation'
autoload :Cookies, 'action_controller/base/cookies'
autoload :Cookies, 'action_controller/metal/cookies'

autoload :ActionControllerError, 'action_controller/base/exceptions'
autoload :SessionRestoreError, 'action_controller/base/exceptions'
autoload :RenderError, 'action_controller/base/exceptions'
autoload :RoutingError, 'action_controller/base/exceptions'
autoload :MethodNotAllowed, 'action_controller/base/exceptions'
autoload :NotImplemented, 'action_controller/base/exceptions'
autoload :UnknownController, 'action_controller/base/exceptions'
autoload :MissingFile, 'action_controller/base/exceptions'
autoload :RenderError, 'action_controller/base/exceptions'
autoload :SessionOverflowError, 'action_controller/base/exceptions'
autoload :UnknownHttpMethod, 'action_controller/base/exceptions'
autoload :ActionControllerError, 'action_controller/metal/exceptions'
autoload :SessionRestoreError, 'action_controller/metal/exceptions'
autoload :RenderError, 'action_controller/metal/exceptions'
autoload :RoutingError, 'action_controller/metal/exceptions'
autoload :MethodNotAllowed, 'action_controller/metal/exceptions'
autoload :NotImplemented, 'action_controller/metal/exceptions'
autoload :UnknownController, 'action_controller/metal/exceptions'
autoload :MissingFile, 'action_controller/metal/exceptions'
autoload :RenderError, 'action_controller/metal/exceptions'
autoload :SessionOverflowError, 'action_controller/metal/exceptions'
autoload :UnknownHttpMethod, 'action_controller/metal/exceptions'

autoload :Routing, 'action_controller/routing'
end

autoload :HTML, 'action_controller/vendor/html-scanner'
autoload :AbstractController, 'action_controller/abstract'
autoload :AbstractController, 'abstract_controller'

autoload :Rack, 'action_dispatch'
autoload :ActionDispatch, 'action_dispatch'
Expand Down
16 changes: 0 additions & 16 deletions actionpack/lib/action_controller/abstract.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActionController
class Base < Http
class Base < Metal
abstract!

include AbstractController::Benchmarker
Expand Down
3 changes: 1 addition & 2 deletions actionpack/lib/action_controller/caching/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def cache_layout?
end

def content_for_layout(controller)
# TODO: Remove this when new base is merged in
template = controller.respond_to?(:template) ? controller.template : controller._action_view
template = controller.view_context
template.layout && template.instance_variable_get('@cached_content_for_layout')
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
require 'action_controller/abstract'

module ActionController
# ActionController::Http provides a way to get a valid Rack application from a controller.
# ActionController::Metal 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
# ActionController::Metal 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
class Metal < AbstractController::Base
abstract!

# :api: public
Expand Down Expand Up @@ -72,11 +70,11 @@ def location=(url)
def call(name, env)
@_env = env
process(name)
to_rack
to_a
end

# :api: private
def to_rack
def to_a
[status, headers, response_body]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def assign_shortcuts(*) end

# TODO: Remove this after we flip
def template
@template ||= _action_view
@template ||= view_context
end

def process_action(*)
Expand Down Expand Up @@ -141,7 +141,7 @@ def prepend_view_path(path)
end

def view_paths
_action_view.view_paths
view_context.view_paths
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def params
end

# :api: private
def to_rack
def to_a
@_response.prepare!
@_response.to_a
end
Expand Down
Loading

0 comments on commit 04abe53

Please sign in to comment.