translatable_routes 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.rdoc +11 -25
- data/lib/translatable_routes.rb +0 -1
- data/lib/translatable_routes/action_dispatch/mapper.rb +45 -46
- data/lib/translatable_routes/action_dispatch/named_route_collection.rb +6 -10
- data/lib/translatable_routes/railtie.rb +2 -6
- data/lib/translatable_routes/version.rb +1 -1
- data/test/dummy/app/controllers/namespace/pages_controller.rb +6 -0
- data/test/dummy/app/controllers/namespace/resources_controller.rb +6 -0
- data/test/dummy/app/controllers/pages_controller.rb +7 -1
- data/test/dummy/app/controllers/resources_controller.rb +1 -1
- data/test/dummy/config/application.rb +0 -7
- data/test/dummy/config/locales/{en-US.yml → en.yml} +1 -2
- data/test/dummy/config/locales/{es-AR.yml → es.yml} +1 -2
- data/test/dummy/config/routes.rb +11 -2
- data/test/dummy/log/development.log +353 -0
- data/test/dummy/log/test.log +5534 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/helpers_test.rb +17 -0
- data/test/routes_test.rb +28 -87
- metadata +31 -40
- data/lib/translatable_routes/action_controller/base.rb +0 -38
- data/test/dummy/app/controllers/namespace/nested_controller.rb +0 -6
- data/test/dummy/app/controllers/namespace/nested_resources_controller.rb +0 -6
- data/test/dummy/app/controllers/params_controller.rb +0 -6
- data/test/dummy/app/controllers/simple_controller.rb +0 -6
- data/test/dummy/app/views/pages/show.html.erb +0 -0
- data/test/dummy/config/locales/es-UY.yml +0 -9
- data/test/locale_test.rb +0 -34
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HelpersTest < ActionView::TestCase
|
4
|
+
|
5
|
+
test "should create helpers" do
|
6
|
+
I18n.available_locales.each do |locale|
|
7
|
+
I18n.locale = locale
|
8
|
+
|
9
|
+
assert_equal "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.nested')}", namespace_nested_path
|
10
|
+
assert_equal "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.resources')}", namespace_resources_path
|
11
|
+
assert_equal "/#{locale}/#{I18n.t('routes.simple')}", simple_path
|
12
|
+
assert_equal "/#{locale}/complex/1/2", complex_path(1, 2)
|
13
|
+
assert_equal "/#{locale}/#{I18n.t('routes.resources')}", resources_path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/test/routes_test.rb
CHANGED
@@ -2,94 +2,35 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class RoutesTest < ActionDispatch::IntegrationTest
|
4
4
|
|
5
|
-
test "should translate
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
test "should translate routes" do
|
6
|
+
I18n.available_locales.each do |locale|
|
7
|
+
I18n.locale = locale
|
8
|
+
|
9
|
+
assert_recognizes(
|
10
|
+
{ controller: 'namespace/pages', action: 'nested', locale: locale.to_s },
|
11
|
+
"/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.nested')}"
|
12
|
+
)
|
13
|
+
|
14
|
+
assert_recognizes(
|
15
|
+
{ controller: 'namespace/resources', action: 'index', locale: locale.to_s },
|
16
|
+
"/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.resources')}"
|
17
|
+
)
|
18
|
+
|
19
|
+
assert_recognizes(
|
20
|
+
{ controller: 'pages', action: 'simple', locale: locale.to_s },
|
21
|
+
"/#{locale}/#{I18n.t('routes.simple')}"
|
22
|
+
)
|
23
|
+
|
24
|
+
assert_recognizes(
|
25
|
+
{ controller: 'pages', action: 'complex', locale: locale.to_s, p1: '1', p2: '2' },
|
26
|
+
"/#{locale}/complex/1/2"
|
27
|
+
)
|
28
|
+
|
29
|
+
assert_recognizes(
|
30
|
+
{ controller: 'resources', action: 'index', locale: locale.to_s },
|
31
|
+
"/#{locale}/#{I18n.t('routes.resources')}"
|
32
|
+
)
|
11
33
|
|
12
|
-
assert_recognizes(
|
13
|
-
{ controller: 'namespace/nested_resources', action: 'show', subdomain: country.to_s },
|
14
|
-
"http://#{country}.example.org/#{I18n.t('routes.namespace')}/#{I18n.t('routes.nested_resources')}"
|
15
|
-
)
|
16
|
-
|
17
|
-
assert_recognizes(
|
18
|
-
{ controller: 'namespace/nested', action: 'show', subdomain: country.to_s },
|
19
|
-
"http://#{country}.example.org/#{I18n.t('routes.namespace')}/#{I18n.t('routes.nested')}"
|
20
|
-
)
|
21
|
-
|
22
|
-
assert_recognizes(
|
23
|
-
{ controller: 'simple', action: 'show', subdomain: country.to_s },
|
24
|
-
"http://#{country}.example.org/#{I18n.t('routes.simple')}"
|
25
|
-
)
|
26
|
-
|
27
|
-
assert_recognizes(
|
28
|
-
{ controller: 'params', action: 'show', p1: '1', p2: '2', subdomain: country.to_s },
|
29
|
-
"http://#{country}.example.org/params/1/2"
|
30
|
-
)
|
31
|
-
|
32
|
-
assert_recognizes(
|
33
|
-
{ controller: 'resources', action: 'show', subdomain: country.to_s },
|
34
|
-
"http://#{country}.example.org/#{I18n.t('routes.resources')}"
|
35
|
-
)
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
test "should translate prefix routes" do
|
43
|
-
with_routes_type :prefix do
|
44
|
-
I18n.available_locales.select{ |l| l != :en }.each do |locale|
|
45
|
-
I18n.locale = locale
|
46
|
-
|
47
|
-
assert_recognizes(
|
48
|
-
{ controller: 'namespace/nested', action: 'show', locale: locale.to_s },
|
49
|
-
"/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.nested')}"
|
50
|
-
)
|
51
|
-
|
52
|
-
assert_recognizes(
|
53
|
-
{ controller: 'namespace/nested_resources', action: 'show', locale: locale.to_s },
|
54
|
-
"/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.nested_resources')}"
|
55
|
-
)
|
56
|
-
|
57
|
-
assert_recognizes(
|
58
|
-
{ controller: 'simple', action: 'show', locale: locale.to_s },
|
59
|
-
"/#{locale}/#{I18n.t('routes.simple')}"
|
60
|
-
)
|
61
|
-
|
62
|
-
assert_recognizes(
|
63
|
-
{ controller: 'params', action: 'show', locale: locale.to_s, p1: '1', p2: '2' },
|
64
|
-
"/#{locale}/params/1/2"
|
65
|
-
)
|
66
|
-
|
67
|
-
assert_recognizes(
|
68
|
-
{ controller: 'resources', action: 'show', locale: locale.to_s },
|
69
|
-
"/#{locale}/#{I18n.t('routes.resources')}"
|
70
|
-
)
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
protected
|
77
|
-
|
78
|
-
def with_routes_type(type)
|
79
|
-
Rails.application.config.translatable_routes.selection = type
|
80
|
-
with_routing do |set|
|
81
|
-
set.draw do
|
82
|
-
localized do
|
83
|
-
namespace :namespace do
|
84
|
-
get 'nested', to: 'nested#show', as: :nested
|
85
|
-
resource :nested_resources
|
86
|
-
end
|
87
|
-
get 'simple', to: 'simple#show', as: :simple
|
88
|
-
get 'params/:p1/:p2', to: 'params#show', as: :params
|
89
|
-
resource :resources
|
90
|
-
end
|
91
|
-
end
|
92
|
-
yield
|
93
34
|
end
|
94
35
|
end
|
95
36
|
|
metadata
CHANGED
@@ -1,75 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translatable_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Museways
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: 3.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Minimalistic toolkit to handle translatable routes and detect locale
|
42
42
|
from subdomain or prefix.
|
43
43
|
email:
|
44
|
-
- contact@
|
44
|
+
- contact@museways.com
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
-
|
49
|
+
- MIT-LICENSE
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- lib/translatable_routes.rb
|
50
53
|
- lib/translatable_routes/action_dispatch/mapper.rb
|
51
54
|
- lib/translatable_routes/action_dispatch/named_route_collection.rb
|
52
55
|
- lib/translatable_routes/railtie.rb
|
53
56
|
- lib/translatable_routes/version.rb
|
54
|
-
-
|
55
|
-
-
|
56
|
-
- Rakefile
|
57
|
-
- README.rdoc
|
57
|
+
- test/dummy/README.rdoc
|
58
|
+
- test/dummy/Rakefile
|
58
59
|
- test/dummy/app/assets/javascripts/application.js
|
59
60
|
- test/dummy/app/assets/stylesheets/application.css
|
60
61
|
- test/dummy/app/controllers/application_controller.rb
|
61
|
-
- test/dummy/app/controllers/namespace/
|
62
|
-
- test/dummy/app/controllers/namespace/
|
62
|
+
- test/dummy/app/controllers/namespace/pages_controller.rb
|
63
|
+
- test/dummy/app/controllers/namespace/resources_controller.rb
|
63
64
|
- test/dummy/app/controllers/pages_controller.rb
|
64
|
-
- test/dummy/app/controllers/params_controller.rb
|
65
65
|
- test/dummy/app/controllers/resources_controller.rb
|
66
|
-
- test/dummy/app/controllers/simple_controller.rb
|
67
66
|
- test/dummy/app/helpers/application_helper.rb
|
68
67
|
- test/dummy/app/views/layouts/application.html.erb
|
69
|
-
- test/dummy/app/views/pages/show.html.erb
|
70
68
|
- test/dummy/bin/bundle
|
71
69
|
- test/dummy/bin/rails
|
72
70
|
- test/dummy/bin/rake
|
71
|
+
- test/dummy/config.ru
|
73
72
|
- test/dummy/config/application.rb
|
74
73
|
- test/dummy/config/boot.rb
|
75
74
|
- test/dummy/config/database.yml
|
@@ -84,11 +83,9 @@ files:
|
|
84
83
|
- test/dummy/config/initializers/secret_token.rb
|
85
84
|
- test/dummy/config/initializers/session_store.rb
|
86
85
|
- test/dummy/config/initializers/wrap_parameters.rb
|
87
|
-
- test/dummy/config/locales/en
|
88
|
-
- test/dummy/config/locales/es
|
89
|
-
- test/dummy/config/locales/es-UY.yml
|
86
|
+
- test/dummy/config/locales/en.yml
|
87
|
+
- test/dummy/config/locales/es.yml
|
90
88
|
- test/dummy/config/routes.rb
|
91
|
-
- test/dummy/config.ru
|
92
89
|
- test/dummy/db/development.sqlite3
|
93
90
|
- test/dummy/db/schema.rb
|
94
91
|
- test/dummy/log/development.log
|
@@ -97,18 +94,16 @@ files:
|
|
97
94
|
- test/dummy/public/422.html
|
98
95
|
- test/dummy/public/500.html
|
99
96
|
- test/dummy/public/favicon.ico
|
100
|
-
- test/dummy/Rakefile
|
101
|
-
- test/dummy/README.rdoc
|
102
97
|
- test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
|
103
98
|
- test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
|
104
99
|
- test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
|
105
100
|
- test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
|
106
101
|
- test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
|
107
102
|
- test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
108
|
-
- test/
|
103
|
+
- test/helpers_test.rb
|
109
104
|
- test/routes_test.rb
|
110
105
|
- test/test_helper.rb
|
111
|
-
homepage: https://github.com/
|
106
|
+
homepage: https://github.com/museways/translatable_routes
|
112
107
|
licenses:
|
113
108
|
- MIT
|
114
109
|
metadata: {}
|
@@ -118,17 +113,17 @@ require_paths:
|
|
118
113
|
- lib
|
119
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
115
|
requirements:
|
121
|
-
- -
|
116
|
+
- - ">="
|
122
117
|
- !ruby/object:Gem::Version
|
123
118
|
version: '0'
|
124
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
120
|
requirements:
|
126
|
-
- -
|
121
|
+
- - ">="
|
127
122
|
- !ruby/object:Gem::Version
|
128
123
|
version: '0'
|
129
124
|
requirements: []
|
130
125
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.2.2
|
132
127
|
signing_key:
|
133
128
|
specification_version: 4
|
134
129
|
summary: Translatable Routes for Rails.
|
@@ -136,15 +131,12 @@ test_files:
|
|
136
131
|
- test/dummy/app/assets/javascripts/application.js
|
137
132
|
- test/dummy/app/assets/stylesheets/application.css
|
138
133
|
- test/dummy/app/controllers/application_controller.rb
|
139
|
-
- test/dummy/app/controllers/namespace/
|
140
|
-
- test/dummy/app/controllers/namespace/
|
134
|
+
- test/dummy/app/controllers/namespace/pages_controller.rb
|
135
|
+
- test/dummy/app/controllers/namespace/resources_controller.rb
|
141
136
|
- test/dummy/app/controllers/pages_controller.rb
|
142
|
-
- test/dummy/app/controllers/params_controller.rb
|
143
137
|
- test/dummy/app/controllers/resources_controller.rb
|
144
|
-
- test/dummy/app/controllers/simple_controller.rb
|
145
138
|
- test/dummy/app/helpers/application_helper.rb
|
146
139
|
- test/dummy/app/views/layouts/application.html.erb
|
147
|
-
- test/dummy/app/views/pages/show.html.erb
|
148
140
|
- test/dummy/bin/bundle
|
149
141
|
- test/dummy/bin/rails
|
150
142
|
- test/dummy/bin/rake
|
@@ -162,9 +154,8 @@ test_files:
|
|
162
154
|
- test/dummy/config/initializers/secret_token.rb
|
163
155
|
- test/dummy/config/initializers/session_store.rb
|
164
156
|
- test/dummy/config/initializers/wrap_parameters.rb
|
165
|
-
- test/dummy/config/locales/en
|
166
|
-
- test/dummy/config/locales/es
|
167
|
-
- test/dummy/config/locales/es-UY.yml
|
157
|
+
- test/dummy/config/locales/en.yml
|
158
|
+
- test/dummy/config/locales/es.yml
|
168
159
|
- test/dummy/config/routes.rb
|
169
160
|
- test/dummy/config.ru
|
170
161
|
- test/dummy/db/development.sqlite3
|
@@ -183,6 +174,6 @@ test_files:
|
|
183
174
|
- test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
|
184
175
|
- test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
|
185
176
|
- test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
186
|
-
- test/
|
177
|
+
- test/helpers_test.rb
|
187
178
|
- test/routes_test.rb
|
188
179
|
- test/test_helper.rb
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module TranslatableRoutes
|
2
|
-
module ActionController
|
3
|
-
module Base
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
prepend_before_filter :select_locale
|
8
|
-
end
|
9
|
-
|
10
|
-
protected
|
11
|
-
|
12
|
-
def select_locale
|
13
|
-
if Rails.application.config.translatable_routes.selection == :subdomain
|
14
|
-
Rails.application.config.translatable_routes.mapping.each_pair do |key, value|
|
15
|
-
if (value.is_a? Array and value.include? request.subdomain.to_sym) or value == request.subdomain.to_sym
|
16
|
-
I18n.locale = "#{key}-#{request.subdomain.upcase}"
|
17
|
-
break
|
18
|
-
end
|
19
|
-
end
|
20
|
-
elsif not params[:locale].nil?
|
21
|
-
I18n.locale = params[:locale]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def subdomains
|
26
|
-
@subdomains ||= begin
|
27
|
-
values = []
|
28
|
-
Rails.application.config.translatable_routes.mapping.values.each do |value|
|
29
|
-
value = [value] unless value.is_a? Array
|
30
|
-
values.concat value
|
31
|
-
end
|
32
|
-
values
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
File without changes
|
data/test/locale_test.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LocaleTest < ActionController::TestCase
|
4
|
-
tests PagesController
|
5
|
-
|
6
|
-
test "should select correct locale by subdomain" do
|
7
|
-
Rails.application.config.translatable_routes.selection = :subdomain
|
8
|
-
subdomains = []
|
9
|
-
Rails.application.config.translatable_routes.mapping.each_pair do |lang, countries|
|
10
|
-
countries = [countries] unless countries.is_a? Array
|
11
|
-
countries.each do |country|
|
12
|
-
|
13
|
-
@request.host = "#{country}.example.org"
|
14
|
-
get :show
|
15
|
-
assert_equal I18n.locale.to_s, "#{lang}-#{country.upcase}"
|
16
|
-
|
17
|
-
subdomains << country
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
assert_equal @controller.send(:subdomains), subdomains
|
22
|
-
end
|
23
|
-
|
24
|
-
test "should select correct locale by prefix" do
|
25
|
-
Rails.application.config.translatable_routes.selection = :prefix
|
26
|
-
I18n.available_locales.select{ |l| l != :en }.each do |locale|
|
27
|
-
|
28
|
-
get :show, locale: locale.to_s
|
29
|
-
assert_equal I18n.locale.to_s, locale.to_s
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|