aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/environment.rb1
-rw-r--r--config/routes.rb2
-rw-r--r--vendor/gems/routing-filter-0.2.3/.specification151
-rw-r--r--vendor/gems/routing-filter-0.2.3/Gemfile8
-rw-r--r--vendor/gems/routing-filter-0.2.3/Gemfile.lock82
-rw-r--r--vendor/gems/routing-filter-0.2.3/MIT-LICENSE20
-rw-r--r--vendor/gems/routing-filter-0.2.3/README.markdown204
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing-filter.rb1
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter.rb27
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/adapters/rails_2.rb69
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/adapters/rails_3.rb77
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/chain.rb22
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/filter.rb37
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/extension.rb76
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/locale.rb83
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/pagination.rb47
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/uuid.rb40
-rw-r--r--vendor/gems/routing-filter-0.2.3/lib/routing_filter/version.rb3
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/all.rb1
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/blocks.rb33
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/filters/all_filters/generation.rb42
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/filters/all_filters/recognition.rb92
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/filters/all_filters_test.rb25
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/filters/extension_test.rb54
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/filters/locale_test.rb69
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/filters/pagination_test.rb29
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/filters/uuid_test.rb40
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/rails_test.rb92
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/routes_test.rb31
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/routing_filter_test.rb47
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/test_adapters/rails_2.rb17
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/test_adapters/rails_3.rb28
-rw-r--r--vendor/gems/routing-filter-0.2.3/test/test_helper.rb41
33 files changed, 1591 insertions, 0 deletions
diff --git a/config/environment.rb b/config/environment.rb
index 9177b3712..9ccc39f89 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -58,6 +58,7 @@ Rails::Initializer.run do |config|
config.gem "recaptcha", :lib => "recaptcha/rails"
config.gem 'rspec', :lib => false, :version => '1.3.1'
config.gem 'rspec-rails', :lib => false, :version => '1.3.3'
+ config.gem 'routing-filter'
config.gem 'will_paginate', :version => '~> 2.3.11', :source => 'http://gemcutter.org'
#GettextI18nRails.translations_are_html_safe = true
# Your secret key for verifying cookie session data integrity.
diff --git a/config/routes.rb b/config/routes.rb
index 0b4993158..a3ccb381e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -195,6 +195,8 @@ ActionController::Routing::Routes.draw do |map|
rule.admin_rule_update '/admin/censor/update', :action => 'update'
rule.admin_rule_destroy '/admin/censor/destroy/:censor_rule_id', :action => 'destroy'
end
+ map.filter('locale')
+
# Allow downloading Web Service WSDL as a file with an extension
# instead of a file named 'wsdl'
diff --git a/vendor/gems/routing-filter-0.2.3/.specification b/vendor/gems/routing-filter-0.2.3/.specification
new file mode 100644
index 000000000..081da6e32
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/.specification
@@ -0,0 +1,151 @@
+--- !ruby/object:Gem::Specification
+name: routing-filter
+version: !ruby/object:Gem::Version
+ hash: 17
+ prerelease:
+ segments:
+ - 0
+ - 2
+ - 3
+ version: 0.2.3
+platform: ruby
+authors:
+- Sven Fuchs
+autorequire:
+bindir: bin
+cert_chain: []
+
+date: 2011-01-24 00:00:00 +00:00
+default_executable:
+dependencies:
+- !ruby/object:Gem::Dependency
+ name: actionpack
+ prerelease: false
+ requirement: &id001 !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ hash: 3
+ segments:
+ - 0
+ version: "0"
+ type: :runtime
+ version_requirements: *id001
+- !ruby/object:Gem::Dependency
+ name: i18n
+ prerelease: false
+ requirement: &id002 !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ hash: 3
+ segments:
+ - 0
+ version: "0"
+ type: :development
+ version_requirements: *id002
+- !ruby/object:Gem::Dependency
+ name: rails
+ prerelease: false
+ requirement: &id003 !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ hash: 3
+ segments:
+ - 0
+ version: "0"
+ type: :development
+ version_requirements: *id003
+- !ruby/object:Gem::Dependency
+ name: test_declarative
+ prerelease: false
+ requirement: &id004 !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ hash: 3
+ segments:
+ - 0
+ version: "0"
+ type: :development
+ version_requirements: *id004
+description: Routing filters wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
+email: svenfuchs@artweb-design.de
+executables: []
+
+extensions: []
+
+extra_rdoc_files: []
+
+files:
+- lib/routing-filter.rb
+- lib/routing_filter/adapters/rails_2.rb
+- lib/routing_filter/adapters/rails_3.rb
+- lib/routing_filter/chain.rb
+- lib/routing_filter/filter.rb
+- lib/routing_filter/filters/extension.rb
+- lib/routing_filter/filters/locale.rb
+- lib/routing_filter/filters/pagination.rb
+- lib/routing_filter/filters/uuid.rb
+- lib/routing_filter/version.rb
+- lib/routing_filter.rb
+- test/all.rb
+- test/blocks.rb
+- test/filters/all_filters/generation.rb
+- test/filters/all_filters/recognition.rb
+- test/filters/all_filters_test.rb
+- test/filters/extension_test.rb
+- test/filters/locale_test.rb
+- test/filters/pagination_test.rb
+- test/filters/uuid_test.rb
+- test/rails_test.rb
+- test/routes_test.rb
+- test/routing_filter_test.rb
+- test/test_adapters/rails_2.rb
+- test/test_adapters/rails_3.rb
+- test/test_helper.rb
+- Gemfile
+- Gemfile.lock
+- MIT-LICENSE
+- README.markdown
+has_rdoc: true
+homepage: http://github.com/svenfuchs/routing-filter
+licenses: []
+
+post_install_message:
+rdoc_options: []
+
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ hash: 3
+ segments:
+ - 0
+ version: "0"
+required_rubygems_version: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ hash: 3
+ segments:
+ - 0
+ version: "0"
+requirements: []
+
+rubyforge_project: "[none]"
+rubygems_version: 1.4.2
+signing_key:
+specification_version: 3
+summary: Routing filters wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation
+test_files: []
+
diff --git a/vendor/gems/routing-filter-0.2.3/Gemfile b/vendor/gems/routing-filter-0.2.3/Gemfile
new file mode 100644
index 000000000..2837fde79
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/Gemfile
@@ -0,0 +1,8 @@
+source :rubygems
+
+group :test do
+ gem 'rails', '~> 3.0'
+ gem 'i18n'
+ gem 'test_declarative'
+ gem 'ruby-debug'
+end
diff --git a/vendor/gems/routing-filter-0.2.3/Gemfile.lock b/vendor/gems/routing-filter-0.2.3/Gemfile.lock
new file mode 100644
index 000000000..e80776164
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/Gemfile.lock
@@ -0,0 +1,82 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ arel (2.0.6)
+ builder (2.1.2)
+ columnize (0.3.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ linecache (0.43)
+ mail (2.2.12)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+ test_declarative (0.0.5)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ i18n
+ rails (~> 3.0)
+ ruby-debug
+ test_declarative
diff --git a/vendor/gems/routing-filter-0.2.3/MIT-LICENSE b/vendor/gems/routing-filter-0.2.3/MIT-LICENSE
new file mode 100644
index 000000000..ac93a5835
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Sven Fuchs
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/README.markdown b/vendor/gems/routing-filter-0.2.3/README.markdown
new file mode 100644
index 000000000..f59d5ce5b
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/README.markdown
@@ -0,0 +1,204 @@
+# Routing Filter
+
+Routing filters wrap around the complex beast that the Rails routing system is
+to allow for unseen flexibility and power in Rails URL recognition and
+generation.
+
+As powerful and awesome the Rails' routes are, when you need to design your
+URLs in a manner that only slightly leaves the paved cowpaths of Rails
+conventions, you're usually unable to use all the goodness of helpers and
+convenience that Rails ships with.
+
+This library comes with four more or less reusable filters and it is easy to
+implement custom ones. Maybe the most popular one is the Locale routing filter:
+
+* `Locale` - prepends the page's :locale (e.g. /de/products)
+* `Pagination` - appends page/:num (e.g. /products/page/2)
+* `Uuid` - prepends a uuid for authentication or other purposes (e.g. /d00fbbd1-82b6-4c1a-a57d-098d529d6854/products/1)
+* `Extension` - appends an extension (e.g. /products.html)
+
+Please note that Rails 3's routing system is much more powerful and flexible
+than Rails 2 was. There are many usecases that now can be covered with just
+Rails 3 default routing features that weren't doable in Rails 2. For an example
+of a quite complex and flexible route see this [gist by Andrew White](http://gist.github.com/653543)
+
+## Requirements
+
+routing-filter currently only works with Rails. It should not be all too hard
+to get it working with plain Rack::Mount but I haven't had that usecase, yet.
+
+## Installation
+
+Just install the Gem:
+
+ $ gem install routing-filter
+
+The Gem should work out of the box for Rails 3 after specifying it in your
+application's Gemfile.
+
+ # Gemfile
+ gem 'routing-filter'
+
+In order to use it with Rails 2.x you could specify it in your environment.rb
+
+ # config/environment.rb
+ gem 'routing-filter'
+
+## Usage
+
+Once the Gem has loaded you can setup the filters in your routes file like this:
+
+ # in config/routes.rb
+ Rails.application.routes.draw do
+ filter :pagination, :uuid
+ end
+
+Filters can also accept options:
+
+ Rails.application.routes.draw do
+ filter :extension, :exclude => %r(^admin/)
+ end
+
+## Running the tests
+
+There are two Gemfiles in the `ci` directory in order to run the tests against different dependencies. The Rails 3 Gemfile is symlinked to the root folder, so it will be used by default.
+
+Running the tests with Rails 3.x:
+
+ $ bundle install
+ $ ruby -Itest -Ilib test/all.rb
+
+Running the tests with Rails 2.3.x:
+
+ $ BUNDLE_GEMFILE=ci/Gemfile.rails-2.3.x bundle install
+ $ BUNDLE_GEMFILE=ci/Gemfile.rails-2.3.x ruby -Itest -Ilib test/all.rb
+
+## Filter order
+
+You can picture the way routing-filter wraps filters around your application as a russian puppet pattern. Your application sits in the center and is wrapped by a number of filters. An incoming request's path will be past through these layers of filters from the outside in until it is passed to the regular application routes set. When you generate URLs on the other hand then the filters will be run from the inside out.
+
+Filter order might be confusing at first. The reason for that is that the way rack/mount (which is used by Rails as a core routing engine) is confusing in this respect and Rails tries to make the best of it.
+
+Suppose you have a filter :custom in your application routes.rb file and an engine that adds a :common filter. Then Rails makes it so that your application's routes file will be loaded first (basically route.rb files are loaded in reverse engine load order).
+
+Thus routing-filter will make your :custom filter the *inner-most* filter, wrapping the application *first*. The :common filter from your engine will be wrapped *around* that onion and will be made the *outer-most* filter.
+
+This way common base filters (such as the locale filter) can run first and do not need to know about the specifics of other (more specialized, custom) filters. Custom filters on the other hand can easily take into account that common filters might already have run and adjust accordingly.
+
+
+## Implementing your own filters
+
+For example implementations have a look at the existing filters in
+[lib/routing_filter/filters](http://github.com/svenfuchs/routing-filter/tree/master/lib/routing_filter/filters)
+
+The following would be a sceleton of an empty filter:
+
+ module RoutingFilter
+ class Awesomeness < Filter
+ def around_recognize(path, env, &block)
+ # Alter the path here before it gets recognized.
+ # Make sure to yield (calls the next around filter if present and
+ # eventually `recognize_path` on the routeset):
+ yield.tap do |params|
+ # You can additionally modify the params here before they get passed
+ # to the controller.
+ end
+ end
+
+ def around_generate(params, &block)
+ # Alter arguments here before they are passed to `url_for`.
+ # Make sure to yield (calls the next around filter if present and
+ # eventually `url_for` on the controller):
+ yield.tap do |result|
+ # You can change the generated url_or_path here. Make sure to use
+ # one of the "in-place" modifying String methods though (like sub!
+ # and friends).
+ end
+ end
+ end
+ end
+
+You can specify the filter explicitely in your routes.rb:
+
+ Rails.application.routes.draw do
+ filter :awesomeness
+ end
+
+(I am not sure if it makes sense to provide more technical information than
+this because the usage of this plugin definitely requires some advanced
+knowledge about Rails internals and especially its routing system. So, I
+figure, anyone who could use this should also be able to read the code and
+figure out what it's doing much better then from any lengthy documentation.
+
+If I'm mistaken on this please drop me an email with your suggestions.)
+
+
+## Rationale: Two example usecases
+
+### Conditionally prepending the locale
+
+An early usecase from which this originated was the need to define a locale
+at the beginning of an URL in a way so that
+
+* the locale can be omitted when it is the default locale
+* all the url\_helpers that are generated by named routes as well as url_for continue to work in
+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 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.
+
+### Expanding /sections/:id to nested tree segments
+
+Another usecase that eventually spawned the implementation of this plugin was
+the need to map an arbitrary count of path segments to a certain model
+instance. In an application that I've been working on recently I needed to
+map URL paths to a nested tree of models like so:
+
+ root
+ + docs
+ + 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 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 big, bold `/*everything` catch-all ("globbing") 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: 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 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.
+
+* We can tinker with the URLs that we receive from the server and feed URLs to
+Rails that perfectly match the best breed of Rails' conventions.
+* Inside of the application we can use all the nice helper goodness and
+conveniences that rely on these conventions being followed.
+* Finally we can accept URLs that have been generated by the url\_helpers and,
+again, mutate them in the way that matches our requirements.
+
+So, even though the plugin itself is a blatant monkey-patch to one of the
+most complex area of Rails internals, this solution seems to be effectively
+less intrusive and pricey than others are.
+
+## Etc
+
+Authors: [Sven Fuchs](http://www.artweb-design.de) <svenfuchs at artweb-design dot de>
+License: MIT
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing-filter.rb b/vendor/gems/routing-filter-0.2.3/lib/routing-filter.rb
new file mode 100644
index 000000000..1189921d8
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing-filter.rb
@@ -0,0 +1 @@
+require 'routing_filter' \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter.rb
new file mode 100644
index 000000000..49dca2e79
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter.rb
@@ -0,0 +1,27 @@
+require 'action_pack'
+require 'active_support/core_ext/string/inflections'
+
+module RoutingFilter
+ autoload :Filter, 'routing_filter/filter'
+ autoload :Chain, 'routing_filter/chain'
+ autoload :Extension, 'routing_filter/filters/extension'
+ autoload :Locale, 'routing_filter/filters/locale'
+ autoload :Pagination, 'routing_filter/filters/pagination'
+ autoload :Uuid, 'routing_filter/filters/uuid'
+
+ class << self
+ def build(name, options)
+ const_get(name.to_s.camelize).new(options)
+ end
+
+ def active=(active)
+ @@active = active
+ end
+
+ def active?
+ defined?(@@active) ? @@active : @@active = true
+ end
+ end
+end
+
+require "routing_filter/adapters/rails_#{ActionPack::VERSION::MAJOR}" \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/adapters/rails_2.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/adapters/rails_2.rb
new file mode 100644
index 000000000..f80910b96
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/adapters/rails_2.rb
@@ -0,0 +1,69 @@
+require 'action_controller'
+
+# allows to install a filter to the route set by calling: map.filter 'locale'
+ActionController::Routing::RouteSet::Mapper.class_eval do
+ def filter(*args)
+ @set.add_filters(*args)
+ end
+end
+
+# same here for the optimized url generation in named routes
+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 (.*)))
+ # returned string must not contain newlines, or we'll spill out of inline code comments in
+ # ActionController::Routing::RouteSet::NamedRouteCollection#define_url_helper
+ "returning(#{match[1]}) { |result|" +
+ " ActionController::Routing::Routes.filters.run(:around_generate, *args, &lambda{ result }) " +
+ "} if #{match[2]}"
+ end
+ end
+ alias_method_chain :generate_optimisation_block, :filtering
+end
+
+ActionController::Routing::RouteSet.class_eval do
+ attr_writer :filters
+
+ def filters
+ @filters ||= RoutingFilter::Chain.new
+ end
+
+ def add_filters(*names)
+ options = names.extract_options!
+ names.each { |name| filters.unshift(RoutingFilter.build(name, options)) }
+ end
+
+ def recognize_path_with_filtering(path, env = {})
+ path = ::URI.unescape(path.dup) # string is frozen due to memoize
+ filters.run(:around_recognize, path, env, &lambda{ recognize_path_without_filtering(path, env) })
+ end
+ alias_method_chain :recognize_path, :filtering
+
+ def generate_with_filtering(*args)
+ filters.run(:around_generate, args.first, &lambda{ generate_without_filtering(*args) })
+ end
+ alias_method_chain :generate, :filtering
+
+ def clear_with_filtering!
+ @filters.clear if @filters
+ clear_without_filtering!
+ end
+ alias_method_chain :clear!, :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?
+ alias_method :extract_request_environment_without_host, :extract_request_environment unless method_defined? :extract_request_environment_without_host
+ def extract_request_environment(request)
+ extract_request_environment_without_host(request).tap do |env|
+ env.merge! :host => request.host,
+ :port => request.port,
+ :host_with_port => request.host_with_port,
+ :domain => request.domain,
+ :subdomain => request.subdomains.first
+ end
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/adapters/rails_3.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/adapters/rails_3.rb
new file mode 100644
index 000000000..9c8a9fe9d
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/adapters/rails_3.rb
@@ -0,0 +1,77 @@
+require 'action_dispatch'
+require 'active_support/core_ext/module/aliasing'
+require 'active_support/core_ext/hash/reverse_merge'
+
+mappers = [ActionDispatch::Routing::Mapper]
+mappers << ActionDispatch::Routing::DeprecatedMapper if defined?(ActionDispatch::Routing::DeprecatedMapper)
+mappers.each do |mapper|
+ mapper.class_eval do
+ def filter(*args)
+ @set.add_filters(*args)
+ end
+ end
+end
+
+ActionDispatch::Routing::RouteSet.class_eval do
+ def filters
+ @set.filters if @set
+ end
+
+ def add_filters(*names)
+ options = names.extract_options!
+ names.each { |name| filters.unshift(RoutingFilter.build(name, options)) }
+ end
+
+ # def recognize_path_with_filtering(path, env = {})
+ # @set.filters.run(:around_recognize, path.dup, env, &lambda{ recognize_path_without_filtering(path.dup, env) })
+ # end
+ # alias_method_chain :recognize_path, :filtering
+
+ def generate_with_filtering(options, recall = {}, extras = false)
+ filters.run(:around_generate, options, &lambda{ generate_without_filtering(options, recall, extras) })
+ end
+ alias_method_chain :generate, :filtering
+
+ def clear_with_filtering!
+ filters.clear if filters
+ clear_without_filtering!
+ end
+ alias_method_chain :clear!, :filtering
+end
+
+require 'rack/mount/route_set'
+require 'rack/mount/code_generation'
+
+Rack::Mount::RouteSet.class_eval do
+ def filters
+ @filters || RoutingFilter::Chain.new.tap { |f| @filters = f unless frozen? }
+ end
+end
+
+# gah. so who's hoped monkeypatching optimized code wouldn't be necessary with rails 3 anymore?
+Rack::Mount::CodeGeneration.class_eval do
+ def optimize_recognize_with_filtering!
+ optimize_recognize_without_filtering!
+ (class << self; self; end).class_eval do
+ alias_method_chain :recognize, :filtering
+ end
+ end
+ alias :optimize_recognize_without_filtering! :optimize_recognize!
+ alias :optimize_recognize! :optimize_recognize_with_filtering!
+
+ # note: if you overly and unnecessarily use blocks in your lowlevel libraries you make it fricking
+ # hard for your users to hook in anywhere
+ def recognize_with_filtering(request, &block)
+ path, route, matches, params = request.env['PATH_INFO'], nil, nil, nil
+ original_path = path.dup
+
+ filters.run(:around_recognize, path, request.env) do
+ route, matches, params = recognize_without_filtering(request)
+ params || {}
+ end
+
+ request.env['PATH_INFO'] = original_path # hmm ...
+ block.call(route, matches, params) if route
+ end
+end
+
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/chain.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/chain.rb
new file mode 100644
index 000000000..3dde98857
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/chain.rb
@@ -0,0 +1,22 @@
+module RoutingFilter
+ class Chain < Array
+ def <<(filter)
+ filter.previous, last.next = last, filter if last
+ super
+ end
+ alias push <<
+
+ def unshift(filter)
+ filter.next, first.previous = first, filter if first
+ super
+ end
+
+ def run(method, *args, &final)
+ active? ? first.run(method, *args, &final) : final.call
+ end
+
+ def active?
+ RoutingFilter.active? && !empty?
+ end
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filter.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filter.rb
new file mode 100644
index 000000000..1ec5c4867
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filter.rb
@@ -0,0 +1,37 @@
+module RoutingFilter
+ class Filter
+ attr_accessor :next, :previous, :options
+
+ def initialize(options = {})
+ @options = options
+ end
+
+ def run(method, *args, &block)
+ _next = self.next ? proc {|path, env| self.next.run(method, *args, &block) } : block
+ RoutingFilter.active? ? send(method, *args, &_next) : _next.call(*args)
+ end
+
+ def run_reverse(method, *args, &block)
+ _prev = previous ? lambda { previous.run_reverse(method, *args, &block) } : block
+ RoutingFilter.active? ? send(method, *args, &_prev) : _prev.call(*args)
+ end
+
+ protected
+
+ def extract_segment!(pattern, path)
+ path.sub!(pattern) { $2 || '' }
+ path.replace('/') if path.empty?
+ $1
+ end
+
+ def prepend_segment!(result, segment)
+ url = result.is_a?(Array) ? result.first : result
+ url.sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{segment}#{$2 == '/' ? '' : $2}" }
+ end
+
+ def append_segment!(result, segment)
+ url = result.is_a?(Array) ? result.first : result
+ url.sub!(%r(/?($|\?))) { "/#{segment}#{$1}" }
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/extension.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/extension.rb
new file mode 100644
index 000000000..3d30c667e
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/extension.rb
@@ -0,0 +1,76 @@
+# The Extension filter chops a file extension off from the end of the
+# recognized path. When a path is generated the filter re-adds the extension
+# to the path accordingly.
+#
+# incoming url: /de/products/page/1
+# filtered url: /de/products
+# params: params[:locale] = 'de'
+#
+# You can install the filter like this:
+#
+# # in config/routes.rb
+# Rails.application.routes.draw do
+# filter :locale
+# end
+#
+# To make your named_route helpers or url_for add the pagination segments you
+# can use:
+#
+# products_path(:locale => 'de')
+# url_for(:products, :locale => 'de'))
+
+module RoutingFilter
+ class Extension < Filter
+ attr_reader :extension, :exclude
+
+ def initialize(*args)
+ super
+ @exclude = options[:exclude]
+ @extension = options[:extension] || 'html'
+ end
+
+ def around_recognize(path, env, &block)
+ extract_extension!(path) unless excluded?(path)
+ yield(path, env)
+ end
+
+ def around_generate(params, &block)
+ yield.tap do |result|
+ url = result.is_a?(Array) ? result.first : result
+ append_extension!(url) if append_extension?(url)
+ end
+ end
+
+ protected
+
+ def extract_extension!(path)
+ path.sub!(/\.#{extension}$/, '')
+ $1
+ end
+
+ def append_extension?(url)
+ !(blank?(url) || excluded?(url) || mime_extension?(url))
+ end
+
+ def append_extension!(url)
+ url.replace url.sub(/(\?|$)/, ".#{extension}\\1")
+ end
+
+ def blank?(url)
+ url.blank? || !!url.match(%r(^/(\?|$)))
+ end
+
+ def excluded?(url)
+ case exclude
+ when Regexp
+ url =~ exclude
+ when Proc
+ exclude.call(url)
+ end
+ end
+
+ def mime_extension?(url)
+ url =~ /\.#{Mime::EXTENSION_LOOKUP.keys.join('|')}(\?|$)/
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/locale.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/locale.rb
new file mode 100644
index 000000000..74e07968f
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/locale.rb
@@ -0,0 +1,83 @@
+# The Locale filter extracts segments matching /:locale from the beginning of
+# the recognized path and exposes the page parameter as params[:page]. When a
+# path is generated the filter adds the segments to the path accordingly if
+# the page parameter is passed to the url helper.
+#
+# incoming url: /de/products/page/1
+# filtered url: /de/products
+# params: params[:locale] = 'de'
+#
+# You can install the filter like this:
+#
+# # in config/routes.rb
+# Rails.application.routes.draw do
+# filter :locale
+# end
+#
+# To make your named_route helpers or url_for add the pagination segments you
+# can use:
+#
+# products_path(:locale => 'de')
+# url_for(:products, :locale => 'de'))
+
+require 'i18n'
+
+module RoutingFilter
+ class Locale < Filter
+ @@include_default_locale = true
+ cattr_writer :include_default_locale
+
+ class << self
+ def include_default_locale?
+ @@include_default_locale
+ end
+
+ def locales
+ @@locales ||= I18n.available_locales.map(&:to_sym)
+ end
+
+ def locales=(locales)
+ @@locales = locales.map(&:to_sym)
+ end
+
+ def locales_pattern
+ @@locales_pattern ||= %r(^/(#{self.locales.map { |l| Regexp.escape(l.to_s) }.join('|')})(?=/|$))
+ end
+ end
+
+ def around_recognize(path, env, &block)
+ locale = extract_segment!(self.class.locales_pattern, path) # remove the locale from the beginning of the path
+ yield.tap do |params| # invoke the given block (calls more filters and finally routing)
+ params[:locale] = locale if locale # set recognized locale to the resulting params hash
+ end
+ end
+
+ def around_generate(*args, &block)
+ params = args.extract_options! # this is because we might get a call like forum_topics_path(forum, topic, :locale => :en)
+
+ locale = params.delete(:locale) # extract the passed :locale option
+ locale = I18n.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false)
+ locale = nil unless valid_locale?(locale) # reset to no locale when locale is not valid
+
+ args << params
+
+ yield.tap do |result|
+ prepend_segment!(result, locale) if prepend_locale?(locale)
+ end
+ end
+
+ protected
+
+ def valid_locale?(locale)
+ locale && self.class.locales.include?(locale.to_sym)
+ end
+
+ def default_locale?(locale)
+ locale && locale.to_sym == I18n.default_locale.to_sym
+ end
+
+ def prepend_locale?(locale)
+ locale && (self.class.include_default_locale? || !default_locale?(locale))
+ end
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/pagination.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/pagination.rb
new file mode 100644
index 000000000..0decb8b20
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/pagination.rb
@@ -0,0 +1,47 @@
+# The Pagination filter extracts segments matching /page/:page from the end of
+# the recognized url and exposes the page parameter as params[:page]. When a
+# url is generated the filter adds the segments to the url accordingly if the
+# page parameter is passed to the url helper.
+#
+# incoming url: /products/page/1
+# filtered url: /products
+# params: params[:page] = 1
+#
+# You can install the filter like this:
+#
+# # in config/routes.rb
+# Rails.application.routes.draw do
+# filter :pagination
+# end
+#
+# To make your named_route helpers or url_for add the pagination segments you
+# can use:
+#
+# products_path(:page => 1)
+# url_for(:products, :page => 1)
+
+module RoutingFilter
+ class Pagination < Filter
+ PAGINATION_SEGMENT = %r(/page/([\d]+)/?$)
+
+ def around_recognize(path, env, &block)
+ page = extract_segment!(PAGINATION_SEGMENT, path)
+ yield(path, env).tap do |params|
+ params[:page] = page.to_i if page
+ end
+ end
+
+ def around_generate(params, &block)
+ page = params.delete(:page)
+ yield.tap do |result|
+ append_segment!(result, "page/#{page}") if append_page?(page)
+ end
+ end
+
+ protected
+
+ def append_page?(page)
+ page && page.to_i != 1
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/uuid.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/uuid.rb
new file mode 100644
index 000000000..8f62e69bb
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/filters/uuid.rb
@@ -0,0 +1,40 @@
+# The Uuid filter extracts an UUID segment from the beginning of the recognized
+# path and exposes the page parameter as params[:page]. When a path is generated
+# the filter adds the segments to the path accordingly if the page parameter is
+# passed to the url helper.
+#
+# incoming url: /d00fbbd1-82b6-4c1a-a57d-098d529d6854/product/1
+# filtered url: /product/1
+# params: params[:uuid] = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
+#
+# You can install the filter like this:
+#
+# # in config/routes.rb
+# Rails.application.routes.draw do
+# filter :uuid
+# end
+#
+# To make your named_route helpers or url_for add the uuid segment you can use:
+#
+# product_path(:uuid => uuid)
+# url_for(product, :uuid => uuid)
+
+module RoutingFilter
+ class Uuid < Filter
+ UUID_SEGMENT = %r(^/?([a-z\d]{8}\-[a-z\d]{4}\-[a-z\d]{4}\-[a-z\d]{4}\-[a-z\d]{12})(/)?)
+
+ def around_recognize(path, env, &block)
+ uuid = extract_segment!(UUID_SEGMENT, path)
+ yield.tap do |params|
+ params[:uuid] = uuid if uuid
+ end
+ end
+
+ def around_generate(params, &block)
+ uuid = params.delete(:uuid)
+ yield.tap do |result|
+ prepend_segment!(result, uuid) if uuid
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/lib/routing_filter/version.rb b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/version.rb
new file mode 100644
index 000000000..567bb92b8
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/lib/routing_filter/version.rb
@@ -0,0 +1,3 @@
+module RoutingFilter
+ VERSION = '0.2.3'
+end \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/test/all.rb b/vendor/gems/routing-filter-0.2.3/test/all.rb
new file mode 100644
index 000000000..5faf13e5b
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/all.rb
@@ -0,0 +1 @@
+Dir[File.expand_path('../**/*_test.rb', __FILE__)].each { |file| require file } \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/test/blocks.rb b/vendor/gems/routing-filter-0.2.3/test/blocks.rb
new file mode 100644
index 000000000..abe601a5b
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/blocks.rb
@@ -0,0 +1,33 @@
+# def foo
+# f = Proc.new { return "return from foo from inside proc" }
+# f.call # control leaves foo here
+# return "return from foo"
+# end
+#
+# def bar
+# f = lambda { return "return from lambda" }
+# f.call # control does not leave bar here
+# return "return from bar"
+# end
+#
+# puts foo # prints "return from foo from inside proc"
+# puts bar # prints "return from bar"
+
+
+class RouteSet
+ def call
+ recognize &Proc.new { return 'return from recognize block' }
+ p "KEKSE"
+ # recognize do
+ # return 'return from recognize block'
+ # end
+ end
+
+ def recognize
+ yield
+ p "KEKSE"
+ end
+end
+
+
+puts RouteSet.new.call
diff --git a/vendor/gems/routing-filter-0.2.3/test/filters/all_filters/generation.rb b/vendor/gems/routing-filter-0.2.3/test/filters/all_filters/generation.rb
new file mode 100644
index 000000000..f30130261
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/filters/all_filters/generation.rb
@@ -0,0 +1,42 @@
+module Generation
+ test 'generates the path /some.html (extension)' do
+ params = self.params
+ assert_equal '/some.html', routes.generate(params)
+ end
+
+ # extension with any
+
+ test 'generates the path /de/some (extension, locale)' do
+ params = self.params.merge(:locale => 'de')
+ assert_equal '/de/some.html', routes.generate(params)
+ end
+
+ test 'generates the path /some/page/2 (extension, pagination)' do
+ params = self.params.merge(:page => 2)
+ assert_equal '/some/page/2.html', routes.generate(params)
+ end
+
+ test 'generates the path /:uuid/some (extension, uuid)' do
+ params = self.params.merge(:uuid => uuid)
+ assert_equal "/#{uuid}/some.html", routes.generate(params)
+ end
+
+ # extension, locale with any
+
+ test 'generates the path /de/some/page/2 (extension, locale, pagination)' do
+ params = self.params.merge(:locale => 'de', :page => 2)
+ assert_equal '/de/some/page/2.html', routes.generate(params)
+ end
+
+ test 'generates the path /de/:uuid/some (extension, locale, uuid)' do
+ params = self.params.merge(:locale => 'de', :uuid => uuid)
+ assert_equal "/de/#{uuid}/some.html", routes.generate(params)
+ end
+
+ # all
+
+ test 'generates the path /de/some/page/2 (extension, pagination, uuid)' do
+ params = self.params.merge(:locale => 'de', :page => 2, :uuid => uuid)
+ assert_equal "/de/#{uuid}/some/page/2.html", routes.generate(params)
+ end
+end \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/test/filters/all_filters/recognition.rb b/vendor/gems/routing-filter-0.2.3/test/filters/all_filters/recognition.rb
new file mode 100644
index 000000000..b02b13491
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/filters/all_filters/recognition.rb
@@ -0,0 +1,92 @@
+module Recognition
+ # 1 filter
+
+ test 'recognizes the path /some.html (extension)' do
+ params = self.params
+ assert_equal params, routes.recognize_path('/some.html')
+ end
+
+ test 'recognizes the path /de/some (locale)' do
+ params = self.params.merge(:locale => 'de')
+ assert_equal params, routes.recognize_path('/de/some')
+ end
+
+ test 'recognizes the path /some/page/2 (pagination)' do
+ params = self.params.merge(:page => 2)
+ assert_equal params, routes.recognize_path('/some/page/2')
+ end
+
+ test 'recognizes the path /:uuid/some (uuid)' do
+ params = self.params.merge(:uuid => uuid)
+ assert_equal params, routes.recognize_path("/#{uuid}/some")
+ end
+
+ # extension with any
+
+ test 'recognizes the path /de/some.html (extension, locale)' do
+ params = self.params.merge(:locale => 'de')
+ assert_equal params, routes.recognize_path('/de/some.html')
+ end
+
+ test 'recognizes the path /some/page/2.html (extension, pagination)' do
+ params = self.params.merge(:page => 2)
+ assert_equal params, routes.recognize_path('/some/page/2.html')
+ end
+
+ test 'recognizes the path /:uuid/some.html (extension, uuid)' do
+ params = self.params.merge(:uuid => uuid)
+ assert_equal params, routes.recognize_path("/#{uuid}/some.html")
+ end
+
+ # locale with any
+
+ test 'recognizes the path /de/some/page/2 (locale, pagination)' do
+ params = self.params.merge(:locale => 'de', :page => 2)
+ assert_equal params, routes.recognize_path('/de/some/page/2')
+ end
+
+ test 'recognizes the path /de/:uuid/some (locale, uuid)' do
+ params = self.params.merge(:locale => 'de', :uuid => uuid)
+ assert_equal params, routes.recognize_path("/de/#{uuid}/some")
+ end
+
+ # pagination with any
+
+ test 'recognizes the path /:uuid/some/page/2 (pagination, uuid)' do
+ params = self.params.merge(:page => 2, :uuid => uuid)
+ assert_equal params, routes.recognize_path("/#{uuid}/some/page/2")
+ end
+
+ # extension, locale with any
+
+ test 'recognizes the path /de/some/page/2.html (extension, locale, pagination)' do
+ params = self.params.merge(:locale => 'de', :page => 2)
+ assert_equal params, routes.recognize_path("/de/some/page/2.html")
+ end
+
+ test 'recognizes the path /de/:uuid/some.html (extension, locale, uuid)' do
+ params = self.params.merge(:locale => 'de', :uuid => uuid)
+ assert_equal params, routes.recognize_path("/de/#{uuid}/some.html")
+ end
+
+ # extension, pagination with any
+
+ test 'recognizes the path /some/page/2.html (extension, pagination, uuid)' do
+ params = self.params.merge(:page => 2, :uuid => uuid)
+ assert_equal params, routes.recognize_path("/#{uuid}/some/page/2.html")
+ end
+
+ # locale, pagination with any
+
+ test 'recognizes the path /de/some/page/2 (locale, pagination, uuid)' do
+ params = self.params.merge(:locale => 'de', :page => 2, :uuid => uuid)
+ assert_equal params, routes.recognize_path("/de/#{uuid}/some/page/2")
+ end
+
+ # all
+
+ test 'recognizes the path /de/:uuid/some/page/2.html (extension, locale, pagination, uuid)' do
+ params = self.params.merge(:locale => 'de', :page => 2, :uuid => uuid)
+ assert_equal params, routes.recognize_path("/de/#{uuid}/some/page/2.html")
+ end
+end \ No newline at end of file
diff --git a/vendor/gems/routing-filter-0.2.3/test/filters/all_filters_test.rb b/vendor/gems/routing-filter-0.2.3/test/filters/all_filters_test.rb
new file mode 100644
index 000000000..2ec825e79
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/filters/all_filters_test.rb
@@ -0,0 +1,25 @@
+require 'test_helper'
+require 'filters/all_filters/generation'
+require 'filters/all_filters/recognition'
+
+class AllFiltersTest < Test::Unit::TestCase
+ attr_reader :routes, :params, :uuid
+
+ def setup
+ I18n.locale = nil
+ I18n.default_locale = :en
+ I18n.available_locales = %w(de en)
+
+ RoutingFilter::Locale.include_default_locale = false
+
+ @params = { :controller => 'some', :action => 'index' }
+ @uuid = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
+
+ @routes = draw_routes do
+ filter :uuid, :pagination ,:locale, :extension
+ match 'some', :to => 'some#index'
+ end
+ end
+
+ include Recognition, Generation
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/filters/extension_test.rb b/vendor/gems/routing-filter-0.2.3/test/filters/extension_test.rb
new file mode 100644
index 000000000..865463c17
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/filters/extension_test.rb
@@ -0,0 +1,54 @@
+require 'test_helper'
+
+class ForceExtensionTest < Test::Unit::TestCase
+ attr_reader :routes, :params
+
+ def setup
+ @routes = draw_routes do
+ filter :extension, :exclude => %r(^/(admin|$))
+ match '/', :to => 'some#index'
+ match 'some/:id(.:format)', :to => 'some#show'
+ match '/admin/some/new', :to => 'some#new'
+ end
+ @params = { :controller => 'some', :action => 'show', :id => '1' }
+ end
+
+ test 'recognizes the path some/1.html and strips the extension' do
+ assert_nil routes.recognize_path('/some/1.html')[:format]
+ end
+
+ test 'recognizes the path some/1.xml but does not strip the extension' do
+ assert 'xml', routes.recognize_path('/some/1.xml')[:format]
+ end
+
+ test 'appends the extension .html to the generated path' do
+ assert_equal '/some/1.html', routes.generate(params)
+ end
+
+ test 'does not touch existing extensions in generated paths' do
+ assert_equal '/some/1.xml', routes.generate(params.merge(:format => 'xml'))
+ end
+
+ test 'does not touch url query params in generated paths' do
+ assert_equal '/some/1.html?foo=bar', routes.generate(params.merge(:foo => 'bar'))
+ end
+
+ test 'excludes / by default' do
+ assert_equal '/', routes.generate(:controller => 'some', :action => 'index')
+ end
+
+ test 'excludes / by default (with url query params)' do
+ assert_equal '/?foo=bar', routes.generate(:controller => 'some', :action => 'index', :foo => 'bar')
+ end
+
+ test 'excludes with custom regexp' do
+ assert_equal '/admin/some/new', routes.generate(:controller => 'some', :action => 'new')
+ end
+
+ # TODO - why would anyone want to have this?
+ #
+ # test 'does not exclude / when :exclude => false was passed' do
+ # routes.filters.first.instance_variable_set(:@exclude, false)
+ # assert_equal '/.html', routes.generate(:controller => 'some', :action => 'index')
+ # end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/filters/locale_test.rb b/vendor/gems/routing-filter-0.2.3/test/filters/locale_test.rb
new file mode 100644
index 000000000..874872330
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/filters/locale_test.rb
@@ -0,0 +1,69 @@
+require 'test_helper'
+
+class LocaleTest < Test::Unit::TestCase
+ attr_reader :routes, :show_params, :index_params
+
+ def setup
+ I18n.locale = nil
+ I18n.default_locale = :en
+ I18n.available_locales = %w(de en)
+
+ RoutingFilter::Locale.include_default_locale = true
+
+ @index_params = { :controller => 'some', :action => 'index' }
+ @show_params = { :controller => 'some', :action => 'show', :id => '1' }
+
+ @routes = draw_routes do
+ filter :locale
+ match 'products/:id', :to => 'some#show'
+ match '/', :to => 'some#index'
+ end
+ end
+
+ test 'recognizes the path /en' do
+ assert_equal index_params.merge(:locale => 'en'), routes.recognize_path('/en')
+ end
+
+ test 'recognizes the path /en/' do
+ assert_equal index_params.merge(:locale => 'en'), routes.recognize_path('/en/')
+ end
+
+ test 'recognizes the path /en/products/1' do
+ assert_equal show_params.merge(:locale => 'en'), routes.recognize_path('/en/products/1')
+ end
+
+ test 'recognizes the path /de/products/1' do
+ assert_equal show_params.merge(:locale => 'de'), routes.recognize_path('/de/products/1')
+ end
+
+
+ test 'prepends the segments /:locale to the generated path / if the current locale is not the default locale' do
+ I18n.locale = 'de'
+ assert_equal '/de', routes.generate(index_params)
+ end
+
+ test 'prepends the segments /:locale to the generated path /products/1 if the current locale is not the default locale' do
+ I18n.locale = 'de'
+ assert_equal '/de/products/1', routes.generate(show_params)
+ end
+
+ test 'prepends the segments /:locale to the generated path if it was passed as a param' do
+ assert_equal '/de/products/1', routes.generate(show_params.merge(:locale => 'de'))
+ end
+
+ test 'prepends the segments /:locale if the given locale is the default_locale and include_default_locale is true' do
+ assert RoutingFilter::Locale.include_default_locale?
+ assert_equal '/en/products/1', routes.generate(show_params.merge(:locale => 'en'))
+ end
+
+ test 'does not prepend the segments /:locale if the current locale is the default_locale and include_default_locale is false' do
+ I18n.locale = 'en'
+ RoutingFilter::Locale.include_default_locale = false
+ assert_equal '/products/1', routes.generate(show_params)
+ end
+
+ test 'does not prepend the segments /:locale if the given locale is the default_locale and include_default_locale is false' do
+ RoutingFilter::Locale.include_default_locale = false
+ assert_equal '/products/1', routes.generate(show_params.merge(:locale => I18n.default_locale))
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/filters/pagination_test.rb b/vendor/gems/routing-filter-0.2.3/test/filters/pagination_test.rb
new file mode 100644
index 000000000..bafd8ed5c
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/filters/pagination_test.rb
@@ -0,0 +1,29 @@
+require 'test_helper'
+
+class PaginationTest < Test::Unit::TestCase
+ attr_reader :routes, :params
+
+ def setup
+ @routes = draw_routes do
+ filter :pagination
+ match 'some', :to => 'some#index'
+ end
+ @params = { :controller => 'some', :action => 'index', :page => 2 }
+ end
+
+ test 'recognizes the path some/page/2' do
+ assert_equal params, routes.recognize_path('/some/page/2')
+ end
+
+ test 'appends the segments /page/:page to the generated path if the passed :page param does not equal 1' do
+ assert_equal '/some/page/2', routes.generate(params)
+ end
+
+ test 'does not append anything to the generated path if the passed :page param equals 1' do
+ assert_equal '/some', routes.generate(params.merge(:page => 1))
+ end
+
+ test 'appends the segments /page/:page to the generated path but respects url query params' do
+ assert_equal '/some/page/2?foo=bar', routes.generate(params.merge(:foo => 'bar'))
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/filters/uuid_test.rb b/vendor/gems/routing-filter-0.2.3/test/filters/uuid_test.rb
new file mode 100644
index 000000000..28e67d44e
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/filters/uuid_test.rb
@@ -0,0 +1,40 @@
+require 'test_helper'
+
+class UuidTest < Test::Unit::TestCase
+ attr_reader :routes, :uuid, :params
+
+ def setup
+ @routes = draw_routes do
+ filter :uuid
+ match 'some/:id', :to => 'some#show'
+ end
+ @uuid = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
+ @params = { :controller => 'some', :action => 'show', :id => '1', :uuid => uuid }
+ end
+
+ test 'recognizes the path :uuid/product/1' do
+ assert_equal params, routes.recognize_path("/#{uuid}/some/1")
+ end
+
+ test 'prepends the :uuid segment to the generated path if passed as a param' do
+ assert_equal "/#{uuid}/some/1", routes.generate(params)
+ end
+
+ test 'matches uuid segments' do
+ pattern = Uuid::UUID_SEGMENT
+ uuids = %w(
+ d00fbbd1-82b6-4c1a-a57d-098d529d6854 cdb33760-94da-11df-981c-0800200c9a66
+ 0c65a6ec-6491-4316-a137-0021cf4e6471 cbbd44c3-c195-48e5-be04-3cc8a6578f51
+ )
+ uuids.each { |uuid| assert pattern.match("/#{uuid}/"), "does not match /#{uuid}/ but should" }
+ end
+
+ test 'does not match non-uuid segments' do
+ pattern = Uuid::UUID_SEGMENT
+ uuids = %w(
+ !aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa aaaa-aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa
+ aaaaaaaa_aaaa_aaaa_aaaa_aaaaaaaaaaaa aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa
+ )
+ uuids.each { |uuid| assert !pattern.match("/#{uuid}/"), "matches /#{uuid}/ but shouldn't" }
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/rails_test.rb b/vendor/gems/routing-filter-0.2.3/test/rails_test.rb
new file mode 100644
index 000000000..9d04e511a
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/rails_test.rb
@@ -0,0 +1,92 @@
+require 'test_helper'
+require "test_adapters/rails_#{ActionPack::VERSION::MAJOR}"
+
+class RailsTest < Test::Unit::TestCase
+ include TestRailsAdapter
+
+ I18n.available_locales = [:en, :de]
+
+ class TestsController < ActionController::Base
+ include Rails.application.routes.url_helpers if defined?(Rails)
+
+ def index
+ url = url_for(params.merge(:only_path => true))
+ render :text => params.merge(:url => url).inspect
+ end
+
+ def show
+ url = foo_path(params)
+ render :text => params.merge(:url => url).inspect
+ end
+ end
+
+ def params
+ response.status.to_s.include?('200') ? eval(response.body).symbolize_keys : {}
+ end
+
+ test "get to /" do
+ get '/'
+ assert_nil params[:locale]
+ assert_nil params[:page]
+ assert_nil params[:uuid]
+ assert_equal '/en.html', params[:url]
+ end
+
+ test "get to /foo/1" do
+ get '/foo/1'
+ assert_nil params[:locale]
+ assert_nil params[:page]
+ assert_nil params[:uuid]
+ assert_equal '/en/foo/1.html', params[:url]
+ end
+
+ test "get to /de" do
+ get '/de'
+ assert_equal 'de', params[:locale]
+ assert_nil params[:page]
+ assert_nil params[:uuid]
+ assert_equal '/de.html', params[:url]
+ end
+
+ test "get to /de/foo/1" do
+ get '/de/foo/1'
+ assert_equal 'de', params[:locale]
+ assert_nil params[:page]
+ assert_nil params[:uuid]
+ assert_equal '/de/foo/1.html', params[:url]
+ end
+
+ test "get to /page/2" do
+ get '/page/2'
+ assert_nil params[:locale]
+ assert_equal 2, params[:page]
+ assert_nil params[:uuid]
+ assert_equal '/en/page/2.html', params[:url]
+ end
+
+ test "get to /foo/1/page/2" do
+ get '/foo/1/page/2'
+ assert_nil params[:locale]
+ assert_equal 2, params[:page]
+ assert_nil params[:uuid]
+ assert_equal '/en/foo/1/page/2.html', params[:url]
+ end
+
+ test "get to /:uuid" do
+ uuid = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
+ get "/#{uuid}"
+ assert_nil params[:locale]
+ assert_nil params[:page]
+ assert_equal uuid, params[:uuid]
+ assert_equal "/en/#{uuid}.html", params[:url]
+ end
+
+ test "get to /foo/1/:uuid" do
+ uuid = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
+ get "/#{uuid}/foo/1"
+ assert_nil params[:locale]
+ assert_nil params[:page]
+ assert_equal uuid, params[:uuid]
+ assert_equal "/en/#{uuid}/foo/1.html", params[:url]
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/routes_test.rb b/vendor/gems/routing-filter-0.2.3/test/routes_test.rb
new file mode 100644
index 000000000..8c803dbfe
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/routes_test.rb
@@ -0,0 +1,31 @@
+require 'test_helper'
+
+class RoutesTest < Test::Unit::TestCase
+ class RoutingFilter::Test < Filter
+ def around_recognize(path, env, &block)
+ 'recognized'
+ end
+
+ def around_generate(*args, &block)
+ 'generated'
+ end
+ end
+
+ attr_reader :routes
+
+ def setup
+ @routes = draw_routes { |set| set.filter :test }
+ end
+
+ test "routes.filter instantiates and registers a filter" do
+ assert routes.filters.first.is_a?(RoutingFilter::Test)
+ end
+
+ # test "filter.around_recognize is being called" do
+ # assert_equal 'recognized', routes.recognize_path('/')
+ # end
+
+ test "filter.around_generate is being called" do
+ assert_equal 'generated', routes.generate({})
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/routing_filter_test.rb b/vendor/gems/routing-filter-0.2.3/test/routing_filter_test.rb
new file mode 100644
index 000000000..41b1b70b4
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/routing_filter_test.rb
@@ -0,0 +1,47 @@
+require 'test_helper'
+
+include RoutingFilter
+
+class RoutingFilterTest < Test::Unit::TestCase
+ class FooFilter < Filter
+ attr_reader :name
+
+ def initialize(name)
+ @name = name
+ end
+
+ def foo(log, &block)
+ log << name
+ yield
+ end
+ end
+
+ attr_reader :chain
+
+ def setup
+ @chain = Chain.new
+ @chain.unshift FooFilter.new('custom filter')
+ @chain.unshift FooFilter.new('common filter')
+ end
+
+ test "filter.previous is nil for the first filter in the chain" do
+ assert_nil chain.first.previous
+ end
+
+ test "filter.previous returns the previous filter in the chain" do
+ assert_equal chain.first, chain.last.previous
+ end
+
+ test "filter.next is nil for the last filter in the chain" do
+ assert_nil chain.last.next
+ end
+
+ test "filter.next returns the next filter in the chain" do
+ assert_equal chain.last, chain.first.next
+ end
+
+ test "chain.run calls the given method on registered filters in reverse order" do
+ log = []
+ assert_equal 'common filter, custom filter, finalizer', chain.run(:foo, log, &lambda { log << 'finalizer' }).join(', ')
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/test_adapters/rails_2.rb b/vendor/gems/routing-filter-0.2.3/test/test_adapters/rails_2.rb
new file mode 100644
index 000000000..6e8b5fd32
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/test_adapters/rails_2.rb
@@ -0,0 +1,17 @@
+require 'test_helper'
+
+module TestRailsAdapter
+ routes = ActionController::Routing::Routes = ActionController::Routing::RouteSet.new
+ routes.draw do |map|
+ map.connect '/', :controller => 'rails_test/tests', :action => 'index'
+ map.foo '/foo/:id', :controller => 'rails_test/tests', :action => 'show'
+ map.filter :uuid, :pagination ,:locale, :extension
+ end
+
+ attr_reader :session
+ delegate :get, :response, :to => :session
+
+ def setup
+ @session = ActionController::Integration::Session.new(lambda { |env| ActionController::Routing::Routes.call(env) })
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/test_adapters/rails_3.rb b/vendor/gems/routing-filter-0.2.3/test/test_adapters/rails_3.rb
new file mode 100644
index 000000000..05cafaa47
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/test_adapters/rails_3.rb
@@ -0,0 +1,28 @@
+require 'test_helper'
+
+require "rails"
+require 'rack/test'
+
+module TestRailsAdapter
+ include ::Rack::Test::Methods
+
+ APP = Class.new(Rails::Application).tap do |app|
+ app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
+ app.config.session_store :cookie_store, :key => "_myapp_session"
+ app.config.active_support.deprecation = :log
+ app.routes.draw do
+ match "/" => "rails_test/tests#index"
+ match "/foo/:id" => "rails_test/tests#show", :as => 'foo'
+ filter :uuid, :pagination ,:locale, :extension
+ end
+ app.initialize!
+ end
+
+ def app
+ APP
+ end
+
+ def response
+ last_response
+ end
+end
diff --git a/vendor/gems/routing-filter-0.2.3/test/test_helper.rb b/vendor/gems/routing-filter-0.2.3/test/test_helper.rb
new file mode 100644
index 000000000..2a0d9f71a
--- /dev/null
+++ b/vendor/gems/routing-filter-0.2.3/test/test_helper.rb
@@ -0,0 +1,41 @@
+ENV['RAILS_ENV'] = 'test'
+
+require 'rubygems'
+require 'test/unit'
+require 'bundler/setup'
+
+require 'i18n'
+require 'action_pack'
+require 'active_support'
+require 'action_controller'
+require 'active_support/core_ext/enumerable.rb'
+require 'test_declarative'
+require 'routing_filter'
+
+include RoutingFilter
+
+class SomeController < ActionController::Base
+end
+
+class Test::Unit::TestCase
+ def draw_routes(&block)
+ normalized_block = rails_2? ? lambda { |set| set.instance_eval(&block) } : block
+ klass = rails_2? ? ActionController::Routing::RouteSet : ActionDispatch::Routing::RouteSet
+ klass.new.tap { |set| set.draw(&normalized_block) }
+ end
+
+ def rails_2?
+ ActionPack::VERSION::MAJOR == 2
+ end
+end
+
+if ActionPack::VERSION::MAJOR == 2
+ ActionController::Routing::RouteSet::Mapper.class_eval do
+ def match(pattern, options)
+ pattern.gsub!('(.:format)', '.:format')
+ controller, action = options.delete(:to).split('#')
+ options.merge!(:controller => controller, :action => action)
+ connect(pattern, options)
+ end
+ end
+end