public
Description: response for lets you decorate your actions respond_to blocks
Homepage: http://blog.ardes.com/response_for
Clone URL: git://github.com/ianwhite/response_for.git
Click here to lend your support to: response_for and make a donation at www.pledgie.com !
Final notes and docfixes for 0.2.0 release.  This is the 0.2.0 release
ianwhite (author)
Sat Sep 13 20:40:54 -0700 2008
commit  9dc94651a1ca42721e95af36728cdf8366156eca
tree    c0ffd3fb3ac96617cde4eb5f2b81d966aea105f6
parent  37e2d2edda0f2d1bad8571ea21573895c2ad1dd6
...
2
3
4
5
 
6
7
 
8
9
 
 
 
 
 
10
11
12
...
36
37
38
39
40
41
42
...
2
3
4
 
5
6
 
7
8
 
9
10
11
12
13
14
15
16
...
40
41
42
 
43
44
45
0
@@ -2,11 +2,15 @@
0
 
0
 response_for (see Ardes::ResponseFor::ClassMethods) allows you to decorate the respond_to block of actions on sublcassed controllers.  This works nicely with http://plugins.ardes.com/doc/resources_controller
0
 
0
-== Version 0.2
0
+== Current Version 0.2-stable
0
 
0
-Version 0.2 of response_for has BC-breaking API changes, has vastly simplified internals, and is supported only for Rails >= 2.1.x.
0
+Version 0.2-stable of response_for has BC-breaking API changes, has vastly simplified internals, and is supported only for Rails >= 2.1.x.
0
 
0
-Version 0.2 was released on Sept 14th 2008.
0
+Version 0.2.0 was released on Sept 14th 2008.
0
+
0
+As of version 0.2.0, response_for's functionality can be summed up in one sentence:
0
+
0
+"response_for allows you to specify default responses for any action (or before filter) that doesn't render or redirect"
0
 
0
 == Version 0.1
0
 
0
@@ -36,7 +40,6 @@ using rails >= 2.1 then use the 0.1-stable branch
0
     
0
     response_for :index, :show, :types => [:html, :xml, :js]
0
   end
0
-  
0
 
0
 === Specs and Coverage
0
 
...
17
18
19
20
21
22
23
...
41
42
43
44
 
45
46
47
48
49
50
51
52
53
54
55
56
 
57
58
59
60
61
62
63
64
65
66
 
 
 
67
68
69
...
101
102
103
104
105
 
 
106
107
108
109
110
111
 
 
112
113
114
...
129
130
131
 
132
133
134
...
139
140
141
 
 
142
143
144
...
17
18
19
 
20
21
22
...
40
41
42
 
43
44
 
 
 
 
 
 
 
 
 
 
 
45
46
 
 
 
 
 
 
 
 
 
47
48
49
50
51
52
...
84
85
86
 
 
87
88
89
90
91
92
 
 
93
94
95
96
97
...
112
113
114
115
116
117
118
...
123
124
125
126
127
128
129
130
0
@@ -17,7 +17,6 @@ module Ardes #:nodoc:
0
       # == Usage
0
       #
0
       #   response_for :action1 [, :action2], [,:types => [:mime, :type, :list]] [ do |format| ... end] # or
0
-      #   response_for :action1 [, :action2], [,:type => :mime_type] [ do |format| ... end]
0
       #
0
       # === Example
0
       #
0
@@ -41,29 +40,13 @@ module Ardes #:nodoc:
0
       #     response_for :index, :show, :types => [:html, :xml, :js]
0
       #   end
0
       #
0
-      # === respond_to takes precedence
0
+      # === when response_for kicks in
0
       # 
0
-      # If you write your action with a respond_to block, response_for will never be invoked for that action.
0
-      # If you want to write a controller so that its subclasses can use response_for then do this:
0
-      #
0
-      #   # before
0
-      #   def show
0
-      #     @thing = Thing.find(params[:id])
0
-      #     respond_to do |format|
0
-      #       format.html { }
0
-      #       format.xml  { render :xml => @thing }
0
-      #     end
0
-      #   end
0
+      # response_for only kicks in if the action (or any filters) have not already redirected or rendered.
0
       # 
0
-      #   # after
0
-      #   def show
0
-      #     @thing = Thing.find(params[:id])
0
-      #   end
0
-      #
0
-      #   response_for :show do |format|
0
-      #     format.html { }
0
-      #     format.xml  { render :xml => @thing }
0
-      #   end
0
+      # This means that if you foresee wanting to override your action's responses, you should write them without
0
+      # a respond_to block, but with a response_for block (the latter can be overridden by subsequent response_fors, the 
0
+      # former cannot)
0
       # 
0
       # === Other examples 
0
       #
0
@@ -101,14 +84,14 @@ module Ardes #:nodoc:
0
           action_responses[action].unshift types_block if types_block
0
           action_responses[action].unshift block if block
0
           
0
-          # if there's no action yet defined, create a stub - this is so that you
0
-          # can provide responses for actions which are simply templates, or simply define responses
0
+          # if there's no action yet defined, create an empty one - this is so that you
0
+          # we may provide responses for templates
0
           class_eval "def #{action}; end" unless instance_methods.include?(action)
0
         end
0
       end
0
     
0
-      # remove any response for the specified actions.  If no arguments are given, the
0
-      # entire all repsonses for all actions are removed
0
+      # remove any response for the specified actions.  If no arguments are given,
0
+      # then all repsonses for all actions are removed
0
       def remove_response_for(*actions)
0
         if actions.empty?
0
           instance_variable_set('@action_responses', nil)
0
@@ -129,6 +112,7 @@ module Ardes #:nodoc:
0
     end
0
     
0
   protected
0
+    # if there are responses for the current action, then respond_to them
0
     def respond_to_action_responses
0
       if (responses = self.class.action_responses[action_name]) && responses.any?
0
         respond_to do |responder|
0
@@ -139,6 +123,8 @@ module Ardes #:nodoc:
0
       end
0
     end
0
     
0
+    # this method is invoked if we've got to the end of an action without
0
+    # performing, which is when we respond_to any repsonses defined 
0
     def default_render_with_response_for
0
       respond_to_action_responses
0
       default_render_without_response_for unless performed?

Comments