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 AbstractController::Rendering
|
2009-08-14 15:00:52 -04:00
|
|
|
|
2010-03-12 14:39:53 -05:00
|
|
|
# Before processing, set the request formats in current controller formats.
|
2010-03-13 15:28:34 -05:00
|
|
|
def process_action(*) #:nodoc:
|
2010-03-08 05:32:01 -05:00
|
|
|
self.formats = request.formats.map { |x| x.to_sym }
|
2009-08-06 17:48:48 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2010-03-12 14:39:53 -05:00
|
|
|
# Check for double render errors and set the content_type after rendering.
|
|
|
|
def render(*args) #:nodoc:
|
2010-02-24 13:17:24 -05:00
|
|
|
raise ::AbstractController::DoubleRenderError if response_body
|
2010-03-07 21:23:16 -05:00
|
|
|
super
|
2010-03-12 14:39:53 -05:00
|
|
|
self.content_type ||= Mime[formats.first].to_s
|
2010-03-08 05:32:01 -05:00
|
|
|
response_body
|
2010-03-07 21:23:16 -05:00
|
|
|
end
|
|
|
|
|
2009-08-06 17:48:48 -04:00
|
|
|
private
|
2009-10-21 15:47:10 -04:00
|
|
|
|
2010-03-12 14:39:53 -05:00
|
|
|
# Normalize arguments by catching blocks and setting them on :update.
|
|
|
|
def _normalize_args(action=nil, options={}, &blk) #:nodoc:
|
2010-03-08 05:32:01 -05:00
|
|
|
options = super
|
2010-03-07 21:23:16 -05:00
|
|
|
options[:update] = blk if block_given?
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
2010-03-12 14:39:53 -05:00
|
|
|
# Normalize both text and status options.
|
|
|
|
def _normalize_options(options) #:nodoc:
|
2010-02-24 13:17:24 -05:00
|
|
|
if options.key?(:text) && options[:text].respond_to?(:to_text)
|
|
|
|
options[:text] = options[:text].to_text
|
|
|
|
end
|
|
|
|
|
2010-01-22 11:57:36 -05:00
|
|
|
if options[:status]
|
|
|
|
options[:status] = Rack::Utils.status_code(options[:status])
|
|
|
|
end
|
|
|
|
|
2010-03-07 21:23:16 -05:00
|
|
|
super
|
2010-01-22 11:57:36 -05:00
|
|
|
end
|
2010-02-24 13:17:24 -05:00
|
|
|
|
2010-03-12 14:39:53 -05:00
|
|
|
# Process controller specific options, as status, content-type and location.
|
|
|
|
def _process_options(options) #:nodoc:
|
2010-02-24 13:17:24 -05:00
|
|
|
status, content_type, location = options.values_at(:status, :content_type, :location)
|
2010-03-08 05:32:01 -05:00
|
|
|
|
2010-02-24 13:17:24 -05:00
|
|
|
self.status = status if status
|
|
|
|
self.content_type = content_type if content_type
|
|
|
|
self.headers["Location"] = url_for(location) if location
|
2010-03-08 05:32:01 -05:00
|
|
|
|
|
|
|
super
|
2010-02-24 13:17:24 -05:00
|
|
|
end
|
2010-03-08 05:32:01 -05:00
|
|
|
|
2009-08-06 17:48:48 -04:00
|
|
|
end
|
|
|
|
end
|