aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG.md5
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb43
-rw-r--r--actionpack/lib/action_controller/base.rb3
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb8
-rw-r--r--actionview/lib/action_view/rendering.rb12
5 files changed, 24 insertions, 47 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 8b78e0f801..b11154b352 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,8 +1,3 @@
-* Introduce `BasicRendering` which is the most basic rendering implementation. It
- allows to `render :text` and `render :nothing` without depending on Action View.
-
- *Łukasz Strzałkowski*
-
* Separate Action View completely from Action Pack.
*Łukasz Strzałkowski*
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 4596aad46c..575b9807d0 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -10,6 +10,14 @@ module AbstractController
end
end
+ class UnsupportedOperationError < Error
+ DEFAULT_MESSAGE = "Unsupported render operation. BasicRendering supports only :text and :nothing options. For more, you need to include ActionView."
+
+ def initialize
+ super DEFAULT_MESSAGE
+ end
+ end
+
module Rendering
extend ActiveSupport::Concern
@@ -22,6 +30,8 @@ module AbstractController
# sticks the result in self.response_body.
# :api: public
def render(*args, &block)
+ options = _normalize_render(*args, &block)
+ self.response_body = render_to_body(options)
end
# Raw rendering of a template to a string.
@@ -40,11 +50,10 @@ module AbstractController
render_to_body(options)
end
- # Raw rendering of a template.
+ # Performs the actual template rendering.
# :api: public
def render_to_body(options = {})
- _process_options(options)
- _render_template(options)
+ raise UnsupportedOperationError
end
# Return Content-Type of rendered content
@@ -97,32 +106,4 @@ module AbstractController
options
end
end
-
- # Basic rendering implements the most minimal rendering layer.
- # It only supports rendering :text and :nothing. Passing any other option will
- # result in `UnsupportedOperationError` exception. For more functionality like
- # different formats, layouts etc. you should use `ActionView` gem.
- module BasicRendering
- extend ActiveSupport::Concern
-
- # Render text or nothing (empty string) to response_body
- # :api: public
- def render(*args, &block)
- super(*args, &block)
- opts = args.first
- if opts.has_key?(:text) && opts[:text].present?
- self.response_body = opts[:text]
- elsif opts.has_key?(:nothing) && opts[:nothing]
- self.response_body = " "
- else
- raise UnsupportedOperationError
- end
- end
-
- class UnsupportedOperationError < StandardError
- def initialize
- super "Unsupported render operation. BasicRendering supports only :text and :nothing options. For more, you need to include ActionView."
- end
- end
- end
end
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index df416908f0..4b2c00c86a 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -3,7 +3,7 @@ require "action_controller/metal/params_wrapper"
module ActionController
# The <tt>metal</tt> anonymous class was introduced to solve issue with including modules in <tt>ActionController::Base</tt>.
- # Modules needes to be included in particluar order. First wee need to have <tt>AbstractController::Rendering</tt> included,
+ # Modules needes to be included in particluar order. First we need to have <tt>AbstractController::Rendering</tt> included,
# next we should include actuall implementation which would be for example <tt>ActionView::Rendering</tt> and after that
# <tt>ActionController::Rendering</tt>. This order must be preserved and as we want to have middle module included dynamicaly
# <tt>metal</tt> class was introduced. It has <tt>AbstractController::Rendering</tt> included and is parent class of
@@ -14,7 +14,6 @@ module ActionController
#
metal = Class.new(Metal) do
include AbstractController::Rendering
- include AbstractController::BasicRendering
end
# Action Controllers are the core of a web request in \Rails. They are made up of one or more actions that are executed
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index 7b4f1f73a5..37dee1738f 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -28,8 +28,12 @@ module ActionController
end
end
- def render_to_body(*)
- super || " "
+ def render_to_body(options = {})
+ super || if options[:text].present?
+ options[:text]
+ else
+ " "
+ end
end
private
diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb
index c1945cc0c5..e0486ba596 100644
--- a/actionview/lib/action_view/rendering.rb
+++ b/actionview/lib/action_view/rendering.rb
@@ -77,13 +77,6 @@ module ActionView
@_view_renderer ||= ActionView::Renderer.new(lookup_context)
end
- # Render template to response_body
- # :api: public
- def render(*args, &block)
- options = _normalize_render(*args, &block)
- self.response_body = render_to_body(options)
- end
-
# Find and renders a template based on the options given.
# :api: private
def _render_template(options) #:nodoc:
@@ -91,6 +84,11 @@ module ActionView
view_renderer.render(view_context, options)
end
+ def render_to_body(options = {})
+ _process_options(options)
+ _render_template(options)
+ end
+
def rendered_format
Mime[lookup_context.rendered_format]
end