~ubuntu-branches/ubuntu/raring/ruby-actionpack-3.2/raring

« back to all changes in this revision

Viewing changes to lib/action_controller/metal/rendering.rb

  • Committer: Package Import Robot
  • Author(s): Ondřej Surý
  • Date: 2012-04-25 09:14:01 UTC
  • Revision ID: package-import@ubuntu.com-20120425091401-3nkf83btcemhjquo
Tags: upstream-3.2.3
Import upstream version 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module ActionController
 
2
  module Rendering
 
3
    extend ActiveSupport::Concern
 
4
 
 
5
    include AbstractController::Rendering
 
6
 
 
7
    # Before processing, set the request formats in current controller formats.
 
8
    def process_action(*) #:nodoc:
 
9
      self.formats = request.formats.map { |x| x.ref }
 
10
      super
 
11
    end
 
12
 
 
13
    # Check for double render errors and set the content_type after rendering.
 
14
    def render(*args) #:nodoc:
 
15
      raise ::AbstractController::DoubleRenderError if response_body
 
16
      super
 
17
      self.content_type ||= Mime[lookup_context.rendered_format].to_s
 
18
      response_body
 
19
    end
 
20
 
 
21
    # Overwrite render_to_string because body can now be set to a rack body.
 
22
    def render_to_string(*)
 
23
      if self.response_body = super
 
24
        string = ""
 
25
        response_body.each { |r| string << r }
 
26
        string
 
27
      end
 
28
    ensure
 
29
      self.response_body = nil
 
30
    end
 
31
 
 
32
    private
 
33
 
 
34
    # Normalize arguments by catching blocks and setting them on :update.
 
35
    def _normalize_args(action=nil, options={}, &blk) #:nodoc:
 
36
      options = super
 
37
      options[:update] = blk if block_given?
 
38
      options
 
39
    end
 
40
 
 
41
    # Normalize both text and status options.
 
42
    def _normalize_options(options) #:nodoc:
 
43
      if options.key?(:text) && options[:text].respond_to?(:to_text)
 
44
        options[:text] = options[:text].to_text
 
45
      end
 
46
 
 
47
      if options[:status]
 
48
        options[:status] = Rack::Utils.status_code(options[:status])
 
49
      end
 
50
 
 
51
      super
 
52
    end
 
53
 
 
54
    # Process controller specific options, as status, content-type and location.
 
55
    def _process_options(options) #:nodoc:
 
56
      status, content_type, location = options.values_at(:status, :content_type, :location)
 
57
 
 
58
      self.status = status if status
 
59
      self.content_type = content_type if content_type
 
60
      self.headers["Location"] = url_for(location) if location
 
61
 
 
62
      super
 
63
    end
 
64
  end
 
65
end