dragoman 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4090b145af56cf395749d4563c858dc9d7ec438e
4
- data.tar.gz: 4f1f281ed36a13365785fafa7eb487157372db5e
3
+ metadata.gz: c50f0ba55cd1b168ff9e181f96432d0a958a1fe5
4
+ data.tar.gz: ac628c72a7880a938596ed4239d7af3a6adebd66
5
5
  SHA512:
6
- metadata.gz: 4000a0878013f2345310d757ab55e0d98d3862021f632a0bb1220f3ea0596133be2840a88aba3ceb418ce3007769e245e624e8aa2826ea9fc757cd2c14bad75e
7
- data.tar.gz: ffd681555d10500818eeefa7858ca2b9ff3df0dc3e326a2d203fa7e522f9a262d309bee554aecd475fd94589cdc00c1901396a80923329525012faad35083a1d
6
+ metadata.gz: 1abbc1032a4f4a01d0cc41cdb8db0819d60bdb86b094b6c807796be7bfc674c76c1cef4e5b87b539394acc14a90329ce178ef6e70b7af39cc015c0a4d795f05e
7
+ data.tar.gz: 3d7683e61754b51c76424d92fec15cd96ec952b3345db3fe30b1f731ad317db5cbdcd29bb48f65423bc384f0df077f1387828c9b1cbf37ba365f3c8b86b6b949
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ gemfiles/*.lock
19
+ log
@@ -26,7 +26,7 @@ module Dragoman
26
26
 
27
27
  def add_route_with_localization(action, options)
28
28
  if @current_locale
29
- options[:path] = Dragoman::Translator.translate_path(action, @current_locale) if action.present? && !canonical_action?(action)
29
+ options[:path] = Dragoman::Translator.translate_path(options[:path] || action, @current_locale) unless canonical_action?(action)
30
30
  options[:locale] = @current_locale
31
31
  end
32
32
  add_route_without_localization action, options
@@ -37,6 +37,7 @@ module Dragoman
37
37
  options = args.extract_options!.dup
38
38
  if options[:path] || args.any?
39
39
  options[:path] = Dragoman::Translator.translate_path(options[:path] || args.flatten.join('/'), @current_locale)
40
+ options[:shallow_path] = Dragoman::Translator.translate_path(options[:shallow_path], @current_locale) if options[:shallow_path]
40
41
  end
41
42
  scope_without_localization options, &block
42
43
  else
@@ -47,7 +48,7 @@ module Dragoman
47
48
  def resources_with_localization(*resources, &block)
48
49
  options = resources.extract_options!.dup
49
50
  if @current_locale
50
- options[:path] = Dragoman::Translator.translate_path(resources.last, @current_locale)
51
+ options[:path] = Dragoman::Translator.translate_path(options[:path] || resources.last, @current_locale)
51
52
  end
52
53
  resources_without_localization(*resources, options, &block)
53
54
  end
@@ -29,7 +29,7 @@ module Dragoman
29
29
 
30
30
  def add_route_with_localization(action, options)
31
31
  if @current_locale
32
- options[:path] = Dragoman::Translator.translate_path(action, @current_locale) if action.present? && !canonical_action?(action, true)
32
+ options[:path] = Dragoman::Translator.translate_path(options[:path] || action, @current_locale) unless canonical_action?(action, true)
33
33
  options[:locale] = @current_locale
34
34
  end
35
35
  add_route_without_localization action, options
@@ -3,6 +3,7 @@ module Dragoman
3
3
  class Translator
4
4
 
5
5
  def self.translate_path path, locale
6
+ return path if path.blank?
6
7
  parsed_path = Dragoman::Journey::Parser.new.parse(path.to_s)
7
8
  Dragoman::TranslationVisitor.new(locale).accept(parsed_path)
8
9
  end
@@ -1,3 +1,3 @@
1
1
  module Dragoman
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -10,10 +10,28 @@ Dummy::Application.routes.draw do
10
10
  get 'payments' => 'application#index'
11
11
  end
12
12
 
13
- resources :products
13
+ resources :products#, path_names: {edit: 'accept'}
14
14
  resource :account
15
15
 
16
- get '' => 'application#test', as: 'empty'
16
+ get '' => 'application#index', as: 'empty'
17
+
18
+ namespace 'empty', path: '' do
19
+ get 'books' => 'application#index'
20
+ end
21
+ resources :invitations, only: [] do
22
+ member do
23
+ get :edit, path: 'accept'
24
+ end
25
+ end
26
+
27
+ resources :chairs, only: :index, path: 'seats'
28
+
29
+ # shallow routes
30
+ scope 'fast', shallow_path: 'fast' do
31
+ resources :cars, :only => [:index] do
32
+ resources :drivers, :only => [:show], shallow: true
33
+ end
34
+ end
17
35
  end
18
36
 
19
37
  end
@@ -10,4 +10,11 @@ nl:
10
10
  new: nieuw
11
11
  edit: wijzigen
12
12
  account: profiel
13
+ books: boeken
14
+ invitations: uitnodigingen
15
+ accept: accepteren
16
+ seats: stoelen
17
+ drivers: bestuurders
18
+ fast: snelle
19
+ cars: autos
13
20
 
@@ -50,6 +50,25 @@ describe 'routes' do
50
50
  expect(empty_en_path).to eq '/'
51
51
  end
52
52
 
53
+ it 'skips empty scopes' do
54
+ expect(empty_books_nl_path).to eq '/boeken'
55
+ expect(empty_books_en_path).to eq '/books'
56
+ end
57
+
58
+ it 'looks up translations by the path option if present' do
59
+ expect(edit_invitation_nl_path(2)).to eq '/uitnodigingen/2/accepteren'
60
+ end
61
+
62
+ it 'looks up resources translations by the path option if present' do
63
+ expect(chairs_nl_path).to eq '/stoelen'
64
+ expect(chairs_en_path).to eq '/seats'
65
+ end
66
+
67
+ it 'translated shallow paths' do
68
+ expect(driver_nl_path(3)).to eq '/snelle/bestuurders/3'
69
+ expect(driver_en_path(3)).to eq '/fast/drivers/3'
70
+ end
71
+
53
72
  describe 'adds untranslated path helpers' do
54
73
  it 'uses the I18n locale' do
55
74
  I18n.locale = :nl
@@ -59,7 +78,6 @@ describe 'routes' do
59
78
 
60
79
  describe 'adds untranslated url helpers' do
61
80
  it 'uses the I18n locale' do
62
- print_routes
63
81
  I18n.locale = :nl
64
82
  expect(payments_url).to eq 'http://example.com/geheim/betalingen'
65
83
  end
data/spec/spec_helper.rb CHANGED
@@ -20,7 +20,6 @@ RSpec.configure do |config|
20
20
 
21
21
  config.after(:each) do
22
22
  I18n.locale = I18n.default_locale = :en
23
- # Rails.application.reload_routes!
24
23
  end
25
24
 
26
25
  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.2
4
+ version: 0.0.3
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-04 00:00:00.000000000 Z
12
+ date: 2015-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails