diff options
author | José Valim <jose.valim@gmail.com> | 2011-04-18 08:12:51 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-04-18 08:12:51 +0200 |
commit | 4f044528c0373b0a581a12b1311a7a544ded6c58 (patch) | |
tree | 2aa96082073fe9e5c8df88fed86d0f303c7d49cc /actionpack | |
parent | b839d4093356914b305b6fd0140782e8e198402e (diff) | |
download | rails-4f044528c0373b0a581a12b1311a7a544ded6c58.tar.gz rails-4f044528c0373b0a581a12b1311a7a544ded6c58.tar.bz2 rails-4f044528c0373b0a581a12b1311a7a544ded6c58.zip |
Slightly reorganize rendering stack.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/abstract_controller/rendering.rb | 31 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/renderers.rb | 6 |
2 files changed, 28 insertions, 9 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 66f6d0eebb..d0dd730b06 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -105,16 +105,22 @@ module AbstractController # Normalize arguments, options and then delegates render_to_body and # sticks the result in self.response_body. def render(*args, &block) - self.response_body = render_to_string(*args, &block) + options = _normalize_render(*args, &block) + self.response_body = render_to_body(options) end # Raw rendering of a template to a string. Just convert the results of - # render_to_body into a String. + # render_response into a String. # :api: plugin def render_to_string(*args, &block) - options = _normalize_args(*args, &block) - _normalize_options(options) - render_to_body(options).tap { self.response_body = nil } + options = _normalize_render(*args, &block) + if self.response_body = render_to_body(options) + string = "" + response_body.each { |r| string << r } + string + end + ensure + self.response_body = nil end # Raw rendering of a template to a Rack-compatible body. @@ -151,8 +157,17 @@ module AbstractController hash end - # Normalize options by converting render "foo" to render :action => "foo" and + # Normalize args and options. + # :api: private + def _normalize_render(*args, &block) + options = _normalize_args(*args, &block) + _normalize_options(options) + options + end + + # Normalize args by converting render "foo" to render :action => "foo" and # render "foo/bar" to render :file => "foo/bar". + # :api: plugin def _normalize_args(action=nil, options={}) case action when NilClass @@ -169,6 +184,8 @@ module AbstractController options end + # Normalize options. + # :api: plugin def _normalize_options(options) if options[:partial] == true options[:partial] = action_name @@ -182,6 +199,8 @@ module AbstractController options end + # Process extra options. + # :api: plugin def _process_options(options) end end diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index dfda6618e7..0ad9dbeda9 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -95,17 +95,17 @@ module ActionController json = json.to_json(options) unless json.kind_of?(String) json = "#{options[:callback]}(#{json})" unless options[:callback].blank? self.content_type ||= Mime::JSON - self.response_body = json + json end add :js do |js, options| self.content_type ||= Mime::JS - self.response_body = js.respond_to?(:to_js) ? js.to_js(options) : js + js.respond_to?(:to_js) ? js.to_js(options) : js end add :xml do |xml, options| self.content_type ||= Mime::XML - self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml(options) : xml + xml.respond_to?(:to_xml) ? xml.to_xml(options) : xml end end end |