aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/abstract/renderer.rb30
-rw-r--r--actionpack/lib/action_controller/base/render.rb16
-rw-r--r--actionpack/lib/action_controller/base/responder.rb21
-rw-r--r--actionpack/lib/action_controller/new_base/base.rb3
-rw-r--r--actionpack/lib/action_controller/new_base/layouts.rb4
-rw-r--r--actionpack/lib/action_controller/new_base/renderer.rb8
-rw-r--r--actionpack/lib/action_controller/testing/process.rb1
7 files changed, 56 insertions, 27 deletions
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb
index 68c3b07b84..a86eef889e 100644
--- a/actionpack/lib/action_controller/abstract/renderer.rb
+++ b/actionpack/lib/action_controller/abstract/renderer.rb
@@ -17,28 +17,50 @@ module AbstractController
end
def render(options = {})
- self.response_body = render_to_string(options)
+ self.response_body = render_to_body(options)
end
- # Raw rendering of a template.
+ # Raw rendering of a template to a Rack-compatible body.
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
#
# :api: plugin
- def render_to_string(options = {})
+ def render_to_body(options = {})
name = options[:_template_name] || action_name
template = options[:_template] || view_paths.find_by_parts(name.to_s, formats, options[:_prefix])
_render_template(template, options)
end
+ # Raw rendering of a template to a string.
+ # ====
+ # @option _prefix<String> The template's path prefix
+ # @option _layout<String> The relative path to the layout template to use
+ #
+ # :api: plugin
+ def render_to_string(options = {})
+ AbstractController::Renderer.body_to_s(render_to_body(options))
+ end
+
def _render_template(template, options)
_action_view._render_template_with_layout(template)
end
def view_paths() _view_paths end
+ # Return a string representation of a Rack-compatible response body.
+ def self.body_to_s(body)
+ if body.respond_to?(:to_str)
+ body
+ else
+ strings = []
+ body.each { |part| strings << part.to_s }
+ body.close if body.respond_to?(:close)
+ strings.join
+ end
+ end
+
module ClassMethods
def append_view_path(path)
@@ -55,4 +77,4 @@ module AbstractController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/base/render.rb b/actionpack/lib/action_controller/base/render.rb
index 0d24f18633..606df58518 100644
--- a/actionpack/lib/action_controller/base/render.rb
+++ b/actionpack/lib/action_controller/base/render.rb
@@ -1,3 +1,5 @@
+require 'action_controller/abstract/renderer'
+
module ActionController
DEFAULT_RENDER_STATUS_CODE = "200 OK"
@@ -306,9 +308,9 @@ module ActionController
(name.is_a?(String) ? name.sub(/^#{controller_path}\//, '') : name).to_s
end
- # Renders according to the same rules as <tt>render</tt>, but returns the result in a string instead
- # of sending it as the response body to the browser.
- def render_to_string(options = nil, &block) #:doc:
+ # Same rules as <tt>render</tt>, but returns a Rack-compatible body
+ # instead of sending the response.
+ def render_to_body(options = nil, &block) #:doc:
render(options, &block)
response.body
ensure
@@ -316,7 +318,11 @@ module ActionController
erase_render_results
reset_variables_added_to_assigns
end
-
+
+ def render_to_string(options = {})
+ AbstractController::Renderer.body_to_s(render_to_body(options))
+ end
+
# Clears the rendered results, allowing for another render to be performed.
def erase_render_results #:nodoc:
response.body = []
@@ -387,4 +393,4 @@ module ActionController
render_for_parts(parts, layout, options)
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/base/responder.rb b/actionpack/lib/action_controller/base/responder.rb
index 989f82444b..1aee980da6 100644
--- a/actionpack/lib/action_controller/base/responder.rb
+++ b/actionpack/lib/action_controller/base/responder.rb
@@ -5,18 +5,19 @@ module ActionController
end
private
- def render_for_text(text = nil, append_response = false) #:nodoc:
+ def render_for_text(text) #:nodoc:
@performed_render = true
- if append_response
- response.body ||= ''
- response.body << text.to_s
- else
- response.body = case text
- when Proc then text
- when nil then " " # Safari doesn't pass the headers of the return if the response is zero length
- else text.to_s
+ case text
+ when Proc
+ response.body = text
+ when nil
+ # Safari 2 doesn't pass response headers if the response is zero-length
+ if response.body_parts.empty?
+ response.body_parts << ' '
end
+ else
+ response.body_parts << text
end
end
@@ -39,4 +40,4 @@ module ActionController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb
index 0400ddbf7a..08e7a1a0e7 100644
--- a/actionpack/lib/action_controller/new_base/base.rb
+++ b/actionpack/lib/action_controller/new_base/base.rb
@@ -42,7 +42,6 @@ module ActionController
# :api: plugin
def response_body=(body)
- @_response["Content-Length"] = body.length
@_response.body = body
end
@@ -58,4 +57,4 @@ module ActionController
response.to_a
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb
index 149847c968..a8e0809ac6 100644
--- a/actionpack/lib/action_controller/new_base/layouts.rb
+++ b/actionpack/lib/action_controller/new_base/layouts.rb
@@ -9,7 +9,7 @@ module ActionController
end
end
- def render_to_string(options)
+ def render_to_body(options)
# render :text => ..., :layout => ...
# or
# render :anything_else
@@ -34,4 +34,4 @@ module ActionController
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb
index 044c15f409..ed34c46aed 100644
--- a/actionpack/lib/action_controller/new_base/renderer.rb
+++ b/actionpack/lib/action_controller/new_base/renderer.rb
@@ -8,7 +8,7 @@ module ActionController
end
def render(action, options = {})
- # TODO: Move this into #render_to_string
+ # TODO: Move this into #render_to_body
if action.is_a?(Hash)
options, action = action, nil
else
@@ -17,10 +17,10 @@ module ActionController
_process_options(options)
- self.response_body = render_to_string(options)
+ self.response_body = render_to_body(options)
end
- def render_to_string(options)
+ def render_to_body(options)
unless options.is_a?(Hash)
options = {:action => options}
end
@@ -59,4 +59,4 @@ module ActionController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb
index 86e193efa9..7e2857614c 100644
--- a/actionpack/lib/action_controller/testing/process.rb
+++ b/actionpack/lib/action_controller/testing/process.rb
@@ -287,6 +287,7 @@ module ActionController #:nodoc:
include TestResponseBehavior
def recycle!
+ body_parts.clear
headers.delete('ETag')
headers.delete('Last-Modified')
end