Browse files

Added the :xml render option

  • Loading branch information...
1 parent 2daac47 commit ad1c90de3a766d12a0906c7cf3772f3bc0e1b445 Yehuda Katz + Carl Lerche committed May 21, 2009
View
2 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
View
2 actionpack/lib/action_controller/new_base/base.rb
@@ -11,8 +11,8 @@ class Base < Http
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
View
30 actionpack/lib/action_controller/new_base/render_options.rb
@@ -18,15 +18,23 @@ def render_to_body(options)
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 @@ def _render_json(json, options)
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
View
3 actionpack/lib/action_controller/new_base/renderer.rb
@@ -79,9 +79,10 @@ def _render_partial(partial, options)
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

0 comments on commit ad1c90d

Please sign in to comment.