auto_breadcrumbs 0.2.7 → 0.3.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: 5f47820303623b48f4d748c007ffe6713103ba21
4
- data.tar.gz: df793fd159ca98d4fdf9b2174e2328ce1c999c3d
3
+ metadata.gz: 49f9086b4ad4960dddcca1e29c99977bf0f5fdcc
4
+ data.tar.gz: 77084a18e6d528247d1ac4a8bc57886f2426cef7
5
5
  SHA512:
6
- metadata.gz: 382059adb923f5bc3f2b6e1483d698aa69ff71997a16cf356b7ac11fd77b420981cdb622735e81ee82cc02e1410954d074014692b9bc60462ffc168eb5ab2a37
7
- data.tar.gz: e7f73f93b53bfb50234844c27cf6dc88edd95807348006e47805ab045c1d76b5db729031dba189c7f4ecc031fd83575c7f1b34f6edbf4267a59935871b878dd7
6
+ metadata.gz: 9ff92bed3f963ce8c7cd33c2c632091eaa55aa7b56d499d11bc0ca697f792cbbfb25aa7a3452c2c19d05cd6f70a4c34963ae615a261faa494d6542ae1577f22a
7
+ data.tar.gz: a1e94c04dfc5c42eb1b87571c2c5ebc2314c6ae2ee983689bfc5516e09d3c85b52803bf9c052fb009aa413fd1dd2f111c792757887db0fffd735925ccdfc9a32
data/README.md CHANGED
@@ -60,6 +60,17 @@ For example, if you go to `/users/1/edit` it will show breadcrums like `Home / U
60
60
  In case when translations are absent it will try to build breadcrumbs automatically depending on resource and action names.
61
61
  For example, if you visit `/countries/new` it will show breadcrums `Home / Countries / New`.
62
62
 
63
+ You can also use helper methods `resource_translation` and `action_translation` like this:
64
+
65
+ ```erb
66
+ <!DOCTYPE html>
67
+ <html>
68
+ <head>
69
+ <title><%= [resource_translation, action_translation].compact.join(' | ') %></title>
70
+ </head>
71
+ </html>
72
+ ```
73
+
63
74
  ## Customization
64
75
 
65
76
  For more information about customization of breadcrumbs visit [breadcrumbs_on_rails](https://github.com/weppos/breadcrumbs_on_rails).
@@ -21,8 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'breadcrumbs_on_rails'
22
22
 
23
23
  spec.add_development_dependency 'activemodel'
24
-
25
24
  spec.add_development_dependency 'rspec-rails'
26
25
  spec.add_development_dependency 'capybara'
27
- spec.add_development_dependency 'poltergeist'
26
+ spec.add_development_dependency 'pry'
28
27
  end
@@ -17,38 +17,57 @@ module AutoBreadcrumbs
17
17
  add_breadcrumb breadcrumbs_t('root'), :root_path
18
18
 
19
19
  unless request.path == root_path
20
- add_breadcrumb(resource_translation, index_path) if resource_translation
21
- add_breadcrumb(action_translation) if action_translation
20
+ # nested resources
21
+ Rails.application.routes.router.recognize(request) do |route, matches, param|
22
+ route.required_parts[0...-1].each do |required_part|
23
+ resources_name = required_part.to_s.gsub('_id', '').pluralize
24
+ resource_translation = resource_translation(resources_name)
25
+ resource_index_path = index_path(resources_name)
26
+ action_translation = action_translation(resources_name, 'show')
27
+
28
+ add_breadcrumb(resource_translation, resource_index_path) if resource_translation
29
+ add_breadcrumb(action_translation) if action_translation
30
+ end
31
+ end
32
+
33
+ resource_translation = resource_translation(params[:controller])
34
+ resource_index_path = index_path(params[:controller])
35
+ action_translation = action_translation(params[:controller], params[:action])
36
+
37
+ add_breadcrumb(resource_translation, resource_index_path) if resource_translation
38
+ add_breadcrumb(action_translation) if action_translation
22
39
  end
23
40
  end
24
41
 
25
- def resource_translation
26
- if index_path
27
- breadcrumbs_t("controllers.#{ params[:controller] }.index") ||
28
- params[:controller].humanize
42
+ def resource_translation(resources_name)
43
+ if index_path(resources_name)
44
+ breadcrumbs_t("controllers.#{ resources_name }.index") ||
45
+ resources_name.humanize
29
46
  end
30
47
  end
31
48
 
32
- def action_translation
33
- unless params[:action] == 'index'
34
- breadcrumbs_t("controllers.#{ params[:controller] }.#{ breadcrumbs_action_name }") ||
35
- breadcrumbs_t("actions.#{ breadcrumbs_action_name }") ||
36
- breadcrumbs_action_name.humanize
49
+ def action_translation(resources_name, action_name)
50
+ mapped_action_name = breadcrumbs_action_name(action_name)
51
+
52
+ unless mapped_action_name == 'index'
53
+ breadcrumbs_t("controllers.#{ resources_name }.#{ mapped_action_name }") ||
54
+ breadcrumbs_t("actions.#{ mapped_action_name }") ||
55
+ mapped_action_name.humanize
37
56
  end
38
57
  end
39
58
 
40
- def index_path
41
- url_for(controller: params[:controller]) rescue nil
59
+ def index_path(resources_name)
60
+ url_for(controller: resources_name) rescue nil
42
61
  end
43
62
 
44
- def breadcrumbs_action_name
45
- case params[:action]
63
+ def breadcrumbs_action_name(action_name)
64
+ case action_name
46
65
  when 'create'
47
66
  'new'
48
67
  when 'update'
49
68
  'edit'
50
69
  else
51
- params[:action]
70
+ action_name
52
71
  end
53
72
  end
54
73
 
@@ -1,3 +1,3 @@
1
1
  module AutoBreadcrumbs
2
- VERSION = '0.2.7'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -0,0 +1 @@
1
+ I18n.enforce_available_locales = false
@@ -12,5 +12,5 @@ en:
12
12
  sync: 'Synchronization'
13
13
  dup: 'Duplication'
14
14
  cities:
15
- index: 'Cities / Towns'
15
+ index: 'Cities & Towns'
16
16
  show: 'Browse'
@@ -11,5 +11,7 @@ Dummy::Application.routes.draw do
11
11
 
12
12
  resources :country_names, only: [:index]
13
13
 
14
- resources :cities, only: [:edit, :show]
14
+ resources :cities, only: [:index, :edit, :show] do
15
+ resources :users, only: :show
16
+ end
15
17
  end
@@ -2,81 +2,91 @@ require 'spec_helper'
2
2
  require 'features/pages/breadcrumb_page'
3
3
 
4
4
  feature 'Rendering breadcrumbs' do
5
- let(:locale) { YAML.load(File.open(Rails.root.join('config/locales/auto_breadcrumbs.en.yml')))['en']['auto_breadcrumbs'] }
6
-
7
- # Root page -------------------------------------------------------------------------------------
8
-
9
- let(:root_page) { BreadcrumbPage.new(index: root_path) }
10
- let(:root_breadcrumbs) { [locale['root']] }
11
-
12
- # Country name page -----------------------------------------------------------------------------
13
-
14
- let(:country_name_page) { BreadcrumbPage.new(index: country_names_path) }
15
- let(:country_name_index_breadcrumbs) { root_breadcrumbs + ['Country names'] }
16
-
17
- # City page -------------------------------------------------------------------------------------
18
-
19
- let(:city_page) {
20
- BreadcrumbPage.new edit: edit_city_path('id'),
21
- show: city_path('id')
22
- }
23
- let(:city_edit_breadcrumbs) { root_breadcrumbs + [locale['actions']['edit']] }
24
- let(:city_show_breadcrumbs) { root_breadcrumbs + [locale['controllers']['cities']['show']] }
25
-
26
- # User page -------------------------------------------------------------------------------------
27
-
28
- let(:user_page) {
29
- BreadcrumbPage.new index: users_path,
30
- show: user_path('id'),
31
- edit: edit_user_path('id'),
32
- dup: dup_user_path('id'),
33
- ban: ban_user_path('id'),
34
- sync: sync_users_path
35
- }
36
- let(:user_index_breadcrumbs) { root_breadcrumbs + [locale['controllers']['users']['index']] }
37
- let(:user_show_breadcrumbs) { user_index_breadcrumbs + [locale['actions']['show']] }
38
- let(:user_edit_breadcrumbs) { user_index_breadcrumbs + [locale['controllers']['users']['edit']] }
39
- let(:user_dup_breadcrumbs) { user_index_breadcrumbs + [locale['controllers']['users']['dup']] }
40
- let(:user_sync_breadcrumbs) { user_index_breadcrumbs + [locale['controllers']['users']['sync']] }
41
- let(:user_ban_breadcrumbs) { user_index_breadcrumbs + ['Ban'] }
5
+ let(:locale) do
6
+ locale_file = File.open(Rails.root.join('config/locales/auto_breadcrumbs.en.yml'))
7
+ YAML.load(locale_file)['en']['auto_breadcrumbs']
8
+ end
42
9
 
43
- # -----------------------------------------------------------------------------------------------
10
+ let(:root_breadcrumbs) { ['Home'] }
44
11
 
45
12
  scenario 'on root page' do
13
+ root_page = BreadcrumbPage.new(index: root_path)
14
+
46
15
  root_page.visit_page(:index)
16
+
47
17
  expect(root_page.breadcrumbs).to eq(root_breadcrumbs)
48
18
  end
49
19
 
50
20
  scenario 'without translation' do
21
+ country_name_page = BreadcrumbPage.new(index: country_names_path)
22
+
51
23
  country_name_page.visit_page(:index)
24
+ country_name_index_breadcrumbs = root_breadcrumbs + ['Country names']
25
+
52
26
  expect(country_name_page.breadcrumbs).to eq(country_name_index_breadcrumbs)
53
27
  end
54
28
 
55
29
  scenario 'when resource without index action' do
30
+ city_page = BreadcrumbPage.new(edit: edit_city_path('id'), show: city_path('id'))
31
+
56
32
  city_page.visit_page(:edit)
33
+ city_edit_breadcrumbs = root_breadcrumbs + ['Cities & Towns', 'Edit']
34
+
57
35
  expect(city_page.breadcrumbs).to eq(city_edit_breadcrumbs)
58
36
 
59
37
  city_page.visit_page(:show)
38
+ city_show_breadcrumbs = root_breadcrumbs + ['Cities & Towns', 'Browse']
39
+
60
40
  expect(city_page.breadcrumbs).to eq(city_show_breadcrumbs)
61
41
  end
62
42
 
63
43
  scenario 'when resource with index action' do
44
+ user_page = BreadcrumbPage.new(
45
+ index: users_path,
46
+ show: user_path('id'),
47
+ edit: edit_user_path('id'),
48
+ dup: dup_user_path('id'),
49
+ ban: ban_user_path('id'),
50
+ sync: sync_users_path
51
+ )
52
+
64
53
  user_page.visit_page(:index)
54
+ user_index_breadcrumbs = root_breadcrumbs + ['Users']
55
+
65
56
  expect(user_page.breadcrumbs).to eq(user_index_breadcrumbs)
66
57
 
67
58
  user_page.visit_page(:show)
59
+ user_show_breadcrumbs = user_index_breadcrumbs + ['Show']
60
+
68
61
  expect(user_page.breadcrumbs).to eq(user_show_breadcrumbs)
69
62
 
70
63
  user_page.visit_page(:edit)
64
+ user_edit_breadcrumbs = user_index_breadcrumbs + ['Settings']
65
+
71
66
  expect(user_page.breadcrumbs).to eq(user_edit_breadcrumbs)
72
67
 
73
68
  user_page.visit_page(:dup)
69
+ user_dup_breadcrumbs = user_index_breadcrumbs + ['Duplication']
70
+
74
71
  expect(user_page.breadcrumbs).to eq(user_dup_breadcrumbs)
75
72
 
76
73
  user_page.visit_page(:sync)
74
+ user_sync_breadcrumbs = user_index_breadcrumbs + ['Synchronization']
75
+
77
76
  expect(user_page.breadcrumbs).to eq(user_sync_breadcrumbs)
78
77
 
79
78
  user_page.visit_page(:ban)
79
+ user_ban_breadcrumbs = user_index_breadcrumbs + ['Ban']
80
+
80
81
  expect(user_page.breadcrumbs).to eq(user_ban_breadcrumbs)
81
82
  end
83
+
84
+ scenario 'nested resources' do
85
+ nested_user_page = BreadcrumbPage.new(show: city_user_path('city_id', 'id'))
86
+
87
+ nested_user_page.visit_page(:show)
88
+ nested_breadcrumbs = root_breadcrumbs + ['Cities & Towns', 'Browse', 'Users', 'Show']
89
+
90
+ expect(nested_user_page.breadcrumbs).to eq(nested_breadcrumbs)
91
+ end
82
92
  end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,4 @@ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
5
  require 'rspec/rails'
6
6
  require 'capybara/rspec'
7
7
  require 'capybara/rails'
8
- require 'capybara/poltergeist'
9
-
10
- Capybara.javascript_driver = :poltergeist
8
+ require 'pry'
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_breadcrumbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: breadcrumbs_on_rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: capybara
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: poltergeist
70
+ name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Automatically add breadcrumbs to each page by using locales
@@ -87,8 +87,8 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .rspec
91
- - .travis.yml
90
+ - ".rspec"
91
+ - ".travis.yml"
92
92
  - Gemfile
93
93
  - LICENSE.txt
94
94
  - README.md
@@ -113,6 +113,7 @@ files:
113
113
  - spec/dummy/config/environments/development.rb
114
114
  - spec/dummy/config/environments/production.rb
115
115
  - spec/dummy/config/environments/test.rb
116
+ - spec/dummy/config/initializers/i18n.rb
116
117
  - spec/dummy/config/initializers/secret_token.rb
117
118
  - spec/dummy/config/locales/auto_breadcrumbs.en.yml
118
119
  - spec/dummy/config/routes.rb
@@ -133,17 +134,17 @@ require_paths:
133
134
  - lib
134
135
  required_ruby_version: !ruby/object:Gem::Requirement
135
136
  requirements:
136
- - - '>='
137
+ - - ">="
137
138
  - !ruby/object:Gem::Version
138
139
  version: '0'
139
140
  required_rubygems_version: !ruby/object:Gem::Requirement
140
141
  requirements:
141
- - - '>='
142
+ - - ">="
142
143
  - !ruby/object:Gem::Version
143
144
  version: '0'
144
145
  requirements: []
145
146
  rubyforge_project:
146
- rubygems_version: 2.0.3
147
+ rubygems_version: 2.2.2
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: Automatically adding breadcrumbs by using locales
@@ -162,6 +163,7 @@ test_files:
162
163
  - spec/dummy/config/environments/development.rb
163
164
  - spec/dummy/config/environments/production.rb
164
165
  - spec/dummy/config/environments/test.rb
166
+ - spec/dummy/config/initializers/i18n.rb
165
167
  - spec/dummy/config/initializers/secret_token.rb
166
168
  - spec/dummy/config/locales/auto_breadcrumbs.en.yml
167
169
  - spec/dummy/config/routes.rb
@@ -172,3 +174,4 @@ test_files:
172
174
  - spec/features/pages/breadcrumb_page.rb
173
175
  - spec/features/rendering_breadcrumbs_spec.rb
174
176
  - spec/spec_helper.rb
177
+ has_rdoc: