i18n_routing 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ 0.4.7 (February 14, 2011)
2
+
3
+ * Fix bug in empty translation handling
4
+ * Hack Rack::Mount to handle :locale constraints in top of i18n_locale
5
+ * Fix requirements bug introduced by Rails 3.0.4
6
+ * Add Gemfile with bundler for easy spec on different rails versions
7
+
1
8
  0.4.6 (February 14, 2011)
2
9
 
3
10
  * Handle empty translation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+ gem "rails", '3.0.6'
3
+ gem 'rspec', '>=2.5.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.6)
6
+ actionpack (= 3.0.6)
7
+ mail (~> 2.2.15)
8
+ actionpack (3.0.6)
9
+ activemodel (= 3.0.6)
10
+ activesupport (= 3.0.6)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.6)
19
+ activesupport (= 3.0.6)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.6)
23
+ activemodel (= 3.0.6)
24
+ activesupport (= 3.0.6)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.6)
28
+ activemodel (= 3.0.6)
29
+ activesupport (= 3.0.6)
30
+ activesupport (3.0.6)
31
+ arel (2.0.9)
32
+ builder (2.1.2)
33
+ diff-lcs (1.1.2)
34
+ erubis (2.6.6)
35
+ abstract (>= 1.0.0)
36
+ i18n (0.5.0)
37
+ mail (2.2.16)
38
+ activesupport (>= 2.3.6)
39
+ i18n (>= 0.4.0)
40
+ mime-types (~> 1.16)
41
+ treetop (~> 1.4.8)
42
+ mime-types (1.16)
43
+ polyglot (0.3.1)
44
+ rack (1.2.2)
45
+ rack-mount (0.6.14)
46
+ rack (>= 1.0.0)
47
+ rack-test (0.5.7)
48
+ rack (>= 1.0)
49
+ rails (3.0.6)
50
+ actionmailer (= 3.0.6)
51
+ actionpack (= 3.0.6)
52
+ activerecord (= 3.0.6)
53
+ activeresource (= 3.0.6)
54
+ activesupport (= 3.0.6)
55
+ bundler (~> 1.0)
56
+ railties (= 3.0.6)
57
+ railties (3.0.6)
58
+ actionpack (= 3.0.6)
59
+ activesupport (= 3.0.6)
60
+ rake (>= 0.8.7)
61
+ thor (~> 0.14.4)
62
+ rake (0.8.7)
63
+ rspec (2.5.0)
64
+ rspec-core (~> 2.5.0)
65
+ rspec-expectations (~> 2.5.0)
66
+ rspec-mocks (~> 2.5.0)
67
+ rspec-core (2.5.1)
68
+ rspec-expectations (2.5.0)
69
+ diff-lcs (~> 1.1.2)
70
+ rspec-mocks (2.5.0)
71
+ thor (0.14.6)
72
+ treetop (1.4.9)
73
+ polyglot (>= 0.3.1)
74
+ tzinfo (0.3.26)
75
+
76
+ PLATFORMS
77
+ ruby
78
+
79
+ DEPENDENCIES
80
+ rails (= 3.0.6)
81
+ rspec (>= 2.5.0)
@@ -8,7 +8,6 @@ module I18nRouting
8
8
 
9
9
  # Return the correct translation for given values
10
10
  def self.translation_for(name, type = :resources, option = nil)
11
-
12
11
  # First, if an option is given, try to get the translation in the routes scope
13
12
  if option
14
13
  default = "{option}Noi18nRoutingTranslation"
@@ -50,5 +49,4 @@ module I18nRouting
50
49
 
51
50
  return h
52
51
  end
53
-
54
52
  end
@@ -8,7 +8,6 @@
8
8
  module ActionController
9
9
  module Routing
10
10
  class Route #:nodoc:
11
-
12
11
  alias_method :mkd_initialize, :initialize
13
12
  def initialize(segments = [], requirements = {}, conditions = {})
14
13
  @glang = requirements.delete(:glang)
@@ -33,7 +32,6 @@ end
33
32
  module ActionController
34
33
  module Routing
35
34
  class RouteSet #:nodoc:
36
-
37
35
  attr :locales, true
38
36
  attr :i18n_verbose, true
39
37
 
@@ -46,11 +44,9 @@ module ActionController
46
44
  ensure
47
45
  @set.locales = old_value
48
46
  end
49
-
50
47
  end
51
48
 
52
49
  class NamedRouteCollection #:nodoc:
53
-
54
50
  alias_method :mkd_define_url_helper, :define_url_helper
55
51
  def define_url_helper(route, name, kind, options)
56
52
  gl = Thread.current[:globalized]
@@ -85,7 +81,6 @@ module ActionController
85
81
  end
86
82
  protected :gl#{selector}
87
83
  end_eval
88
-
89
84
  end
90
85
  end
91
86
  end
@@ -115,7 +110,6 @@ module ActionController
115
110
 
116
111
  gl_add_named_route(name, path, options)
117
112
  end
118
-
119
113
  end
120
114
  end
121
115
  end
@@ -155,7 +149,6 @@ module ActionController
155
149
  end
156
150
 
157
151
  def create_globalized_resources(type, namespace, *entities, &block)
158
-
159
152
  Thread.current[:i18n_nested_deep] ||= 0
160
153
  Thread.current[:i18n_nested_deep] += 1
161
154
 
@@ -36,7 +36,7 @@ module I18nRouting
36
36
  localized_path = I18nRouting.translation_for(resource.name, type)
37
37
 
38
38
  # A translated route exists :
39
- if localized_path and String === localized_path
39
+ if !localized_path.blank? and String === localized_path
40
40
  puts("[I18n] > localize %-10s: %40s (%s) => /%s" % [type, resource.name, locale, localized_path]) if @i18n_verbose
41
41
  opts = options.dup
42
42
  opts[:path] = localized_path
@@ -118,10 +118,12 @@ module I18nRouting
118
118
  def initialize(*args)
119
119
  super
120
120
 
121
- # Add i18n as valid conditions for Rack::Mount
121
+ # Add i18n_locale as valid conditions for Rack::Mount / And add also :locale, as Rails 3.0.4 removed it ...
122
122
  @valid_conditions = @set.instance_eval { @set }.instance_eval { @valid_conditions }
123
- @valid_conditions << :i18n_locale if !@valid_conditions.include?(:i18n_locale)
124
- @set.valid_conditions << :i18n_locale if !@set.valid_conditions.include?(:i18n_locale)
123
+ [:i18n_locale, :locale].each do |k|
124
+ @valid_conditions << k if !@valid_conditions.include?(k)
125
+ @set.valid_conditions << k if !@set.valid_conditions.include?(k)
126
+ end
125
127
 
126
128
  # Extends the current RouteSet in order to define localized helper for named routes
127
129
  # When calling define_url_helper, it calls define_localized_url_helper too.
@@ -153,7 +155,6 @@ module I18nRouting
153
155
  @i18n_routing_path_set = true
154
156
  end
155
157
 
156
-
157
158
  old_value = @locales
158
159
  @locales = locales
159
160
  @i18n_verbose ||= opts.delete(:verbose)
@@ -233,7 +234,6 @@ module I18nRouting
233
234
  end
234
235
 
235
236
  @scope[:nested_deep].pop
236
-
237
237
  end
238
238
 
239
239
  # Alias methods in order to handle i18n routes
@@ -246,7 +246,6 @@ module I18nRouting
246
246
  [:map_method, :member, :collection].each do |m|
247
247
  rfname = "#{m}_without_i18n_routing".to_sym
248
248
  mod.send :define_method, "#{m}_with_i18n_routing".to_sym do |*args, &block|
249
-
250
249
  if @localized_branch and @scope[:i18n_scope_level_resource] and @scope[:i18n_real_resource_name]
251
250
  o = @scope[:scope_level_resource]
252
251
  @scope[:scope_level_resource] = @scope[:i18n_scope_level_resource]
@@ -265,7 +264,6 @@ module I18nRouting
265
264
  end
266
265
 
267
266
  send(rfname, *args, &block)
268
-
269
267
  end
270
268
 
271
269
  mod.send :alias_method_chain, m, :i18n_routing
@@ -279,12 +277,10 @@ module I18nRouting
279
277
  def resources_with_i18n_routing(*resources, &block)
280
278
  create_globalized_resources(:resources, *resources, &block)
281
279
  end
282
-
283
280
  end
284
281
 
285
282
  # Used for localize simple named routes
286
283
  class LocalizedMapping < ActionDispatch::Routing::Mapper::Mapping
287
-
288
284
  attr_reader :path
289
285
 
290
286
  def initialize(locale, set, scope, path, options)
@@ -308,21 +304,20 @@ module I18nRouting
308
304
  @options[:constraints] = @options[:constraints] ? @options[:constraints].dup : {}
309
305
  @options[:constraints][:i18n_locale] = locale.to_s
310
306
  @options[:anchor] = true
307
+ # Force the recomputation of the requirements with the new values
308
+ @requirements = nil
311
309
  else
312
310
  @localized_path = nil
313
311
  end
314
-
315
312
  end
316
313
 
317
314
  # Return true if this route is localizable
318
315
  def localizable?
319
316
  @localized_path != nil
320
317
  end
321
-
322
318
  end
323
319
 
324
320
  module NamedRouteCollection
325
-
326
321
  attr_reader :localizable
327
322
 
328
323
  def set_localizable_route(localizable)
@@ -366,7 +361,6 @@ module I18nRouting
366
361
  # Rack::Mount::Route module
367
362
  # Exists in order to use apropriate localized route when using url_for
368
363
  module RackMountRoute
369
-
370
364
  # Alias methods in order to handle i18n routes
371
365
  def self.included(mod)
372
366
  mod.send :alias_method_chain, :generate, :i18n_routing
@@ -387,7 +381,6 @@ module I18nRouting
387
381
  return nil if @locale and @locale != I18n.locale.to_sym
388
382
  generate_without_i18n_routing(method, params, recall, options)
389
383
  end
390
-
391
384
  end
392
385
  end
393
386
 
@@ -47,6 +47,7 @@ describe :localized_routes do
47
47
  l.localized_root '/', :controller => "about", :action => "show"
48
48
  l.about_with_locale 'about', :controller => "about", :action => "show"
49
49
  l.about_with_locale_with_sep 'about', :controller => "about", :action => "show"
50
+ l.resources :empty__resources
50
51
  end
51
52
 
52
53
  map.resources :drones, :path_prefix => 'doubledrones/unimatrix/zero'
@@ -73,10 +74,11 @@ describe :localized_routes do
73
74
  match 'welcome/to/our/page' => "welcome#index", :as => :welcome
74
75
  match 'empty' => 'empty#show', :as => :empty
75
76
 
76
- scope '/:locale' do #, :constraints => { :locale => /[a-z]{2}/ } do ### Commented => this constraint fail on rails 3.0.4 ??
77
+ scope '/:locale', :constraints => { :locale => /[a-z]{2}/ } do ### this constraint fail on rails 3.0.4, so I had to hack a turn around
77
78
  match '/' => "about#show", :as => :localized_root
78
79
  match 'about' => "about#show", :as => :about_with_locale
79
80
  match '/about' => "about#show", :as => :about_with_locale_with_sep
81
+ resources :empty__resources
80
82
  end
81
83
 
82
84
  resources :users do
@@ -225,6 +227,8 @@ describe :localized_routes do
225
227
  routes.send(:empty_path).should == "/empty"
226
228
  routes.send(:empty_resources_path).should_not == "/#{I18n.t 'empty', :scope => :named_routes_path}"
227
229
  routes.send(:empty_resources_path).should == "/empty_resources"
230
+ nested_routes.keys.include?(:fr_empty__resources).should == false # Because translation is empty
231
+ nested_routes.keys.include?('fr_empty__resources').should == false # Because translation is empty
228
232
  end
229
233
 
230
234
  it "named_route generates route using localized values and I18n.locale as a string" do
data/spec/locales/fr.yml CHANGED
@@ -22,6 +22,7 @@ fr:
22
22
  countries: 'pays'
23
23
  bars: bars_fr
24
24
  empty_resources: ''
25
+ empty__resources: ''
25
26
  resource:
26
27
  foo: foo_fr
27
28
  foofoo: froufrou
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
- require 'rubygems'
1
+ require "rubygems"
2
+ require "bundler/setup"
2
3
  require 'rspec'
3
4
 
4
5
  $rails_version = ARGV.find { |e| e =~ /rails_spec_version=.*/ }.split('=').last.to_i rescue nil
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: i18n_routing
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.6
5
+ version: 0.4.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Guillaume Luccisano
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-14 00:00:00 -08:00
13
+ date: 2011-04-17 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -43,6 +43,8 @@ files:
43
43
  - spec/locales/pt-br.yml
44
44
  - spec/spec_helper.rb
45
45
  - CHANGELOG.rdoc
46
+ - Gemfile
47
+ - Gemfile.lock
46
48
  - MIT-LICENSE
47
49
  - Rakefile
48
50
  - README.rdoc