translatable_routes 1.3.2 → 1.3.3

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: ec25e210398145edc2a2021602b5a48b1ada634a
4
- data.tar.gz: 1353d95eb6f9ff625a21d6749f36f16c4770a047
3
+ metadata.gz: be4091ea73bb827796addc31258c8be2796284cc
4
+ data.tar.gz: eeeee1ab0fb27a8072d7f8a939ff877cde527c1b
5
5
  SHA512:
6
- metadata.gz: 086e5600e84c582bce332e771f985b7ba6ba29c52a42b0e84aa2249c679c761e00ad815448d27296060ddbec7943f18ceafe7a56b1fc0eb2f001c2712e3311d0
7
- data.tar.gz: 83ce66bba1083954613d1911cbf3734cf0e6c44001e98a1411aa4fcbf9d9e83d8272a0c30e18514ba479bdb069e096b322139c50fc4788cb56e5c75dba7d4e82
6
+ metadata.gz: 062244dd2bb527f8f94bf4bea9da1dcd8af0660a852a91ea1fd3484848f43f3b4e5ccc9d6bdf6fffae6423a14ee9e5966a40d398a1306c44ea256e049b411f73
7
+ data.tar.gz: 559de805002e6d4afb6d7128ca57ec9a56b7d53803ebf56298f3df4db84fe9a9178a207d6dbdddb6b5eac209e0541b23eea079aa03f67a34207d27f6bac0a3c0
data/README.rdoc CHANGED
@@ -1,18 +1,18 @@
1
- {<img src="https://badge.fury.io/rb/translatable_routes.png" alt="Gem Version" />}[http://badge.fury.io/rb/translatable_routes] {<img src="https://codeclimate.com/github/museways/translatable_routes.png" />}[https://codeclimate.com/github/museways/translatable_routes] {<img src="https://travis-ci.org/museways/translatable_routes.png?branch=master" alt="Build Status" />}[https://travis-ci.org/museways/translatable_routes] {<img src="https://gemnasium.com/museways/translatable_routes.png" alt="Dependency Status" />}[https://gemnasium.com/museways/translatable_routes]
1
+ {<img src="https://badge.fury.io/rb/translatable_routes.png" alt="Gem Version" />}[http://badge.fury.io/rb/translatable_routes] {<img src="https://codeclimate.com/github/museways/translatable_routes.png" />}[https://codeclimate.com/github/museways/translatable_routes] {<img src="https://travis-ci.org/museways/translatable_routes.png?branch=master" alt="Build Status" />}[https://travis-ci.org/museways/translatable_routes]
2
2
 
3
3
  = Translatable Routes
4
4
 
5
- Minimalistic toolkit to translate routes.
5
+ Minimalistic toolkit to translate routes in rails.
6
6
 
7
7
  = Install
8
8
 
9
9
  Put this line in your Gemfile:
10
10
  gem 'translatable_routes'
11
-
11
+
12
12
  Then bundle:
13
13
  $ bundle
14
-
15
- = Usage
14
+
15
+ = Configuration
16
16
 
17
17
  In your config/routes.rb use the localized method to decide wich routes will be localized:
18
18
  localized do
@@ -25,13 +25,15 @@ Put your translations inside the routes key in your locales yamls:
25
25
  users: "usuarios"
26
26
  profile: "perfil"
27
27
  about: "nosotros"
28
-
29
- (There is no need to put the full path "users/1/profile", just translate each slug individually)
28
+
29
+ NOTE: There is no need to put the full path, just translate each part individually.
30
+
31
+ = Usage
30
32
 
31
33
  Helpers will continue working the same but I18n.locale will be use as default locale:
32
- about_path # /en/about in case I18n.locale is :en
34
+ about_path # Will output /en/about in case I18n.locale is :en
33
35
 
34
- This gem will not provide a default locale selection, since you may be interested in differente types of logics, you should add it manually. Here it's a very simple example:
36
+ Here is an example of what you may want to add to your controllers to select the current locale:
35
37
  before_action :select_locale
36
38
 
37
39
  protected
@@ -39,3 +41,11 @@ This gem will not provide a default locale selection, since you may be intereste
39
41
  def select_locale
40
42
  I18n.locale = params[:locale]
41
43
  end
44
+
45
+ = Credits
46
+
47
+ This gem is maintained and funded by museways[http://museways.com].
48
+
49
+ = License
50
+
51
+ It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -1,7 +1,6 @@
1
1
  require 'translatable_routes/action_dispatch/named_route_collection'
2
2
  require 'translatable_routes/action_dispatch/mapper'
3
3
  require 'translatable_routes/railtie'
4
- require 'translatable_routes/version'
5
4
 
6
5
  module TranslatableRoutes
7
6
  end
@@ -8,16 +8,22 @@ module TranslatableRoutes
8
8
  scope(':locale') { yield }
9
9
  @locales = nil
10
10
  end
11
-
11
+
12
12
  def add_route(action, options)
13
13
  if @locales
14
14
  @locales.each do |locale|
15
- original_scope_level_resource = @scope[:scope_level_resource].dup if @scope[:scope_level_resource]
16
- original_path = @scope[:path].dup if @scope[:path]
15
+ if @scope[:scope_level_resource]
16
+ original_scope_level_resource = @scope[:scope_level_resource].dup
17
+ end
18
+ if @scope[:path]
19
+ original_path = @scope[:path].dup
20
+ end
17
21
  original_path_names = @scope[:path_names].dup
18
22
  original_options = options.dup
19
23
  @scope[:path] = i18n_path(@scope[:path], locale)
20
- @scope[:path_names].each { |key, value| value = i18n_path(value, locale) }
24
+ @scope[:path_names].each do |key, value|
25
+ @scope[:path_names][key] = i18n_path(value, locale)
26
+ end
21
27
  options[:path] = i18n_path(options[:path], locale)
22
28
  options[:constraints] = { locale: locale.to_s }
23
29
  options[:defaults] = { locale: locale.to_s }
@@ -33,8 +39,12 @@ module TranslatableRoutes
33
39
  options[:as] = "#{options[:as] || action}_#{locale}"
34
40
  end
35
41
  super i18n_path(action, locale), options
36
- @scope[:scope_level_resource] = original_scope_level_resource if @scope[:scope_level_resource]
37
- @scope[:path] = original_path if @scope[:path]
42
+ if @scope[:scope_level_resource]
43
+ @scope[:scope_level_resource] = original_scope_level_resource
44
+ end
45
+ if @scope[:path]
46
+ @scope[:path] = original_path
47
+ end
38
48
  @scope[:path_names] = original_path_names
39
49
  options = original_options
40
50
  end
@@ -51,14 +61,18 @@ module TranslatableRoutes
51
61
  end
52
62
 
53
63
  protected
54
-
64
+
55
65
  def i18n_path(path, locale)
56
66
  case path
57
67
  when String
58
68
  i18n_path = []
59
69
  path.split('/').each do |part|
60
70
  next if part == ''
61
- i18n_path << ((part[0] == ':' or part[0] == '*') ? part : I18n.t("routes.#{part}", locale: locale, default: part.gsub(/_/, '-')))
71
+ if part[0] == ':' or part[0] == '*'
72
+ i18n_path << part
73
+ else
74
+ i18n_path << I18n.t("routes.#{part}", locale: locale, default: part.gsub(/_/, '-'))
75
+ end
62
76
  end
63
77
  i18n_path.join('/')
64
78
  when Symbol
@@ -7,7 +7,7 @@ module TranslatableRoutes
7
7
  %w(path url).each do |type|
8
8
  helper = :"#{name}_#{type}"
9
9
  @module.remove_possible_method helper
10
- @module.module_eval do
10
+ @module.module_eval do
11
11
  define_method helper do |*args|
12
12
  options = args.extract_options!
13
13
  suffix = (options[:locale] || I18n.locale).to_s.gsub('-', '_').downcase
@@ -1,5 +1,5 @@
1
1
  module TranslatableRoutes
2
2
 
3
- VERSION = '1.3.2'
3
+ VERSION = '1.3.3'
4
4
 
5
5
  end
@@ -6359,3 +6359,138 @@ RoutesTest: test_should_translate_routes
6359
6359
  HelpersTest: test_should_create_helpers
6360
6360
  ---------------------------------------
6361
6361
   (0.0ms) rollback transaction
6362
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6363
+  (0.1ms) select sqlite_version(*)
6364
+  (0.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6365
+  (0.1ms) SELECT version FROM "schema_migrations"
6366
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6367
+  (0.1ms) begin transaction
6368
+ ---------------------------------
6369
+ RoutesTest: test_translate_routes
6370
+ ---------------------------------
6371
+  (0.1ms) rollback transaction
6372
+  (0.0ms) begin transaction
6373
+ --------------------------------
6374
+ HelpersTest: test_create_helpers
6375
+ --------------------------------
6376
+  (0.0ms) rollback transaction
6377
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6378
+  (0.1ms) select sqlite_version(*)
6379
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6380
+  (0.1ms) SELECT version FROM "schema_migrations"
6381
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6382
+  (0.1ms) begin transaction
6383
+ ---------------------------------
6384
+ RoutesTest: test_translate_routes
6385
+ ---------------------------------
6386
+  (0.1ms) rollback transaction
6387
+  (0.0ms) begin transaction
6388
+ --------------------------------
6389
+ HelpersTest: test_create_helpers
6390
+ --------------------------------
6391
+  (0.1ms) rollback transaction
6392
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6393
+  (0.1ms) select sqlite_version(*)
6394
+  (0.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6395
+  (0.0ms) SELECT version FROM "schema_migrations"
6396
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6397
+  (0.1ms) begin transaction
6398
+ ---------------------------------
6399
+ RoutesTest: test_translate_routes
6400
+ ---------------------------------
6401
+  (0.2ms) rollback transaction
6402
+  (0.1ms) begin transaction
6403
+ --------------------------------
6404
+ HelpersTest: test_create_helpers
6405
+ --------------------------------
6406
+  (0.1ms) rollback transaction
6407
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6408
+  (0.1ms) select sqlite_version(*)
6409
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6410
+  (0.0ms) SELECT version FROM "schema_migrations"
6411
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6412
+  (0.1ms) begin transaction
6413
+ ---------------------------------
6414
+ RoutesTest: test_translate_routes
6415
+ ---------------------------------
6416
+  (0.1ms) rollback transaction
6417
+  (0.0ms) begin transaction
6418
+ --------------------------------
6419
+ HelpersTest: test_create_helpers
6420
+ --------------------------------
6421
+  (0.1ms) rollback transaction
6422
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6423
+  (0.1ms) select sqlite_version(*)
6424
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6425
+  (0.1ms) SELECT version FROM "schema_migrations"
6426
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6427
+  (0.1ms) begin transaction
6428
+ ---------------------------------
6429
+ RoutesTest: test_translate_routes
6430
+ ---------------------------------
6431
+  (0.1ms) rollback transaction
6432
+  (0.0ms) begin transaction
6433
+ --------------------------------
6434
+ HelpersTest: test_create_helpers
6435
+ --------------------------------
6436
+  (0.1ms) rollback transaction
6437
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6438
+  (0.1ms) select sqlite_version(*)
6439
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6440
+  (0.1ms) SELECT version FROM "schema_migrations"
6441
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6442
+  (0.1ms) begin transaction
6443
+ --------------------------------
6444
+ HelpersTest: test_create_helpers
6445
+ --------------------------------
6446
+  (0.0ms) rollback transaction
6447
+  (0.0ms) begin transaction
6448
+ ---------------------------------
6449
+ RoutesTest: test_translate_routes
6450
+ ---------------------------------
6451
+  (0.1ms) rollback transaction
6452
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6453
+  (0.1ms) select sqlite_version(*)
6454
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6455
+  (0.1ms) SELECT version FROM "schema_migrations"
6456
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6457
+  (0.1ms) begin transaction
6458
+ --------------------------------
6459
+ HelpersTest: test_create_helpers
6460
+ --------------------------------
6461
+  (0.0ms) rollback transaction
6462
+  (0.0ms) begin transaction
6463
+ ---------------------------------
6464
+ RoutesTest: test_translate_routes
6465
+ ---------------------------------
6466
+  (0.1ms) rollback transaction
6467
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6468
+  (0.1ms) select sqlite_version(*)
6469
+  (0.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6470
+  (0.1ms) SELECT version FROM "schema_migrations"
6471
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6472
+  (0.1ms) begin transaction
6473
+ ---------------------------------
6474
+ RoutesTest: test_translate_routes
6475
+ ---------------------------------
6476
+  (0.1ms) rollback transaction
6477
+  (0.0ms) begin transaction
6478
+ --------------------------------
6479
+ HelpersTest: test_create_helpers
6480
+ --------------------------------
6481
+  (0.0ms) rollback transaction
6482
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
6483
+  (0.1ms) select sqlite_version(*)
6484
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6485
+  (0.0ms) SELECT version FROM "schema_migrations"
6486
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
6487
+  (0.1ms) begin transaction
6488
+ --------------------------------
6489
+ HelpersTest: test_create_helpers
6490
+ --------------------------------
6491
+  (0.1ms) rollback transaction
6492
+  (0.0ms) begin transaction
6493
+ ---------------------------------
6494
+ RoutesTest: test_translate_routes
6495
+ ---------------------------------
6496
+  (0.1ms) rollback transaction
data/test/helpers_test.rb CHANGED
@@ -2,15 +2,45 @@ require 'test_helper'
2
2
 
3
3
  class HelpersTest < ActionView::TestCase
4
4
 
5
- test "should create helpers" do
5
+ test "create helpers" do
6
6
  I18n.available_locales.each do |locale|
7
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
8
+ assert_equal(
9
+ "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.nested')}",
10
+ namespace_nested_path
11
+ )
12
+ assert_equal(
13
+ "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.resources')}",
14
+ namespace_resources_path
15
+ )
16
+ assert_equal(
17
+ "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.resources')}/#{I18n.t('routes.new')}",
18
+ new_namespace_resource_path
19
+ )
20
+ assert_equal(
21
+ "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.resources')}/10/#{I18n.t('routes.edit')}",
22
+ edit_namespace_resource_path(10)
23
+ )
24
+ assert_equal(
25
+ "/#{locale}/#{I18n.t('routes.simple')}",
26
+ simple_path
27
+ )
28
+ assert_equal(
29
+ "/#{locale}/complex/1/2",
30
+ complex_path(1, 2)
31
+ )
32
+ assert_equal(
33
+ "/#{locale}/#{I18n.t('routes.resources')}",
34
+ resources_path
35
+ )
36
+ assert_equal(
37
+ "/#{locale}/#{I18n.t('routes.resources')}/#{I18n.t('routes.new')}",
38
+ new_resource_path
39
+ )
40
+ assert_equal(
41
+ "/#{locale}/#{I18n.t('routes.resources')}/10/#{I18n.t('routes.edit')}",
42
+ edit_resource_path(10)
43
+ )
14
44
  end
15
45
  end
16
46
 
data/test/routes_test.rb CHANGED
@@ -2,35 +2,45 @@ require 'test_helper'
2
2
 
3
3
  class RoutesTest < ActionDispatch::IntegrationTest
4
4
 
5
- test "should translate routes" do
5
+ test "translate routes" do
6
6
  I18n.available_locales.each do |locale|
7
7
  I18n.locale = locale
8
-
9
8
  assert_recognizes(
10
9
  { controller: 'namespace/pages', action: 'nested', locale: locale.to_s },
11
10
  "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.nested')}"
12
11
  )
13
-
14
12
  assert_recognizes(
15
13
  { controller: 'namespace/resources', action: 'index', locale: locale.to_s },
16
14
  "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.resources')}"
17
15
  )
18
-
16
+ assert_recognizes(
17
+ { controller: 'namespace/resources', action: 'new', locale: locale.to_s },
18
+ "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.resources')}/#{I18n.t('routes.new')}"
19
+ )
20
+ assert_recognizes(
21
+ { controller: 'namespace/resources', action: 'edit', locale: locale.to_s, id: '10' },
22
+ "/#{locale}/#{I18n.t('routes.namespace')}/#{I18n.t('routes.resources')}/10/#{I18n.t('routes.edit')}"
23
+ )
19
24
  assert_recognizes(
20
25
  { controller: 'pages', action: 'simple', locale: locale.to_s },
21
26
  "/#{locale}/#{I18n.t('routes.simple')}"
22
27
  )
23
-
24
28
  assert_recognizes(
25
29
  { controller: 'pages', action: 'complex', locale: locale.to_s, p1: '1', p2: '2' },
26
30
  "/#{locale}/complex/1/2"
27
31
  )
28
-
29
32
  assert_recognizes(
30
33
  { controller: 'resources', action: 'index', locale: locale.to_s },
31
34
  "/#{locale}/#{I18n.t('routes.resources')}"
32
35
  )
33
-
36
+ assert_recognizes(
37
+ { controller: 'resources', action: 'new', locale: locale.to_s },
38
+ "/#{locale}/#{I18n.t('routes.resources')}/#{I18n.t('routes.new')}"
39
+ )
40
+ assert_recognizes(
41
+ { controller: 'resources', action: 'edit', locale: locale.to_s, id: '10' },
42
+ "/#{locale}/#{I18n.t('routes.resources')}/10/#{I18n.t('routes.edit')}"
43
+ )
34
44
  end
35
45
  end
36
46
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translatable_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Museways
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-09 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,7 +44,7 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.3'
47
- description: Minimalistic toolkit to translate routes.
47
+ description: Minimalistic toolkit to translate routes in rails.
48
48
  email:
49
49
  - contact@museways.com
50
50
  executables: []
@@ -131,7 +131,7 @@ rubyforge_project:
131
131
  rubygems_version: 2.2.2
132
132
  signing_key:
133
133
  specification_version: 4
134
- summary: Translatable Routes for Rails.
134
+ summary: Translatable routes for rails.
135
135
  test_files:
136
136
  - test/dummy/app/assets/javascripts/application.js
137
137
  - test/dummy/app/assets/stylesheets/application.css