diff options
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/abstract/renderer.rb | 30 | ||||
-rw-r--r-- | actionpack/lib/action_controller/base/render.rb | 16 | ||||
-rw-r--r-- | actionpack/lib/action_controller/base/responder.rb | 21 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/base.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/layouts.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/renderer.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_controller/testing/process.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/rewindable_input.rb | 25 | ||||
-rw-r--r-- | actionpack/lib/action_view.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_view/template/template.rb | 1 |
13 files changed, 70 insertions, 44 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 100a0be1db..aee6b9dc9f 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -30,6 +30,7 @@ rescue LoadError require 'active_support' end end +require 'active_support/core/all' require File.join(File.dirname(__FILE__), "action_pack") 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 diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb index bd5a38cc82..5feb8a4863 100644 --- a/actionpack/lib/action_dispatch.rb +++ b/actionpack/lib/action_dispatch.rb @@ -30,6 +30,7 @@ rescue LoadError require 'active_support' end end +require 'active_support/core/all' $:.unshift "#{File.dirname(__FILE__)}/action_dispatch/vendor/rack-1.0" begin diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index 6df572268c..abaee2829e 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -1,3 +1,5 @@ +require 'active_support/json' + module ActionDispatch class ParamsParser ActionController::Base.param_parsers[Mime::XML] = :xml_simple diff --git a/actionpack/lib/action_dispatch/middleware/rewindable_input.rb b/actionpack/lib/action_dispatch/middleware/rewindable_input.rb index 725414efc4..c818f28cce 100644 --- a/actionpack/lib/action_dispatch/middleware/rewindable_input.rb +++ b/actionpack/lib/action_dispatch/middleware/rewindable_input.rb @@ -1,27 +1,18 @@ module ActionDispatch class RewindableInput - class RewindableIO < ActiveSupport::BasicObject - def initialize(io) - @io = io - @rewindable = io.is_a?(::StringIO) - end - - def method_missing(method, *args, &block) - unless @rewindable - @io = ::StringIO.new(@io.read) - @rewindable = true - end - - @io.__send__(method, *args, &block) - end - end - def initialize(app) @app = app end def call(env) - env['rack.input'] = RewindableIO.new(env['rack.input']) + begin + env['rack.input'].rewind + rescue NoMethodError, Errno::ESPIPE + # Handles exceptions raised by input streams that cannot be rewound + # such as when using plain CGI under Apache + env['rack.input'] = StringIO.new(env['rack.input'].read) + end + @app.call(env) end end diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index e604c2a581..dd352f9ce0 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -30,6 +30,7 @@ rescue LoadError require 'active_support' end end +require 'active_support/core/all' require File.join(File.dirname(__FILE__), "action_pack") diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index 0d2f201458..b6967a2013 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -1,3 +1,4 @@ +require 'set' require "action_view/template/path" module ActionView #:nodoc: |