route_translator 4.2.5 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE +1 -1
- data/README.md +12 -1
- data/lib/route_translator.rb +26 -12
- data/lib/route_translator/host.rb +16 -10
- data/lib/route_translator/translator.rb +46 -129
- data/lib/route_translator/translator/path.rb +49 -0
- data/lib/route_translator/translator/path/segment.rb +41 -0
- data/lib/route_translator/translator/route_helpers.rb +52 -0
- data/lib/route_translator/version.rb +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba50272fd47e4a93ea47418a84de0cf5489eaee4
|
4
|
+
data.tar.gz: 0b4458fa81aea378ecb5fe39c50b655d7c637a97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e082a7feb66e67415ac691ce77939cf3a9f8f90aa5199ca285837c7d1fe9ad6d1f8ee40bbf659206ade3aa2e72cb224ba2c4de3a9e3b12f00fd8fff1faf08c66
|
7
|
+
data.tar.gz: cb761bd633952e302c7a76223f96992c2f9caee66a0babbf7fc56b0a7e0508686df7ddc28dd71174b86487fe2d52032ff871972a4b3f14cb07f28af80b6db65b
|
data/CHANGELOG.md
CHANGED
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2007 Raul Murciano [http://raul.murciano.net], Domestika INTERNET S.L. [http://domestika.org], 2015 Enric Lluelles [http://enric.lluell.es]
|
3
|
+
Copyright (c) 2007 Raul Murciano [http://raul.murciano.net], Domestika INTERNET S.L. [http://domestika.org], 2015 Enric Lluelles [http://enric.lluell.es], 2016 Geremia Taglialatela
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Build Status](https://travis-ci.org/enriclluelles/route_translator.svg?branch=master)](https://travis-ci.org/enriclluelles/route_translator)
|
5
5
|
[![Dependency Status](https://gemnasium.com/enriclluelles/route_translator.svg)](https://gemnasium.com/enriclluelles/route_translator)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/enriclluelles/route_translator/badges/gpa.svg)](https://codeclimate.com/github/enriclluelles/route_translator)
|
7
|
-
[![Coverage Status](https://coveralls.io/repos/enriclluelles/route_translator/badge.svg?branch=master
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/github/enriclluelles/route_translator/badge.svg?branch=master)](https://coveralls.io/github/enriclluelles/route_translator?branch=master)
|
8
8
|
|
9
9
|
RouteTranslator is a gem to allow you to manage the translations of your app routes with a simple dictionary format.
|
10
10
|
|
@@ -223,7 +223,18 @@ If `host_locales` option is set, the following options will be forced (even if y
|
|
223
223
|
|
224
224
|
This is to avoid odd behaviour brought about by route conflicts and because `host_locales` forces and hides the host-locale dynamically.
|
225
225
|
|
226
|
+
### Testing
|
227
|
+
Testing your controllers with routes-translator is easy, just add a locale parameter for your localized routes. Otherwise, an ActionController::UrlGenerationError will raise.
|
226
228
|
|
229
|
+
```ruby
|
230
|
+
describe 'GET index' do
|
231
|
+
it 'should respond with success' do
|
232
|
+
get :index, { locale: 'fr' }
|
233
|
+
|
234
|
+
expect(response).to be_success
|
235
|
+
end
|
236
|
+
end
|
237
|
+
```
|
227
238
|
|
228
239
|
## Contributing
|
229
240
|
|
data/lib/route_translator.rb
CHANGED
@@ -14,7 +14,20 @@ module RouteTranslator
|
|
14
14
|
:generate_unnamed_unlocalized_routes, :available_locales,
|
15
15
|
:host_locales, :disable_fallback)
|
16
16
|
|
17
|
-
|
17
|
+
class << self
|
18
|
+
private
|
19
|
+
|
20
|
+
def resolve_host_locale_config_conflicts
|
21
|
+
@config.generate_unlocalized_routes = false
|
22
|
+
@config.generate_unnamed_unlocalized_routes = false
|
23
|
+
@config.force_locale = false
|
24
|
+
@config.hide_locale = false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module_function
|
29
|
+
|
30
|
+
def config(&block)
|
18
31
|
@config ||= Configuration.new
|
19
32
|
@config.force_locale ||= false
|
20
33
|
@config.hide_locale ||= false
|
@@ -22,23 +35,24 @@ module RouteTranslator
|
|
22
35
|
@config.locale_param_key ||= :locale
|
23
36
|
@config.generate_unnamed_unlocalized_routes ||= false
|
24
37
|
@config.host_locales ||= ActiveSupport::OrderedHash.new
|
25
|
-
@config.available_locales ||=
|
38
|
+
@config.available_locales ||= []
|
26
39
|
@config.disable_fallback ||= false
|
27
40
|
yield @config if block
|
28
|
-
|
41
|
+
resolve_host_locale_config_conflicts unless @config.host_locales.empty?
|
29
42
|
@config
|
30
43
|
end
|
31
44
|
|
32
|
-
def
|
33
|
-
|
34
|
-
@config.generate_unlocalized_routes = false
|
35
|
-
@config.generate_unnamed_unlocalized_routes = false
|
36
|
-
@config.force_locale = false
|
37
|
-
@config.hide_locale = false
|
38
|
-
end
|
45
|
+
def locale_param_key
|
46
|
+
config.locale_param_key
|
39
47
|
end
|
40
48
|
|
41
|
-
def
|
42
|
-
config.
|
49
|
+
def available_locales
|
50
|
+
locales = config.available_locales
|
51
|
+
|
52
|
+
if locales.any?
|
53
|
+
locales.map(&:to_sym)
|
54
|
+
else
|
55
|
+
I18n.available_locales.dup
|
56
|
+
end
|
43
57
|
end
|
44
58
|
end
|
@@ -1,16 +1,12 @@
|
|
1
1
|
module RouteTranslator
|
2
2
|
module Host
|
3
|
-
|
4
|
-
|
5
|
-
result << locale.to_sym if host =~ regex_for(pattern)
|
6
|
-
end
|
7
|
-
locales &= I18n.available_locales
|
8
|
-
(locales.first || I18n.default_locale).to_sym
|
9
|
-
end
|
3
|
+
class << self
|
4
|
+
private
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def regex_for(host_string)
|
7
|
+
escaped = Regexp.escape(host_string).gsub('\*', '.*?').gsub('\.', '\.?')
|
8
|
+
Regexp.new("^#{escaped}$", Regexp::IGNORECASE)
|
9
|
+
end
|
14
10
|
end
|
15
11
|
|
16
12
|
def native_locale?(locale)
|
@@ -20,5 +16,15 @@ module RouteTranslator
|
|
20
16
|
def native_locales
|
21
17
|
config.host_locales.values.map { |locale| :"native_#{locale}" }
|
22
18
|
end
|
19
|
+
|
20
|
+
module_function
|
21
|
+
|
22
|
+
def locale_from_host(host)
|
23
|
+
locales = RouteTranslator.config.host_locales.each_with_object([]) do |(pattern, locale), result|
|
24
|
+
result << locale.to_sym if host =~ regex_for(pattern)
|
25
|
+
end
|
26
|
+
locales &= I18n.available_locales
|
27
|
+
(locales.first || I18n.default_locale).to_sym
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
@@ -1,157 +1,74 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('../translator/route_helpers', __FILE__)
|
4
|
+
require File.expand_path('../translator/path', __FILE__)
|
5
|
+
|
2
6
|
module RouteTranslator
|
3
7
|
module Translator
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
class << self
|
9
|
+
private
|
10
|
+
|
11
|
+
def available_locales
|
12
|
+
locales = RouteTranslator.available_locales
|
13
|
+
locales.push(*RouteTranslator.native_locales) if RouteTranslator.native_locales.present?
|
14
|
+
# Make sure the default locale is translated in last place to avoid
|
15
|
+
# problems with wildcards when default locale is omitted in paths. The
|
16
|
+
# default routes will catch all paths like wildcard if it is translated first.
|
17
|
+
locales.delete I18n.default_locale
|
18
|
+
locales.push I18n.default_locale
|
19
|
+
end
|
20
|
+
|
21
|
+
def host_locales_option?
|
22
|
+
RouteTranslator.config.host_locales.present?
|
23
|
+
end
|
24
|
+
|
25
|
+
def translate_name(name, locale, named_routes_names)
|
26
|
+
return unless name.present?
|
27
|
+
translated_name = "#{name}_#{locale.to_s.underscore}"
|
28
|
+
if named_routes_names.include?(translated_name.to_sym)
|
29
|
+
nil
|
30
|
+
else
|
31
|
+
translated_name
|
32
|
+
end
|
20
33
|
end
|
21
34
|
|
22
|
-
|
23
|
-
|
24
|
-
['url', url_helpers_module, url_helpers_list]
|
25
|
-
].each do |suffix, helper_container, helper_list|
|
26
|
-
new_helper_name = "#{old_name}_#{suffix}"
|
35
|
+
def translate_conditions(conditions, translated_path)
|
36
|
+
translated_conditions = conditions.dup
|
27
37
|
|
28
|
-
|
38
|
+
translated_conditions[:path_info] = translated_path
|
39
|
+
translated_conditions[:parsed_path_info] = ActionDispatch::Journey::Parser.new.parse(translated_conditions[:path_info]) if conditions[:parsed_path_info]
|
29
40
|
|
30
|
-
|
31
|
-
|
41
|
+
if translated_conditions[:required_defaults] && !translated_conditions[:required_defaults].include?(RouteTranslator.locale_param_key)
|
42
|
+
translated_conditions[:required_defaults] << RouteTranslator.locale_param_key
|
32
43
|
end
|
33
44
|
|
34
|
-
|
45
|
+
translated_conditions
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
38
|
-
|
39
|
-
%w(ActionController ActionMailer ActionView).each do |klass_name|
|
40
|
-
next unless Module.const_defined?(klass_name)
|
41
|
-
klass_name.constantize::TestCase.__send__(:include, helper_container)
|
42
|
-
end
|
43
|
-
end
|
49
|
+
module_function
|
44
50
|
|
45
|
-
def
|
46
|
-
|
51
|
+
def translations_for(app, conditions, requirements, defaults, route_name, anchor, route_set)
|
52
|
+
RouteTranslator::Translator::RouteHelpers.add route_name, route_set.named_routes
|
47
53
|
|
48
54
|
available_locales.each do |locale|
|
49
|
-
new_conditions = conditions.dup
|
50
55
|
begin
|
51
|
-
|
56
|
+
translated_path = RouteTranslator::Translator::Path.translate(conditions[:path_info], locale)
|
52
57
|
rescue I18n::MissingTranslationData => e
|
53
58
|
raise e unless RouteTranslator.config.disable_fallback
|
54
59
|
next
|
55
60
|
end
|
56
|
-
new_conditions[:parsed_path_info] = ActionDispatch::Journey::Parser.new.parse(new_conditions[:path_info]) if conditions[:parsed_path_info]
|
57
|
-
if new_conditions[:required_defaults] && !new_conditions[:required_defaults].include?(RouteTranslator.locale_param_key)
|
58
|
-
new_conditions[:required_defaults] << RouteTranslator.locale_param_key
|
59
|
-
end
|
60
|
-
new_defaults = defaults.merge(RouteTranslator.locale_param_key => locale.to_s.gsub('native_', ''))
|
61
|
-
new_requirements = requirements.merge(RouteTranslator.locale_param_key => locale.to_s)
|
62
|
-
new_route_name = translate_name(route_name, locale)
|
63
|
-
new_route_name = nil if new_route_name && route_set.named_routes.routes[new_route_name.to_sym] # TODO: Investigate this :(
|
64
|
-
block.call(app, new_conditions, new_requirements, new_defaults, new_route_name, anchor)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.available_locales
|
69
|
-
available_locales = config_locales || I18n.available_locales.dup
|
70
|
-
available_locales.push(*RouteTranslator.native_locales) if RouteTranslator.native_locales.present?
|
71
|
-
# Make sure the default locale is translated in last place to avoid
|
72
|
-
# problems with wildcards when default locale is omitted in paths. The
|
73
|
-
# default routes will catch all paths like wildcard if it is translated first.
|
74
|
-
available_locales.push(available_locales.delete(I18n.default_locale))
|
75
|
-
end
|
76
61
|
|
77
|
-
|
78
|
-
if RouteTranslator.config.available_locales
|
79
|
-
RouteTranslator.config.available_locales.map(&:to_sym)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# Translates a path and adds the locale prefix.
|
84
|
-
def self.translate_path(path, locale)
|
85
|
-
new_path = path.dup
|
86
|
-
final_optional_segments = new_path.slice!(%r{(\([^\/]+\))$})
|
87
|
-
translated_segments = new_path.split('/').map do |seg|
|
88
|
-
seg.split('.').map { |phrase| translate_path_segment(phrase, locale) }.join('.')
|
89
|
-
end
|
90
|
-
translated_segments.reject!(&:empty?)
|
62
|
+
new_conditions = translate_conditions(conditions, translated_path)
|
91
63
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
joined_segments = translated_segments.join('/')
|
97
|
-
|
98
|
-
"/#{joined_segments}#{final_optional_segments}".gsub(%r{\/\(\/}, '(/')
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.display_locale?(locale)
|
102
|
-
!RouteTranslator.config.hide_locale && !RouteTranslator.native_locale?(locale) &&
|
103
|
-
(!default_locale?(locale) ||
|
104
|
-
RouteTranslator.config.force_locale ||
|
105
|
-
RouteTranslator.config.generate_unlocalized_routes ||
|
106
|
-
RouteTranslator.config.generate_unnamed_unlocalized_routes)
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.translate_name(n, locale)
|
110
|
-
"#{n}_#{locale.to_s.underscore}" if n.present?
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.default_locale?(locale)
|
114
|
-
I18n.default_locale.to_sym == locale.to_sym
|
115
|
-
end
|
116
|
-
|
117
|
-
# Tries to translate a single path segment. If the path segment
|
118
|
-
# contains sth. like a optional format "people(.:format)", only
|
119
|
-
# "people" will be translated, if there is no translation, the path
|
120
|
-
# segment is blank, begins with a ":" (param key) or "*" (wildcard),
|
121
|
-
# the segment is returned untouched
|
122
|
-
def self.translate_path_segment(segment, locale)
|
123
|
-
return segment if segment.empty?
|
124
|
-
named_param, hyphenized = segment.split('-'.freeze, 2) if segment.starts_with?(':'.freeze)
|
125
|
-
return "#{named_param}-#{translate_path_segment(hyphenized.dup, locale)}" if hyphenized
|
126
|
-
return segment if segment.starts_with?('('.freeze) || segment.starts_with?('*'.freeze) || segment.include?(':'.freeze)
|
127
|
-
|
128
|
-
appended_part = segment.slice!(/(\()$/)
|
129
|
-
match = TRANSLATABLE_SEGMENT.match(segment)[1] if TRANSLATABLE_SEGMENT.match(segment)
|
130
|
-
|
131
|
-
(translate_string(match, locale) || segment) + appended_part.to_s
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.translate_string(str, locale)
|
135
|
-
locale = locale.to_s.gsub('native_', '')
|
136
|
-
opts = { scope: :routes, locale: locale }
|
137
|
-
if RouteTranslator.config.disable_fallback && locale.to_s != I18n.default_locale.to_s
|
138
|
-
opts[:fallback] = true
|
139
|
-
else
|
140
|
-
opts[:default] = str
|
64
|
+
new_defaults = defaults.merge(RouteTranslator.locale_param_key => locale.to_s.gsub('native_', ''))
|
65
|
+
new_requirements = requirements.merge(RouteTranslator.locale_param_key => locale.to_s)
|
66
|
+
new_route_name = translate_name(route_name, locale, route_set.named_routes.routes)
|
67
|
+
yield app, new_conditions, new_requirements, new_defaults, new_route_name, anchor
|
141
68
|
end
|
142
|
-
res = I18n.translate(str, opts)
|
143
|
-
URI.escape(res)
|
144
|
-
end
|
145
|
-
|
146
|
-
def self.locale_param_present?(path)
|
147
|
-
!path.split('/').detect { |segment| segment.to_s == ":#{RouteTranslator.locale_param_key}" }.nil?
|
148
|
-
end
|
149
|
-
|
150
|
-
def self.host_locales_option?
|
151
|
-
RouteTranslator.config.host_locales.present?
|
152
69
|
end
|
153
70
|
|
154
|
-
def
|
71
|
+
def route_name_for(args, old_name, suffix, kaller)
|
155
72
|
args_hash = args.detect { |arg| arg.is_a?(Hash) }
|
156
73
|
args_locale = host_locales_option? && args_hash && args_hash[:locale]
|
157
74
|
current_locale_name = I18n.locale.to_s.underscore
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path('../path/segment', __FILE__)
|
2
|
+
|
3
|
+
module RouteTranslator
|
4
|
+
module Translator
|
5
|
+
module Path
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
|
9
|
+
def display_locale?(locale)
|
10
|
+
!RouteTranslator.config.hide_locale && !RouteTranslator.native_locale?(locale) &&
|
11
|
+
(!default_locale?(locale) || config_requires_locale?)
|
12
|
+
end
|
13
|
+
|
14
|
+
def config_requires_locale?
|
15
|
+
config = RouteTranslator.config
|
16
|
+
(config.force_locale || config.generate_unlocalized_routes || config.generate_unnamed_unlocalized_routes).present?
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_locale?(locale)
|
20
|
+
locale.to_sym == I18n.default_locale.to_sym
|
21
|
+
end
|
22
|
+
|
23
|
+
def locale_param_present?(path)
|
24
|
+
path.split('/').include? ":#{RouteTranslator.locale_param_key}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module_function
|
29
|
+
|
30
|
+
# Translates a path and adds the locale prefix.
|
31
|
+
def translate(path, locale)
|
32
|
+
new_path = path.dup
|
33
|
+
final_optional_segments = new_path.slice!(%r{(\([^\/]+\))$})
|
34
|
+
translated_segments = new_path.split('/').map do |seg|
|
35
|
+
seg.split('.').map { |phrase| Segment.translate(phrase, locale) }.join('.')
|
36
|
+
end
|
37
|
+
translated_segments.reject!(&:empty?)
|
38
|
+
|
39
|
+
if display_locale?(locale) && !locale_param_present?(new_path)
|
40
|
+
translated_segments.unshift(locale.to_s.downcase)
|
41
|
+
end
|
42
|
+
|
43
|
+
joined_segments = translated_segments.join('/')
|
44
|
+
|
45
|
+
"/#{joined_segments}#{final_optional_segments}".gsub(%r{\/\(\/}, '(/')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RouteTranslator
|
2
|
+
module Translator
|
3
|
+
module Path
|
4
|
+
module Segment
|
5
|
+
class << self
|
6
|
+
def translate_string(str, locale)
|
7
|
+
locale = locale.to_s.gsub('native_', '')
|
8
|
+
opts = { scope: :routes, locale: locale }
|
9
|
+
if RouteTranslator.config.disable_fallback && locale.to_s != I18n.default_locale.to_s
|
10
|
+
opts[:fallback] = true
|
11
|
+
else
|
12
|
+
opts[:default] = str
|
13
|
+
end
|
14
|
+
res = I18n.translate(str, opts)
|
15
|
+
URI.escape(res)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module_function
|
20
|
+
|
21
|
+
# Translates a single path segment.
|
22
|
+
#
|
23
|
+
# If the path segment contains something like an optional format
|
24
|
+
# "people(.:format)", only "people" will be translated.
|
25
|
+
# If there is no translation, the path segment is blank, begins with a
|
26
|
+
# ":" (param key) or "*" (wildcard), the segment is returned untouched.
|
27
|
+
def translate(segment, locale)
|
28
|
+
return segment if segment.empty?
|
29
|
+
named_param, hyphenized = segment.split('-'.freeze, 2) if segment.starts_with?(':'.freeze)
|
30
|
+
return "#{named_param}-#{translate(hyphenized.dup, locale)}" if hyphenized
|
31
|
+
return segment if segment.starts_with?('('.freeze) || segment.starts_with?('*'.freeze) || segment.include?(':'.freeze)
|
32
|
+
|
33
|
+
appended_part = segment.slice!(/(\()$/)
|
34
|
+
match = TRANSLATABLE_SEGMENT.match(segment)[1] if TRANSLATABLE_SEGMENT.match(segment)
|
35
|
+
|
36
|
+
(translate_string(match, locale) || segment) + appended_part.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module RouteTranslator
|
2
|
+
module Translator
|
3
|
+
module RouteHelpers
|
4
|
+
class << self
|
5
|
+
private
|
6
|
+
|
7
|
+
def add_helpers_to_test_cases(helper_container)
|
8
|
+
%w(ActionController ActionMailer ActionView).each do |klass_name|
|
9
|
+
next unless Module.const_defined?(klass_name)
|
10
|
+
klass_name.constantize::TestCase.__send__(:include, helper_container)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
# Add standard route helpers for default locale e.g.
|
18
|
+
# I18n.locale = :de
|
19
|
+
# people_path -> people_de_path
|
20
|
+
# I18n.locale = :fr
|
21
|
+
# people_path -> people_fr_path
|
22
|
+
def add(old_name, named_route_collection)
|
23
|
+
if named_route_collection.respond_to?(:url_helpers_module)
|
24
|
+
url_helpers_module = named_route_collection.url_helpers_module
|
25
|
+
path_helpers_module = named_route_collection.path_helpers_module
|
26
|
+
url_helpers_list = named_route_collection.helper_names
|
27
|
+
path_helpers_list = named_route_collection.helper_names
|
28
|
+
else
|
29
|
+
url_helpers_module = named_route_collection.module
|
30
|
+
path_helpers_module = named_route_collection.module
|
31
|
+
url_helpers_list = named_route_collection.helpers
|
32
|
+
path_helpers_list = named_route_collection.helpers
|
33
|
+
end
|
34
|
+
|
35
|
+
[
|
36
|
+
['path', path_helpers_module, path_helpers_list],
|
37
|
+
['url', url_helpers_module, url_helpers_list]
|
38
|
+
].each do |suffix, helper_container, helper_list|
|
39
|
+
new_helper_name = "#{old_name}_#{suffix}"
|
40
|
+
|
41
|
+
helper_list.push(new_helper_name.to_sym) unless helper_list.include?(new_helper_name.to_sym)
|
42
|
+
|
43
|
+
helper_container.__send__(:define_method, new_helper_name) do |*args|
|
44
|
+
__send__(Translator.route_name_for(args, old_name, suffix, self), *args)
|
45
|
+
end
|
46
|
+
|
47
|
+
add_helpers_to_test_cases(helper_container)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: route_translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Geremia Taglialatela
|
8
8
|
- Enric Lluelles
|
9
|
+
- Raul Murciano
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2016-
|
13
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: activesupport
|
@@ -71,14 +72,14 @@ dependencies:
|
|
71
72
|
requirements:
|
72
73
|
- - "~>"
|
73
74
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.8.
|
75
|
+
version: 0.8.13
|
75
76
|
type: :development
|
76
77
|
prerelease: false
|
77
78
|
version_requirements: !ruby/object:Gem::Requirement
|
78
79
|
requirements:
|
79
80
|
- - "~>"
|
80
81
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.8.
|
82
|
+
version: 0.8.13
|
82
83
|
- !ruby/object:Gem::Dependency
|
83
84
|
name: minitest
|
84
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,7 +150,7 @@ dependencies:
|
|
149
150
|
version: 0.11.2
|
150
151
|
description: Translates the Rails routes of your application into the languages defined
|
151
152
|
in your locale files
|
152
|
-
email: enric@lluell.es
|
153
|
+
email: tagliala.dev@gmail.com enric@lluell.es
|
153
154
|
executables: []
|
154
155
|
extensions: []
|
155
156
|
extra_rdoc_files: []
|
@@ -164,6 +165,9 @@ files:
|
|
164
165
|
- lib/route_translator/extensions/route_set.rb
|
165
166
|
- lib/route_translator/host.rb
|
166
167
|
- lib/route_translator/translator.rb
|
168
|
+
- lib/route_translator/translator/path.rb
|
169
|
+
- lib/route_translator/translator/path/segment.rb
|
170
|
+
- lib/route_translator/translator/route_helpers.rb
|
167
171
|
- lib/route_translator/version.rb
|
168
172
|
homepage: http://github.com/enriclluelles/route_translator
|
169
173
|
licenses:
|