2009-08-06 17:48:48 -04:00
|
|
|
module ActionController
|
2009-12-20 20:15:31 -05:00
|
|
|
module Rendering
|
2009-08-06 17:48:48 -04:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2010-02-18 15:26:16 -05:00
|
|
|
include RackDelegation
|
|
|
|
include AbstractController::Rendering
|
|
|
|
include AbstractController::LocalizedCache
|
2009-08-14 15:00:52 -04:00
|
|
|
|
2009-08-06 17:48:48 -04:00
|
|
|
def process_action(*)
|
2010-02-18 15:26:16 -05:00
|
|
|
self.formats = request.formats.map {|x| x.to_sym }
|
2009-08-06 17:48:48 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2010-01-20 08:21:27 -05:00
|
|
|
def render(*args)
|
2010-01-23 04:29:22 -05:00
|
|
|
if response_body
|
|
|
|
raise ::AbstractController::DoubleRenderError
|
|
|
|
end
|
|
|
|
|
2010-01-20 08:21:27 -05:00
|
|
|
args << {} unless args.last.is_a?(Hash)
|
|
|
|
super(*args)
|
|
|
|
self.content_type ||= args.last[:_template].mime_type.to_s
|
2009-08-06 17:48:48 -04:00
|
|
|
response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_to_body(options)
|
|
|
|
_process_options(options)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2009-10-21 15:47:10 -04:00
|
|
|
|
2009-12-30 19:45:56 -05:00
|
|
|
def _render_partial(options)
|
|
|
|
options[:partial] = action_name if options[:partial] == true
|
|
|
|
options[:_details] = {:formats => formats}
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2010-02-16 17:26:29 -05:00
|
|
|
def _determine_template(options)
|
|
|
|
if options.key?(:text) && options[:text].respond_to?(:to_text)
|
|
|
|
options[:text] = options[:text].to_text
|
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-10-21 13:55:47 -04:00
|
|
|
def format_for_text
|
|
|
|
formats.first
|
|
|
|
end
|
|
|
|
|
2009-08-06 17:48:48 -04:00
|
|
|
def _process_options(options)
|
|
|
|
status, content_type, location = options.values_at(:status, :content_type, :location)
|
|
|
|
self.status = status if status
|
|
|
|
self.content_type = content_type if content_type
|
|
|
|
self.headers["Location"] = url_for(location) if location
|
|
|
|
end
|
2010-01-22 11:57:36 -05:00
|
|
|
|
|
|
|
def _normalize_options(action=nil, options={}, &blk)
|
|
|
|
case action
|
|
|
|
when NilClass
|
|
|
|
when Hash
|
|
|
|
options = super(action.delete(:action), action)
|
|
|
|
when String, Symbol
|
|
|
|
options = super
|
|
|
|
else
|
|
|
|
options.merge! :partial => action
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:status]
|
|
|
|
options[:status] = Rack::Utils.status_code(options[:status])
|
|
|
|
end
|
|
|
|
|
|
|
|
options[:update] = blk if block_given?
|
|
|
|
options
|
|
|
|
end
|
2009-08-06 17:48:48 -04:00
|
|
|
end
|
|
|
|
end
|