breadcrumb_helper 0.1.1 → 0.2.0
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 +4 -4
- data/README.md +87 -16
- data/lib/breadcrumb_helper/main.rb +17 -0
- data/lib/breadcrumb_helper/version.rb +1 -1
- data/lib/generators/templates/breadcrumb_items.html.erb +7 -3
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3931b76ff470a9c63291b8aea824a303adc155c6c238e8318c3192607a9b43f1
|
4
|
+
data.tar.gz: 45718826d12b2a2961af56fe250a3927c4aacb72126c26c1a225e3403338eb49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d6217f08eea2596a885dc4716dc6d2e538fb6fae02992d1e8adf1f5deb1d896b22369d85d61fe448ce1a30e6ad70705af8a0ada32ec9259be6612a7d269299
|
7
|
+
data.tar.gz: ace507d1dad54a246864fe3a22deb1ed00bc5efa760c384cf18f33e00c8324d64c3bd8ebf5604deeabddf167812954afe0e3be5ca34683cd920b26585f8eb657
|
data/README.md
CHANGED
@@ -1,34 +1,105 @@
|
|
1
|
-
#
|
1
|
+
# Breadcrumb Helper for Rails
|
2
2
|
|
3
|
-
|
3
|
+
## Installation
|
4
4
|
|
5
|
-
|
5
|
+
Add this to your Gemfile:
|
6
6
|
|
7
|
-
|
7
|
+
```bash
|
8
|
+
gem 'breadcrumb_helper', '~> 0.1'
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
8
12
|
|
9
|
-
|
13
|
+
### Generate the files
|
10
14
|
|
11
|
-
|
15
|
+
To start, use the provided generator for a simplified and streamlined workflow:
|
12
16
|
|
13
|
-
|
17
|
+
```bash
|
18
|
+
rails generate breadcrumbs namespace
|
19
|
+
```
|
14
20
|
|
15
|
-
|
21
|
+
For example:
|
16
22
|
|
17
|
-
|
23
|
+
```bash
|
24
|
+
rails generate breadcrumbs test/namespace
|
25
|
+
```
|
26
|
+
will generate the following files in `test/namespace` folder structure respectively.
|
27
|
+
1. `app/helpers/concerns/breadcrumb_helper/test/namespace.rb`
|
28
|
+
2. `app/views/test/namespace/_breadcrumbs.html.erb`
|
29
|
+
3. `app/views/test/namespace/_breadcrumb_items.html.erb`
|
18
30
|
|
19
|
-
|
31
|
+
### Structuring the breadcrumbs
|
32
|
+
|
33
|
+
The generator will provide a file inside `concerns` folder of `helpers`. This should be included (`include`) or prepended (`prepend`) to your helper files. Assume that we have a `Test::Namespace::SomeController` with `show` and `index` actions. There should exist a `Test::Namespace::SomeHelper` file that includes or prepends the `BreadcrumbHelper::Test::Namespace` module.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
module Test::Namespace
|
37
|
+
module SomeHelper
|
38
|
+
include BreadcrumbHelper::Test::Namespace
|
39
|
+
# or prepend BreadcrumbHelper::Test::Namespace
|
40
|
+
|
41
|
+
# ...
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Since `SomeController` have `show` and `index` actions, our helper can define breadcrumbs for each action as such:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
module Test::Namespace
|
50
|
+
module SomeHelper
|
51
|
+
include BreadcrumbHelper::Test::Namespace
|
52
|
+
|
53
|
+
def index_breadcrumbs
|
54
|
+
add_breadcrumb name: 'Home'
|
55
|
+
end
|
56
|
+
|
57
|
+
def show_breadcrumbs
|
58
|
+
add_breadcrumb name: 'Home', path: root_path
|
59
|
+
add_breadcrumb name: 'Specific Data'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
With this setup, the controller's `index` and `show` actions will have their respective breadcrumbs rendered as defined in your helper.
|
66
|
+
|
67
|
+
### Render the breadcrumbs
|
68
|
+
|
69
|
+
Somewhere in your `layouts` (anywhere, really), simply call `render 'breadcrumbs'` to render them.
|
70
|
+
|
71
|
+
## Gotchas
|
72
|
+
|
73
|
+
### Railtie Configuration
|
74
|
+
|
75
|
+
This gem's Railtie sets the Rails application's `config.action_controller.include_all_helpers` to `false`. This is a non-negotiable setup as the way breadcrumbs are defined in each helper *will have unavoidably similar method names*.
|
76
|
+
|
77
|
+
By default, Rails includes **all helper files** into a controller. This will result to some method names getting replaced when there are similar ones across all helpers. In order to avoid this, the mentioned config needs to be disabled so that **it only loads the related helper associated with the controller**.
|
78
|
+
|
79
|
+
### Crumb Stoppers
|
80
|
+
|
81
|
+
As of `0.2.0`, this gem now supports a feature called Crumb Stoppers. Suppose we have the given code:
|
20
82
|
|
21
|
-
|
83
|
+
```ruby
|
84
|
+
module Some::Namespace
|
85
|
+
module MyHelper
|
86
|
+
prepend BreadcrumbHelper::Some::Namespace
|
22
87
|
|
23
|
-
|
88
|
+
def show_breadcrumbs
|
89
|
+
add_breadcrumb name: 'Home', path: root_path
|
90
|
+
add_breadcrumb name: @product.name # Assume this does not exist because of an unauthorized error that was rendered earlier.
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
24
95
|
|
25
|
-
|
96
|
+
With Crumb Stoppers, the breadcrumb trails will still display Home, and will not raise an exception.
|
26
97
|
|
27
|
-
|
98
|
+
Without Crumb Stoppers, the developer will need to add support for code *in each breadcrumb action*. To avoid this problem, the current default code of the gem is changed so that it stops the breadcrumb trail when it encounters a `NoMethodError` exception. Do note that it will still display the breadcrumbs that has no errors prior for a more beautiful display. However, the implementation is only integrated mostly in the view template, so for those who are updating the gem from `0.1.*`, I would advise to copy the code style found in the template to avail the Crumb Stoppers feature.
|
28
99
|
|
29
100
|
## Contributing
|
30
101
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
102
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tieeeeen1994/breadcrumb_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tieeeeen1994/breadcrumb_helper/blob/master/CODE_OF_CONDUCT.md).
|
32
103
|
|
33
104
|
## License
|
34
105
|
|
@@ -36,4 +107,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
36
107
|
|
37
108
|
## Code of Conduct
|
38
109
|
|
39
|
-
Everyone interacting in the BreadcrumbHelper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
110
|
+
Everyone interacting in the BreadcrumbHelper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tieeeeen1994/breadcrumb_helper/blob/master/CODE_OF_CONDUCT.md).
|
@@ -21,6 +21,23 @@ module BreadcrumbHelper
|
|
21
21
|
render('breadcrumb_items', items: breadcrumb_items)
|
22
22
|
end
|
23
23
|
|
24
|
+
# Tries to render the item name.
|
25
|
+
# This is a dynamic value, hence this method exists so that it can become the interface for displaying item names
|
26
|
+
# with the benefit of added guard clauses.
|
27
|
+
# It is recommended to use this in the view files.
|
28
|
+
def render_breadcrumb_item_name(item)
|
29
|
+
item[:name].to_s
|
30
|
+
rescue NoMethodError
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# Tries to render the item path.
|
35
|
+
# It does nothing special, but support for it is added just in case there are updates.
|
36
|
+
# It is still more recommended to use this in the view files.
|
37
|
+
def render_breadcrumb_item_path(item)
|
38
|
+
item[:path]
|
39
|
+
end
|
40
|
+
|
24
41
|
private
|
25
42
|
|
26
43
|
# Absolute source of truth for breadcrumb items, only modifiable through add_breadcrumb method.
|
@@ -1,11 +1,15 @@
|
|
1
1
|
<% items.each do |item| %>
|
2
|
-
<%
|
2
|
+
<% item_name = render_breadcrumb_item_name(item) %>
|
3
|
+
<% break unless item_name %>
|
4
|
+
|
5
|
+
<% item_path = render_breadcrumb_item_path(item) %>
|
6
|
+
<% if item_path %>
|
3
7
|
<li class="breadcrumb-item">
|
4
|
-
<a href="<%=
|
8
|
+
<a href="<%= item_path %>"><%= item_name %></a>
|
5
9
|
</li>
|
6
10
|
<% else %>
|
7
11
|
<li class="breadcrumb-item active" aria-current="page">
|
8
|
-
<%=
|
12
|
+
<%= item_name %>
|
9
13
|
</li>
|
10
14
|
<% end %>
|
11
15
|
<% end %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breadcrumb_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tien
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '7'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- tieeeeen1994@gmail.com
|
30
30
|
executables: []
|
@@ -50,7 +50,7 @@ licenses:
|
|
50
50
|
metadata:
|
51
51
|
homepage_uri: https://github.com/tieeeeen1994/rails-breadcrumb-helpers
|
52
52
|
rubygems_mfa_required: 'true'
|
53
|
-
post_install_message:
|
53
|
+
post_install_message:
|
54
54
|
rdoc_options: []
|
55
55
|
require_paths:
|
56
56
|
- lib
|
@@ -65,8 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
|
-
rubygems_version: 3.5
|
69
|
-
signing_key:
|
68
|
+
rubygems_version: 3.3.5
|
69
|
+
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: Provides easy helper methods to generate breadcrumbs in Rails views.
|
72
72
|
test_files: []
|