route_translator 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba50272fd47e4a93ea47418a84de0cf5489eaee4
4
- data.tar.gz: 0b4458fa81aea378ecb5fe39c50b655d7c637a97
3
+ metadata.gz: 05ad52625a32748551a12b0e27d2e5015b79d3f8
4
+ data.tar.gz: dd8bf10e6a132f9d06eca06b472d90de6315179e
5
5
  SHA512:
6
- metadata.gz: e082a7feb66e67415ac691ce77939cf3a9f8f90aa5199ca285837c7d1fe9ad6d1f8ee40bbf659206ade3aa2e72cb224ba2c4de3a9e3b12f00fd8fff1faf08c66
7
- data.tar.gz: cb761bd633952e302c7a76223f96992c2f9caee66a0babbf7fc56b0a7e0508686df7ddc28dd71174b86487fe2d52032ff871972a4b3f14cb07f28af80b6db65b
6
+ metadata.gz: ba81dea5c5b94d54ae225e6d103061313c254c7e217ea3daf486472edcf2842c7b329d86c66980626baf5eeecf102b6bf1157273b30a187b7abb5332c495fbe9
7
+ data.tar.gz: 0c912b8081f3a80b856318b0f3e3f1887ba5547f2cd89f9fa4c25cb95240fe743afe1355fe4e9dc31b0614886ce9094e9cc1753f38816aa51f75c00773988ef6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.4.0 (2016-07-01)
4
+
5
+ * Support custom locale path segments, i.e. /uk/en/widgets
6
+ * Using AS::Concern instead of monkey patching ActionController
7
+ * Update development dependencies
8
+
3
9
  ## 4.3.0 (2016-03-03)
4
10
 
5
11
  * Refactor translator module
data/README.md CHANGED
@@ -20,7 +20,6 @@ Right now it works with all the different flavours of rails 3-4 (3.2, 4.0, 4.1,
20
20
 
21
21
  ```ruby
22
22
  MyApp::Application.routes.draw do
23
-
24
23
  namespace :admin do
25
24
  resources :cars
26
25
  end
@@ -60,7 +59,6 @@ Right now it works with all the different flavours of rails 3-4 (3.2, 4.0, 4.1,
60
59
 
61
60
  ```ruby
62
61
  MyApp::Application.routes.draw do
63
-
64
62
  namespace :admin do
65
63
  resources :cars
66
64
  end
@@ -181,6 +179,9 @@ end
181
179
  Useful when one uses this with a locale route constraint, so non-ES routes can 404 on a Spanish website.
182
180
  * **available_locales**
183
181
  Use this to limit the locales for which URLs should be generated for. Accepts an array of strings or symbols.
182
+ * **locale_segment_proc**
183
+ The locale segment of the url will by default be `locale.to_s.downcase`
184
+ You can supply your own mechanism via a Proc that takes `locale` as an argument, e.g. `config.locale_segment_proc = ->(locale) { locale.to_s.upcase }`
184
185
 
185
186
 
186
187
  ### Host-based Locale
@@ -197,12 +198,12 @@ Here are a few examples of possible mappings:
197
198
 
198
199
  ```ruby
199
200
  RouteTranslator.config.host_locales =
200
- { # Matches:
201
- '*.es' => :es, # TLD: ['domain.es', 'subdomain.domain.es', 'www.long.string.of.subdomains.es'] etc.
202
- 'ru.wikipedia.*' => :ru, # Subdomain: ['ru.wikipedia.org', 'ru.wikipedia.net', 'ru.wikipedia.com'] etc.
203
- '*.subdomain.domain.*' => :ru, # Mixture: ['subdomain.domain.org', 'www.subdomain.domain.net'] etc.
204
- 'news.bbc.co.uk' => :en, # Exact match: ['news.bbc.co.uk'] only
205
- }
201
+ { # Matches:
202
+ '*.es' => :es, # TLD: ['domain.es', 'subdomain.domain.es', 'www.long.string.of.subdomains.es'] etc.
203
+ 'ru.wikipedia.*' => :ru, # Subdomain: ['ru.wikipedia.org', 'ru.wikipedia.net', 'ru.wikipedia.com'] etc.
204
+ '*.subdomain.domain.*' => :ru, # Mixture: ['subdomain.domain.org', 'www.subdomain.domain.net'] etc.
205
+ 'news.bbc.co.uk' => :en, # Exact match: ['news.bbc.co.uk'] only
206
+ }
206
207
  ```
207
208
 
208
209
  In the case of a host matching more than once, the order in which the matchers are defined will be taken into account, like so:
@@ -229,7 +230,7 @@ Testing your controllers with routes-translator is easy, just add a locale param
229
230
  ```ruby
230
231
  describe 'GET index' do
231
232
  it 'should respond with success' do
232
- get :index, { locale: 'fr' }
233
+ get :index, locale: 'fr'
233
234
 
234
235
  expect(response).to be_success
235
236
  end
@@ -12,7 +12,7 @@ module RouteTranslator
12
12
  Configuration = Struct.new(:force_locale, :hide_locale,
13
13
  :generate_unlocalized_routes, :locale_param_key,
14
14
  :generate_unnamed_unlocalized_routes, :available_locales,
15
- :host_locales, :disable_fallback)
15
+ :host_locales, :disable_fallback, :locale_segment_proc)
16
16
 
17
17
  class << self
18
18
  private
@@ -37,6 +37,7 @@ module RouteTranslator
37
37
  @config.host_locales ||= ActiveSupport::OrderedHash.new
38
38
  @config.available_locales ||= []
39
39
  @config.disable_fallback ||= false
40
+ @config.locale_segment_proc ||= nil
40
41
  yield @config if block
41
42
  resolve_host_locale_config_conflicts unless @config.host_locales.empty?
42
43
  @config
@@ -1,8 +1,15 @@
1
1
  require 'action_controller'
2
+ require 'active_support/concern'
2
3
 
3
- module ActionController
4
- class Base
5
- around_filter :set_locale_from_url
4
+ module RouteTranslator
5
+ module Controller
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ around_filter :set_locale_from_url
10
+ end
11
+
12
+ private
6
13
 
7
14
  def set_locale_from_url
8
15
  tmp_default_locale = RouteTranslator::Host.locale_from_host(request.host)
@@ -25,13 +32,19 @@ module ActionController
25
32
  end
26
33
  end
27
34
 
28
- class TestCase
35
+ module TestCase
36
+ extend ActiveSupport::Concern
29
37
  include ActionController::UrlFor
30
38
 
31
- delegate :env, :request, to: :@controller
39
+ included do
40
+ delegate :env, :request, to: :@controller
41
+ end
32
42
 
33
43
  def _routes
34
44
  @routes
35
45
  end
36
46
  end
37
47
  end
48
+
49
+ ActionController::Base.send :include, RouteTranslator::Controller
50
+ ActionController::TestCase.send :include, RouteTranslator::TestCase
@@ -10,7 +10,7 @@ module RouteTranslator
10
10
 
11
11
  def available_locales
12
12
  locales = RouteTranslator.available_locales
13
- locales.push(*RouteTranslator.native_locales) if RouteTranslator.native_locales.present?
13
+ locales.concat(RouteTranslator.native_locales) if RouteTranslator.native_locales.present?
14
14
  # Make sure the default locale is translated in last place to avoid
15
15
  # problems with wildcards when default locale is omitted in paths. The
16
16
  # default routes will catch all paths like wildcard if it is translated first.
@@ -23,6 +23,16 @@ module RouteTranslator
23
23
  def locale_param_present?(path)
24
24
  path.split('/').include? ":#{RouteTranslator.locale_param_key}"
25
25
  end
26
+
27
+ def locale_segment(locale)
28
+ if RouteTranslator.config.locale_segment_proc
29
+ locale_segment_proc = RouteTranslator.config.locale_segment_proc
30
+
31
+ locale_segment_proc.to_proc.call(locale)
32
+ else
33
+ locale.to_s.downcase
34
+ end
35
+ end
26
36
  end
27
37
 
28
38
  module_function
@@ -37,7 +47,7 @@ module RouteTranslator
37
47
  translated_segments.reject!(&:empty?)
38
48
 
39
49
  if display_locale?(locale) && !locale_param_present?(new_path)
40
- translated_segments.unshift(locale.to_s.downcase)
50
+ translated_segments.unshift(locale_segment(locale))
41
51
  end
42
52
 
43
53
  joined_segments = translated_segments.join('/')
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module RouteTranslator
3
- VERSION = '4.3.0'.freeze
3
+ VERSION = '4.4.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geremia Taglialatela
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-03-03 00:00:00.000000000 Z
13
+ date: 2016-07-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -120,20 +120,34 @@ dependencies:
120
120
  - - "<"
121
121
  - !ruby/object:Gem::Version
122
122
  version: '5.0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rake
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '11.2'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '11.2'
123
137
  - !ruby/object:Gem::Dependency
124
138
  name: rubocop
125
139
  requirement: !ruby/object:Gem::Requirement
126
140
  requirements:
127
141
  - - "~>"
128
142
  - !ruby/object:Gem::Version
129
- version: 0.37.2
143
+ version: 0.41.1
130
144
  type: :development
131
145
  prerelease: false
132
146
  version_requirements: !ruby/object:Gem::Requirement
133
147
  requirements:
134
148
  - - "~>"
135
149
  - !ruby/object:Gem::Version
136
- version: 0.37.2
150
+ version: 0.41.1
137
151
  - !ruby/object:Gem::Dependency
138
152
  name: simplecov
139
153
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +164,9 @@ dependencies:
150
164
  version: 0.11.2
151
165
  description: Translates the Rails routes of your application into the languages defined
152
166
  in your locale files
153
- email: tagliala.dev@gmail.com enric@lluell.es
167
+ email:
168
+ - tagliala.dev@gmail.com
169
+ - enric@lluell.es
154
170
  executables: []
155
171
  extensions: []
156
172
  extra_rdoc_files: []
@@ -189,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
205
  version: '0'
190
206
  requirements: []
191
207
  rubyforge_project:
192
- rubygems_version: 2.5.1
208
+ rubygems_version: 2.6.4
193
209
  signing_key:
194
210
  specification_version: 4
195
211
  summary: Translate your Rails routes in a simple manner