<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>SPECDOC</filename>
    </added>
    <added>
      <filename>spec/controllers/all_foo_removed_controller_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/back_to_foo_controller_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/default_respond_to_behaviour_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/foo_controller_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/foo_removed_controller_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/inline_xml_foo_controller_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/xml_foo_controller_spec.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/xml_only_foo_controller_spec.rb</filename>
    </added>
    <added>
      <filename>spec/specs/action_responses_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -0,0 +1 @@
+* initial release of response_for
\ No newline at end of file</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,30 @@ http://plugins.ardes.com &gt; response_for
 
 = response_for
 
+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
+
+=== Example
+
+  class FooController &lt; ApplicationController
+    def index
+      @foos = Foo.find(:all)
+    end
+    
+    def show
+      @foo = Foo.find(params[:id])
+    end
+  end
+  
+  # this controller needs to respond_to fbml on index, and
+  # js, html and xml (templates) on index and show
+  class SpecialFooController &lt; FooController
+    response_for :index do |format|
+      format.fbml { render :inline =&gt; turn_into_facebook(@foos) }
+    end
+    
+    response_for :index, :show, :types =&gt; [:html, :xml, :js]
+  end
+  
 === Specs and Coverage
 * {SPECDOC}[link:files/SPECDOC.html] lists the specifications
 * {RSpec Report}[link:rspec_report.html] is a report of spec pass/fails</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,152 @@
-module Ardes
+module Ardes #:nodoc:
   module ResponseFor
+    def self.included(base)
+      base.class_eval do
+        extend ClassMethods
+        alias_method_chain :respond_to, :response_for
+        alias_method_chain :render, :response_for
+        alias_method_chain :erase_render_results, :response_for
+      end
+    end
     
+    module ClassMethods
+      # response_for allows you to decorate your respond_to actions on sublcassed
+      # controllers, so you don't have to rewrite the entire action.
+      #
+      # === Example
+      #
+      #   class FooController &lt; ApplicationController
+      #     def index
+      #       @foos = Foo.find(:all)
+      #     end
+      #   
+      #     def show
+      #       @foo = Foo.find(params[:id])
+      #     end
+      #   end
+      #   
+      #   # this controller needs to respond_to fbml on index, and
+      #   # js, html and xml (templates) on index and show
+      #   class SpecialFooController &lt; FooController
+      #     response_for :index do |format|
+      #       format.fbml { render :inline =&gt; turn_into_facebook(@foos) }
+      #     end
+      #   
+      #     response_for :index, :show, :types =&gt; [:html, :xml, :js]
+      #   end
+      #
+      # === Usage
+      #
+      #   response_for :action1 [, :action2], [,:types =&gt; [:mime, :type, :list]] [,:replace =&gt; &lt;boolean&gt;] [ do |format| ... end]
+      #
+      # For example:
+      #
+      #   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?
+      #       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
+      # * 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
+      #   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)
+        
+        types = (options[:types] &amp;&amp; proc{|r| options[:types].each {|t| r.send(t)}}) || nil
+        
+        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?
+        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
+      def remove_response_for(*actions)
+        actions.collect(&amp;:to_s).each {|action| respond_to_replaced[action] = action_responses[action] = nil}
+      end
+      
+      # Convenience method for removing an action that is inherited by a superclass.
+      #
+      #   # we don't want :create and :destroy, but we want other stuff from FooController
+      #   class FazController &lt; FooController
+      #     remove_action :create, :destroy
+      #   end
+      def remove_action(*actions)
+        actions.each {|a| self.class_eval &quot;undef #{a}&quot;}
+      end
+    
+    protected
+      # return action_responses Hash. On initialize, return a hash whose contents are duplicates
+      # of the superclass's action_responses.
+      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 {}))
+      end
+      
+      def respond_to_replaced
+        read_inheritable_attribute(:respond_to_replaced) || write_inheritable_attribute(:respond_to_replaced, {})
+      end
+    end
+  
+  protected
+    def respond_to_with_response_for(*types, &amp;block)
+      instance_variable_set('@performed_respond_to', true)
+      respond_to_without_response_for do |responder|
+        unless self.class.send(:respond_to_replaced)[action_name]
+          types.each {|type| responder.send(type)}
+          block.call(responder) if block
+        end
+        if action_blocks = self.class.send(:action_responses)[action_name]
+          action_blocks.each {|b| instance_exec(responder, &amp;b)}
+        end
+      end
+    end
+    
+    # removes the @performed_respond_to along with the standard erase_render_results call
+    def erase_render_results_with_response_for
+      instance_variable_set('@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; !block_given? &amp;&amp; args.reject(&amp;:nil?) == [] &amp;&amp; self.class.send(:action_responses)[action_name]
+        respond_to
+        return if performed?
+      end
+      render_without_response_for(*args, &amp;block)
+    end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/ardes/response_for.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-class FooBarController &lt; ApplicationController
+class FooController &lt; ApplicationController
   def foo
     @foo = &quot;Foo&quot;
     respond_to do |format|
@@ -6,41 +6,40 @@ class FooBarController &lt; ApplicationController
     end
   end
   
+  # testing that erase_render_results works as expected
   def bar
-    @bar = &quot;Bar&quot;
+    respond_to(:json)
+    erase_render_results
   end
 end
 
-class XmlFooBarController &lt; FooBarController
-  response_for :foo, :bar do |format|
-    format.xml {}
-  end
-end
-
-class XmlOnlyFooBarController &lt; FooBarController
-  response_for :foo, :bar, :replace =&gt; true do |format|
-    format.xml {}
-  end
+class XmlFooController &lt; FooController
+  response_for :just_a_template, :foo, :bar, :types =&gt; [:xml]
 end
 
-class XmlAndMoreFooBarController &lt; XmlFooBarController
+class InlineXmlFooController &lt; FooController
   response_for :foo do |format|
-    format.rjs do 
-      render :update do |page|
-        page.replace_html 'foo', 'Foo'
-      end
+    format.xml do
+      render :inline =&gt; xml_call(action_name) # to be stubbed in specs
     end
   end
-  
-  response_for :bar do |format|
-    format.html { render :action =&gt; 'more_bar' }
-  end
 end
 
-class FooRemovedController &lt; FooBarController
+class XmlOnlyFooController &lt; FooController
+  response_for :foo, :bar, :types =&gt; [:xml], :replace =&gt; true
+end
+
+class BackToFooController &lt; XmlFooController
+  remove_response_for :foo, :bar
+end
+
+class FooRemovedController &lt; FooController
   remove_action :foo
+  
+  def foo2; end
+  def foo3; end
 end
 
-class FooBarRemovedController &lt; FooBarController
-  remove_action :foo, :bar
+class AllFooRemovedController &lt; FooRemovedController
+  remove_action :foo2, :foo3
 end
\ No newline at end of file</diff>
      <filename>spec/app.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>spec/controllers/xml_foo_bar_controller_spec.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>f0b98bf1938e3a3905d432f636865869d18c40e1</id>
    </parent>
  </parents>
  <author>
    <name>ian</name>
    <email>ian@845bbffb-5c18-0410-91b3-f25c072b94c1</email>
  </author>
  <url>http://github.com/ianwhite/response_for/commit/570f798d210f0bf6b129811de2d75df1f2739d04</url>
  <id>570f798d210f0bf6b129811de2d75df1f2739d04</id>
  <committed-date>2007-10-23T06:09:53-07:00</committed-date>
  <authored-date>2007-10-23T06:09:53-07:00</authored-date>
  <message>response_for: initial release

git-svn-id: https://svn.ardes.com/rails_plugins/response_for@456 845bbffb-5c18-0410-91b3-f25c072b94c1</message>
  <tree>3aeefc3bbbb8e5a17b90f3c3333c433b7c603492</tree>
  <committer>
    <name>ian</name>
    <email>ian@845bbffb-5c18-0410-91b3-f25c072b94c1</email>
  </committer>
</commit>
