diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/Rakefile | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/render_options.rb | 30 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/renderer.rb | 3 |
4 files changed, 28 insertions, 9 deletions
diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 2041f5a844..d192a2e3bf 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -63,7 +63,7 @@ Rake::TestTask.new(:test_new_base_on_old_tests) do |t| t.test_files = %w( addresses_render base benchmark caching capture content_type dispatcher flash mime_responds record_identifier redirect - render render_json + render render_json render_xml send_file request_forgery_protection rescue url_rewriter verification webservice ).map { |name| "test/controller/#{name}_test.rb" } end diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index 6e1f92c45d..08ffafb27e 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -11,8 +11,8 @@ module ActionController include ActionController::UrlFor include ActionController::Redirector include ActionController::Renderer - include ActionController::RenderOptions include ActionController::Renderers::Json + include ActionController::Renderers::Xml include ActionController::Layouts include ActionController::ConditionalGet diff --git a/actionpack/lib/action_controller/new_base/render_options.rb b/actionpack/lib/action_controller/new_base/render_options.rb index e7ed2bd278..a9ac0e0a41 100644 --- a/actionpack/lib/action_controller/new_base/render_options.rb +++ b/actionpack/lib/action_controller/new_base/render_options.rb @@ -18,15 +18,23 @@ module ActionController end end - module Renderers - module Json + module RenderOption + extend ActiveSupport::DependencyModule + + included do extend ActiveSupport::DependencyModule - depends_on RenderOptions - - included do - _renderers << :json + + def self.register_renderer(name) + included { _renderers << name } end + end + end + + module Renderers + module Json + include RenderOption + register_renderer :json def _render_json(json, options) json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str) @@ -35,5 +43,15 @@ module ActionController self.response_body = json end end + + module Xml + include RenderOption + register_renderer :xml + + def _render_xml(xml, options) + response.content_type ||= Mime::XML + self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml + end + end end end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index 840168397d..2a52eedb59 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -79,9 +79,10 @@ module ActionController end def _process_options(options) - status, content_type = options.values_at(:status, :content_type) + status, content_type, location = options.values_at(:status, :content_type, :location) response.status = status.to_i if status response.content_type = content_type if content_type + response.headers["Location"] = url_for(location) if location end end end |