i18n_routing 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +4 -0
- data/Rakefile +28 -28
- data/i18n_routing.gemspec +17 -0
- data/lib/i18n_routing.rb +1 -1
- data/lib/i18n_routing_rails2.rb +37 -37
- data/lib/i18n_routing_rails3.rb +33 -25
- data/spec/i18n_routing/i18n_spec.rb +117 -120
- data/spec/spec_helper.rb +7 -2
- metadata +6 -4
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -11,5 +11,9 @@ Warning: The plugin is not currently running well with deep nesting resources fo
|
|
11
11
|
* Do nested resources for Rails3
|
12
12
|
* Another bug fix ?
|
13
13
|
|
14
|
+
== Contributors
|
15
|
+
|
16
|
+
* kwi (Guillaume Luccisano)
|
17
|
+
* bigtiger (Jim Remsik)
|
14
18
|
|
15
19
|
Copyright (c) 2010 Guillaume Luccisano - g-mai|: guillaume.luccisano, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'spec/rake/spectask'
|
4
|
-
|
5
|
-
spec_files = Rake::FileList["spec/**/*_spec.rb"]
|
6
|
-
|
7
|
-
|
8
|
-
desc "Run specs for current Rails version"
|
9
|
-
Spec::Rake::SpecTask.new do |t|
|
10
|
-
t.spec_files = spec_files
|
11
|
-
t.spec_opts = lambda {
|
12
|
-
@rails_spec_version ? ["-c -- rails_spec_version=#{@rails_spec_version}"] : ["-c"]
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
task :default => :spec
|
17
|
-
|
18
|
-
desc "Run Rails 2.x specs"
|
19
|
-
task :rails2_spec do
|
20
|
-
@rails_spec_version = 2
|
21
|
-
Rake::Task['spec'].invoke
|
22
|
-
end
|
23
|
-
|
24
|
-
desc "Run Rails 3.x specs"
|
25
|
-
task :rails3_spec do
|
26
|
-
@rails_spec_version = 3
|
27
|
-
Rake::Task['spec'].invoke
|
28
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
spec_files = Rake::FileList["spec/**/*_spec.rb"]
|
6
|
+
|
7
|
+
|
8
|
+
desc "Run specs for current Rails version"
|
9
|
+
Spec::Rake::SpecTask.new do |t|
|
10
|
+
t.spec_files = spec_files
|
11
|
+
t.spec_opts = lambda {
|
12
|
+
@rails_spec_version ? ["-c --format specdoc -- rails_spec_version=#{@rails_spec_version}"] : ["-c --format specdoc"]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :spec
|
17
|
+
|
18
|
+
desc "Run Rails 2.x specs"
|
19
|
+
task :rails2_spec do
|
20
|
+
@rails_spec_version = 2
|
21
|
+
Rake::Task['spec'].invoke
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Run Rails 3.x specs"
|
25
|
+
task :rails3_spec do
|
26
|
+
@rails_spec_version = 3
|
27
|
+
Rake::Task['spec'].invoke
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "i18n_routing"
|
3
|
+
s.version = "0.2.4"
|
4
|
+
s.author = "Guillaume Luccisano"
|
5
|
+
s.email = "guillaume.luccisano@gmail.com"
|
6
|
+
s.homepage = "http://github.com/kwi/i18n_routing"
|
7
|
+
s.summary = "I18n routing module for Rails 2.3.x and Rails 3. Translate your routes with ease !"
|
8
|
+
s.description = "I18n_routing is a plugin for Ruby on Rails that lets you easily translate your routes trough the I18n api included in Rails since version 2.2"
|
9
|
+
|
10
|
+
s.add_dependency('i18n', '> 0.3.5')
|
11
|
+
|
12
|
+
s.files = Dir["{lib,spec}/**/*", "[A-Z]*", "init.rb"]
|
13
|
+
s.require_path = "lib"
|
14
|
+
|
15
|
+
s.rubyforge_project = s.name
|
16
|
+
s.required_rubygems_version = ">= 1.3.4"
|
17
|
+
end
|
data/lib/i18n_routing.rb
CHANGED
data/lib/i18n_routing_rails2.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
module ActionController
|
9
9
|
module Routing
|
10
10
|
class Route #:nodoc:
|
11
|
-
|
11
|
+
|
12
12
|
alias_method :mkd_initialize, :initialize
|
13
13
|
def initialize(segments = [], requirements = {}, conditions = {})
|
14
14
|
@glang = requirements.delete(:glang)
|
@@ -23,7 +23,7 @@ module ActionController
|
|
23
23
|
if @glang and !r.blank?
|
24
24
|
r << " and I18n.locale == :#{@glang}"
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
return r
|
28
28
|
end
|
29
29
|
end
|
@@ -33,10 +33,10 @@ end
|
|
33
33
|
module ActionController
|
34
34
|
module Routing
|
35
35
|
class RouteSet #:nodoc:
|
36
|
-
|
36
|
+
|
37
37
|
attr :locales, true
|
38
38
|
attr :i18n_verbose, true
|
39
|
-
|
39
|
+
|
40
40
|
class Mapper
|
41
41
|
def localized(locales = I18n.available_locales, opts = {})
|
42
42
|
old_value = @set.locales
|
@@ -46,9 +46,9 @@ module ActionController
|
|
46
46
|
ensure
|
47
47
|
@set.locales = old_value
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
class NamedRouteCollection #:nodoc:
|
53
53
|
|
54
54
|
alias_method :mkd_define_url_helper, :define_url_helper
|
@@ -95,7 +95,7 @@ module ActionController
|
|
95
95
|
if @locales and !path.blank? and !Thread.current[:i18n_no_named_localization]
|
96
96
|
#puts "ADD NAMED ROUTE : #{path}"
|
97
97
|
name = name.to_s
|
98
|
-
|
98
|
+
|
99
99
|
@locales.each do |l|
|
100
100
|
I18n.locale = l
|
101
101
|
nt = "#{l}_#{name}"
|
@@ -104,7 +104,7 @@ module ActionController
|
|
104
104
|
puts("[I18n] > localize %-10s: %40s (%s) => %s" % ['route', name, l, t]) if @i18n_verbose
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
old_v = Thread.current[:globalized]
|
109
109
|
Thread.current[:globalized] = true
|
110
110
|
gl_add_named_route(name, path, options)
|
@@ -126,33 +126,33 @@ module ActionController
|
|
126
126
|
def initialize(entities, options)
|
127
127
|
@real_path = options.delete(:real_path)
|
128
128
|
@real_path = @real_path.to_s.singularize if @real_path
|
129
|
-
|
129
|
+
|
130
130
|
mkd_initialize(entities, options)
|
131
131
|
end
|
132
132
|
|
133
133
|
def nesting_name_prefix
|
134
134
|
@real_path ? "#{shallow_name_prefix}#{@real_path}_" : "#{shallow_name_prefix}#{singular}_"
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
def nesting_path_prefix
|
138
138
|
@nesting_path_prefix ||= (@real_path ? "#{shallow_path_prefix}/#{path_segment}/:#{@real_path}_id" : "#{shallow_path_prefix}/#{path_segment}/:#{singular}_id")
|
139
139
|
end
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
def switch_globalized_state(state)
|
143
143
|
old_g = Thread.current[:globalized]
|
144
144
|
Thread.current[:globalized] = state
|
145
145
|
yield
|
146
146
|
Thread.current[:globalized] = old_g
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
def switch_no_named_localization(state)
|
150
150
|
old_g = Thread.current[:i18n_no_named_localization]
|
151
151
|
Thread.current[:i18n_no_named_localization] = state
|
152
152
|
yield
|
153
153
|
Thread.current[:i18n_no_named_localization] = old_g
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
def create_globalized_resources(type, namespace, *entities, &block)
|
157
157
|
|
158
158
|
Thread.current[:i18n_nested_deep] ||= 0
|
@@ -160,12 +160,12 @@ module ActionController
|
|
160
160
|
|
161
161
|
if @set.locales
|
162
162
|
name = entities.dup.shift.to_s
|
163
|
-
|
163
|
+
|
164
164
|
options = entities.extract_options!
|
165
165
|
opts = options.dup
|
166
|
-
|
166
|
+
|
167
167
|
opts[:controller] ||= name
|
168
|
-
|
168
|
+
|
169
169
|
locales = @set.locales
|
170
170
|
translated = nil
|
171
171
|
localized(nil) do
|
@@ -176,7 +176,7 @@ module ActionController
|
|
176
176
|
nt = "#{l}_#{name}"
|
177
177
|
opts[:as] = t
|
178
178
|
opts[:glang] = l
|
179
|
-
opts[:real_path] = opts[:singular] || name
|
179
|
+
opts[:real_path] = opts[:singular] || name
|
180
180
|
localized([l]) do
|
181
181
|
translated = true
|
182
182
|
switch_no_named_localization(true) do
|
@@ -199,7 +199,7 @@ module ActionController
|
|
199
199
|
else
|
200
200
|
send(type, *entities, &block)
|
201
201
|
end
|
202
|
-
|
202
|
+
|
203
203
|
Thread.current[:i18n_nested_deep] -= 1
|
204
204
|
end
|
205
205
|
|
@@ -214,25 +214,25 @@ module ActionController
|
|
214
214
|
end
|
215
215
|
|
216
216
|
private
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
end
|
226
|
-
Thread.current[:globalized_s] = resource.singular
|
227
|
-
else
|
228
|
-
Thread.current[:globalized] = nil
|
229
|
-
Thread.current[:globalized_s] = nil
|
230
|
-
end
|
231
|
-
if resource.options[:glang]
|
232
|
-
opts[:glang] = resource.options[:glang]
|
217
|
+
alias_method :gl_action_options_for, :action_options_for
|
218
|
+
def action_options_for(action, resource, method = nil, resource_options = {})
|
219
|
+
opts = gl_action_options_for(action, resource, method, resource_options)
|
220
|
+
|
221
|
+
if Thread.current[:globalized]
|
222
|
+
Thread.current[:globalized] = resource.plural
|
223
|
+
if resource.uncountable?
|
224
|
+
Thread.current[:globalized] = resource.plural.to_s + '_index'
|
233
225
|
end
|
234
|
-
|
235
|
-
|
226
|
+
Thread.current[:globalized_s] = resource.singular
|
227
|
+
else
|
228
|
+
Thread.current[:globalized] = nil
|
229
|
+
Thread.current[:globalized_s] = nil
|
230
|
+
end
|
231
|
+
if resource.options[:glang]
|
232
|
+
opts[:glang] = resource.options[:glang]
|
236
233
|
end
|
234
|
+
|
235
|
+
opts
|
236
|
+
end
|
237
237
|
end
|
238
|
-
end
|
238
|
+
end
|
data/lib/i18n_routing_rails3.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'rack/mount'
|
3
3
|
require 'action_dispatch'
|
4
|
+
require 'active_support/core_ext/module'
|
4
5
|
|
5
6
|
module I18nRouting
|
6
7
|
module Mapper
|
7
8
|
|
8
|
-
|
9
|
+
private
|
9
10
|
# Localize a resources or a resource
|
10
11
|
def localized_resources(type = :resources, *resources, &block)
|
11
12
|
localizable_route = nil
|
@@ -15,7 +16,7 @@ module I18nRouting
|
|
15
16
|
|
16
17
|
options = res.extract_options!
|
17
18
|
r = res.first
|
18
|
-
resource = type == :resource ? ActionDispatch::Routing::Mapper::SingletonResource.new(r, options) : ActionDispatch::Routing::Mapper::Resource.new(r, options)
|
19
|
+
resource = type == :resource ? ActionDispatch::Routing::Mapper::SingletonResource.new(r, options.dup) : ActionDispatch::Routing::Mapper::Resource.new(r, options.dup)
|
19
20
|
|
20
21
|
# Check for translated resource
|
21
22
|
@locales.each do |locale|
|
@@ -24,7 +25,7 @@ module I18nRouting
|
|
24
25
|
|
25
26
|
# A translated route exists :
|
26
27
|
if localized_path and localized_path != resource.name.to_s
|
27
|
-
puts("[I18n] > localize %-10s: %40s (%s) =>
|
28
|
+
puts("[I18n] > localize %-10s: %40s (%s) => /%s" % [type, resource.name, locale, localized_path]) if @i18n_verbose
|
28
29
|
opts = options.dup
|
29
30
|
opts[:path] = localized_path.to_sym
|
30
31
|
opts[:controller] ||= r
|
@@ -45,7 +46,7 @@ module I18nRouting
|
|
45
46
|
end
|
46
47
|
return localizable_route
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
# Set if the next route creation will be a localied route or not
|
50
51
|
# If yes, localizable is a name, or a Mapper::Resource
|
51
52
|
# Can take a block, if so, save the current context, set the new
|
@@ -62,8 +63,8 @@ module I18nRouting
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
-
|
66
|
+
public
|
67
|
+
|
67
68
|
# On Routing::Mapper initialization (when doing Application.routes.draw do ...)
|
68
69
|
# prepare routing system to be i18n ready
|
69
70
|
def initialize(*args)
|
@@ -87,7 +88,7 @@ module I18nRouting
|
|
87
88
|
@set.named_routes.extend I18nRouting::NamedRouteCollection
|
88
89
|
end
|
89
90
|
end
|
90
|
-
|
91
|
+
|
91
92
|
# Rails 3 routing system
|
92
93
|
# Create a block for localized routes, in your routes.rb :
|
93
94
|
#
|
@@ -121,10 +122,10 @@ module I18nRouting
|
|
121
122
|
super
|
122
123
|
end
|
123
124
|
end
|
124
|
-
|
125
|
+
|
125
126
|
super
|
126
127
|
end
|
127
|
-
|
128
|
+
|
128
129
|
def resource(*resources, &block)
|
129
130
|
set_localizable_route(nil) do
|
130
131
|
set_localizable_route(localized_resources(:resource, *resources, &block))
|
@@ -143,12 +144,12 @@ module I18nRouting
|
|
143
144
|
|
144
145
|
# Used for localize simple named routes
|
145
146
|
class LocalizedMapping < ActionDispatch::Routing::Mapper::Mapping
|
146
|
-
|
147
|
+
|
147
148
|
attr_reader :path
|
148
|
-
|
149
|
+
|
149
150
|
def initialize(locale, set, scope, args)
|
150
151
|
super(set, scope, args.clone)
|
151
|
-
|
152
|
+
|
152
153
|
# try to get translated path :
|
153
154
|
I18n.locale = locale
|
154
155
|
ts = @path.gsub(/^\//, '')
|
@@ -167,12 +168,12 @@ module I18nRouting
|
|
167
168
|
end
|
168
169
|
|
169
170
|
end
|
170
|
-
|
171
|
+
|
171
172
|
# Return true if this route is localizable
|
172
173
|
def localizable?
|
173
174
|
@localized_path != nil
|
174
175
|
end
|
175
|
-
|
176
|
+
|
176
177
|
end
|
177
178
|
|
178
179
|
module NamedRouteCollection
|
@@ -190,12 +191,12 @@ module I18nRouting
|
|
190
191
|
selector = url_helper_name(name, kind)
|
191
192
|
|
192
193
|
rlang = if n.kind_of?(ActionDispatch::Routing::Mapper::Resources::Resource) and i = name.to_s.rindex("_#{n.plural}")
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
194
|
+
"#{selector.to_s[0, i]}_glang_#{n.plural}#{selector.to_s[i + "_#{n.plural}".size, selector.to_s.size]}"
|
195
|
+
elsif n.kind_of?(ActionDispatch::Routing::Mapper::Resources::Resource) and i = name.to_s.rindex("_#{n.singular}")
|
196
|
+
"#{selector.to_s[0, i]}_glang_#{n.singular}#{selector.to_s[i + "_#{n.singular}".size, selector.to_s.size]}"
|
197
|
+
else
|
198
|
+
"glang_#{selector}"
|
199
|
+
end
|
199
200
|
|
200
201
|
@module.module_eval <<-end_eval # We use module_eval to avoid leaks
|
201
202
|
alias_method :localized_#{selector}, :#{selector}
|
@@ -210,6 +211,7 @@ module I18nRouting
|
|
210
211
|
localized_#{selector}(*args)
|
211
212
|
end
|
212
213
|
end
|
214
|
+
|
213
215
|
end_eval
|
214
216
|
|
215
217
|
end
|
@@ -220,23 +222,29 @@ module I18nRouting
|
|
220
222
|
# Exists in order to use apropriate localized route when using url_for
|
221
223
|
module RackMountRoute
|
222
224
|
|
225
|
+
# Alias method in order to handle i18n routes
|
226
|
+
def self.included(mod)
|
227
|
+
mod.send :alias_method_chain, :generate, :i18n_routing
|
228
|
+
mod.send :alias_method_chain, :initialize, :i18n_routing
|
229
|
+
end
|
230
|
+
|
223
231
|
# During route initialization, if a condition i18n_locale is present
|
224
232
|
# Delete it, and store it in @locale
|
225
|
-
def
|
233
|
+
def initialize_with_i18n_routing(app, conditions, defaults, name)
|
226
234
|
@locale = conditions[:i18n_locale] ? conditions.delete(:i18n_locale).source.to_sym : nil
|
227
|
-
|
235
|
+
initialize_without_i18n_routing(app, conditions, defaults, name)
|
228
236
|
end
|
229
237
|
|
230
238
|
# Called for dynamic route generation
|
231
239
|
# If a @locale is present and if this locale is not the current one
|
232
240
|
# => return nil and refuse to generate the route
|
233
|
-
def
|
241
|
+
def generate_with_i18n_routing(method, params = {}, recall = {}, options = {})
|
234
242
|
return nil if @locale and @locale != I18n.locale
|
235
|
-
|
243
|
+
generate_without_i18n_routing(method, params, recall, options)
|
236
244
|
end
|
237
245
|
|
238
246
|
end
|
239
247
|
end
|
240
248
|
|
241
249
|
ActionDispatch::Routing::Mapper.send :include, I18nRouting::Mapper
|
242
|
-
Rack::Mount::Route.send :include, I18nRouting::RackMountRoute
|
250
|
+
Rack::Mount::Route.send :include, I18nRouting::RackMountRoute
|
@@ -2,12 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe :localized_routes do
|
4
4
|
before(:all) do
|
5
|
-
|
6
|
-
puts "Route for localize spec"
|
7
|
-
ActionController::Routing::Routes.clear!
|
8
|
-
|
9
|
-
if Rails.version < '3'
|
10
5
|
|
6
|
+
if !rails3?
|
7
|
+
ActionController::Routing::Routes.clear!
|
11
8
|
ActionController::Routing::Routes.draw do |map|
|
12
9
|
map.not_about 'not_about', :controller => 'not_about'
|
13
10
|
map.resources :not_users
|
@@ -30,10 +27,16 @@ describe :localized_routes do
|
|
30
27
|
end
|
31
28
|
end
|
32
29
|
end
|
30
|
+
|
31
|
+
@r = ActionController::Routing::Routes
|
32
|
+
|
33
|
+
class UrlTester
|
34
|
+
include ActionController::UrlWriter
|
35
|
+
end
|
33
36
|
|
34
37
|
else
|
35
|
-
|
36
|
-
|
38
|
+
@r = ActionDispatch::Routing::RouteSet.new
|
39
|
+
@r.draw do
|
37
40
|
match 'not_about' => "not_about#show", :as => :not_about
|
38
41
|
resources :not_users
|
39
42
|
resource :not_contact
|
@@ -43,160 +46,154 @@ describe :localized_routes do
|
|
43
46
|
|
44
47
|
resources :users
|
45
48
|
resource :contact
|
46
|
-
|
49
|
+
|
47
50
|
resources :authors do
|
48
51
|
resources :books
|
49
52
|
end
|
50
|
-
|
53
|
+
|
51
54
|
resources :universes do
|
52
55
|
resources :galaxies do
|
53
56
|
resources :planets
|
54
57
|
end
|
55
58
|
end
|
56
|
-
|
59
|
+
|
57
60
|
end
|
58
61
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
|
63
|
+
class UrlTester; end
|
64
|
+
UrlTester.send :include, @r.url_helpers
|
62
65
|
|
63
|
-
class UrlTester
|
64
|
-
include ActionController::UrlWriter
|
65
66
|
end
|
66
67
|
|
67
|
-
@routes = UrlTester.new
|
68
|
-
end
|
69
|
-
|
70
|
-
def routes
|
71
|
-
@routes
|
72
68
|
end
|
73
|
-
|
69
|
+
|
70
|
+
let(:nested_routes) { @r.named_routes.instance_eval { routes } }
|
71
|
+
let(:routes) { UrlTester.new }
|
72
|
+
|
74
73
|
def url_for(opts)
|
75
|
-
|
74
|
+
@r.generate_extras(opts).first
|
76
75
|
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
77
|
+
context "do not break existing behavior" do
|
78
|
+
|
79
|
+
it "of named_routes" do
|
80
|
+
routes.send(:not_about_path).should == "/not_about"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "of a singular resource" do
|
84
|
+
routes.send(:not_contact_path).should == "/not_contact"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "of resources" do
|
88
|
+
routes.send(:not_users_path).should == "/not_users"
|
89
|
+
end
|
90
|
+
|
88
91
|
end
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
I18n.locale = :en
|
94
|
-
routes.send(:about_path).should == "/#{I18n.t :about, :scope => :named_routes_path}"
|
93
|
+
context "for default routes" do
|
94
|
+
|
95
|
+
before do
|
95
96
|
I18n.locale = :de # Not localized
|
97
|
+
end
|
98
|
+
|
99
|
+
it "named_route uses default values" do
|
96
100
|
routes.send(:about_path).should == "/about"
|
97
101
|
end
|
98
|
-
|
99
|
-
it "
|
100
|
-
I18n.locale = :fr
|
101
|
-
routes.send(:contact_path).should == "/#{I18n.t :contact, :scope => :resource}"
|
102
|
-
I18n.locale = :en
|
103
|
-
routes.send(:contact_path).should == "/#{I18n.t :contact, :scope => :resource}"
|
104
|
-
I18n.locale = :de # Not localized
|
102
|
+
|
103
|
+
it "resource generates routes using default values" do
|
105
104
|
routes.send(:contact_path).should == "/contact"
|
106
105
|
end
|
107
|
-
|
108
|
-
it "
|
109
|
-
I18n.locale = :fr
|
110
|
-
routes.send(:users_path).should == "/#{I18n.t :users, :scope => :resources}"
|
111
|
-
I18n.locale = :en
|
112
|
-
routes.send(:users_path).should == "/#{I18n.t :users, :scope => :resources}"
|
113
|
-
I18n.locale = :de # Not localized
|
106
|
+
|
107
|
+
it "resources generates routes using default values" do
|
114
108
|
routes.send(:users_path).should == "/users"
|
115
109
|
end
|
116
|
-
|
117
|
-
it "
|
118
|
-
I18n.locale = :fr
|
119
|
-
url_for(:controller => :users).should == "/#{I18n.t :users, :scope => :resources}"
|
120
|
-
url_for(:controller => :about, :action => :show).should == "/#{I18n.t :about, :scope => :named_routes_path}"
|
121
|
-
I18n.locale = :en
|
122
|
-
url_for(:controller => :users).should == "/#{I18n.t :users, :scope => :resources}"
|
123
|
-
I18n.locale = :de # Not localized
|
110
|
+
|
111
|
+
it "url_for generates route using default values" do
|
124
112
|
url_for(:controller => :users).should == "/users"
|
125
113
|
end
|
126
|
-
|
127
|
-
it "
|
128
|
-
|
114
|
+
|
115
|
+
it "nested resources generate routes using default values" do
|
116
|
+
routes.send(:author_books_path, 1).should == "/authors/1/books"
|
129
117
|
end
|
130
|
-
|
131
|
-
it "
|
132
|
-
|
133
|
-
routes.send(:
|
134
|
-
|
135
|
-
routes.send(:authors_path).should == "/authors"
|
118
|
+
|
119
|
+
it "deep nested resources generate routes using default values" do
|
120
|
+
routes.send(:universes_path).should == "/universes"
|
121
|
+
routes.send(:universe_galaxies_path, 1).should == "/universes/1/galaxies"
|
122
|
+
routes.send(:universe_galaxy_planets_path, 1, 1).should == "/universes/1/galaxies/1/planets"
|
136
123
|
end
|
137
|
-
|
138
|
-
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
context "" do
|
128
|
+
|
129
|
+
before do
|
139
130
|
I18n.locale = :fr
|
131
|
+
end
|
132
|
+
|
133
|
+
it "named_route generates route using localized values" do
|
134
|
+
routes.send(:about_path).should == "/#{I18n.t :about, :scope => :named_routes_path}"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "resource generates routes using localized valuess" do
|
138
|
+
routes.send(:contact_path).should == "/#{I18n.t :contact, :scope => :resource}"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "resources generates routes using localized values" do
|
142
|
+
routes.send(:users_path).should == "/#{I18n.t :users, :scope => :resources}"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "url_for generates routes using localized values" do
|
146
|
+
url_for(:controller => :users).should == "/#{I18n.t :users, :scope => :resources}"
|
147
|
+
url_for(:controller => :about, :action => :show).should == "/#{I18n.t :about, :scope => :named_routes_path}"
|
148
|
+
end
|
149
|
+
|
150
|
+
it "nested resources generate routes using localized values" do
|
140
151
|
routes.send(:author_books_path, 1).should == "/#{I18n.t :authors, :scope => :resources}/1/#{I18n.t :books, :scope => :resources}"
|
141
|
-
I18n.locale = :de # Not localized
|
142
|
-
routes.send(:author_books_path, 1).should == "/authors/1/books"
|
143
152
|
end
|
144
|
-
|
145
|
-
it "
|
146
|
-
I18n.locale = :fr
|
153
|
+
|
154
|
+
it "deep nested resources generate routes using localized values" do
|
147
155
|
routes.send(:universes_path).should == "/#{I18n.t :universes, :scope => :resources}"
|
148
156
|
routes.send(:universe_galaxies_path, 1).should == "/#{I18n.t :universes, :scope => :resources}/1/#{I18n.t :galaxies, :scope => :resources}"
|
149
157
|
routes.send(:universe_galaxy_planets_path, 1, 1).should == "/#{I18n.t :universes, :scope => :resources}/1/#{I18n.t :galaxies, :scope => :resources}/1/#{I18n.t :planets, :scope => :resources}"
|
150
|
-
I18n.locale = :de # Not localized
|
151
|
-
routes.send(:universes_path).should == "/universes"
|
152
|
-
routes.send(:universe_galaxies_path, 1).should == "/universes/1/galaxies"
|
153
|
-
routes.send(:universe_galaxy_planets_path, 1, 1).should == "/universes/1/galaxies/1/planets"
|
154
158
|
end
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
r[:author_fr_books].should_not be_nil
|
161
|
-
|
162
|
-
if Rails.version < '3'
|
163
|
-
r[:author_books].significant_keys.should include(:author_id)
|
164
|
-
r[:author_fr_books].significant_keys.should include(:author_id)
|
165
|
-
else
|
166
|
-
r[:author_books].segment_keys.should include(:author_id)
|
167
|
-
r[:author_fr_books].segment_keys.should include(:author_id)
|
159
|
+
|
160
|
+
context "when nested" do
|
161
|
+
|
162
|
+
it "named routes should not be nil" do
|
163
|
+
nested_routes[:author_fr_books].should_not be_nil
|
168
164
|
end
|
165
|
+
|
166
|
+
context "in Rails #{Rails.version}" do
|
167
|
+
it "include the correct significant keys" do
|
168
|
+
v = !rails3? ? :significant_keys : :segment_keys
|
169
|
+
nested_routes[:author_books].send(v).should include(:author_id)
|
170
|
+
nested_routes[:author_fr_books].send(v).should include(:author_id)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
169
174
|
end
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
r[:universe_galaxy_planet].segment_keys.should include(:galaxy_id)
|
186
|
-
r[:universe_galaxy_fr_planet].segment_keys.should include(:galaxy_id)
|
175
|
+
|
176
|
+
context "when deeply nested" do
|
177
|
+
|
178
|
+
it "named routes should not be nil" do
|
179
|
+
nested_routes[:universe_galaxy_fr_planet].should_not be_nil
|
180
|
+
end
|
181
|
+
|
182
|
+
context "in Rails #{Rails.version}" do
|
183
|
+
it "include the correct significant keys" do
|
184
|
+
v = !rails3? ? :significant_keys : :segment_keys
|
185
|
+
nested_routes[:universe_galaxy_planet].send(v).should include(:universe_id)
|
186
|
+
nested_routes[:universe_galaxy_fr_planet].send(v).should include(:universe_id)
|
187
|
+
nested_routes[:universe_galaxy_planet].send(v).should include(:galaxy_id)
|
188
|
+
nested_routes[:universe_galaxy_fr_planet].send(v).should include(:galaxy_id)
|
189
|
+
end
|
187
190
|
end
|
188
191
|
end
|
189
192
|
|
190
|
-
it "
|
191
|
-
|
192
|
-
|
193
|
-
r.keys.should_not include(:fr_author_books) # Whant fr_author_books
|
193
|
+
it "nested resources do not deep translate with multi helpers" do
|
194
|
+
nested_routes.keys.should_not include(:fr_author_books) # Want fr_author_books
|
194
195
|
end
|
195
|
-
|
196
|
-
# it "zZ Just print routes :)" do
|
197
|
-
# r = ActionController::Routing::Routes.named_routes.instance_eval { @routes }
|
198
|
-
# puts r.keys.collect(&:to_s).sort.to_yaml
|
199
|
-
# puts "Nb Routes : #{r.keys.size}"
|
200
|
-
# end
|
201
196
|
|
202
|
-
end
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,8 +5,8 @@ $rails_version = ARGV.find { |e| e =~ /rails_spec_version=.*/ }.split('=').last.
|
|
5
5
|
|
6
6
|
if !$rails_version
|
7
7
|
begin
|
8
|
-
require 'rails'
|
9
|
-
rescue Exception
|
8
|
+
require 'rails'
|
9
|
+
rescue Exception
|
10
10
|
$rails_version = 2
|
11
11
|
end
|
12
12
|
end
|
@@ -26,9 +26,14 @@ if Rails.version < '3'
|
|
26
26
|
else
|
27
27
|
gem 'actionpack', '> 2.9'
|
28
28
|
require 'action_controller'
|
29
|
+
require 'action_dispatch'
|
29
30
|
require 'rack/mount'
|
30
31
|
end
|
31
32
|
|
33
|
+
def rails3?
|
34
|
+
!(Rails.version < '3')
|
35
|
+
end
|
36
|
+
|
32
37
|
puts "Launching spec for Rails #{Rails.version}"
|
33
38
|
|
34
39
|
# Add I18n load_path
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 4
|
9
|
+
version: 0.2.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Guillaume Luccisano
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-30 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -48,10 +48,12 @@ files:
|
|
48
48
|
- spec/locales/fr.yml
|
49
49
|
- spec/spec_helper.rb
|
50
50
|
- CHANGELOG.rdoc
|
51
|
+
- i18n_routing-0.2.4.gem
|
52
|
+
- i18n_routing.gemspec
|
53
|
+
- init.rb
|
51
54
|
- MIT-LICENSE
|
52
55
|
- Rakefile
|
53
56
|
- README.rdoc
|
54
|
-
- init.rb
|
55
57
|
has_rdoc: true
|
56
58
|
homepage: http://github.com/kwi/i18n_routing
|
57
59
|
licenses: []
|