diff options
author | Tom Ward <tom@popdog.net> | 2008-07-18 20:14:12 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-18 20:14:12 -0500 |
commit | c3d1fda555c4bd5f8821d830c685ae5d0e7e52d0 (patch) | |
tree | 41a5e9b018d724a82c33ab117bc1e6403e6cbbc5 /actionpack/lib | |
parent | d2ccb852d4e1f6f1b01e43f32213053ae3bef408 (diff) | |
download | rails-c3d1fda555c4bd5f8821d830c685ae5d0e7e52d0.tar.gz rails-c3d1fda555c4bd5f8821d830c685ae5d0e7e52d0.tar.bz2 rails-c3d1fda555c4bd5f8821d830c685ae5d0e7e52d0.zip |
Set the response content type to that of found template if not explicitly set elsewhere [#444 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderable.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_view/template.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_view/template_handlers/builder.rb | 3 |
4 files changed, 16 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index ae6b284854..fe51af62e6 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -379,6 +379,12 @@ module ActionView #:nodoc: @assigns.each { |key, value| instance_variable_set("@#{key}", value) } end + def set_controller_content_type(content_type) + if controller.respond_to?(:response) + controller.response.content_type ||= content_type + end + end + def execute(method, local_assigns = {}) send(method, local_assigns) do |*names| instance_variable_get "@content_for_#{names.first || 'layout'}" diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index 4f865cbced..2b825ac4e9 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -24,10 +24,13 @@ module ActionView memoize :compiled_source def render(view, local_assigns = {}) + compile(local_assigns) + view._first_render ||= self view._last_render = self + view.send(:evaluate_assigns) - compile(local_assigns) + view.send(:set_controller_content_type, mime_type) if respond_to?(:mime_type) view.send(:execute, method(local_assigns), local_assigns) end diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index eba42518d7..1f528dd900 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -22,6 +22,11 @@ module ActionView #:nodoc: end memoize :format_and_extension + def mime_type + Mime::Type.lookup_by_extension(format) if format + end + memoize :mime_type + def path [base_path, [name, format, extension].compact.join('.')].compact.join('/') end diff --git a/actionpack/lib/action_view/template_handlers/builder.rb b/actionpack/lib/action_view/template_handlers/builder.rb index 335ec1abb4..7d24a5c423 100644 --- a/actionpack/lib/action_view/template_handlers/builder.rb +++ b/actionpack/lib/action_view/template_handlers/builder.rb @@ -6,8 +6,7 @@ module ActionView include Compilable def compile(template) - # ActionMailer does not have a response - "controller.respond_to?(:response) && controller.response.content_type ||= Mime::XML;" + + "set_controller_content_type(Mime::XML);" + "xml = ::Builder::XmlMarkup.new(:indent => 2);" + "self.output_buffer = xml.target!;" + template.source + |