<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>.gitignore</filename>
    </added>
    <added>
      <filename>spec/helper/mock_filter.rb</filename>
    </added>
    <added>
      <filename>spec/helper/spec_helper.rb</filename>
    </added>
    <added>
      <filename>spec/locale_filter_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -61,7 +61,7 @@ at the beginning of an URL in a way so that
 a concise manner (i.e. without specifying all parameters again and again)
 * ideally also plays nicely with default route helpers in tests/specs
 
-You can read about this struggle and to possible, yet unsatisfying solutions
+You can read about this struggle and two possible, yet unsatisfying solutions
 [here](http://www.artweb-design.de/2007/5/13/concise-localized-rails-url-helpers-solved-twice).
 The conclusion so far is that Rails itself does not provide the tools to solve
 this problem in a clean and dry way.
@@ -76,27 +76,28 @@ map URL paths to a nested tree of models like so:
       + api
       + wiki
   
-E.g. the docs section should map to the path /docs, the api section to 
-the path /docs/api and so on. Furthermore, after these paths need to be 
-more things to be specified. E.g. the wiki needs define a usual Rails resource
-like /docs/wiki/pages/1/edit.
+E.g. the docs section should map to the path `/docs`, the api section to 
+the path `/docs/api` and so on. Furthermore, after these paths there need to be 
+more things to be specified. E.g. the wiki needs to define a whole Rails 
+resource with URLs like `/docs/wiki/pages/1/edit`.
 
 The only way to solve this problem with Rails' routing toolkit is to map
-a bold /*whatever catch-all (&quot;glob&quot;) and process the whole path in a custom
-dispatcher.
+a big, bold `/*everything` catch-all (&quot;globbing&quot;) route and process the whole 
+path in a custom dispatcher.
 
 This, of course, is a really unsatisfying solution because one has to
-reimplement everything that Rails routes are here to help with, both with
-regards to URL recognition (like parameter mappings, resources, ...) and
-generation (url\_helpers don't work).
+reimplement everything that Rails routes are here to help with: regarding both 
+URL recognition (like parameter mappings, resources, ...) and generation 
+(url\_helpers).
 
 ## Solution
 
-This plugin offers a solution that takes exactly the opposite route. Instead
-of trying to change things *between* the URL recognition and generation stages
-to achieve the desired result it *wraps around* the whole routing system and
-allows to filter both what goes into it (URL recognition) and what comes out
-of it (URL generation). 
+This plugin offers a solution that takes exactly the opposite route. 
+
+Instead of trying to change things *between* the URL recognition and
+generation stages to achieve the desired result it *wraps around* the whole
+routing system and allows to pre- and post-filter both what goes into it 
+(URL recognition) and what comes out of it (URL generation).
 
 This way we can leave *everything* else completely untouched. 
 </diff>
      <filename>README.markdown</filename>
    </modified>
    <modified>
      <diff>@@ -1,36 +1,70 @@
-module RoutingFilter; end # make dependencies happy
+module RoutingFilter
+  mattr_accessor :active
+  @@active = true
+  
+  class &lt;&lt; self
+    def around_recognition(route, path, env)
+      return route.recognize_path_without_filtering(path, env) unless RoutingFilter.active
+      path = path.dup
+      chain = [lambda{ route.recognize_path_without_filtering(path, env) }]
+      ActionController::Routing::Routes.filters.each do |filter|
+        chain.unshift lambda{
+          filter.around_recognition(route, path, env, &amp;chain.shift)
+        }
+      end
+      chain.shift.call
+    end
+  
+    def around_generation(controller, *args)
+      return controller.url_for_without_filtering(*args) unless RoutingFilter.active
+      chain = [lambda{ controller.url_for_without_filtering(*args) }]
+      ActionController::Routing::Routes.filters.each do |filter|
+        chain.unshift lambda{
+          filter.around_generation(controller, *args, &amp;chain.shift)
+        }
+      end
+      chain.shift.call *args
+    end
+  
+    def around_generation_optimized(controller, result, *args)
+      return result unless RoutingFilter.active
+      chain = [lambda{ result }]
+      ActionController::Routing::Routes.filters.each do |filter|
+        chain.unshift lambda{
+          filter.around_generation(controller, *args, &amp;chain.shift)
+        }
+      end
+      chain.shift.call
+    end
+  end
+end
 
 # allows to install a filter to the route set by calling: map.filter 'locale'
 ActionController::Routing::RouteSet::Mapper.class_eval do
   def filter(name, options = {})
     klass = &quot;RoutingFilter::#{name.to_s.camelize}&quot;.constantize
-    @set.filters ||= []
     @set.filters.push klass.new(options)
   end
 end
 
 # hook into url_for and call before and after filters
 ActionController::Base.class_eval do
-  def url_for_with_filtering(options = nil)
-    ActionController::Routing::Routes.filter_generate self, :before, options
-    returning url_for_without_filtering(options) do |result|
-      ActionController::Routing::Routes.filter_generate self, :after, result, options
-    end
+  def url_for_with_filtering(*args)
+    RoutingFilter.around_generation(self, *args)
   end
   alias_method_chain :url_for, :filtering
 end
 
 # same here for the optimized url generation in named routes
-ActionController::Routing::RouteSet::NamedRouteCollection.class_eval do  
+ActionController::Routing::RouteSet::NamedRouteCollection.class_eval do
   # gosh. monkey engineering optimization code
   def generate_optimisation_block_with_filtering(*args)
     code = generate_optimisation_block_without_filtering *args
     if match = code.match(%r(^return (.*) if (.*)))
       &lt;&lt;-code
         if #{match[2]}
-          ActionController::Routing::Routes.filter_generate self, :before, *args
           result = #{match[1]}
-          ActionController::Routing::Routes.filter_generate self, :after, result, *args
+          RoutingFilter.around_generation_optimized self, result, *args
           return result
         end
       code
@@ -39,44 +73,30 @@ ActionController::Routing::RouteSet::NamedRouteCollection.class_eval do
   alias_method_chain :generate_optimisation_block, :filtering
 end
 
-ActionController::Routing::RouteSet.class_eval do  
+ActionController::Routing::RouteSet.class_eval do
   # allow to register filters to the route set
   def filters
     @filters ||= []
   end
-  
-  # call filter stage (:before or :after) with the passed args
-  def filter_generate(base, stage, *args)
-    filters.each do |filter|
-      filter.send :&quot;#{stage}_generate&quot;, base, *args if filter.respond_to? :&quot;#{stage}_generate&quot;
-    end
-  end
-  
+
   # wrap recognition filters around recognize_path
   def recognize_path_with_filtering(path, env)
-    path = path.dup
-    chain = [lambda{|path, env| recognize_path_without_filtering(path, env) }]
-    filters.each do |filter|
-      chain.unshift lambda{|path, env|
-        filter.around_recognition(self, path, env, &amp;chain.shift)
-      }
-    end
-    chain.shift.call path, env
+    RoutingFilter.around_recognition(self, path, env)
   end
   alias_method_chain :recognize_path, :filtering
 
   # add some useful information to the request environment
   # right, this is from jamis buck's excellent article about routes internals
   # http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2
-  # TODO move this ... where?  
+  # TODO move this ... where?
   alias_method :extract_request_environment_without_host, :extract_request_environment unless method_defined? :extract_request_environment_without_host
   def extract_request_environment(request)
     returning extract_request_environment_without_host(request) do |env|
       env.merge! :host =&gt; request.host,
                  :port =&gt; request.port,
                  :host_with_port =&gt; request.host_with_port,
-                 :domain =&gt; request.domain, 
+                 :domain =&gt; request.domain,
                  :subdomain =&gt; request.subdomains.first
     end
-  end  
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/routing_filter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,5 +5,13 @@ module RoutingFilter
     def initialize(options)
       @options = options
     end
+    
+    def around_recognition(route, path, env, &amp;block)
+      yield path, env
+    end
+    
+    def around_generation(controller, options, &amp;block)
+      yield options
+    end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/routing_filter/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,23 +1,37 @@
+require 'i18n'
+
 module RoutingFilter
   class Locale &lt; Base
-    @@default_locale = 'en'
+    @@default_locale = :en
     cattr_reader :default_locale
     
+    class &lt;&lt; self
+      def default_locale=(locale)
+        @@default_locale = locale.to_sym
+      end
+    end
+    
     # remove the locale from the beginning of the path, pass the path
     # to the given block and set it to the resulting params hash
     def around_recognition(route, path, env, &amp;block)
       locale = nil
       path.sub! %r(^/([a-zA-Z]{2})(?=/|$)) do locale = $1; '' end
-      returning yield(path, env) do |params|
+      returning yield do |params|
         params[:locale] = locale if locale
       end
     end
-
-    # prepend the current locale to the path if it's not the default locale
-    def after_generate(base, result, *args)
-      locale = base.instance_variable_get(:@locale)
-      result.replace &quot;/#{locale}#{result}&quot; if locale and locale != @@default_locale
-      # TODO won't work with full urls, stupid
+    
+    def around_generation(controller, *args, &amp;block)
+      options = args.extract_options!
+      locale = options.delete(:locale) || I18n.locale.to_sym
+      returning yield do |result|
+        prepend_locale! result, locale if locale != @@default_locale
+      end
+    end
+    
+    def prepend_locale!(result, locale)
+      result.match %r(^(http.?://[^/]*)?(.*))
+      result.replace &quot;#{$1}/#{locale}#{$2}&quot;
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/routing_filter/locale.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,136 +1,64 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
-
-Routing = ActionController::Routing
+require File.dirname(__FILE__) + '/helper/spec_helper.rb'
 
 describe 'RoutingFilter' do
+  include RoutingFilterHelpers
+
   before :each do
     @controller = instantiate_controller :locale =&gt; 'de', :section_id =&gt; 1
-  end
-  
-  def draw_routes(&amp;block)
-    set = returning Routing::RouteSet.new do |set|
-      class &lt;&lt; set; def clear!; end; end
-      set.draw &amp;block 
-      silence_warnings{ Routing.const_set 'Routes', set }
-    end
-    set
-  end
-  
-  def instantiate_controller(params)
-    returning ActionController::Base.new do |controller|
-      request = ActionController::TestRequest.new
-      url = ActionController::UrlRewriter.new(request, params)
-      controller.stub!(:request).and_return request
-      controller.instance_variable_set :@url, url 
-      controller
+    @set = draw_routes do |map|
+      map.section 'sections/:section_id', :controller =&gt; 'sections', :action =&gt; &quot;show&quot;
+      map.filter 'locale'
+      map.filter 'mock'
     end
+    @locale_filter = @set.filters.first
+    @mock_filter = @set.filters.last
   end
   
-  describe 'basics' do
-    before :each do
-      @set = draw_routes do |map|
-        map.section 'sections/:section_id', :controller =&gt; 'sections', :action =&gt; &quot;show&quot;
-        map.filter 'locale'
-        map.filter 'root_section'
-      end
-  
-      @locale_filter = @set.filters.first
-      @root_section_filter = @set.filters.last          
-    end
-    
-    it 'installs a filter to the route set' do
-      @locale_filter.should be_instance_of(RoutingFilter::Locale)
-    end
-  
-    it 'calls the first filter for route recognition' do
-      @locale_filter.should_receive(:around_recognition).and_return {}
-      @set.recognize_path '/de/sections/1', {}
-    end
-  
-    it 'calls the second filter for route recognition' do
-      @root_section_filter.should_receive(:around_recognition).and_return {}
-      @set.recognize_path '/de/sections/1', {}
-    end
-  
-    it 'calls the filter for url_for' do
-      @locale_filter.should_receive :after_generate
-      @controller.send :url_for, :controller =&gt; 'sections', :action =&gt; 'show', :section_id =&gt; 1
-    end
-  
-    it 'calls the filter for named route url_helper' do
-      @locale_filter.should_receive :after_generate
-      @controller.send :section_path, :section_id =&gt; 1
-    end      
-    
-    it 'calls the filter for named route url_helper with &quot;optimized&quot; generation blocks' do
-      @locale_filter.should_receive :after_generate
-      @controller.send :section_path, 1
-    end
-  
-    it 'calls the filter for named route polymorphic_path' do
-      @locale_filter.should_receive :after_generate
-      @controller.send :section_path, Section.new
-    end
+  def recognize_path(path = '/de/sections/1', options = {})
+    @set.recognize_path path, options
   end
   
-  describe 'the locale filter' do
-    before :each do
-      @set = draw_routes do |map|
-        map.section 'sections/:section_id', :controller =&gt; 'sections', :action =&gt; &quot;show&quot;
-        map.filter 'locale'
-      end
-          
-      @locale_filter = @set.filters.first
-      @root_section_filter = @set.filters.last          
-    end
-    
-    it 'recognizes the path /de/sections/1 and sets the :locale param' do
-      @set.recognize_path('/de/sections/1', {})[:locale].should == 'de'
-    end
-    
-    it 'recognizes the path /sections/1 and does not set a :locale param' do
-      @set.recognize_path('/sections/1', {})[:locale].should be_nil
-    end
-    
-    it 'with the default locale set does not change a generated path' do
-      @controller.instance_variable_set :@locale, 'en'
-      @controller.send(:section_path, :section_id =&gt; 1).should == '/sections/1'
-    end
-    
-    it 'with a non-default locale appends it to the generated path' do
-      @controller.instance_variable_set :@locale, 'de'
-      @controller.send(:section_path, :section_id =&gt; 1).should == '/de/sections/1'
-    end
-    
-    it 'with no locale present does not change a generated path' do
-      @controller.instance_variable_set :@locale, nil
-      @controller.send(:section_path, :section_id =&gt; 1).should == '/sections/1'
-    end
+  def generate_url_for(options = {:controller =&gt; 'sections', :action =&gt; 'show', :section_id =&gt; 1})
+    @controller.send :url_for, options
   end
-end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 
+  it 'installs filters to the route set' do
+    @locale_filter.should be_instance_of(RoutingFilter::Locale)
+    @mock_filter.should be_instance_of(RoutingFilter::Mock)
+  end
 
+  it 'calls the first filter for route recognition' do
+    @locale_filter.should_receive :around_recognition
+    recognize_path
+  end
 
+  it 'calls the second filter for route recognition' do
+    @mock_filter.should_receive :around_recognition
+    recognize_path
+  end
 
+  it 'calls the first filter for url generation' do
+    @locale_filter.should_receive :around_generation
+    generate_url_for
+  end
 
+  it 'calls the second filter for url generation' do
+    @mock_filter.should_receive :around_generation
+    generate_url_for
+  end
 
+  it 'calls the first filter for named route url_helper' do
+    @locale_filter.should_receive :around_generation
+    @controller.send :section_path, :section_id =&gt; 1
+  end
+  
+  it 'calls the filter for named route url_helper with &quot;optimized&quot; generation blocks' do
+    @locale_filter.should_receive :around_generation
+    @controller.send :section_path, 1
+  end
+  
+  it 'calls the filter for named route polymorphic_path' do
+    @locale_filter.should_receive :around_generation
+    @controller.send :section_path, Section.new
+  end
+end
\ No newline at end of file</diff>
      <filename>spec/routing_filter_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>spec/root_section.rb</filename>
    </removed>
    <removed>
      <filename>spec/spec_helper.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>d50a9841e002f08080f9df44a0133686d09be482</id>
    </parent>
  </parents>
  <author>
    <name>Sven Fuchs</name>
    <email>svenfuchs@artweb-design.de</email>
  </author>
  <url>http://github.com/svenfuchs/routing-filter/commit/cfc170a430d82db0eb226b67181a0b976947ab6d</url>
  <id>cfc170a430d82db0eb226b67181a0b976947ab6d</id>
  <committed-date>2008-09-20T07:37:47-07:00</committed-date>
  <authored-date>2008-09-20T07:37:47-07:00</authored-date>
  <message>refactor to around_generation</message>
  <tree>1e0bd712ab323385bd76ba986ed2d34661e9f406</tree>
  <committer>
    <name>Sven Fuchs</name>
    <email>svenfuchs@artweb-design.de</email>
  </committer>
</commit>
