<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>spec/controllers/default_rails_behaviour_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/inherited_controllers_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/no_response_if_performed_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/pick_template_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/remove_response_for_spec.rb</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/inherited</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/respond_to_block</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/respond_to_types</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/response_for_block</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/response_for_mix_of_block_and_types</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/response_for_types</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/template_only/an_action.atom.erb</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/template_only/an_action.html.erb</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/template_only/an_action.js.erb</filename>
    </added>
    <added>
      <filename>spec/fixtures/views/pick_template_spec/template_only/an_action.xml.erb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,4 @@
+.DS_Store
 doc/*
 garlic
 garlic.rb</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -1,50 +1,149 @@
 
-BackToFooController
-- get :foo, :format =&gt; 'xml' should not render foo
-
-FooBailOutController
-- get :foo, :bail_out =&gt; true should redirect
-
-FooController
-- get :foo should render text/html: foo
-- get :foo should assign @foo
-- get :foo, :format =&gt; 'html' should render foo
-- get :foo, :format =&gt; 'xml' should not render foo
-
-FooAController
-- get :foo should call a
-- get :baz should call bazza (inside the response_for block)
-
-FooBController
-- get :foo should call b
-
-InlineXmlFooController
-- get :foo should assign @foo
-- get :foo, :format =&gt; 'html' should render 'foo'
-- get :foo, :format =&gt; 'xml' should call xml_call with 'foo
-- get :foo, :format =&gt; 'xml' should have response.body of 'XML'
-
-XmlFooController
-- get :foo should render foo
-- get :foo should assign @foo
-- get :foo, :format =&gt; 'html' should render foo
-- get :foo, :format =&gt; 'xml' should render foo
-- get :bar, :format =&gt; 'xml' should render bar
-
-XmlOnlyFooController
-- get :foo should render xml: foo
-- get :bar should render xml: bar
-- get :foo should assign @foo
-- get :foo, :format =&gt; 'html' should not render foo
-- get :foo, :format =&gt; 'xml' should render foo
-
-class method #action_responses
-- @child.action_responses[:action] should be copy of parent's action response for :action
-- @grandchild.action_responses[:action] should be copy of @child.action_responses[:action]
-- @child.action_responses[:action] not be same object as parent's action response for :action
-- @grandchild.action_responses[:action] not be same object as @child.action_responses[:action]
-- adding to @grandchild.action_responses[:action] should not change parents
-
-Finished in 0.328216 seconds
-
-28 examples, 0 failures
+DefaultRailsBehaviourSpec::TheController GET :two_respond_tos
+- should recieve first and second in order
+
+DefaultRailsBehaviourSpec::TheController GET :two_responses
+- should only receive first and NOT second
+
+action_responses
+- SuperController.action_responses should not == SubController.action_responses
+- SuperController should have one action_response for 'a_response'
+- SubController should have two action_responses for 'a_response', and one each for 'an_action', and 'performing_action'
+
+InheritedControllerSpec::SuperController GET :an_action
+- should execute action
+- should render :an_action
+
+InheritedControllerSpec::SuperController GET :a_response
+- should execute inside the super response block
+- should NOT execute inside the sub response block
+
+InheritedControllerSpec::SuperController GET :performing_action
+- should redirect
+
+InheritedControllerSpec::SubController GET :an_action (decorated with redirecting response_for)
+- should execute action
+- should redirect
+
+InheritedControllerSpec::SubController GET :a_response (decorated with a new response)
+- should NOT execute the super response
+- should execute the sub response
+
+InheritedControllerSpec::SubController GET :performing_action
+- should NOT execute the sub response
+- should redirect as per the super def
+
+NoResponseIfPerformedSpec::TheController when before_filter redirects, GET :an_action
+- should redirect to 'http://redirected.from.before_filter'
+- should not execute inside response_for
+
+NoResponseIfPerformedSpec::TheController when before_filter doesn't redirect, GET :an_action
+- should execute inside response for
+- should render :an_action
+
+Picking template PickTemplateSpec::TemplateOnlyController GET :an_action, HTTP_ACCEPT =
+- text/html, should render an_action.html
+- application/xml, should IGNORE and render an_action.html
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::RespondToTypesController
+- GET :an_action, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::RespondToTypesController GET :an_action, HTTP_ACCEPT =
+- text/html, should render an_action.html
+- application/xml, should render an_action.xml
+- text/javascript, should render an_action.js
+- application/atom+xml, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::RespondToTypesController GET :an_action, :format =&gt;
+- :html, should render an_action.html
+- :js, should render an_action.js
+- :xml, should render an_action.xml
+- :atom, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::RespondToBlockController
+- GET :an_action, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::RespondToBlockController GET :an_action, HTTP_ACCEPT =
+- text/html, should render an_action.html
+- application/xml, should render an_action.xml
+- text/javascript, should render an_action.js
+- application/atom+xml, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::RespondToBlockController GET :an_action, :format =&gt;
+- :html, should render an_action.html
+- :js, should render an_action.js
+- :xml, should render an_action.xml
+- :atom, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForTypesController
+- GET :an_action, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForTypesController GET :an_action, HTTP_ACCEPT =
+- text/html, should render an_action.html
+- application/xml, should render an_action.xml
+- text/javascript, should render an_action.js
+- application/atom+xml, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForTypesController GET :an_action, :format =&gt;
+- :html, should render an_action.html
+- :js, should render an_action.js
+- :xml, should render an_action.xml
+- :atom, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForBlockController
+- GET :an_action, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForBlockController GET :an_action, HTTP_ACCEPT =
+- text/html, should render an_action.html
+- application/xml, should render an_action.xml
+- text/javascript, should render an_action.js
+- application/atom+xml, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForBlockController GET :an_action, :format =&gt;
+- :html, should render an_action.html
+- :js, should render an_action.js
+- :xml, should render an_action.xml
+- :atom, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForMixOfBlockAndTypesController
+- GET :an_action, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForMixOfBlockAndTypesController GET :an_action, HTTP_ACCEPT =
+- text/html, should render an_action.html
+- application/xml, should render an_action.xml
+- text/javascript, should render an_action.js
+- application/atom+xml, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::ResponseForMixOfBlockAndTypesController GET :an_action, :format =&gt;
+- :html, should render an_action.html
+- :js, should render an_action.js
+- :xml, should render an_action.xml
+- :atom, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::InheritedController
+- GET :an_action, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::InheritedController GET :an_action, HTTP_ACCEPT =
+- text/html, should render an_action.html
+- application/xml, should render an_action.xml
+- text/javascript, should render an_action.js
+- application/atom+xml, should render an_action.atom
+
+Picking template [:atom, :xml, :html, :js] PickTemplateSpec::InheritedController GET :an_action, :format =&gt;
+- :html, should render an_action.html
+- :js, should render an_action.js
+- :xml, should render an_action.xml
+- :atom, should render an_action.atom
+
+RemoveResponseForSpec::TheController
+- should have action_responses for :foo and :bar
+
+RemoveResponseForSpec::TheController.remove_response_for :bar
+- should hanve action_responses for :foo
+
+RemoveResponseForSpec::TheController.remove_response_for
+- should have empty action_responses
+
+Finished in 0.451715 seconds
+
+79 examples, 0 failures</diff>
      <filename>SPECDOC</filename>
    </modified>
    <modified>
      <diff>@@ -3,19 +3,21 @@ module Ardes #:nodoc:
     def self.included(base)
       base.class_eval do
         extend ClassMethods
-        alias_method_chain :run_before_filters, :response_for
-        alias_method_chain :respond_to, :response_for
-        alias_method_chain :render, :response_for
-        alias_method_chain :erase_render_results, :response_for
+        alias_method_chain :default_render, :response_for
       end
     end
     
     module ClassMethods
-      # response_for allows you to decorate your actions with small respond_to
-      # chunks.
-      # 
-      # One use for this is with subclassed controllers, so you don't have to rewrite the entire action.
+      # response_for allows you to specify a default response for your actions that don't specify a
+      # respond_to block.
       # 
+      # Using response_for, you may keep the response logic out of the action, so that it can be overriden easily
+      # without having to rewrite the entire action.  This is very useful when subclassing controllers.
+      #
+      # == Usage
+      #
+      #   response_for :action1 [, :action2], [,:types =&gt; [:mime, :type, :list]] [ do |format| ... end] # or
+      #   response_for :action1 [, :action2], [,:type =&gt; :mime_type] [ do |format| ... end]
       #
       # === Example
       #
@@ -39,134 +41,107 @@ module Ardes #:nodoc:
       #     response_for :index, :show, :types =&gt; [:html, :xml, :js]
       #   end
       #
-      # === Important
-      # If you want to make sure that no repsonse_for can override your repsond_to
-      # block, then use respond_to_without_response_for
-      #
-      # An example of this would be when you want to redirect on html in a 
-      # before_filterl, and you definitely don't want response_for to override that
+      # === respond_to takes precedence
       # 
-      # === Usage
+      # If you write your action with a respond_to block, response_for will never be invoked for that action.
+      # If you want to write a controller so that its subclasses can use response_for then do this:
       #
-      #   response_for :action1 [, :action2], [,:types =&gt; [:mime, :type, :list]] [,:replace =&gt; &lt;boolean&gt;] [ do |format| ... end]
+      #   # before
+      #   def show
+      #     @thing = Thing.find(params[:id])
+      #     respond_to do |format|
+      #       format.html { }
+      #       format.xml  { render :xml =&gt; @thing }
+      #     end
+      #   end
+      # 
+      #   # after
+      #   def show
+      #     @thing = Thing.find(params[:id])
+      #   end
       #
-      # For example:
+      #   response_for :show do |format|
+      #     format.html { }
+      #     format.xml  { render :xml =&gt; @thing }
+      #   end
+      # 
+      # === Other examples 
       #
       #   response_for :index, :types =&gt; [:fbml]    # index will respond to fbml and try to render, say, index.fbml.builder
       #
       #   response_for :update do |format|          # this example is for a resources_controller controller
-      #     if resource.valid?
+      #     if !(resource.new_record? || resource.changed?) # =&gt; resource.saved?
       #       format.js { render(:update) {|page| page.replace(dom_id(resource), :partial =&gt; resource}}
       #     else
       #       format.js { render(:update) {|page| page.visual_effect :shake, dom_id(resource) }}
       #     end
       #   end
       #
-      #   response_for :index, :replace =&gt; true do |format|   # will ignore index's current respond_to block, and use the following
-      #     format.xml
-      #     format.js
-      #   end
-      #
       # === Notes
       #
-      # * You don't need to have a respond_to block in the action for response_for to work
-      # * You can stack up multiple response_for calls, the most recent has precedence
+      # * If the before_filters or action renders or redirects, then response_for will not be invoked
+      # * you can stack up multiple response_for calls, the most recent has precedence
       # * the specifed block is executed within the controller instance, so you can use controller
-      #   instance methods are instance variables (i.e. you can make it look just like a regular
+      #   instance methods and instance variables (i.e. you can make it look just like a regular
       #   respond_to block)
       # * you can add a response_for an action that is just a public template (where there is no
       #   actual action method defined)
       # * you can combine the :types option with a block, the block has precedence if you specify the
       #   same mime type in both.
       def response_for(*actions, &amp;block)
-        options = actions.extract_options!
-        options.assert_valid_keys(:replace, :types)
+        (options = actions.extract_options!).assert_valid_keys(:types)
         
-        types = (options[:types] &amp;&amp; proc{|r| options[:types].each {|t| r.send(t)}}) || nil
+        types_block = if options[:types]
+          proc {|responder| Array(options[:types]).each {|type| responder.send type}}
+        end
         
+        # store responses against action names
         actions.collect(&amp;:to_s).each do |action|
-          if options[:replace]
-            action_responses[action] = []
-            respond_to_replaced[action] = true
-          else
-            action_responses[action] ||= []
-          end
-          action_responses[action] &lt;&lt; types if types
-          action_responses[action] &lt;&lt; block if block_given?
+          action_responses[action] ||= []
+          action_responses[action].unshift types_block if types_block
+          action_responses[action].unshift block if block
+          
+          # if there's no action yet defined, create a stub - this is so that you
+          # can provide responses for actions which are simply templates, or simply define responses
+          class_eval &quot;def #{action}; end&quot; unless instance_methods.include?(action)
         end
       end
-      
-      # Removes any response_for for the supplied action names.
-      # This will not remove any respond_to block that is defined in the action itself
+    
+      # remove any response for the specified actions.  If no arguments are given, the
+      # entire all repsonses for all actions are removed
       def remove_response_for(*actions)
-        actions.collect(&amp;:to_s).each {|action| respond_to_replaced[action] = action_responses[action] = nil}
+        if actions.empty?
+          instance_variable_set('@action_responses', nil)
+        else
+          actions.each {|action| action_responses.delete(action.to_s)}
+        end
       end
-    
-    protected
-      # return action_responses Hash. On initialize, return a hash whose contents are duplicates
-      # of the superclass's action_responses.
+      
+      # return action_responses Hash. On initialize, set and return hash whose values are copies of superclass action_responses, if any
       def action_responses
-        instance_variable_get('@action_responses') or
-          instance_variable_set('@action_responses', (superclass.action_responses.inject({}) {|m,(k,v)| m.merge(k =&gt; v.dup)} rescue {}))
+        instance_variable_get('@action_responses') || instance_variable_set('@action_responses', copy_of_each_of_superclass_action_responses)
       end
       
-      # hash of actions where the respond_to blcok has been replaced
-      def respond_to_replaced
-        read_inheritable_attribute(:respond_to_replaced) || write_inheritable_attribute(:respond_to_replaced, {})
+    private
+      def copy_of_each_of_superclass_action_responses
+        (superclass.action_responses rescue {}).inject({}){|m,(k,v)| m.merge(k =&gt; v.dup)}
       end
     end
-  
-  protected
-    # we only want response_for to trigger once we've got to the performing action stage
-    # otherwise respond_to in before filters will act unpredictably
-    def run_before_filters_with_response_for(*args)
-      @running_before_filters = true
-      run_before_filters_without_response_for(*args)
-    ensure
-      @running_before_filters = nil
-    end
     
-    # if you want to ignore any response_for blocks, and gain exclusive respond_to
-    # control, pass :exclusive =&gt; true
-    #
-    #   respond_to :exclusive =&gt; true do |format|
-    #
-    # But, also see ClassMethods#remove_response_for
-    def respond_to_with_response_for(*types, &amp;block)
-      options = types.extract_options!
-      return respond_to_without_response_for(*types, &amp;block) if options[:exclusive] || @running_before_filters
-      
-      respond_to_without_response_for do |responder|
-        if action_blocks = self.class.send(:action_responses)[action_name]
-          action_blocks.reverse.each {|b| instance_exec(responder, &amp;b)}
-        end
-        unless self.class.send(:respond_to_replaced)[action_name]
-          types.each {|type| responder.send(type)}
-          block.call(responder) if block
+  protected
+    def respond_to_action_responses
+      if (responses = self.class.action_responses[action_name]) &amp;&amp; responses.any?
+        respond_to do |responder|
+          responses.each do |response|
+            instance_exec(responder, &amp;response)
+          end
         end
       end
-    ensure
-      @performed_respond_to = true
     end
     
-    # removes the @performed_respond_to along with the standard erase_render_results call
-    def erase_render_results_with_response_for
-      @performed_respond_to = false
-      erase_render_results_without_response_for
-    end
-    
-    # Adds a hook for when render is called without arguments or a block.
-    # Prior to rendering, call respond_to if there is a response_for, and 
-    # if respond_to has not yet been performed.
-    #
-    # This allows actions without an explicit respond_to block to be decorated
-    # with response_for
-    def render_with_response_for(*args, &amp;block)
-      if !instance_variable_get('@performed_respond_to') &amp;&amp; self.class.send(:action_responses)[action_name] &amp;&amp; !block_given? &amp;&amp; args.reject{|a| a.nil? || a.empty?}.empty?
-        respond_to
-        return if performed?
-      end
-      render_without_response_for(*args, &amp;block)
+    def default_render_with_response_for
+      respond_to_action_responses
+      default_render_without_response_for unless performed?
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/ardes/response_for.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>spec/app.rb</filename>
    </removed>
    <removed>
      <filename>spec/controllers/back_to_foo_controller_spec.rb</filename>
    </removed>
    <removed>
      <filename>spec/controllers/foo_bail_out_controller_spec.rb</filename>
    </removed>
    <removed>
      <filename>spec/controllers/foo_controller_spec.rb</filename>
    </removed>
    <removed>
      <filename>spec/controllers/inerited_controllers_spec.rb</filename>
    </removed>
    <removed>
      <filename>spec/controllers/inline_xml_foo_controller_spec.rb</filename>
    </removed>
    <removed>
      <filename>spec/controllers/xml_foo_controller_spec.rb</filename>
    </removed>
    <removed>
      <filename>spec/controllers/xml_only_foo_controller_spec.rb</filename>
    </removed>
    <removed>
      <filename>spec/specs/action_responses_spec.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>64e4e9efdb54187596c34d2b877544faa292ea0a</id>
    </parent>
  </parents>
  <author>
    <name>Ian White</name>
    <email>ian.w.white@gmail.com</email>
  </author>
  <url>http://github.com/ianwhite/response_for/commit/3b1ae5e4eecda3b200177a804eeae3f9d5ba10ab</url>
  <id>3b1ae5e4eecda3b200177a804eeae3f9d5ba10ab</id>
  <committed-date>2008-09-13T19:48:13-07:00</committed-date>
  <authored-date>2008-09-13T19:48:13-07:00</authored-date>
  <message>API change and rewrite.  Vastly simplified and consistent internals.  response_for can now be summed up as this 'adds a default respond_to to your actions which dont render or redirect'</message>
  <tree>a5f99c0f75ef7d51c7a63b0c7633fa1c50e3bb4f</tree>
  <committer>
    <name>Ian White</name>
    <email>ian.w.white@gmail.com</email>
  </committer>
</commit>
