dat_gretel 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +56 -0
- data/Gemfile +23 -0
- data/LICENSE.txt +22 -0
- data/README.md +359 -0
- data/Rakefile +10 -0
- data/dat_gretel.gemspec +22 -0
- data/gemfiles/Gemfile-rails.3.1.x +19 -0
- data/gemfiles/Gemfile-rails.3.2.x +19 -0
- data/gemfiles/Gemfile-rails.4.0.x +19 -0
- data/gemfiles/Gemfile-rails.4.1.x +19 -0
- data/gemfiles/Gemfile-rails.5.2.x +19 -0
- data/lib/dat_gretel.rb +82 -0
- data/lib/dat_gretel/crumb.rb +70 -0
- data/lib/dat_gretel/crumbs.rb +64 -0
- data/lib/dat_gretel/deprecated.rb +1 -0
- data/lib/dat_gretel/deprecated/default_style_key.rb +25 -0
- data/lib/dat_gretel/deprecated/layout.rb +15 -0
- data/lib/dat_gretel/deprecated/show_root_alone.rb +27 -0
- data/lib/dat_gretel/deprecated/yield_links.rb +44 -0
- data/lib/dat_gretel/link.rb +40 -0
- data/lib/dat_gretel/renderer.rb +259 -0
- data/lib/dat_gretel/resettable.rb +13 -0
- data/lib/dat_gretel/version.rb +3 -0
- data/lib/dat_gretel/view_helpers.rb +71 -0
- data/lib/generators/dat_gretel/USAGE +8 -0
- data/lib/generators/dat_gretel/install_generator.rb +12 -0
- data/lib/generators/dat_gretel/templates/breadcrumbs.rb +28 -0
- data/test/dat_gretel_test.rb +24 -0
- data/test/deprecated_test.rb +45 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +5 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/models/issue.rb +3 -0
- data/test/dummy/app/models/project.rb +3 -0
- data/test/dummy/app/views/breadcrumbs/site.rb +3 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +14 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/breadcrumbs.rb +3 -0
- data/test/dummy/config/breadcrumbs/test_crumbs.rb +85 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +2 -0
- data/test/dummy/config/environments/production.rb +2 -0
- data/test/dummy/config/environments/test.rb +2 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +11 -0
- data/test/dummy/db/migrate/20130122163007_create_projects.rb +9 -0
- data/test/dummy/db/migrate/20130122163051_create_issues.rb +10 -0
- data/test/dummy/db/schema.rb +28 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/fixtures/issues.yml +4 -0
- data/test/fixtures/projects.yml +3 -0
- data/test/gretel_test.rb +24 -0
- data/test/helper_methods_test.rb +552 -0
- data/test/test_helper.rb +15 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ccaad8cb8f8ec8530bb91ea0e8bc410457c66828a7fd03bb0d6dbed37ce2f189
|
4
|
+
data.tar.gz: 00a5aa6e1f77ab33b97b0914f22a686f394e46bc879e4e861dd82c8b1d5037ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6c38ca23c2eaeca2e3f537bd88ea7596b2ba380cc813fc94bc48ee782d6ea61b8368f0dc6772d97330a48643b70befdc0dfe8b92f367dfac7eb69808aed8d40
|
7
|
+
data.tar.gz: 6be2a36c0ac7ecfa5ce9f39c89127380856aee330e3c39e388be62416b6905cc11653fdb434190d34b76429a83beb19ea7c5ea1c89f9ddb3dc4170f2fbfa83ae
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
gemfiles/*.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
log/*.log
|
20
|
+
test/dummy/db/*.sqlite3
|
21
|
+
test/dummy/log/*.log
|
22
|
+
test/dummy/tmp/
|
23
|
+
test/dummy/.sass-cache
|
24
|
+
.DS_Store
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
rvm:
|
4
|
+
- 2.5.1
|
5
|
+
- 2.2.2
|
6
|
+
gemfile:
|
7
|
+
- gemfiles/Gemfile-rails.4.0.x
|
8
|
+
- gemfiles/Gemfile-rails.4.1.x
|
9
|
+
- gemfiles/Gemfile-rails.5.2.x
|
10
|
+
before_script:
|
11
|
+
- "cd test/dummy; rake db:migrate; rake db:test:prepare; cd ../.."
|
12
|
+
notifications:
|
13
|
+
email: false
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: 2.5.1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Version 3.0.9
|
4
|
+
* Adds breadcrumbs option `link_current_to_request_path` to link the current breadcrumb to the request path(#28 via #29)
|
5
|
+
* Fixes semantic breadcrumbs when the last item has no link (via #55)
|
6
|
+
* Downgrades Rails dependency to 3.1 (via #56)
|
7
|
+
* Fixes jRuby issue with `Rails::Application` constant (via #50)
|
8
|
+
* Fixes deprecation warnings for `alias_method_chain` (via #66)
|
9
|
+
* Updated coprights (via #63)
|
10
|
+
|
11
|
+
## Version 3.0.8
|
12
|
+
* Parent breadcrumbs can now also be inferred from models responding to `model_name`.
|
13
|
+
|
14
|
+
## Version 3.0.7
|
15
|
+
* Pretext and posttext classes are now customizable with `<%= breadcrumbs pretext_class: "some-class" %>` and `<%= breadcrumbs posttext_class: "some-other-class" %>`.
|
16
|
+
|
17
|
+
## Version 3.0.6
|
18
|
+
* Pretext and posttext are now enclosed in spans with `<span class="pretext">` and `<span class="posttext">`.
|
19
|
+
* Semantic breadcrumbs are now rendered in spans instead of divs to enable easier styling.
|
20
|
+
|
21
|
+
## Version 3.0.3
|
22
|
+
* Breadcrumbs can now be rendered for use in the [Foundation 5](http://foundation.zurb.com/) framework. Use `breadcrumbs style: :foundation5`.
|
23
|
+
* Breadcrumbs are now automatically loaded from any engines' `config/breadcrumbs.rb` and `config/breadcrumbs/**/*.rb`. See the readme for details.
|
24
|
+
* You can now pass options to links to be used when you render manually. See the readme for details.
|
25
|
+
* Breadcrumb configuration files can now be put in the `app/views/breadcrumbs/` folder. This is an experimental feature that may replace loading breadcrumbs from the `config` folder in the future.
|
26
|
+
|
27
|
+
## Version 3.0.2
|
28
|
+
* Inferring breadcrumbs is now supported on all instances of objects that respond to `model_name`.
|
29
|
+
|
30
|
+
## Version 3.0.1
|
31
|
+
* Breadcrumbs can now be inferred if you pass in an ActiveRecord model instance. E.g. `breadcrumb @product` is short for `breadcrumb :product, @product`.
|
32
|
+
|
33
|
+
## Version 3.0
|
34
|
+
* Support for defining breadcrumbs using `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See the readme for details on how to upgrade.
|
35
|
+
* Breadcrumbs rendering is now done in a separate class to unclutter the view with helpers. The public API is still the same.
|
36
|
+
* Support for rendering the breadcrumbs in different styles like ul- and ol lists, and for use with [Twitter Bootstrap](http://getbootstrap.com/). See the `:style` option in the readme for more info.
|
37
|
+
* The `:show_root_alone` option is now called `:display_single_fragment` and can be used to display the breadcrumbs only when there are more than one link, also if it is not the root breadcrumb.
|
38
|
+
* Links yielded from `<%= breadcrumbs do |links| %>` now have a `current?` helper that returns true if the link is the last in the trail.
|
39
|
+
* New view helper: `parent_breadcrumb` returns the parent breadcrumb link (with `#key`, `#text`, and `#url`). This can for example be used to create a dynamic back link. You can supply options like `:autoroot` etc.
|
40
|
+
If you supply a block, it will yield the parent breadcrumb if it is present.
|
41
|
+
|
42
|
+
## Version 2.1
|
43
|
+
* Breadcrumbs are now configured in `config/breadcrumbs.rb` and `config/breadcrumbs/**/*.rb` and reloaded when changed in the development environment instead of the initializer that required restart when configuration changed.
|
44
|
+
|
45
|
+
## Version 2.0
|
46
|
+
|
47
|
+
* Totally rewritten for better structure.
|
48
|
+
* `options[:autoroot]` is now `true` by default which means it will automatically link to the `:root` breadcrumb if no parent is specified.
|
49
|
+
* Now accepts `options[:class]` for specifying the CSS class for the breadcrumbs container. Default: `"breadcrumbs"`.
|
50
|
+
* Now accepts `options[:current_class]` for specifying the CSS class for the current link / span. Default: `"current"`.
|
51
|
+
* `options[:link_last]` was deprecated in a previous version and is now removed. Use `options[:link_current]` instead.
|
52
|
+
* The `link` method in `crumb :xx do ... end` no longer takes HTML options. The method for this is now by building the breadcrumbs manually (see the readme).
|
53
|
+
* No longer supports procs for link text or URL as this is unnecessary when you can pass arguments to the block anyway.
|
54
|
+
* It now accepts multiple arguments for `crumb` and `parent` (see the readme).
|
55
|
+
* Breadcrumbs are now rendered with `<%= breadcrumbs %>`, although you can still use the old `<%= breadcrumb %>` (without *s*).
|
56
|
+
* You can now access view helpers from inside `Gretel::Crumbs.layout do .. end`.
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in gretel.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
15
|
+
|
16
|
+
group :development do
|
17
|
+
# jquery-rails is used by the dummy application
|
18
|
+
gem "jquery-rails"
|
19
|
+
end
|
20
|
+
|
21
|
+
group :test do
|
22
|
+
gem 'test-unit', '~> 3.0' if RUBY_VERSION >= "2.2"
|
23
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010-2016 Lasse Bunk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,359 @@
|
|
1
|
+
<a href="https://travis-ci.org/marciodat/gretel"><img src="https://travis-ci.org/marciodat/gretel.svg" alt="Build Status" /></a>
|
2
|
+
|
3
|
+
<img src="http://i.imgur.com/CAKEaBM.png" alt="Handle breadcrumb trails... like a boss :)" />
|
4
|
+
|
5
|
+
This is an update of the amazing `gretel` gem with the following changes:
|
6
|
+
|
7
|
+
- Added `fragment_class`: allows the user to specify classes for framents
|
8
|
+
|
9
|
+
- Updated bootstrap default to the latest version
|
10
|
+
|
11
|
+
- Updated rails to the latest version
|
12
|
+
|
13
|
+
- Updated tests
|
14
|
+
|
15
|
+
Due to some changes on the latest rails version, the gem compatibility has been changed:
|
16
|
+
|
17
|
+
- ruby = 2.2.2 / rails >= 4.0.x
|
18
|
+
|
19
|
+
- ruby = 2.5.1 / rails >= 5.2.x
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
([TL;DR](http://i.imgur.com/nH25yiH.png)) Gretel is a [Ruby on Rails](http://rubyonrails.org) plugin that makes it easy yet flexible to create breadcrumbs.
|
24
|
+
It is based around the idea that breadcrumbs are a concern of the view, so you define a set of breadcrumbs in *config/breadcrumbs.rb* (or multiple files; see below) and specify in the view which breadcrumb to use.
|
25
|
+
Gretel also supports [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417) (those used in Google results).
|
26
|
+
|
27
|
+
Have fun! And please do write, if you (dis)like it – [lassebunk@gmail.com](mailto:lassebunk@gmail.com).
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
In your *Gemfile*:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem "dat_gretel"
|
35
|
+
```
|
36
|
+
|
37
|
+
And run:
|
38
|
+
|
39
|
+
```bash
|
40
|
+
$ bundle install
|
41
|
+
```
|
42
|
+
|
43
|
+
## Example
|
44
|
+
|
45
|
+
Start by generating breadcrumbs configuration file:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
$ rails generate dat_gretel:install
|
49
|
+
```
|
50
|
+
|
51
|
+
Then, in *config/breadcrumbs.rb*:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# Root crumb
|
55
|
+
crumb :root do
|
56
|
+
link "Home", root_path
|
57
|
+
end
|
58
|
+
|
59
|
+
# Issue list
|
60
|
+
crumb :issues do
|
61
|
+
link "All issues", issues_path
|
62
|
+
end
|
63
|
+
|
64
|
+
# Issue
|
65
|
+
crumb :issue do |issue|
|
66
|
+
link issue.title, issue
|
67
|
+
parent :issues
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
At the top of *app/views/issues/show.html.erb*, set the current breadcrumb (assuming you have loaded `@issue` with an issue):
|
72
|
+
|
73
|
+
```erb
|
74
|
+
<% breadcrumb :issue, @issue %>
|
75
|
+
```
|
76
|
+
|
77
|
+
Then, in *app/views/layouts/application.html.erb*:
|
78
|
+
|
79
|
+
```erb
|
80
|
+
<%= breadcrumbs pretext: "You are here: ",
|
81
|
+
separator: " › " %>
|
82
|
+
```
|
83
|
+
|
84
|
+
This will generate the following HTML (indented for readability):
|
85
|
+
|
86
|
+
```html
|
87
|
+
<div class="breadcrumbs">
|
88
|
+
<span class="pretext">You are here:</span>
|
89
|
+
<a href="/">Home</a> ›
|
90
|
+
<a href="/issues">All issues</a> ›
|
91
|
+
<span class="current">My Issue</span>
|
92
|
+
</div>
|
93
|
+
```
|
94
|
+
|
95
|
+
## Options
|
96
|
+
|
97
|
+
You can pass options to `<%= breadcrumbs %>`, e.g. `<%= breadcrumbs pretext: "You are here: " %>`:
|
98
|
+
|
99
|
+
Option | Description | Default
|
100
|
+
------------------------ | -------------------------------------------------------------------------------------------------------------------------- | -------
|
101
|
+
:style | How to render the breadcrumbs. Can be `:inline`, `:ol`, `:ul`, or `:bootstrap`. See below for more info. | `:inline`
|
102
|
+
:pretext | Text to be rendered before breadcrumb, e.g. `"You are here: "`. | None
|
103
|
+
:posttext | Text to be appended after breadcrumb, e.g. `"Text after breacrumb"`, | None
|
104
|
+
:separator | Separator between links, e.g. `" › "`. | `" › "`
|
105
|
+
:autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | True
|
106
|
+
:display_single_fragment | Whether it should display the breadcrumb if it includes only one link. | False
|
107
|
+
:link_current | Whether the current crumb should be linked to. | False
|
108
|
+
:link_current_to_request_path | Whether the current crumb should always link to the current request path. *Note:* This option will have no effect unless `:link_current` is set to `true`. | True
|
109
|
+
:semantic | Whether it should generate [semantic breadcrumbs](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
|
110
|
+
:id | ID for the breadcrumbs container. | None
|
111
|
+
:class | CSS class for the breadcrumbs container. Can be set to `nil` for no class. | `"breadcrumbs"`
|
112
|
+
:current_class | CSS class for the current link or span. Can be set to `nil` for no class. | `"current"`
|
113
|
+
:fragment_class | CSS class for the fragment link or span. Can be set to `nil` for no class. | `"breadcrumb-item"`
|
114
|
+
:pretext_class | CSS class for the pretext, if given. Can be set to `nil` for no class. | `"pretext"`
|
115
|
+
:posttext_class | CSS class for the posttext, if given. Can be set to `nil` for no class. | `"posttext"`
|
116
|
+
:container_tag | Tag type that contains the breadcrumbs. | `:div`
|
117
|
+
:fragment_tag | Tag type to contain each breadcrumb fragment/link. | None
|
118
|
+
|
119
|
+
### Styles
|
120
|
+
|
121
|
+
These are the styles you can use with `breadcrumbs style: :xx`.
|
122
|
+
|
123
|
+
Style | Description
|
124
|
+
-------------- | -----------
|
125
|
+
`:inline` | Renders each link by itself with `›` as the seperator.
|
126
|
+
`:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
|
127
|
+
`:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
|
128
|
+
`:bootstrap` | Renders the links for use in [Twitter Bootstrap](http://getbootstrap.com/).
|
129
|
+
`:foundation5` | Renders the links for use in [Foundation 5](http://foundation.zurb.com/).
|
130
|
+
|
131
|
+
Or you can build the breadcrumbs manually for full customization; see below.
|
132
|
+
|
133
|
+
If you add other widely used styles, please submit a [Pull Request](https://github.com/lassebunk/gretel/pulls) so others can use them too.
|
134
|
+
|
135
|
+
## More examples
|
136
|
+
|
137
|
+
In *config/breadcrumbs.rb*:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
# Root crumb
|
141
|
+
crumb :root do
|
142
|
+
link "Home", root_path
|
143
|
+
end
|
144
|
+
|
145
|
+
# Regular crumb
|
146
|
+
crumb :projects do
|
147
|
+
link "Projects", projects_path
|
148
|
+
end
|
149
|
+
|
150
|
+
# Parent crumbs
|
151
|
+
crumb :project_issues do |project|
|
152
|
+
link "Issues", project_issues_path(project)
|
153
|
+
parent project # inferred to :project
|
154
|
+
end
|
155
|
+
|
156
|
+
# Child
|
157
|
+
crumb :issue do |issue|
|
158
|
+
link issue.name, issue_path(issue)
|
159
|
+
parent :project_issues, issue.project
|
160
|
+
end
|
161
|
+
|
162
|
+
# Recursive parent categories
|
163
|
+
crumb :category do |category|
|
164
|
+
link category.name, category
|
165
|
+
if category.parent
|
166
|
+
parent category.parent # inferred to :category
|
167
|
+
else
|
168
|
+
parent :categories
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Product crumb with recursive parent categories (as defined above)
|
173
|
+
crumb :product do |product|
|
174
|
+
link product.name, product
|
175
|
+
parent product.category # inferred to :category
|
176
|
+
end
|
177
|
+
|
178
|
+
# Crumb with multiple links
|
179
|
+
crumb :test do
|
180
|
+
link "One", one_path
|
181
|
+
link "Two", two_path
|
182
|
+
parent :about
|
183
|
+
end
|
184
|
+
|
185
|
+
# Example of using params to alter the parent, e.g. to
|
186
|
+
# match the user's actual navigation path
|
187
|
+
# URL: /products/123?q=my+search
|
188
|
+
crumb :search do |keyword|
|
189
|
+
link "Search for #{keyword}", search_path(q: keyword)
|
190
|
+
end
|
191
|
+
|
192
|
+
crumb :product do |product|
|
193
|
+
if keyword = params[:q].presence
|
194
|
+
parent :search, keyword
|
195
|
+
else # default
|
196
|
+
parent product.category # inferred to :category
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# Multiple arguments
|
201
|
+
crumb :multiple_test do |a, b, c|
|
202
|
+
link "Test #{a}, #{b}, #{c}", test_path
|
203
|
+
parent :other_test, 3, 4, 5
|
204
|
+
end
|
205
|
+
|
206
|
+
# Breadcrumb without link URL; will not generate a link
|
207
|
+
crumb :without_link do
|
208
|
+
link "Breadcrumb without link"
|
209
|
+
end
|
210
|
+
|
211
|
+
# Breadcrumb using view helper
|
212
|
+
module UsersHelper
|
213
|
+
def user_name_for(user)
|
214
|
+
user.name
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
crumb :user do |user|
|
219
|
+
link user_name_for(user), user
|
220
|
+
end
|
221
|
+
```
|
222
|
+
|
223
|
+
## Building the breadcrumbs manually
|
224
|
+
|
225
|
+
If you supply a block to the `breadcrumbs` method, it will yield an array with the breadcrumb links so you can build the breadcrumbs HTML manually:
|
226
|
+
|
227
|
+
```erb
|
228
|
+
<% breadcrumbs do |links| %>
|
229
|
+
<% if links.any? %>
|
230
|
+
You are here:
|
231
|
+
<% links.each do |link| %>
|
232
|
+
<%= link_to link.text, link.url, class: (link.current? ? "current" : nil) %> (<%= link.key %>)
|
233
|
+
<% end %>
|
234
|
+
<% end %>
|
235
|
+
<% end %>
|
236
|
+
```
|
237
|
+
|
238
|
+
## Getting the parent breadcrumb
|
239
|
+
|
240
|
+
If you want to add a link to the parent breadcrumb, you can use the `parent_breadcrumb` view helper.
|
241
|
+
By default it returns a link instance that has the properties `#key`, `#text`, and `#url`.
|
242
|
+
You can supply options like `autoroot: false` etc.
|
243
|
+
|
244
|
+
If you supply a block, it will yield the link if it is present:
|
245
|
+
|
246
|
+
```erb
|
247
|
+
<% parent_breadcrumb do |link| %>
|
248
|
+
<%= link_to "Back to #{link.text}", link.url %>
|
249
|
+
<% end %>
|
250
|
+
```
|
251
|
+
|
252
|
+
## Nice to know
|
253
|
+
|
254
|
+
### Access to view methods
|
255
|
+
|
256
|
+
When configuring breadcrumbs inside a `crumb :xx do ... end` block, you have access to all methods that are normally accessible in the view where the breadcrumbs are inserted. This includes your view helpers, `params`, `request`, etc.
|
257
|
+
|
258
|
+
### Using multiple breadcrumb configuration files
|
259
|
+
|
260
|
+
If you have a large site and you want to split your breadcrumbs configuration over multiple files, you can create a folder named `config/breadcrumbs` and put your configuration files (e.g. `products.rb` or `frontend.rb`) in there.
|
261
|
+
The format is the same as `config/breadcrumbs.rb` which is also loaded.
|
262
|
+
|
263
|
+
### Loading breadcrumbs from engines
|
264
|
+
|
265
|
+
Breadcrumbs are automatically loaded from any engines' `config/breadcrumbs.rb` and `config/breadcrumbs/**/*.rb`.
|
266
|
+
Breadcrumbs defined in your main app will override breadcrumbs from engines.
|
267
|
+
|
268
|
+
### Inferring breadcrumbs
|
269
|
+
|
270
|
+
Breadcrumbs can be automatically inferred if you pass an instance of an object that responds to `model_name` (like an ActiveRecord model instance).
|
271
|
+
|
272
|
+
For example:
|
273
|
+
|
274
|
+
```erb
|
275
|
+
<% breadcrumb @product %>
|
276
|
+
```
|
277
|
+
|
278
|
+
is short for
|
279
|
+
|
280
|
+
```erb
|
281
|
+
<% breadcrumb :product, @product %>
|
282
|
+
```
|
283
|
+
|
284
|
+
### Passing options to links
|
285
|
+
|
286
|
+
You can pass options to links to be used when you render breadcrumbs manually.
|
287
|
+
|
288
|
+
In *config/breadcrumbs.rb*:
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
crumb :something do
|
292
|
+
link "My Link", my_path, title: "My Title", other: "My Other Option"
|
293
|
+
end
|
294
|
+
```
|
295
|
+
|
296
|
+
Example methods you can then use in the view:
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
breadcrumbs do |links|
|
300
|
+
links.each do |link|
|
301
|
+
link.title? # => true
|
302
|
+
link.title # => "My Title"
|
303
|
+
link.other? # => true
|
304
|
+
link.other # => "My Other Option"
|
305
|
+
link.nonexisting_option? # => false
|
306
|
+
link.nonexisting_option # => nil
|
307
|
+
end
|
308
|
+
end
|
309
|
+
```
|
310
|
+
|
311
|
+
### Automatic reloading of breadcrumb configuration files
|
312
|
+
|
313
|
+
The breadcrumb configuration files are now reloaded in the Rails development environment if they change. In other environments, like production, the files are loaded once, when first needed.
|
314
|
+
|
315
|
+
|
316
|
+
## Documentation
|
317
|
+
|
318
|
+
The original gretel documentation is still valid and can be found at:
|
319
|
+
|
320
|
+
* [Full documentation](http://rubydoc.info/gems/gretel)
|
321
|
+
* [Changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md)
|
322
|
+
* [Tutorial on using Gretel](http://www.sitepoint.com/breadcrumbs-rails-gretel/) (Sitepoint)
|
323
|
+
|
324
|
+
## Versioning
|
325
|
+
|
326
|
+
Follows [semantic versioning](http://semver.org/).
|
327
|
+
|
328
|
+
## Contributing
|
329
|
+
|
330
|
+
You are very welcome to help improve Gretel if you have suggestions for features that other people can use.
|
331
|
+
|
332
|
+
To contribute:
|
333
|
+
|
334
|
+
1. Fork the project
|
335
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
336
|
+
3. Make your changes
|
337
|
+
4. Add/Fix tests
|
338
|
+
5. Prepare database for testing: `cd test/dummy; rake db:migrate; rake db:test:prepare; cd ../..`
|
339
|
+
6. Run `rake` to make sure all tests pass
|
340
|
+
7. Commit your changes (`git commit -am 'Add new feature'`)
|
341
|
+
8. Push to the branch (`git push origin my-new-feature`)
|
342
|
+
9. Create new pull request
|
343
|
+
|
344
|
+
Thanks.
|
345
|
+
|
346
|
+
## Contributors
|
347
|
+
|
348
|
+
Gretel was created by [@lassebunk](https://github.com/lassebunk).
|
349
|
+
|
350
|
+
This fork implements some updates/ fixes and is maintained by [@marciodat](https://github.com/marciodat).
|
351
|
+
|
352
|
+
|
353
|
+
## And then
|
354
|
+
|
355
|
+
<img src="http://i.imgur.com/u4Wbt4n.png" alt="After using Gretel, you'll be like this" />
|
356
|
+
|
357
|
+
Have fun!
|
358
|
+
|
359
|
+
Copyright (c) 2010-2016 [Lasse Bunk](http://lassebunk.dk) / [Marcio Silva](https://github.com/marciodat), released under the MIT license
|