Permalink
Browse files

Move check for current locale to route scoring

  • Loading branch information...
1 parent 7fa741b commit bff3bda74799cfba174cf03bda9036796b2375f7 @jdcrutchley jdcrutchley committed Jan 30, 2012
Showing with 9 additions and 25 deletions.
  1. +2 −1 README.rdoc
  2. +1 −1 i18n_routing.gemspec
  3. +6 −23 lib/i18n_routing_rails32.rb
View
3 README.rdoc
@@ -6,7 +6,7 @@ All necessary informations are available on the wiki: http://wiki.github.com/kwi
For any question, use the i18_routing google group: http://groups.google.com/group/i18n-routing
-Works with Rails 2.3, 3.0 and 3.1
+Works with Rails 2.3, 3.0, 3.1 and 3.2
== TODO for next releases (written the 9th of June 2010)
@@ -29,5 +29,6 @@ Furthermore, if the i18n gem is present on your system, Rails will load it and s
* rudionrails (Rudolf Schmidt)
* fishman (Reza Jelveh)
* toXXIc
+* jdcrutchley (Jamie Crutchley)
Copyright (c) 2010-2011 Guillaume Luccisano - g-mai|: guillaume.luccisano, released under the MIT license
View
2 i18n_routing.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "i18n_routing"
- s.version = "0.6.0"
+ s.version = "0.6.1"
s.author = "Guillaume Luccisano"
s.email = "guillaume.luccisano@gmail.com"
s.homepage = "http://github.com/kwi/i18n_routing"
View
29 lib/i18n_routing_rails32.rb
@@ -389,15 +389,15 @@ def #{selector}(*args)
module JourneyRoute
# Alias methods in order to handle i18n routes
def self.included(mod)
- mod.send :alias_method_chain, :format, :i18n_routing
mod.send :alias_method_chain, :initialize, :i18n_routing
+ mod.send :alias_method_chain, :score, :i18n_routing
end
# During route initialization, if a condition i18n_locale is present
# Delete it, store it in @locale, and add it to @defaults
def initialize_with_i18n_routing(name, app, path, constraints, defaults = {})
@locale = if constraints.key?(:i18n_locale)
- c = defaults[:i18n_locale] = constraints.delete(:i18n_locale)
+ c = constraints.delete(:i18n_locale)
# In rails 3.0 it's a regexp otherwise it's a string, so we need to call source on the regexp
(c.respond_to?(:source) ? c.source : c).to_sym
else
@@ -406,30 +406,13 @@ def initialize_with_i18n_routing(name, app, path, constraints, defaults = {})
initialize_without_i18n_routing(name, app, path, constraints, defaults)
end
- # Called for dynamic route generation
- # If a @locale is present and if this locale is not the current one
- # => return nil and refuse to generate the route
- def format_with_i18n_routing(path_options)
- return nil if @locale and @locale != I18n.locale.to_sym
- format_without_i18n_routing(path_options)
- end
- end
-
-
- # Journey::Formatter module
- # Exists in order to inject the current locale in the routing options
- module JourneyFormatter
- def self.included(mod)
- mod.send :alias_method_chain, :non_recursive, :i18n_routing
- end
-
- def non_recursive_with_i18n_routing(cache, options)
- options << [:i18n_locale, I18n.locale.to_s]
- non_recursive_without_i18n_routing(cache, options)
+ # Return low score for routes that don't match the current locale
+ def score_with_i18n_routing constraints
+ return -1 if @locale && @locale != I18n.locale.to_sym
+ score_without_i18n_routing constraints
end
end
end
ActionDispatch::Routing::Mapper.send :include, I18nRouting::Mapper
Journey::Route.send :include, I18nRouting::JourneyRoute
-Journey::Formatter.send :include, I18nRouting::JourneyFormatter

0 comments on commit bff3bda

Please sign in to comment.