route_translator 4.4.1 → 5.0.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: 47e6b119bdebda6361df7598755063a84fa4c479
4
- data.tar.gz: ea59bc43ae8626a318c3a768f39cf5e51cda19ae
3
+ metadata.gz: 94d116b8b22e3189dfca53c189008da9fca4248b
4
+ data.tar.gz: 9009629caf2f295110ddf69e6bced39dfecf44f0
5
5
  SHA512:
6
- metadata.gz: 49d5166033a4b88019aa91325ca7b7953368e4235e942fb2f00f6c15227b7695863e4534237b46c3c59fb382f7db3dd56a21533bfce87e92d41ca7293da30792
7
- data.tar.gz: 5fd05b592d73575cf6bf0e7229fe74ad8c56eb01d3f868a1b6d86cb13f852affbdfd067ada71a0e5a1a22f75f1cf15bdc94b733d542650d3179486d52ed1ce37
6
+ metadata.gz: 320cbcabb052d70e508b013e8c7c9624e1fff5e3d42ea31db10446f8f684a332af55f38ccecf671b380b0dc6dc1f06f9cb5731acca93068cfbd32930425ce10c
7
+ data.tar.gz: 2bf6d5b205e6a61864fcaf21bc8204570333c5e6f7ebd3ec03d53f327784e617ac9e05aebe40861d476eec203f8ce2f489250ff4a37d3d7a565bcdaf78c3744d
data/CHANGELOG.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # Changelog
2
2
 
3
- ## 4.4.1 (2016-07-15)
3
+ ## 5.0.0 (2016-07-01)
4
4
 
5
- * Add private keyword in Segment module
6
- * Update development dependencies
5
+ * Rails 5 compatibility
7
6
 
8
7
  ## 4.4.0 (2016-07-01)
9
8
 
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # RouteTranslator
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/route_translator.svg)](http://badge.fury.io/rb/route_translator)
4
- [![Build Status](https://travis-ci.org/enriclluelles/route_translator.svg?branch=4-stable)](https://travis-ci.org/enriclluelles/route_translator)
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/github/enriclluelles/route_translator/badge.svg?branch=4-stable)](https://coveralls.io/github/enriclluelles/route_translator?branch=4-stable)
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
 
11
11
  It started as a fork of the awesome [translate_routes](https://github.com/raul/translate_routes) plugin by [Raúl Murciano](https://github.com/raul).
12
12
 
13
- Right now it works with all the different flavours of rails 3-4 (3.2, 4.0, 4.1, 4.2).
13
+ Right now it works with Rails 5.0
14
14
 
15
15
 
16
16
 
@@ -19,7 +19,7 @@ Right now it works with all the different flavours of rails 3-4 (3.2, 4.0, 4.1,
19
19
  1. If you have this `routes.rb` file originally:
20
20
 
21
21
  ```ruby
22
- MyApp::Application.routes.draw do
22
+ Rails.application.routes.draw do
23
23
  namespace :admin do
24
24
  resources :cars
25
25
  end
@@ -58,7 +58,7 @@ Right now it works with all the different flavours of rails 3-4 (3.2, 4.0, 4.1,
58
58
  3. Wrap the groups of routes that you want to translate inside a `localized` block:
59
59
 
60
60
  ```ruby
61
- MyApp::Application.routes.draw do
61
+ Rails.application.routes.draw do
62
62
  namespace :admin do
63
63
  resources :cars
64
64
  end
@@ -131,7 +131,7 @@ Right now it works with all the different flavours of rails 3-4 (3.2, 4.0, 4.1,
131
131
  To disable it add this to your controller:
132
132
 
133
133
  ```ruby
134
- skip_around_filter :set_locale_from_url
134
+ skip_around_action :set_locale_from_url
135
135
  ```
136
136
 
137
137
 
@@ -46,5 +46,7 @@ module RouteTranslator
46
46
  end
47
47
  end
48
48
 
49
- ActionController::Base.send :include, RouteTranslator::Controller
50
- ActionController::TestCase.send :include, RouteTranslator::TestCase
49
+ ActiveSupport.on_load(:action_controller) do
50
+ ActionController::Base.send :include, RouteTranslator::Controller
51
+ ActionController::TestCase.send :include, RouteTranslator::TestCase
52
+ end
@@ -10,31 +10,35 @@ module ActionDispatch
10
10
  @localized = false
11
11
  end
12
12
 
13
- def add_route(action, options) # :nodoc:
14
- path = path_for_action(action, options.delete(:path))
13
+ def add_route(action, controller, options, original_path, to, via, formatted, anchor, options_constraints) # :nodoc:
14
+ path = path_for_action(action, original_path)
15
+ raise ArgumentError, 'path is required' if path.blank?
15
16
 
16
- if action.to_s =~ %r{^[\w\/]+$}
17
- options[:action] ||= action unless action.to_s.include?('/'.freeze)
17
+ action = action.to_s
18
+
19
+ default_action = options.delete(:action) || @scope[:action]
20
+
21
+ if action =~ %r{^[\w\-\/]+$}
22
+ default_action ||= action.tr('-', '_') unless action.include?('/')
18
23
  else
19
24
  action = nil
20
25
  end
21
26
 
22
- if !options.fetch(:as, true)
23
- options.delete(:as)
24
- else
25
- options[:as] = name_for_action(options[:as], action)
26
- end
27
+ as = if !options.fetch(:as, true) # if it's set to nil or false
28
+ options.delete(:as)
29
+ else
30
+ name_for_action(options.delete(:as), action)
31
+ end
27
32
 
28
- begin
29
- mapping = Mapping.new(@set, @scope, path, options)
30
- rescue ArgumentError
31
- mapping = Mapping.build(@scope, @set, URI.parser.escape(path), options.delete(:as), options)
32
- end
33
+ path = Mapping.normalize_path URI.parser.escape(path), formatted
34
+ ast = Journey::Parser.parse path
35
+
36
+ mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options)
33
37
 
34
38
  if @localized
35
- @set.add_localized_route(*mapping.to_route)
39
+ @set.add_localized_route(mapping, ast, as, anchor, @scope, path, controller, default_action, to, via, formatted, options_constraints, options)
36
40
  else
37
- @set.add_route(*mapping.to_route)
41
+ @set.add_route(mapping, ast, as, anchor)
38
42
  end
39
43
  end
40
44
  end
@@ -3,15 +3,18 @@ require 'action_dispatch'
3
3
  module ActionDispatch
4
4
  module Routing
5
5
  class RouteSet
6
- def add_localized_route(app, conditions = {}, requirements = {}, defaults = {}, as = nil, anchor = true)
7
- RouteTranslator::Translator.translations_for(app, conditions, requirements, defaults, as, anchor, self) do |*translated_args|
8
- add_route(*translated_args)
6
+ def add_localized_route(mapping, path_ast, name, anchor, scope, path, controller, default_action, to, via, formatted, options_constraints, options)
7
+ RouteTranslator::Translator.translations_for(self, path, name, options_constraints, options) do |translated_name, translated_path, translated_options_constraints, translated_options|
8
+ translated_path_ast = ::ActionDispatch::Journey::Parser.parse(translated_path)
9
+ translated_mapping = ::ActionDispatch::Routing::Mapper::Mapping.build(scope, self, translated_path_ast, controller, default_action, to, via, formatted, translated_options_constraints, anchor, translated_options)
10
+
11
+ add_route translated_mapping, translated_path_ast, translated_name, anchor
9
12
  end
10
13
 
11
14
  if RouteTranslator.config.generate_unnamed_unlocalized_routes
12
- add_route app, conditions, requirements, defaults, nil, anchor
15
+ add_route mapping, path_ast, nil, anchor
13
16
  elsif RouteTranslator.config.generate_unlocalized_routes
14
- add_route app, conditions, requirements, defaults, as, anchor
17
+ add_route mapping, path_ast, name, anchor
15
18
  end
16
19
  end
17
20
  end
@@ -31,40 +31,30 @@ module RouteTranslator
31
31
  translated_name
32
32
  end
33
33
  end
34
-
35
- def translate_conditions(conditions, translated_path)
36
- translated_conditions = conditions.dup
37
-
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]
40
-
41
- if translated_conditions[:required_defaults] && !translated_conditions[:required_defaults].include?(RouteTranslator.locale_param_key)
42
- translated_conditions[:required_defaults] << RouteTranslator.locale_param_key
43
- end
44
-
45
- translated_conditions
46
- end
47
34
  end
48
35
 
49
36
  module_function
50
37
 
51
- def translations_for(app, conditions, requirements, defaults, route_name, anchor, route_set)
52
- RouteTranslator::Translator::RouteHelpers.add route_name, route_set.named_routes
38
+ def translations_for(route_set, path, name, options_constraints, options)
39
+ RouteTranslator::Translator::RouteHelpers.add name, route_set.named_routes
53
40
 
54
41
  available_locales.each do |locale|
55
42
  begin
56
- translated_path = RouteTranslator::Translator::Path.translate(conditions[:path_info], locale)
43
+ translated_path = RouteTranslator::Translator::Path.translate(path, locale)
57
44
  rescue I18n::MissingTranslationData => e
58
45
  raise e unless RouteTranslator.config.disable_fallback
59
46
  next
60
47
  end
61
48
 
62
- new_conditions = translate_conditions(conditions, translated_path)
49
+ translated_options_constraints = options_constraints.dup
50
+ translated_options = options.dup
51
+
52
+ translated_options_constraints[RouteTranslator.locale_param_key] = locale.to_s
53
+ translated_options[RouteTranslator.locale_param_key] = locale.to_s.gsub('native_', '') unless translated_options.include?(RouteTranslator.locale_param_key)
54
+
55
+ translated_name = translate_name(name, locale, route_set.named_routes.names)
63
56
 
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
57
+ yield translated_name, translated_path, translated_options_constraints, translated_options
68
58
  end
69
59
  end
70
60
 
@@ -3,8 +3,6 @@ module RouteTranslator
3
3
  module Path
4
4
  module Segment
5
5
  class << self
6
- private
7
-
8
6
  def translate_string(str, locale)
9
7
  locale = locale.to_s.gsub('native_', '')
10
8
  opts = { scope: :routes, locale: locale }
@@ -20,22 +20,10 @@ module RouteTranslator
20
20
  # I18n.locale = :fr
21
21
  # people_path -> people_fr_path
22
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
23
+ helper_list = named_route_collection.helper_names
34
24
 
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|
25
+ %w(path url).each do |suffix|
26
+ helper_container = named_route_collection.send(:"#{suffix}_helpers_module")
39
27
  new_helper_name = "#{old_name}_#{suffix}"
40
28
 
41
29
  helper_list.push(new_helper_name.to_sym) unless helper_list.include?(new_helper_name.to_sym)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module RouteTranslator
3
- VERSION = '4.4.1'.freeze
3
+ VERSION = '5.0.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.4.1
4
+ version: 5.0.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-07-15 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
@@ -18,40 +18,40 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '3.2'
21
+ version: 5.0.0
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '5.0'
24
+ version: '5.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '3.2'
31
+ version: 5.0.0
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '5.0'
34
+ version: '5.1'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: actionpack
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '3.2'
41
+ version: 5.0.0
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
- version: '5.0'
44
+ version: '5.1'
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: '3.2'
51
+ version: 5.0.0
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: '5.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: appraisal
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '9.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '9.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: coveralls
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 0.8.14
89
+ version: 0.8.13
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 0.8.14
96
+ version: 0.8.13
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: minitest
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -106,20 +120,20 @@ dependencies:
106
120
  requirements:
107
121
  - - ">="
108
122
  - !ruby/object:Gem::Version
109
- version: '3.2'
123
+ version: 5.0.0
110
124
  - - "<"
111
125
  - !ruby/object:Gem::Version
112
- version: '5.0'
126
+ version: '5.1'
113
127
  type: :development
114
128
  prerelease: false
115
129
  version_requirements: !ruby/object:Gem::Requirement
116
130
  requirements:
117
131
  - - ">="
118
132
  - !ruby/object:Gem::Version
119
- version: '3.2'
133
+ version: 5.0.0
120
134
  - - "<"
121
135
  - !ruby/object:Gem::Version
122
- version: '5.0'
136
+ version: '5.1'
123
137
  - !ruby/object:Gem::Dependency
124
138
  name: rake
125
139
  requirement: !ruby/object:Gem::Requirement
@@ -140,28 +154,28 @@ dependencies:
140
154
  requirements:
141
155
  - - "~>"
142
156
  - !ruby/object:Gem::Version
143
- version: 0.41.2
157
+ version: 0.41.1
144
158
  type: :development
145
159
  prerelease: false
146
160
  version_requirements: !ruby/object:Gem::Requirement
147
161
  requirements:
148
162
  - - "~>"
149
163
  - !ruby/object:Gem::Version
150
- version: 0.41.2
164
+ version: 0.41.1
151
165
  - !ruby/object:Gem::Dependency
152
166
  name: simplecov
153
167
  requirement: !ruby/object:Gem::Requirement
154
168
  requirements:
155
169
  - - "~>"
156
170
  - !ruby/object:Gem::Version
157
- version: 0.12.0
171
+ version: 0.11.2
158
172
  type: :development
159
173
  prerelease: false
160
174
  version_requirements: !ruby/object:Gem::Requirement
161
175
  requirements:
162
176
  - - "~>"
163
177
  - !ruby/object:Gem::Version
164
- version: 0.12.0
178
+ version: 0.11.2
165
179
  description: Translates the Rails routes of your application into the languages defined
166
180
  in your locale files
167
181
  email: