<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -18,6 +18,36 @@ To use it as a GemPlugin, add it to your environment.rb:
 
   config.gem 'mbleigh-subdomain-fu', :source =&gt; &quot;http://gems.github.com&quot;, :lib =&gt; &quot;subdomain-fu&quot;
 
+
+Examples
+========
+
+SubdomainFu works inside of Rails's URL Writing mechanisms to provide an easy and seamless
+way to link and otherwise understand cross-subdomain routing. You can use the :subdomain
+option both in named and non-named routes as well as in generated resources routes.
+
+Let's say my domain is 'intridea.com'. Here are some examples of the use of the :subdomain
+option:
+
+url_for(:controller =&gt; &quot;my_controller&quot;, 
+        :action =&gt; &quot;my_action&quot;, 
+        :subdomain =&gt; &quot;awesome&quot;) # =&gt; http://awesome.intridea.com/my_controller/my_action
+
+Now let's say I'm at http://awesome.intridea.com/ and I want back to the root.
+Specifying &quot;false&quot; will remove any current subdomain:
+
+users_url(:subdomain =&gt; false)  # =&gt; http://intridea.com/users
+
+Note that this plugin does not honor the :only_path notion of routing when doing
+so would go against the intent of the command. For example, if I were at http://intridea.com
+again:
+
+users_path(:subdomain =&gt; &quot;fun&quot;) # =&gt; http://fun.intridea.com/users
+users_path(:subdomain =&gt; false) # =&gt; /users
+                              
+In this way you can rest assured that you will never misdirect your links to the
+same subdomain when you meant to change it.
+
 Configuration
 =============
 
@@ -43,22 +73,30 @@ the usage of the root domain.
 
 SubdomainFu.mirrors = %w(www site we) # Defaults to %w(www)
 
-Examples
-========
+preferred_mirror
+----------------
+
+SubdomainFu also understands the notion of a 'preferred mirror', that is, if you
+always want your links going to 'www.yourdomain.com' instead of 'yourdomain.com',
+you can set the preferred mirror like so:
+
+SubdomainFu.preferred_mirror = &quot;www&quot;
+
+Now when you create a link to a false subdomain
 
-SubdomainFu works in both the URL writing parts of Rails and the routes. For
-URL writing, it provides you an option you can pass into any URL-generating
-call to use (or lose) a subdomain:
+Known Issues / Future Work
+==========================
 
-url_for(:controller =&gt; &quot;my_controller&quot;, :action =&gt; &quot;my_action&quot;, :subdomain =&gt; &quot;awesome&quot;)
-users_url(:subdomain =&gt; false) # specifying &quot;false&quot; will remove any current subdomain
+SubdomainFu will eventually integrate with Rails' routing internals to provide
+the ability to specify routes based on the condition of a specific subdomain or
+simply whether a subdomain is present (or a mirror).
 
-Known Issues / TODO
-===================
+Resources
+=========
 
-* TODO: Implement route conditions that require either a subdomain or no subdomain
-* TODO: Spec out URL Rewriting more completely, test with different domain levels etc.
-* TODO: Implement &quot;preferred_mirror&quot; to automatically use &quot;www&quot; for example if that's desired.
+* Acts As Community Project: http://actsascommunity.com/projects/subdomain-fu
+* GitHub Repository: http://github.com/mbleigh/subdomain-fu
+* Lighthouse: http://mbleigh.lighthouseapp.com/projects/13148-subdomain-fu
 
 Copyright (c) 2008 Michael Bleigh (http://www.mbleigh.com/) and 
 Intridea, Inc. (http://www.intridea.com/). Released under the MIT license
\ No newline at end of file</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-require 'subdomain_fu/routing_extensions'
+# require 'subdomain_fu/routing_extensions'
 require 'subdomain_fu/url_rewriter'
 
 module SubdomainFu
@@ -49,10 +49,17 @@ module SubdomainFu
   
   # Rewrites the subdomain of the host unless they are equivalent (i.e. mirrors of each other)
   def self.rewrite_host_for_subdomains(subdomain, host)
-    if same_subdomain?(subdomain, host)
-      host
+    unless needs_rewrite?(subdomain, host)
+      if has_subdomain?(subdomain) || (subdomain_from(host) == SubdomainFu.preferred_mirror) || (!has_subdomain?(subdomain) &amp;&amp; SubdomainFu.preferred_mirror == nil)
+        puts &quot;We're not changing the host.&quot;
+        host
+      else
+        puts &quot;We're using the preferred mirror.&quot;
+        change_subdomain_of_host(SubdomainFu.preferred_mirror, host)
+      end
     else
-      change_subdomain_of_host(subdomain, host)
+      puts &quot;We're changing the host.&quot;
+      change_subdomain_of_host(subdomain || SubdomainFu.preferred_mirror, host)
     end
   end
   
@@ -65,9 +72,15 @@ module SubdomainFu
   
   # Is this subdomain equivalent to the subdomain found in this host string?
   def self.same_subdomain?(subdomain, host)
-    result = subdomain == SubdomainFu.subdomain_from(host) || 
+    subdomain = nil unless subdomain
+    (subdomain == SubdomainFu.subdomain_from(host)) || 
       (!SubdomainFu.has_subdomain?(subdomain) &amp;&amp; !SubdomainFu.has_subdomain?(SubdomainFu.subdomain_from(host)))
-    result
+  end
+  
+  def self.needs_rewrite?(subdomain, host)
+    subdomain = nil if subdomain.blank? 
+    (!has_subdomain?(subdomain) &amp;&amp; subdomain != SubdomainFu.preferred_mirror &amp;&amp; SubdomainFu.preferred_mirror != nil) || 
+      !same_subdomain?(subdomain, host)
   end
   
   def self.current_subdomain(request)</diff>
      <filename>lib/subdomain-fu.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 # Thanks to Jamis Buck for ideas on this stuff
 # http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2
+# This is not yet a working part of SubdomainFu.
 
 module SubdomainFu
   module RouteExtensions</diff>
      <filename>lib/subdomain_fu/routing_extensions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 module ActionController
   module UrlWriter
     def url_for_with_subdomains(options)
-      if SubdomainFu.same_subdomain?(options[:subdomain], options[:host] || default_url_options[:host])
+      unless SubdomainFu.needs_rewrite?(options[:subdomain], options[:host] || default_url_options[:host])
         options.delete(:subdomain)
       else
         options[:only_path] = false 
@@ -16,7 +16,7 @@ module ActionController
     private
     
     def rewrite_url_with_subdomains(options)
-      if SubdomainFu.same_subdomain?(options[:subdomain], (options[:host] || @request.host_with_port))
+      unless SubdomainFu.needs_rewrite?(options[:subdomain], (options[:host] || @request.host_with_port))
         options.delete(:subdomain)
       else
         options[:only_path] = false</diff>
      <filename>lib/subdomain_fu/url_rewriter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -67,6 +67,27 @@ describe &quot;SubdomainFu URL Writing&quot; do
     end
   end
   
+  describe &quot;Preferred Mirror&quot; do
+    before do
+      SubdomainFu.preferred_mirror = &quot;www&quot;
+    end
+      
+    it &quot;should switch to the preferred mirror instead of no subdomain&quot; do
+      default_url_options[:host] = &quot;awesome.testapp.com&quot;
+      needs_subdomain_url(:subdomain =&gt; false).should == &quot;http://www.testapp.com/needs_subdomain&quot;
+    end
+    
+    it &quot;should force a switch to no subdomain on a mirror if preferred_mirror is false&quot; do
+      SubdomainFu.preferred_mirror = false
+      default_url_options[:host] = &quot;www.testapp.com&quot;
+      needs_subdomain_url(:subdomain =&gt; false).should == &quot;http://testapp.com/needs_subdomain&quot;
+    end
+    
+    after do
+      SubdomainFu.preferred_mirror = nil
+    end
+  end
+  
   after do
     SubdomainFu.tld_size = 0
     default_url_options[:host] = &quot;localhost&quot;</diff>
      <filename>spec/url_rewriter_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>fc8d2bc55ff4082de43f61259bc7113f6b467117</id>
    </parent>
  </parents>
  <author>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </author>
  <url>http://github.com/mbleigh/subdomain-fu/commit/64bef4cc9958da2c6d9686ca5b534298593d086d</url>
  <id>64bef4cc9958da2c6d9686ca5b534298593d086d</id>
  <committed-date>2008-06-20T13:03:29-07:00</committed-date>
  <authored-date>2008-06-20T13:03:29-07:00</authored-date>
  <message>Added Preferred Mirror, updated README in prep for plugin release.</message>
  <tree>85fd0d05aad14e01c614add6b300540a3230f796</tree>
  <committer>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </committer>
</commit>
