Skip to content
This repository
Browse code

Renamed presenter to renderer, added some documentation and defined i…

…ts API.
  • Loading branch information...
commit aed135d3e261cbee153a35fcfbeb47e2e02b12e4 1 parent 1fd65c8
José Valim authored August 06, 2009
4  actionpack/examples/very_simple.rb
@@ -6,7 +6,7 @@
6 6
 class Kaigi < ActionController::Metal
7 7
   include AbstractController::Callbacks
8 8
   include ActionController::RackConvenience
9  
-  include ActionController::Renderer
  9
+  include ActionController::RenderingController
10 10
   include ActionController::Layouts
11 11
   include ActionView::Context
12 12
   
@@ -47,4 +47,4 @@ def set_name
47 47
   map("/kaigi/alt") { run Kaigi.action(:alt) }
48 48
 end.to_app
49 49
 
50  
-Rack::Handler::Mongrel.run app, :Port => 3000
  50
+Rack::Handler::Mongrel.run app, :Port => 3000
20  actionpack/lib/abstract_controller.rb
@@ -2,15 +2,15 @@
2 2
 require "active_support/core_ext/module/delegation"
3 3
 
4 4
 module AbstractController
5  
-  autoload :Base,               "abstract_controller/base"
6  
-  autoload :Benchmarker,        "abstract_controller/benchmarker"
7  
-  autoload :Callbacks,          "abstract_controller/callbacks"
8  
-  autoload :Helpers,            "abstract_controller/helpers"
9  
-  autoload :Layouts,            "abstract_controller/layouts"
10  
-  autoload :Logger,             "abstract_controller/logger"
11  
-  autoload :Renderer,           "abstract_controller/renderer"
  5
+  autoload :Base,                "abstract_controller/base"
  6
+  autoload :Benchmarker,         "abstract_controller/benchmarker"
  7
+  autoload :Callbacks,           "abstract_controller/callbacks"
  8
+  autoload :Helpers,             "abstract_controller/helpers"
  9
+  autoload :Layouts,             "abstract_controller/layouts"
  10
+  autoload :Logger,              "abstract_controller/logger"
  11
+  autoload :RenderingController, "abstract_controller/rendering_controller"
12 12
   # === Exceptions
13  
-  autoload :ActionNotFound,     "abstract_controller/exceptions"
14  
-  autoload :DoubleRenderError,  "abstract_controller/exceptions"
15  
-  autoload :Error,              "abstract_controller/exceptions"
  13
+  autoload :ActionNotFound,      "abstract_controller/exceptions"
  14
+  autoload :DoubleRenderError,   "abstract_controller/exceptions"
  15
+  autoload :Error,               "abstract_controller/exceptions"
16 16
 end
2  actionpack/lib/abstract_controller/helpers.rb
@@ -2,7 +2,7 @@ module AbstractController
2 2
   module Helpers
3 3
     extend ActiveSupport::Concern
4 4
 
5  
-    include Renderer
  5
+    include RenderingController
6 6
 
7 7
     included do
8 8
       extlib_inheritable_accessor(:_helpers) { Module.new }
2  actionpack/lib/abstract_controller/layouts.rb
@@ -2,7 +2,7 @@ module AbstractController
2 2
   module Layouts
3 3
     extend ActiveSupport::Concern
4 4
 
5  
-    include Renderer
  5
+    include RenderingController
6 6
 
7 7
     included do
8 8
       extlib_inheritable_accessor(:_layout_conditions) { Hash.new }
4  actionpack/lib/abstract_controller/renderer.rb → ...k/lib/abstract_controller/rendering_controller.rb
... ...
@@ -1,7 +1,7 @@
1 1
 require "abstract_controller/logger"
2 2
 
3 3
 module AbstractController
4  
-  module Renderer
  4
+  module RenderingController
5 5
     extend ActiveSupport::Concern
6 6
 
7 7
     include AbstractController::Logger
@@ -67,7 +67,7 @@ def render_to_body(options = {})
67 67
     #
68 68
     # :api: plugin
69 69
     def render_to_string(options = {})
70  
-      AbstractController::Renderer.body_to_s(render_to_body(options))
  70
+      AbstractController::RenderingController.body_to_s(render_to_body(options))
71 71
     end
72 72
 
73 73
     # Renders the template from an object.
4  actionpack/lib/action_controller.rb
@@ -8,8 +8,8 @@ module ActionController
8 8
   autoload :Rails2Compatibility,  "action_controller/metal/compatibility"
9 9
   autoload :Redirector,           "action_controller/metal/redirector"
10 10
   autoload :Renderer,             "action_controller/metal/renderer"
  11
+  autoload :RenderingController,  "action_controller/metal/rendering_controller"
11 12
   autoload :RenderOptions,        "action_controller/metal/render_options"
12  
-  autoload :Renderers,            "action_controller/metal/render_options"
13 13
   autoload :Rescue,               "action_controller/metal/rescuable"
14 14
   autoload :Testing,              "action_controller/metal/testing"
15 15
   autoload :UrlFor,               "action_controller/metal/url_for"
@@ -69,4 +69,4 @@ module ActionController
69 69
 require 'active_support/core_ext/module/attr_internal'
70 70
 require 'active_support/core_ext/module/delegation'
71 71
 require 'active_support/core_ext/name_error'
72  
-require 'active_support/inflector'
  72
+require 'active_support/inflector'
4  actionpack/lib/action_controller/base.rb
@@ -10,8 +10,8 @@ class Base < Metal
10 10
     include ActionController::HideActions
11 11
     include ActionController::UrlFor
12 12
     include ActionController::Redirector
13  
-    include ActionController::Renderer
14  
-    include ActionController::Renderers::All
  13
+    include ActionController::RenderingController
  14
+    include ActionController::RenderOptions::All
15 15
     include ActionController::Layouts
16 16
     include ActionController::ConditionalGet
17 17
     include ActionController::RackConvenience
2  actionpack/lib/action_controller/metal/layouts.rb
@@ -158,7 +158,7 @@ module ActionController
158 158
   module Layouts
159 159
     extend ActiveSupport::Concern
160 160
 
161  
-    include ActionController::Renderer
  161
+    include ActionController::RenderingController
162 162
     include AbstractController::Layouts
163 163
 
164 164
     module ClassMethods
162  actionpack/lib/action_controller/metal/mime_responds.rb
... ...
@@ -1,146 +1,4 @@
1 1
 module ActionController #:nodoc:
2  
-
3  
-  # Presenter is responsible to expose a resource for different mime requests,
4  
-  # usually depending on the HTTP verb. The presenter is triggered when
5  
-  # respond_with is called. The simplest case to study is a GET request:
6  
-  #
7  
-  #   class PeopleController < ApplicationController
8  
-  #     respond_to :html, :xml, :json
9  
-  #
10  
-  #     def index
11  
-  #       @people = Person.find(:all)
12  
-  #       respond_with(@people)
13  
-  #     end
14  
-  #   end
15  
-  #
16  
-  # When a request comes, for example with format :xml, three steps happen:
17  
-  #
18  
-  #   1) respond_with searches for a template at people/index.xml;
19  
-  #
20  
-  #   2) if the template is not available, it will create a presenter, passing
21  
-  #      the controller and the resource, and invoke :to_xml on it;
22  
-  #
23  
-  #   3) if the presenter does not respond_to :to_xml, call to_format on it.
24  
-  #
25  
-  # === Builtin HTTP verb semantics
26  
-  #
27  
-  # Rails default presenter holds semantics for each HTTP verb. Depending on the
28  
-  # content type, verb and the resource status, it will behave differently.
29  
-  #
30  
-  # Using Rails default presenter, a POST request could be written as:
31  
-  #
32  
-  #   def create
33  
-  #     @user = User.new(params[:user])
34  
-  #     flash[:notice] = 'User was successfully created.' if @user.save
35  
-  #     respond_with(@user)
36  
-  #   end
37  
-  #
38  
-  # Which is exactly the same as:
39  
-  #
40  
-  #   def create
41  
-  #     @user = User.new(params[:user])
42  
-  #
43  
-  #     respond_to do |format|
44  
-  #       if @user.save
45  
-  #         flash[:notice] = 'User was successfully created.'
46  
-  #         format.html { redirect_to(@user) }
47  
-  #         format.xml { render :xml => @user, :status => :created, :location => @user }
48  
-  #       else
49  
-  #         format.html { render :action => "new" }
50  
-  #         format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
51  
-  #       end
52  
-  #     end
53  
-  #   end
54  
-  #
55  
-  # The same happens for PUT and DELETE requests. By default, it accepts just
56  
-  # :location as parameter, which is used as redirect destination, in both
57  
-  # POST, PUT, DELETE requests for HTML mime, as in the example below:
58  
-  #
59  
-  #   def destroy
60  
-  #     @person = Person.find(params[:id])
61  
-  #     @person.destroy
62  
-  #     respond_with(@person, :location => root_url)
63  
-  #   end
64  
-  #
65  
-  # === Nested resources
66  
-  #
67  
-  # You can given nested resource as you do in form_for and polymorphic_url.
68  
-  # Consider the project has many tasks example. The create action for
69  
-  # TasksController would be like:
70  
-  #
71  
-  #   def create
72  
-  #     @project = Project.find(params[:project_id])
73  
-  #     @task = @project.comments.build(params[:task])
74  
-  #     flash[:notice] = 'Task was successfully created.' if @task.save
75  
-  #     respond_with([@project, @task])
76  
-  #   end
77  
-  #
78  
-  # Given a nested resource, you ensure that the presenter will redirect to
79  
-  # project_task_url instead of task_url.
80  
-  #
81  
-  # Namespaced and singleton resources requires a symbol to be given, as in
82  
-  # polymorphic urls. If a project has one manager which has many tasks, it
83  
-  # should be invoked as:
84  
-  #
85  
-  #   respond_with([@project, :manager, @task])
86  
-  #
87  
-  # Check polymorphic_url documentation for more examples.
88  
-  #
89  
-  class Presenter
90  
-    attr_reader :controller, :request, :format, :resource, :resource_location, :options
91  
-
92  
-    def initialize(controller, resource, options)
93  
-      @controller = controller
94  
-      @request = controller.request
95  
-      @format = controller.formats.first
96  
-      @resource = resource.is_a?(Array) ? resource.last : resource
97  
-      @resource_location = options[:location] || resource
98  
-      @options = options
99  
-    end
100  
-
101  
-    delegate :head, :render, :redirect_to,   :to => :controller
102  
-    delegate :get?, :post?, :put?, :delete?, :to => :request
103  
-
104  
-    # Undefine :to_json since it's defined on Object
105  
-    undef_method :to_json
106  
-
107  
-    def to_html
108  
-      if get?
109  
-        render
110  
-      elsif has_errors?
111  
-        render :action => default_action
112  
-      else
113  
-        redirect_to resource_location
114  
-      end
115  
-    end
116  
-
117  
-    def to_format
118  
-      return render unless resourceful?
119  
-
120  
-      if get?
121  
-        render format => resource
122  
-      elsif has_errors?
123  
-        render format => resource.errors, :status => :unprocessable_entity
124  
-      elsif post?
125  
-        render format => resource, :status => :created, :location => resource_location
126  
-      else
127  
-        head :ok
128  
-      end
129  
-    end
130  
-
131  
-    def resourceful?
132  
-      resource.respond_to?(:"to_#{format}")
133  
-    end
134  
-
135  
-    def has_errors?
136  
-      resource.respond_to?(:errors) && !resource.errors.empty?
137  
-    end
138  
-
139  
-    def default_action
140  
-      request.post? ? :new : :edit
141  
-    end
142  
-  end
143  
-
144 2
   module MimeResponds #:nodoc:
145 3
     extend ActiveSupport::Concern
146 4
 
@@ -339,10 +197,10 @@ def respond_to(*mimes, &block)
339 197
       end
340 198
     end
341 199
 
342  
-    # respond_with wraps a resource around a presenter for default representation.
  200
+    # respond_with wraps a resource around a renderer for default representation.
343 201
     # First it invokes respond_to, if a response cannot be found (ie. no block
344 202
     # for the request was given and template was not available), it instantiates
345  
-    # an ActionController::Presenter with the controller and resource.
  203
+    # an ActionController::Renderer with the controller and resource.
346 204
     #
347 205
     # ==== Example
348 206
     #
@@ -363,19 +221,19 @@ def respond_to(*mimes, &block)
363 221
     #     end
364 222
     #   end
365 223
     #
366  
-    # All options given to respond_with are sent to the underlying presenter.
  224
+    # All options given to respond_with are sent to the underlying renderer,
  225
+    # except for the option :renderer itself. Since the renderer interface
  226
+    # is quite simple (it just needs to respond to call), you can even give
  227
+    # a proc to it.
367 228
     #
368 229
     def respond_with(resource, options={}, &block)
369 230
       respond_to(&block)
370 231
     rescue ActionView::MissingTemplate
371  
-      presenter = ActionController::Presenter.new(self, resource, options)
372  
-      format_method = :"to_#{self.formats.first}"
  232
+      (options.delete(:renderer) || renderer).call(self, resource, options)
  233
+    end
373 234
 
374  
-      if presenter.respond_to?(format_method)
375  
-        presenter.send(format_method)
376  
-      else
377  
-        presenter.to_format
378  
-      end
  235
+    def renderer
  236
+      ActionController::Renderer
379 237
     end
380 238
 
381 239
   protected
10  actionpack/lib/action_controller/metal/render_options.rb
@@ -47,7 +47,7 @@ def base.register_renderer(name)
47 47
     end
48 48
   end
49 49
 
50  
-  module Renderers
  50
+  module RenderOptions
51 51
     module Json
52 52
       extend RenderOption
53 53
       register_renderer :json
@@ -94,10 +94,10 @@ def render_update(proc, options)
94 94
     module All
95 95
       extend ActiveSupport::Concern
96 96
 
97  
-      include ActionController::Renderers::Json
98  
-      include ActionController::Renderers::Js
99  
-      include ActionController::Renderers::Xml
100  
-      include ActionController::Renderers::RJS
  97
+      include ActionController::RenderOptions::Json
  98
+      include ActionController::RenderOptions::Js
  99
+      include ActionController::RenderOptions::Xml
  100
+      include ActionController::RenderOptions::RJS
101 101
     end
102 102
   end
103 103
 end
215  actionpack/lib/action_controller/metal/renderer.rb
... ...
@@ -1,66 +1,181 @@
1  
-module ActionController
2  
-  module Renderer
3  
-    extend ActiveSupport::Concern
  1
+module ActionController #:nodoc:
  2
+  # Renderer is responsible to expose a resource for different mime requests,
  3
+  # usually depending on the HTTP verb. The renderer is triggered when
  4
+  # respond_with is called. The simplest case to study is a GET request:
  5
+  #
  6
+  #   class PeopleController < ApplicationController
  7
+  #     respond_to :html, :xml, :json
  8
+  #
  9
+  #     def index
  10
+  #       @people = Person.find(:all)
  11
+  #       respond_with(@people)
  12
+  #     end
  13
+  #   end
  14
+  #
  15
+  # When a request comes, for example with format :xml, three steps happen:
  16
+  #
  17
+  #   1) respond_with searches for a template at people/index.xml;
  18
+  #
  19
+  #   2) if the template is not available, it will create a renderer, passing
  20
+  #      the controller and the resource and invoke :to_xml on it;
  21
+  #
  22
+  #   3) if the renderer does not respond_to :to_xml, call to_format on it.
  23
+  #
  24
+  # === Builtin HTTP verb semantics
  25
+  #
  26
+  # Rails default renderer holds semantics for each HTTP verb. Depending on the
  27
+  # content type, verb and the resource status, it will behave differently.
  28
+  #
  29
+  # Using Rails default renderer, a POST request for creating an object could
  30
+  # be written as:
  31
+  #
  32
+  #   def create
  33
+  #     @user = User.new(params[:user])
  34
+  #     flash[:notice] = 'User was successfully created.' if @user.save
  35
+  #     respond_with(@user)
  36
+  #   end
  37
+  #
  38
+  # Which is exactly the same as:
  39
+  #
  40
+  #   def create
  41
+  #     @user = User.new(params[:user])
  42
+  #
  43
+  #     respond_to do |format|
  44
+  #       if @user.save
  45
+  #         flash[:notice] = 'User was successfully created.'
  46
+  #         format.html { redirect_to(@user) }
  47
+  #         format.xml { render :xml => @user, :status => :created, :location => @user }
  48
+  #       else
  49
+  #         format.html { render :action => "new" }
  50
+  #         format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
  51
+  #       end
  52
+  #     end
  53
+  #   end
  54
+  #
  55
+  # The same happens for PUT and DELETE requests.
  56
+  #
  57
+  # === Nested resources
  58
+  #
  59
+  # You can given nested resource as you do in form_for and polymorphic_url.
  60
+  # Consider the project has many tasks example. The create action for
  61
+  # TasksController would be like:
  62
+  #
  63
+  #   def create
  64
+  #     @project = Project.find(params[:project_id])
  65
+  #     @task = @project.comments.build(params[:task])
  66
+  #     flash[:notice] = 'Task was successfully created.' if @task.save
  67
+  #     respond_with([@project, @task])
  68
+  #   end
  69
+  #
  70
+  # Giving an array of resources, you ensure that the renderer will redirect to
  71
+  # project_task_url instead of task_url.
  72
+  #
  73
+  # Namespaced and singleton resources requires a symbol to be given, as in
  74
+  # polymorphic urls. If a project has one manager which has many tasks, it
  75
+  # should be invoked as:
  76
+  #
  77
+  #   respond_with([@project, :manager, @task])
  78
+  #
  79
+  # Check polymorphic_url documentation for more examples.
  80
+  #
  81
+  class Renderer
  82
+    attr_reader :controller, :request, :format, :resource, :resource_location, :options
4 83
 
5  
-    include AbstractController::Renderer
  84
+    def initialize(controller, resource, options={})
  85
+      @controller = controller
  86
+      @request = controller.request
  87
+      @format = controller.formats.first
  88
+      @resource = resource.is_a?(Array) ? resource.last : resource
  89
+      @resource_location = options[:location] || resource
  90
+      @options = options
  91
+    end
  92
+
  93
+    delegate :head, :render, :redirect_to,   :to => :controller
  94
+    delegate :get?, :post?, :put?, :delete?, :to => :request
6 95
 
7  
-    def process_action(*)
8  
-      self.formats = request.formats.map {|x| x.to_sym}
9  
-      super
  96
+    # Undefine :to_json since it's defined on Object
  97
+    undef_method :to_json
  98
+
  99
+    # Initializes a new renderer an invoke the proper format. If the format is
  100
+    # not defined, call to_format.
  101
+    #
  102
+    def self.call(*args)
  103
+      renderer = new(*args)
  104
+      method = :"to_#{renderer.format}"
  105
+      renderer.respond_to?(method) ? renderer.send(method) : renderer.to_format
10 106
     end
11 107
 
12  
-    def render(options)
13  
-      super
14  
-      self.content_type ||= begin
15  
-        mime = options[:_template].mime_type
16  
-        formats.include?(mime && mime.to_sym) || formats.include?(:all) ? mime : Mime::Type.lookup_by_extension(formats.first)
17  
-      end.to_s
18  
-      response_body
  108
+    # HTML format does not render the resource, it always attempt to render a
  109
+    # template.
  110
+    #
  111
+    def to_html
  112
+      if get?
  113
+        render
  114
+      elsif has_errors?
  115
+        render :action => default_action
  116
+      else
  117
+        redirect_to resource_location
  118
+      end
19 119
     end
20 120
 
21  
-    def render_to_body(options)
22  
-      _process_options(options)
  121
+    # All others formats try to render the resource given instead. For this
  122
+    # purpose a helper called display as a shortcut to render a resource with
  123
+    # the current format.
  124
+    #
  125
+    def to_format
  126
+      return render unless resourceful?
23 127
 
24  
-      if options.key?(:partial)
25  
-        options[:partial] = action_name if options[:partial] == true
26  
-        options[:_details] = {:formats => formats}
  128
+      if get?
  129
+        display resource
  130
+      elsif has_errors?
  131
+        display resource.errors, :status => :unprocessable_entity
  132
+      elsif post?
  133
+        display resource, :status => :created, :location => resource_location
  134
+      else
  135
+        head :ok
27 136
       end
28  
-
29  
-      super
30 137
     end
31 138
 
32  
-    private
33  
-      def _prefix
34  
-        controller_path
35  
-      end
  139
+  protected
36 140
 
37  
-      def _determine_template(options)
38  
-        if options.key?(:text)
39  
-          options[:_template] = ActionView::TextTemplate.new(options[:text], formats.first)
40  
-        elsif options.key?(:inline)
41  
-          handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb")
42  
-          template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
43  
-          options[:_template] = template
44  
-        elsif options.key?(:template)
45  
-          options[:_template_name] = options[:template]
46  
-        elsif options.key?(:file)
47  
-          options[:_template_name] = options[:file]
48  
-        elsif !options.key?(:partial)
49  
-          options[:_template_name] = (options[:action] || action_name).to_s
50  
-          options[:_prefix] = _prefix
51  
-        end
  141
+    # Checks whether the resource responds to the current format or not.
  142
+    #
  143
+    def resourceful?
  144
+      resource.respond_to?(:"to_#{format}")
  145
+    end
52 146
 
53  
-        super
54  
-      end
  147
+    # display is just a shortcut to render a resource with the current format.
  148
+    #
  149
+    #   display @user, :status => :ok
  150
+    #
  151
+    # For xml request is equivalent to:
  152
+    #
  153
+    #   render :xml => @user, :status => :ok
  154
+    #
  155
+    # Options sent by the user are also used:
  156
+    #
  157
+    #   respond_with(@user, :status => :created)
  158
+    #   display(@user, :status => :ok)
  159
+    #
  160
+    # Results in:
  161
+    #
  162
+    #   render :xml => @user, :status => :created
  163
+    #
  164
+    def display(resource, given_options={})
  165
+      render given_options.merge!(options).merge!(format => resource)
  166
+    end
55 167
 
56  
-      def _render_partial(partial, options)
57  
-      end
  168
+    # Check if the resource has errors or not.
  169
+    #
  170
+    def has_errors?
  171
+      resource.respond_to?(:errors) && !resource.errors.empty?
  172
+    end
58 173
 
59  
-      def _process_options(options)
60  
-        status, content_type, location = options.values_at(:status, :content_type, :location)
61  
-        self.status = status if status
62  
-        self.content_type = content_type if content_type
63  
-        self.headers["Location"] = url_for(location) if location
64  
-      end
  174
+    # By default, render the :edit action for html requests with failure, unless
  175
+    # the verb is post.
  176
+    #
  177
+    def default_action
  178
+      request.post? ? :new : :edit
  179
+    end
65 180
   end
66 181
 end
66  actionpack/lib/action_controller/metal/rendering_controller.rb
... ...
@@ -0,0 +1,66 @@
  1
+module ActionController
  2
+  module RenderingController
  3
+    extend ActiveSupport::Concern
  4
+
  5
+    include AbstractController::RenderingController
  6
+
  7
+    def process_action(*)
  8
+      self.formats = request.formats.map {|x| x.to_sym}
  9
+      super
  10
+    end
  11
+
  12
+    def render(options)
  13
+      super
  14
+      self.content_type ||= begin
  15
+        mime = options[:_template].mime_type
  16
+        formats.include?(mime && mime.to_sym) || formats.include?(:all) ? mime : Mime::Type.lookup_by_extension(formats.first)
  17
+      end.to_s
  18
+      response_body
  19
+    end
  20
+
  21
+    def render_to_body(options)
  22
+      _process_options(options)
  23
+
  24
+      if options.key?(:partial)
  25
+        options[:partial] = action_name if options[:partial] == true
  26
+        options[:_details] = {:formats => formats}
  27
+      end
  28
+
  29
+      super
  30
+    end
  31
+
  32
+    private
  33
+      def _prefix
  34
+        controller_path
  35
+      end
  36
+
  37
+      def _determine_template(options)
  38
+        if options.key?(:text)
  39
+          options[:_template] = ActionView::TextTemplate.new(options[:text], formats.first)
  40
+        elsif options.key?(:inline)
  41
+          handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb")
  42
+          template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
  43
+          options[:_template] = template
  44
+        elsif options.key?(:template)
  45
+          options[:_template_name] = options[:template]
  46
+        elsif options.key?(:file)
  47
+          options[:_template_name] = options[:file]
  48
+        elsif !options.key?(:partial)
  49
+          options[:_template_name] = (options[:action] || action_name).to_s
  50
+          options[:_prefix] = _prefix
  51
+        end
  52
+
  53
+        super
  54
+      end
  55
+
  56
+      def _render_partial(partial, options)
  57
+      end
  58
+
  59
+      def _process_options(options)
  60
+        status, content_type, location = options.values_at(:status, :content_type, :location)
  61
+        self.status = status if status
  62
+        self.content_type = content_type if content_type
  63
+        self.headers["Location"] = url_for(location) if location
  64
+      end
  65
+  end
  66
+end
2  actionpack/lib/action_controller/metal/streaming.rb
@@ -6,7 +6,7 @@ module ActionController #:nodoc:
6 6
   module Streaming
7 7
     extend ActiveSupport::Concern
8 8
 
9  
-    include ActionController::Renderer
  9
+    include ActionController::RenderingController
10 10
 
11 11
     DEFAULT_SEND_FILE_OPTIONS = {
12 12
       :type         => 'application/octet-stream'.freeze,
4  actionpack/lib/action_controller/metal/verification.rb
@@ -2,7 +2,7 @@ module ActionController #:nodoc:
2 2
   module Verification #:nodoc:
3 3
     extend ActiveSupport::Concern
4 4
 
5  
-    include AbstractController::Callbacks, Session, Flash, Renderer
  5
+    include AbstractController::Callbacks, Session, Flash, RenderingController
6 6
 
7 7
     # This module provides a class-level method for specifying that certain
8 8
     # actions are guarded against being called without certain prerequisites
@@ -127,4 +127,4 @@ def apply_remaining_actions(options) # :nodoc:
127 127
       end
128 128
     end
129 129
   end
130  
-end
  130
+end
6  actionpack/test/abstract_controller/abstract_controller_test.rb
@@ -27,7 +27,7 @@ class TestBasic < ActiveSupport::TestCase
27 27
     # Test Render mixin
28 28
     # ====
29 29
     class RenderingController < AbstractController::Base
30  
-      include Renderer
  30
+      include ::AbstractController::RenderingController
31 31
 
32 32
       def _prefix() end
33 33
 
@@ -65,8 +65,8 @@ def rendering_to_string
65 65
         self.response_body = render_to_string :_template_name => "naked_render.erb"
66 66
       end
67 67
     end
68  
-    
69  
-    class TestRenderer < ActiveSupport::TestCase
  68
+
  69
+    class TestRenderingController < ActiveSupport::TestCase
70 70
       test "rendering templates works" do
71 71
         result = Me2.new.process(:index)
72 72
         assert_equal "Hello from index.erb", result.response_body
4  actionpack/test/abstract_controller/helper_test.rb
@@ -4,7 +4,7 @@ module AbstractController
4 4
   module Testing
5 5
   
6 6
     class ControllerWithHelpers < AbstractController::Base
7  
-      include Renderer
  7
+      include RenderingController
8 8
       include Helpers
9 9
       
10 10
       def render(string)
@@ -40,4 +40,4 @@ def test_helpers
40 40
     end
41 41
     
42 42
   end
43  
-end
  43
+end
2  actionpack/test/abstract_controller/layouts_test.rb
@@ -6,7 +6,7 @@ module Layouts
6 6
 
7 7
     # Base controller for these tests
8 8
     class Base < AbstractController::Base
9  
-      include AbstractController::Renderer
  9
+      include AbstractController::RenderingController
10 10
       include AbstractController::Layouts
11 11
 
12 12
       self.view_paths = [ActionView::FixtureResolver.new(
22  actionpack/test/controller/mime_responds_test.rb
@@ -501,8 +501,13 @@ def using_resource_with_parent
501 501
     respond_with([Quiz::Store.new("developer?", 11), Customer.new("david", 13)])
502 502
   end
503 503
 
504  
-  def using_resource_with_location
505  
-    respond_with(Customer.new("david", 13), :location => "http://test.host/")
  504
+  def using_resource_with_status_and_location
  505
+    respond_with(Customer.new("david", 13), :location => "http://test.host/", :status => :created)
  506
+  end
  507
+
  508
+  def using_resource_with_renderer
  509
+    renderer = proc { |c, r, o| c.render :text => "Resource name is #{r.name}" }
  510
+    respond_with(Customer.new("david", 13), :renderer => renderer)
506 511
   end
507 512
 
508 513
 protected
@@ -727,11 +732,20 @@ def test_no_double_render_is_raised
727 732
     end
728 733
   end
729 734
 
730  
-  def test_using_resource_with_location
  735
+  def test_using_resource_with_status_and_location
731 736
     @request.accept = "text/html"
732  
-    post :using_resource_with_location
  737
+    post :using_resource_with_status_and_location
733 738
     assert @response.redirect?
734 739
     assert_equal "http://test.host/", @response.location
  740
+
  741
+    @request.accept = "application/xml"
  742
+    get :using_resource_with_status_and_location
  743
+    assert_equal 201, @response.status
  744
+  end
  745
+
  746
+  def test_using_resource_with_renderer
  747
+    get :using_resource_with_renderer
  748
+    assert_equal "Resource name is david", @response.body
735 749
   end
736 750
 
737 751
   def test_not_acceptable

0 notes on commit aed135d

Please sign in to comment.
Something went wrong with that request. Please try again.