Create AbstractController::Rendering interface
This interface should be use when implementing renderers.
This commit is contained in:
parent
c90971644a
commit
8e3413d410
@ -13,6 +13,7 @@ module AbstractController
|
||||
autoload :DoubleRenderError, "abstract_controller/rendering.rb"
|
||||
autoload :Helpers
|
||||
autoload :Logger
|
||||
autoload :Rendering
|
||||
autoload :Translation
|
||||
autoload :AssetPaths
|
||||
autoload :UrlFor
|
||||
|
@ -6,4 +6,54 @@ def initialize(message = nil)
|
||||
super(message || DEFAULT_MESSAGE)
|
||||
end
|
||||
end
|
||||
|
||||
module Rendering
|
||||
# Raw rendering of a template to a string.
|
||||
#
|
||||
# It is similar to render, except that it does not
|
||||
# set the response_body and it should be guaranteed
|
||||
# to always return a string.
|
||||
#
|
||||
# If a component extends the semantics of response_body
|
||||
# (as Action Controller extends it to be anything that
|
||||
# responds to the method each), this method needs to be
|
||||
# overridden in order to still return a string.
|
||||
# :api: plugin
|
||||
def render_to_string(*args, &block)
|
||||
end
|
||||
|
||||
# Raw rendering of a template.
|
||||
# :api: plugin
|
||||
def render_to_body(options = {})
|
||||
end
|
||||
|
||||
def render(*args, &block)
|
||||
end
|
||||
|
||||
# This method should return a hash with assigns.
|
||||
# You can overwrite this configuration per controller.
|
||||
# :api: public
|
||||
def view_assigns
|
||||
{}
|
||||
end
|
||||
|
||||
# Normalize args by converting render "foo" to render :action => "foo" and
|
||||
# render "foo/bar" to render :file => "foo/bar".
|
||||
# :api: plugin
|
||||
def _normalize_args(action=nil, options={})
|
||||
options
|
||||
end
|
||||
|
||||
# Normalize options.
|
||||
# :api: plugin
|
||||
def _normalize_options(options)
|
||||
options
|
||||
end
|
||||
|
||||
# Process extra options.
|
||||
# :api: plugin
|
||||
def _process_options(options)
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -161,7 +161,11 @@ module ActionController
|
||||
# render action: "overthere" # won't be called if monkeys is nil
|
||||
# end
|
||||
#
|
||||
class Base < Metal
|
||||
metal = Class.new(Metal) do
|
||||
include AbstractController::Rendering
|
||||
end
|
||||
|
||||
class Base < metal
|
||||
abstract!
|
||||
|
||||
# We document the request and response methods here because albeit they are
|
||||
|
@ -29,6 +29,7 @@ class TestBasic < ActiveSupport::TestCase
|
||||
# Test Render mixin
|
||||
# ====
|
||||
class RenderingController < AbstractController::Base
|
||||
include AbstractController::Rendering
|
||||
include ActionView::Rendering
|
||||
|
||||
def _prefixes
|
||||
|
@ -6,8 +6,9 @@ module AbstractController
|
||||
module Testing
|
||||
|
||||
class ControllerWithHelpers < AbstractController::Base
|
||||
include ActionView::Rendering
|
||||
include AbstractController::Helpers
|
||||
include AbstractController::Rendering
|
||||
include ActionView::Rendering
|
||||
|
||||
def with_module
|
||||
render :inline => "Module <%= included_method %>"
|
||||
|
@ -5,6 +5,7 @@ module Layouts
|
||||
|
||||
# Base controller for these tests
|
||||
class Base < AbstractController::Base
|
||||
include AbstractController::Rendering
|
||||
include ActionView::Rendering
|
||||
include ActionView::Layouts
|
||||
|
||||
|
@ -4,6 +4,7 @@ module AbstractController
|
||||
module Testing
|
||||
|
||||
class ControllerRenderer < AbstractController::Base
|
||||
include AbstractController::Rendering
|
||||
include ActionView::Rendering
|
||||
|
||||
def _prefixes
|
||||
|
@ -271,7 +271,6 @@ def assert_header(name, value)
|
||||
module ActionController
|
||||
class Base
|
||||
include ActionController::Testing
|
||||
include ActionView::Layouts
|
||||
# This stub emulates the Railtie including the URL helpers from a Rails application
|
||||
include SharedTestRoutes.url_helpers
|
||||
include SharedTestRoutes.mounted_helpers
|
||||
@ -291,6 +290,7 @@ class TestCase
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class ::ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
|
@ -337,6 +337,7 @@ def test_using_resource_for_put_with_html_rerender_on_failure
|
||||
errors = { :name => :invalid }
|
||||
Customer.any_instance.stubs(:errors).returns(errors)
|
||||
put :using_resource
|
||||
|
||||
assert_equal "text/html", @response.content_type
|
||||
assert_equal 200, @response.status
|
||||
assert_equal "Edit world!\n", @response.body
|
||||
|
@ -755,6 +755,8 @@ def determine_layout
|
||||
end
|
||||
|
||||
class MetalTestController < ActionController::Metal
|
||||
include AbstractController::Rendering
|
||||
include ActionView::Rendering
|
||||
include ActionController::Rendering
|
||||
|
||||
def accessing_logger_in_template
|
||||
|
@ -83,21 +83,11 @@ def view_renderer
|
||||
# Normalize arguments, options and then delegates render_to_body and
|
||||
# sticks the result in self.response_body.
|
||||
def render(*args, &block)
|
||||
super
|
||||
options = _normalize_render(*args, &block)
|
||||
self.response_body = render_to_body(options)
|
||||
end
|
||||
|
||||
# Raw rendering of a template to a string.
|
||||
#
|
||||
# It is similar to render, except that it does not
|
||||
# set the response_body and it should be guaranteed
|
||||
# to always return a string.
|
||||
#
|
||||
# If a component extends the semantics of response_body
|
||||
# (as Action Controller extends it to be anything that
|
||||
# responds to the method each), this method needs to be
|
||||
# overridden in order to still return a string.
|
||||
# :api: plugin
|
||||
def render_to_string(*args, &block)
|
||||
options = _normalize_render(*args, &block)
|
||||
render_to_body(options)
|
||||
@ -126,7 +116,7 @@ def _render_template(options) #:nodoc:
|
||||
# You can overwrite this configuration per controller.
|
||||
# :api: public
|
||||
def view_assigns
|
||||
hash = {}
|
||||
hash = super
|
||||
variables = instance_variables
|
||||
variables -= protected_instance_variables
|
||||
variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
|
||||
@ -148,6 +138,7 @@ def _normalize_render(*args, &block)
|
||||
# render "foo/bar" to render :file => "foo/bar".
|
||||
# :api: plugin
|
||||
def _normalize_args(action=nil, options={})
|
||||
options = super(action, options)
|
||||
case action
|
||||
when NilClass
|
||||
when Hash
|
||||
@ -166,6 +157,7 @@ def _normalize_args(action=nil, options={})
|
||||
# Normalize options.
|
||||
# :api: plugin
|
||||
def _normalize_options(options)
|
||||
options = super(options)
|
||||
if options[:partial] == true
|
||||
options[:partial] = action_name
|
||||
end
|
||||
@ -177,10 +169,5 @@ def _normalize_options(options)
|
||||
options[:template] ||= (options[:action] || action_name).to_s
|
||||
options
|
||||
end
|
||||
|
||||
# Process extra options.
|
||||
# :api: plugin
|
||||
def _process_options(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user