dragoman 0.0.8 → 0.0.9
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.
- checksums.yaml +8 -8
- data/lib/dragoman/mapper.rb +1 -1
- data/lib/dragoman/route_set.rb +3 -1
- data/lib/dragoman/url_helpers.rb +11 -2
- data/lib/dragoman/version.rb +1 -1
- data/spec/routing/routes_spec.rb +48 -43
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmFlODAzNTRiOWE3ODUyYjYzM2E2YTM0ZDQ0MmM1YjBjMTAyZmZmMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGZiZmE2MDhlMzJjODBiN2NkNDUzZDg4ZWE3NTA3NWYzNGE1Nzg2Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWM3ZGEyN2IyODQyMDlkNGU4NzFmZTljNjZlZWVlZTY1NzY1Y2RmNzM1NTY2
|
10
|
+
NTg2YzllYzNjYTZkMjU3MjE5YWY2ZWYzMDg0MTk2YWM1OGJjMjgyOGJkNmVi
|
11
|
+
MzI4ZjIxM2Y4ZjU3ZGZjMjc2ZDZjMTg1Y2I2ZWVkNmQ3NTc4ZGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWQyMjc4MDA5NGQ2MTAyZThkNzBiMjgwYzYwYmY2OWM3MmI1MGZiY2Y2MzJl
|
14
|
+
ZDJlMDUzZWYyMThjNDMxODIxYWQyM2FmYmMxNmRiYzRmM2I2ZGY1ZTUxMDkx
|
15
|
+
YmIwMjYxY2ExYWZhYzYxYTc1M2JmMWZmNDE2YTRjY2Q3ZGM1ZDc=
|
data/lib/dragoman/mapper.rb
CHANGED
@@ -2,7 +2,7 @@ module Dragoman
|
|
2
2
|
module Mapper
|
3
3
|
def localize
|
4
4
|
@locales = I18n.available_locales
|
5
|
-
scope '
|
5
|
+
scope ':locale', shallow_path: ':locale', defaults: {dragoman_options: {locales: @locales}} do
|
6
6
|
yield
|
7
7
|
end
|
8
8
|
@locales = nil
|
data/lib/dragoman/route_set.rb
CHANGED
@@ -13,6 +13,7 @@ module Dragoman
|
|
13
13
|
dragoman_options[:locales].each do |locale|
|
14
14
|
new_conditions = conditions.dup
|
15
15
|
new_requirements = requirements.dup
|
16
|
+
new_defaults = defaults.dup
|
16
17
|
|
17
18
|
new_name = name ? "#{name}_#{locale}" : nil
|
18
19
|
new_name = nil if new_name && named_routes.routes[new_name.to_sym] # Why is this necessary
|
@@ -23,7 +24,8 @@ module Dragoman
|
|
23
24
|
new_conditions[:parsed_path_info] = Dragoman::Journey::Parser.new.parse new_path if new_conditions[:parsed_path_info]
|
24
25
|
end
|
25
26
|
new_requirements[:locale] = locale
|
26
|
-
|
27
|
+
new_defaults[:locale] = locale
|
28
|
+
add_route_without_localization app, new_conditions, new_requirements, new_defaults, new_name, anchor
|
27
29
|
end
|
28
30
|
else
|
29
31
|
add_route_without_localization app, conditions, requirements, defaults, name, anchor
|
data/lib/dragoman/url_helpers.rb
CHANGED
@@ -3,10 +3,10 @@ module Dragoman
|
|
3
3
|
|
4
4
|
def self.add_untranslated_helpers name, path_module, url_module
|
5
5
|
path_module.send :define_method, "#{name}_path" do |*args|
|
6
|
-
__send__(Dragoman::UrlHelpers.localized_helper_name(name, :path), *args)
|
6
|
+
__send__(Dragoman::UrlHelpers.localized_helper_name(name, :path), *Dragoman::UrlHelpers.args_with_locale(*args))
|
7
7
|
end
|
8
8
|
url_module.send :define_method, "#{name}_url" do |*args|
|
9
|
-
__send__(Dragoman::UrlHelpers.localized_helper_name(name, :url), *args)
|
9
|
+
__send__(Dragoman::UrlHelpers.localized_helper_name(name, :url), *Dragoman::UrlHelpers.args_with_locale(*args))
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -15,5 +15,14 @@ module Dragoman
|
|
15
15
|
"#{name}_#{locale}_#{url_helper_type}"
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.args_with_locale *args
|
19
|
+
if args[0].is_a?(Hash)
|
20
|
+
args[0].merge!({locale: I18n.locale})
|
21
|
+
else
|
22
|
+
args << {locale: I18n.locale}
|
23
|
+
end
|
24
|
+
args
|
25
|
+
end
|
26
|
+
|
18
27
|
end
|
19
28
|
end
|
data/lib/dragoman/version.rb
CHANGED
data/spec/routing/routes_spec.rb
CHANGED
@@ -13,92 +13,97 @@ describe 'routes' do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'translates resources' do
|
16
|
-
expect(products_en_path).to eq '/products'
|
17
|
-
expect(new_product_en_path).to eq '/products/new'
|
18
|
-
expect(edit_product_en_path(id: 1)).to eq '/products/1/edit'
|
19
|
-
expect(products_nl_path).to eq '/producten'
|
20
|
-
expect(new_product_nl_path).to eq '/producten/nieuw'
|
21
|
-
expect(edit_product_nl_path(id: 1)).to eq '/producten/1/wijzigen'
|
16
|
+
expect(products_en_path).to eq '/en/products'
|
17
|
+
expect(new_product_en_path).to eq '/en/products/new'
|
18
|
+
expect(edit_product_en_path(id: 1)).to eq '/en/products/1/edit'
|
19
|
+
expect(products_nl_path).to eq '/nl/producten'
|
20
|
+
expect(new_product_nl_path).to eq '/nl/producten/nieuw'
|
21
|
+
expect(edit_product_nl_path(id: 1)).to eq '/nl/producten/1/wijzigen'
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'translates resource' do
|
25
|
-
expect(account_en_path).to eq '/account'
|
26
|
-
expect(edit_account_en_path).to eq '/account/edit'
|
27
|
-
expect(new_account_en_path).to eq '/account/new'
|
28
|
-
expect(account_nl_path).to eq '/profiel'
|
29
|
-
expect(edit_account_nl_path).to eq '/profiel/wijzigen'
|
30
|
-
expect(new_account_nl_path).to eq '/profiel/nieuw'
|
25
|
+
expect(account_en_path).to eq '/en/account'
|
26
|
+
expect(edit_account_en_path).to eq '/en/account/edit'
|
27
|
+
expect(new_account_en_path).to eq '/en/account/new'
|
28
|
+
expect(account_nl_path).to eq '/nl/profiel'
|
29
|
+
expect(edit_account_nl_path).to eq '/nl/profiel/wijzigen'
|
30
|
+
expect(new_account_nl_path).to eq '/nl/profiel/nieuw'
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'translates namespaced routes' do
|
34
|
-
expect(admin_customers_nl_path).to eq '/beheer/klanten'
|
35
|
-
expect(admin_customers_en_path).to eq '/admin/customers'
|
34
|
+
expect(admin_customers_nl_path).to eq '/nl/beheer/klanten'
|
35
|
+
expect(admin_customers_en_path).to eq '/en/admin/customers'
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'translates scoped routes' do
|
39
|
-
expect(payments_nl_path).to eq '/geheim/betalingen'
|
40
|
-
expect(payments_en_path).to eq '/secret/payments'
|
39
|
+
expect(payments_nl_path).to eq '/nl/geheim/betalingen'
|
40
|
+
expect(payments_en_path).to eq '/en/secret/payments'
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'sets the correct locale' do
|
44
|
-
expect(get: '/producten').to route_to(controller: 'products', action: 'index')
|
45
|
-
expect(get: '/products').to route_to(controller: 'products', action: 'index')
|
46
44
|
expect(get: '/nl/producten').to route_to(controller: 'products', action: 'index', locale: 'nl')
|
45
|
+
expect(get: '/nl/products').not_to be_routable
|
46
|
+
expect(get: '/products').not_to be_routable
|
47
47
|
expect(get: '/en/products').to route_to(controller: 'products', action: 'index', locale: 'en')
|
48
48
|
expect(get: '/en/producten').not_to be_routable
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'skips empty paths' do
|
52
|
-
expect(empty_nl_path).to eq '/'
|
53
|
-
expect(empty_en_path).to eq '/'
|
52
|
+
expect(empty_nl_path).to eq '/nl'
|
53
|
+
expect(empty_en_path).to eq '/en'
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'skips empty scopes' do
|
57
|
-
expect(empty_books_nl_path).to eq '/boeken'
|
58
|
-
expect(empty_books_en_path).to eq '/books'
|
57
|
+
expect(empty_books_nl_path).to eq '/nl/boeken'
|
58
|
+
expect(empty_books_en_path).to eq '/en/books'
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'looks up translations by the path option if present' do
|
62
|
-
expect(edit_invitation_nl_path(id: 2)).to eq '/uitnodigingen/2/accepteren'
|
62
|
+
expect(edit_invitation_nl_path(id: 2)).to eq '/nl/uitnodigingen/2/accepteren'
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'looks up resources translations by the path option if present' do
|
66
|
-
expect(chairs_nl_path).to eq '/stoelen'
|
67
|
-
expect(chairs_en_path).to eq '/seats'
|
66
|
+
expect(chairs_nl_path).to eq '/nl/stoelen'
|
67
|
+
expect(chairs_en_path).to eq '/en/seats'
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'translates shallow paths' do
|
71
|
-
expect(driver_nl_path(id: 3)).to eq '/snelle/bestuurders/3'
|
72
|
-
expect(driver_en_path(id: 3)).to eq '/fast/drivers/3'
|
73
|
-
expect(driver_en_path(id: 3, locale: 'en')).to eq '/en/fast/drivers/3'
|
71
|
+
expect(driver_nl_path(id: 3)).to eq '/nl/snelle/bestuurders/3'
|
72
|
+
expect(driver_en_path(id: 3)).to eq '/en/fast/drivers/3'
|
74
73
|
end
|
75
74
|
|
76
75
|
it 'skips blank translations' do
|
77
|
-
expect(music_nl_path).to eq '/music'
|
76
|
+
expect(music_nl_path).to eq '/nl/music'
|
78
77
|
end
|
79
78
|
|
80
79
|
it 'uses the default path if no translation is present' do
|
81
|
-
expect(sounds_en_path).to eq '/glitches'
|
82
|
-
expect(sounds_nl_path).to eq '/sounds'
|
80
|
+
expect(sounds_en_path).to eq '/en/glitches'
|
81
|
+
expect(sounds_nl_path).to eq '/nl/sounds'
|
83
82
|
end
|
84
83
|
|
85
84
|
it 'translates routes in the original order as specified in routes.rb' do
|
86
|
-
expect(get: 'votes/positive').to route_to(action: 'positive', controller: 'votes')
|
87
|
-
expect(get: 'votes/positief').to route_to(action: 'positive', controller: 'votes') # should use 'positive' action instead of 'show'
|
85
|
+
expect(get: '/en/votes/positive').to route_to(action: 'positive', controller: 'votes', locale: 'en')
|
86
|
+
expect(get: '/nl/votes/positief').to route_to(action: 'positive', controller: 'votes', locale: 'nl') # should use 'positive' action instead of 'show'
|
88
87
|
end
|
89
88
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
89
|
+
it 'uses the I18n locale to add untranslated path helpers' do
|
90
|
+
I18n.locale = :nl
|
91
|
+
expect(product_path(id: 1)).to eq '/nl/producten/1'
|
92
|
+
expect(payments_path).to eq '/nl/geheim/betalingen'
|
93
|
+
|
94
|
+
I18n.locale = :en
|
95
|
+
expect(product_path(id: 1)).to eq '/en/products/1'
|
96
|
+
expect(payments_path).to eq '/en/secret/payments'
|
95
97
|
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
it 'uses the I18n locale to add untranslated url helpers' do
|
100
|
+
I18n.locale = :nl
|
101
|
+
expect(product_url(id: 1)).to eq 'http://example.com/nl/producten/1'
|
102
|
+
expect(payments_url).to eq 'http://example.com/nl/geheim/betalingen'
|
103
|
+
|
104
|
+
I18n.locale = :en
|
105
|
+
expect(product_url(id: 1)).to eq 'http://example.com/en/products/1'
|
106
|
+
expect(payments_url).to eq 'http://example.com/en/secret/payments'
|
102
107
|
end
|
103
108
|
|
104
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragoman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pieter Visser
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|