gretel 3.0.6 → 4.0.1
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 +5 -5
- data/.gitignore +7 -2
- data/.travis.yml +9 -3
- data/CHANGELOG.md +28 -1
- data/Gemfile +2 -13
- data/LICENSE.txt +2 -2
- data/README.md +34 -40
- data/Rakefile +1 -1
- data/coverage/coverage.txt +5 -0
- data/gretel.gemspec +9 -5
- data/lib/gretel.rb +4 -21
- data/lib/gretel/crumb.rb +9 -0
- data/lib/gretel/renderer.rb +44 -30
- data/lib/gretel/version.rb +2 -2
- data/lib/gretel/view_helpers.rb +0 -4
- data/test/dummy/app/assets/config/manifest.js +0 -0
- data/test/dummy/config/application.rb +3 -48
- data/test/dummy/config/breadcrumbs/test_crumbs.rb +5 -0
- data/test/dummy/config/environments/development.rb +0 -35
- data/test/dummy/config/environments/production.rb +0 -65
- data/test/dummy/config/environments/test.rb +0 -35
- data/test/dummy/config/routes.rb +4 -4
- data/test/dummy/db/migrate/20130122163007_create_projects.rb +1 -1
- data/test/dummy/db/migrate/20130122163051_create_issues.rb +1 -1
- data/test/dummy/db/schema.rb +16 -17
- data/test/gretel_test.rb +1 -2
- data/test/helper_methods_test.rb +112 -69
- data/test/test_helper.rb +15 -7
- metadata +70 -18
- data/lib/gretel/deprecated.rb +0 -1
- data/lib/gretel/deprecated/default_style_key.rb +0 -11
- data/lib/gretel/deprecated/layout.rb +0 -15
- data/lib/gretel/deprecated/show_root_alone.rb +0 -12
- data/lib/gretel/deprecated/yield_links.rb +0 -20
- data/test/deprecated_test.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5738580a72561b3be8158c37561fa8f2b85b6438b127bc110d70aaac60ec16a8
|
4
|
+
data.tar.gz: 11cf40314f61f69ae51b1bb95c8c078ec3d35c325a3af34a75906d343163fb28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4c29b164147c61f5f5585782a0026af9f532ac45be4ad7822a7816ebbea8949c7e7b0448fc683df7e35d6a82a38817c592fd559560b43ac043e788b5585974f
|
7
|
+
data.tar.gz: c13b14cfa25d40d80e0cb615c01d90bd4d97ff68e8c08fc86245aa18818e3962abd3a111da36d6ee13908b8acd6489a45deeb11ec65406260f3114e2ba96290b
|
data/.gitignore
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
.config
|
5
5
|
.yardoc
|
6
6
|
Gemfile.lock
|
7
|
+
gemfiles/*.lock
|
7
8
|
InstalledFiles
|
8
9
|
_yardoc
|
9
|
-
coverage
|
10
10
|
doc/
|
11
11
|
lib/bundler/man
|
12
12
|
pkg
|
@@ -20,4 +20,9 @@ test/dummy/db/*.sqlite3
|
|
20
20
|
test/dummy/log/*.log
|
21
21
|
test/dummy/tmp/
|
22
22
|
test/dummy/.sass-cache
|
23
|
-
.DS_Store
|
23
|
+
.DS_Store
|
24
|
+
|
25
|
+
/coverage/index.html
|
26
|
+
/coverage/assets
|
27
|
+
/coverage/*.json
|
28
|
+
/coverage/*.json.lock
|
data/.travis.yml
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
2
3
|
rvm:
|
3
|
-
- 2.
|
4
|
-
-
|
4
|
+
- 2.7
|
5
|
+
- 2.6
|
6
|
+
- 2.5
|
7
|
+
env:
|
8
|
+
- RAILS="~> '5.1.0'"
|
9
|
+
- RAILS="~> '5.2.0'"
|
10
|
+
- RAILS="~> '6.0.0'"
|
5
11
|
before_script:
|
6
12
|
- "cd test/dummy; rake db:migrate; rake db:test:prepare; cd ../.."
|
7
13
|
notifications:
|
8
|
-
email: false
|
14
|
+
email: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Version 4.0.1
|
4
|
+
* Replaces data-vocabulary markup as google doesn't support it and now uses schema.org markup (via #17)
|
5
|
+
|
6
|
+
## Version 4.0.0
|
7
|
+
* Support Bootstrap 4. See the `:style` option in the readme for more info
|
8
|
+
* CSS class for fragment link or span is now customizable. See the `:fragment_class` option in the readme for more info
|
9
|
+
* Drop support Ruby < 2.5
|
10
|
+
* Drop support Rails < 5.1
|
11
|
+
* Deprecated codes have been removed:
|
12
|
+
* `breadcrumbs` is no longer accept block, use `tap` instead
|
13
|
+
* `breadcrumbs` is no longer accept `style: :default`, use `style: :inline` instead
|
14
|
+
* `breadcrumbs` is no longer accept `:show_root_alone` option, use `:display_single_fragment` option instead
|
15
|
+
|
16
|
+
## Version 3.0.9
|
17
|
+
* Adds breadcrumbs option `link_current_to_request_path` to link the current breadcrumb to the request path(#28 via #29)
|
18
|
+
* Fixes semantic breadcrumbs when the last item has no link (via #55)
|
19
|
+
* Downgrades Rails dependency to 3.1 (via #56)
|
20
|
+
* Fixes jRuby issue with `Rails::Application` constant (via #50)
|
21
|
+
* Fixes deprecation warnings for `alias_method_chain` (via #66)
|
22
|
+
* Updated coprights (via #63)
|
23
|
+
|
24
|
+
## Version 3.0.8
|
25
|
+
* Parent breadcrumbs can now also be inferred from models responding to `model_name`.
|
26
|
+
|
27
|
+
## Version 3.0.7
|
28
|
+
* Pretext and posttext classes are now customizable with `<%= breadcrumbs pretext_class: "some-class" %>` and `<%= breadcrumbs posttext_class: "some-other-class" %>`.
|
29
|
+
|
3
30
|
## Version 3.0.6
|
4
31
|
* Pretext and posttext are now enclosed in spans with `<span class="pretext">` and `<span class="posttext">`.
|
5
32
|
* Semantic breadcrumbs are now rendered in spans instead of divs to enable easier styling.
|
@@ -39,4 +66,4 @@
|
|
39
66
|
* No longer supports procs for link text or URL as this is unnecessary when you can pass arguments to the block anyway.
|
40
67
|
* It now accepts multiple arguments for `crumb` and `parent` (see the readme).
|
41
68
|
* Breadcrumbs are now rendered with `<%= breadcrumbs %>`, although you can still use the old `<%= breadcrumb %>` (without *s*).
|
42
|
-
* You can now access view helpers from inside `Gretel::Crumbs.layout do .. end`.
|
69
|
+
* You can now access view helpers from inside `Gretel::Crumbs.layout do .. end`.
|
data/Gemfile
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
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
3
|
gemspec
|
7
4
|
|
8
|
-
|
9
|
-
gem
|
10
|
-
|
11
|
-
# Declare any dependencies that are still in development here instead of in
|
12
|
-
# your gemspec. These might include edge Rails or gems from your path or
|
13
|
-
# Git. Remember to move these dependencies to your gemspec before releasing
|
14
|
-
# your gem to rubygems.org.
|
15
|
-
|
16
|
-
# To use debugger
|
17
|
-
# gem 'debugger'
|
5
|
+
rails_version = ENV['RAILS_VERSION'] || '>= 0'
|
6
|
+
gem 'rails', rails_version
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010-
|
1
|
+
Copyright (c) 2010-2020 Lasse Bunk
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
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.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,29 +1,12 @@
|
|
1
|
-
<a href="http://travis-ci.org/
|
1
|
+
<a href="http://travis-ci.org/kzkn/gretel"><img src="https://secure.travis-ci.org/kzkn/gretel.png" alt="Build Status" /></a>
|
2
2
|
|
3
3
|
<img src="http://i.imgur.com/CAKEaBM.png" alt="Handle breadcrumb trails... like a boss :)" />
|
4
4
|
|
5
5
|
([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.
|
6
6
|
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.
|
7
|
-
Gretel also supports [semantic breadcrumbs](
|
7
|
+
Gretel also supports [semantic breadcrumbs](https://developers.google.com/search/docs/data-types/breadcrumb) (those used in Google results).
|
8
8
|
|
9
|
-
Have fun!
|
10
|
-
|
11
|
-
## New in version 3.0
|
12
|
-
|
13
|
-
* Breadcrumbs can now be rendered in different styles like ul- and ol lists, and for use with the [Twitter Bootstrap](http://getbootstrap.com/) framework. See the `:style` option below for more info.
|
14
|
-
* Defining breadcrumbs using `Gretel::Crumbs.layout do ... end` in an initializer has been removed. See below for details on how to upgrade.
|
15
|
-
* The `:show_root_alone` option is now called `:display_single_fragment` and can be used to hide the breadcrumbs when there is only one link, also if it is not the root breadcrumb.
|
16
|
-
The old `:show_root_alone` option is still supported until Gretel version 4.0 and will show a deprecation warning when it's used.
|
17
|
-
* Links yielded from `<%= breadcrumbs do |links| %>` now have a `current?` helper that returns true if the link is the last in the trail.
|
18
|
-
* 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.
|
19
|
-
You can supply options like `:autoroot` etc.
|
20
|
-
If you supply a block, it will yield the parent breadcrumb if it is present.
|
21
|
-
* Breadcrumbs can now be inferred if you pass in an instance of an object that responds to `model_name` (like an ActiveRecord model instance). E.g. `breadcrumb @product` is short for `breadcrumb :product, @product`.
|
22
|
-
|
23
|
-
|
24
|
-
I hope you find these changes as useful as I did – if you have more suggestions, please create an [Issue](https://github.com/lassebunk/gretel/issues) or [Pull Request](https://github.com/lassebunk/gretel/pulls).
|
25
|
-
|
26
|
-
See below for more info or the [changelog](https://github.com/lassebunk/gretel/blob/master/CHANGELOG.md) for less significant changes.
|
9
|
+
Have fun!
|
27
10
|
|
28
11
|
## Installation
|
29
12
|
|
@@ -84,7 +67,7 @@ This will generate the following HTML (indented for readability):
|
|
84
67
|
|
85
68
|
```html
|
86
69
|
<div class="breadcrumbs">
|
87
|
-
You are here
|
70
|
+
<span class="pretext">You are here:</span>
|
88
71
|
<a href="/">Home</a> ›
|
89
72
|
<a href="/issues">All issues</a> ›
|
90
73
|
<span class="current">My Issue</span>
|
@@ -104,10 +87,14 @@ Option | Description
|
|
104
87
|
:autoroot | Whether it should automatically link to the `:root` crumb if no parent is given. | True
|
105
88
|
:display_single_fragment | Whether it should display the breadcrumb if it includes only one link. | False
|
106
89
|
:link_current | Whether the current crumb should be linked to. | False
|
107
|
-
:
|
90
|
+
: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
|
91
|
+
:semantic | Whether it should generate [semantic breadcrumbs](https://developers.google.com/search/docs/data-types/breadcrumb). | False
|
108
92
|
:id | ID for the breadcrumbs container. | None
|
109
|
-
:class | CSS class for the breadcrumbs container.
|
110
|
-
:
|
93
|
+
:class | CSS class for the breadcrumbs container. Can be set to `nil` for no class. | `"breadcrumbs"`
|
94
|
+
:fragment_class | CSS class for the fragment link or span. Can be set to `nil` for no class. | None
|
95
|
+
:current_class | CSS class for the current link or span. Can be set to `nil` for no class. | `"current"`
|
96
|
+
:pretext_class | CSS class for the pretext, if given. Can be set to `nil` for no class. | `"pretext"`
|
97
|
+
:posttext_class | CSS class for the posttext, if given. Can be set to `nil` for no class. | `"posttext"`
|
111
98
|
:container_tag | Tag type that contains the breadcrumbs. | `:div`
|
112
99
|
:fragment_tag | Tag type to contain each breadcrumb fragment/link. | None
|
113
100
|
|
@@ -121,11 +108,12 @@ Style | Description
|
|
121
108
|
`:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
|
122
109
|
`:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
|
123
110
|
`:bootstrap` | Renders the links for use in [Twitter Bootstrap](http://getbootstrap.com/).
|
111
|
+
`:bootstrap4` | Renders the links for use in [Bootstrap v4](https://getbootstrap.com/).
|
124
112
|
`:foundation5` | Renders the links for use in [Foundation 5](http://foundation.zurb.com/).
|
125
113
|
|
126
114
|
Or you can build the breadcrumbs manually for full customization; see below.
|
127
115
|
|
128
|
-
If you add other widely used styles, please submit a [Pull Request](https://github.com/
|
116
|
+
If you add other widely used styles, please submit a [Pull Request](https://github.com/kzkn/gretel/pulls) so others can use them too.
|
129
117
|
|
130
118
|
## More examples
|
131
119
|
|
@@ -145,10 +133,10 @@ end
|
|
145
133
|
# Parent crumbs
|
146
134
|
crumb :project_issues do |project|
|
147
135
|
link "Issues", project_issues_path(project)
|
148
|
-
parent
|
136
|
+
parent project # inferred to :project
|
149
137
|
end
|
150
138
|
|
151
|
-
# Child
|
139
|
+
# Child
|
152
140
|
crumb :issue do |issue|
|
153
141
|
link issue.name, issue_path(issue)
|
154
142
|
parent :project_issues, issue.project
|
@@ -158,7 +146,7 @@ end
|
|
158
146
|
crumb :category do |category|
|
159
147
|
link category.name, category
|
160
148
|
if category.parent
|
161
|
-
parent
|
149
|
+
parent category.parent # inferred to :category
|
162
150
|
else
|
163
151
|
parent :categories
|
164
152
|
end
|
@@ -167,7 +155,7 @@ end
|
|
167
155
|
# Product crumb with recursive parent categories (as defined above)
|
168
156
|
crumb :product do |product|
|
169
157
|
link product.name, product
|
170
|
-
parent
|
158
|
+
parent product.category # inferred to :category
|
171
159
|
end
|
172
160
|
|
173
161
|
# Crumb with multiple links
|
@@ -188,7 +176,7 @@ crumb :product do |product|
|
|
188
176
|
if keyword = params[:q].presence
|
189
177
|
parent :search, keyword
|
190
178
|
else # default
|
191
|
-
parent
|
179
|
+
parent product.category # inferred to :category
|
192
180
|
end
|
193
181
|
end
|
194
182
|
|
@@ -217,10 +205,10 @@ end
|
|
217
205
|
|
218
206
|
## Building the breadcrumbs manually
|
219
207
|
|
220
|
-
|
208
|
+
You can use the `breadcrumbs` method directly as an array. It will return an array with the breadcrumb links so you can build the breadcrumbs HTML manually:
|
221
209
|
|
222
210
|
```erb
|
223
|
-
<% breadcrumbs do |links| %>
|
211
|
+
<% breadcrumbs.tap do |links| %>
|
224
212
|
<% if links.any? %>
|
225
213
|
You are here:
|
226
214
|
<% links.each do |link| %>
|
@@ -347,7 +335,8 @@ in `config/breadcrumbs.rb`.
|
|
347
335
|
## Documentation
|
348
336
|
|
349
337
|
* [Full documentation](http://rubydoc.info/gems/gretel)
|
350
|
-
* [Changelog](https://github.com/
|
338
|
+
* [Changelog](https://github.com/kzkn/gretel/blob/master/CHANGELOG.md)
|
339
|
+
* [Tutorial on using Gretel](http://www.sitepoint.com/breadcrumbs-rails-gretel/) (Sitepoint)
|
351
340
|
|
352
341
|
## Versioning
|
353
342
|
|
@@ -362,17 +351,22 @@ To contribute:
|
|
362
351
|
1. Fork the project
|
363
352
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
364
353
|
3. Make your changes
|
365
|
-
4. Add tests
|
366
|
-
5.
|
367
|
-
6.
|
368
|
-
7.
|
369
|
-
8.
|
354
|
+
4. Add/Fix tests
|
355
|
+
5. Prepare database for testing: `cd test/dummy; rake db:migrate; rake db:test:prepare; cd ../..`
|
356
|
+
6. Run `rake` to make sure all tests pass
|
357
|
+
7. Be sure to check in the changes to `coverage/coverage.txt`
|
358
|
+
8. Commit your changes (`git commit -am 'Add new feature'`)
|
359
|
+
9. Push to the branch (`git push origin my-new-feature`)
|
360
|
+
10. Create new pull request
|
370
361
|
|
371
362
|
Thanks.
|
372
363
|
|
373
364
|
## Contributors
|
374
365
|
|
375
|
-
|
366
|
+
Gretel was created by [@lassebunk](https://github.com/lassebunk) and was maintained by [@WilHall](https://github.com/WilHall).
|
367
|
+
And it is maintained by [@kzkn](https://github.com/kzkn).
|
368
|
+
|
369
|
+
[See the list of contributors](https://github.com/kzkn/gretel/graphs/contributors)
|
376
370
|
|
377
371
|
## And then
|
378
372
|
|
@@ -380,4 +374,4 @@ Thanks.
|
|
380
374
|
|
381
375
|
Have fun!
|
382
376
|
|
383
|
-
Copyright (c) 2010-
|
377
|
+
Copyright (c) 2010-2020 [Lasse Bunk](http://lassebunk.dk), released under the MIT license
|
data/Rakefile
CHANGED
data/gretel.gemspec
CHANGED
@@ -6,17 +6,21 @@ require 'gretel/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "gretel"
|
8
8
|
gem.version = Gretel::VERSION
|
9
|
-
gem.authors = ["Lasse Bunk"]
|
10
|
-
gem.email = ["
|
9
|
+
gem.authors = ["Lasse Bunk", "Kazuki Nishikawa"]
|
10
|
+
gem.email = ["kzkn@users.noreply.github.com"]
|
11
11
|
gem.description = %q{Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create breadcrumbs.}
|
12
12
|
gem.summary = %q{Flexible Ruby on Rails breadcrumbs plugin.}
|
13
|
-
gem.homepage = "http://github.com/
|
13
|
+
gem.homepage = "http://github.com/kzkn/gretel"
|
14
14
|
gem.license = "MIT"
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
17
|
gem.test_files = gem.files.grep(%r{^test/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency "rails", ">=
|
20
|
+
gem.add_dependency "rails", ">= 5.1"
|
21
21
|
gem.add_development_dependency "sqlite3"
|
22
|
-
|
22
|
+
gem.add_development_dependency "jquery-rails"
|
23
|
+
gem.add_development_dependency "test-unit", "~> 3.0"
|
24
|
+
gem.add_development_dependency "simplecov", "~> 0.18.0"
|
25
|
+
gem.add_development_dependency "simplecov-erb", "~> 0.1"
|
26
|
+
end
|
data/lib/gretel.rb
CHANGED
@@ -5,7 +5,6 @@ require 'gretel/crumb'
|
|
5
5
|
require 'gretel/link'
|
6
6
|
require 'gretel/renderer'
|
7
7
|
require 'gretel/view_helpers'
|
8
|
-
require 'gretel/deprecated'
|
9
8
|
|
10
9
|
module Gretel
|
11
10
|
class << self
|
@@ -16,7 +15,9 @@ module Gretel
|
|
16
15
|
# breadcrumbs set in engines.
|
17
16
|
def breadcrumb_paths
|
18
17
|
@breadcrumb_paths ||= begin
|
19
|
-
|
18
|
+
engines = Rails::Engine.subclasses.map(&:instance)
|
19
|
+
|
20
|
+
engine_roots = engines.map { |e| e.config.root }
|
20
21
|
|
21
22
|
[*engine_roots, Rails.root].map do |root|
|
22
23
|
[root.join("config", "breadcrumbs.rb"),
|
@@ -31,24 +32,6 @@ module Gretel
|
|
31
32
|
@breadcrumb_paths = paths
|
32
33
|
end
|
33
34
|
|
34
|
-
# Whether to suppress deprecation warnings.
|
35
|
-
def suppress_deprecation_warnings?
|
36
|
-
!!@suppress_deprecation_warnings
|
37
|
-
end
|
38
|
-
|
39
|
-
# Sets whether to suppress deprecation warnings.
|
40
|
-
def suppress_deprecation_warnings=(value)
|
41
|
-
@suppress_deprecation_warnings = value
|
42
|
-
end
|
43
|
-
|
44
|
-
# Shows a deprecation warning.
|
45
|
-
def show_deprecation_warning(message)
|
46
|
-
return if suppress_deprecation_warnings?
|
47
|
-
message = "[Gretel] #{message}"
|
48
|
-
puts message
|
49
|
-
Rails.logger.warn message
|
50
|
-
end
|
51
|
-
|
52
35
|
# Array of Rails environment names with automatic configuration reload. Default is +["development"]+.
|
53
36
|
def reload_environments
|
54
37
|
@reload_environments ||= ["development"]
|
@@ -75,4 +58,4 @@ module Gretel
|
|
75
58
|
end
|
76
59
|
end
|
77
60
|
|
78
|
-
ActionView::Base.send :include, Gretel::ViewHelpers
|
61
|
+
ActionView::Base.send :include, Gretel::ViewHelpers
|
data/lib/gretel/crumb.rb
CHANGED
@@ -3,6 +3,12 @@ module Gretel
|
|
3
3
|
# Initializes a new crumb from the given +key+.
|
4
4
|
# It finds the breadcrumb created in +Gretel::Crumbs.layout+ and renders the block using the arguments supplied in +args+.
|
5
5
|
def initialize(context, key, *args)
|
6
|
+
if key.class.respond_to?(:model_name)
|
7
|
+
# Enables calling `breadcrumb @product` instead of `breadcrumb :product, @product`
|
8
|
+
args.unshift key
|
9
|
+
key = key.class.model_name.to_s.underscore.to_sym
|
10
|
+
end
|
11
|
+
|
6
12
|
block = Gretel::Crumbs.crumbs[key]
|
7
13
|
raise ArgumentError, "Breadcrumb :#{key} not found." unless block
|
8
14
|
@key = key
|
@@ -38,6 +44,9 @@ module Gretel
|
|
38
44
|
#
|
39
45
|
# Example:
|
40
46
|
# parent :category, category
|
47
|
+
#
|
48
|
+
# Or short, which will infer the key from the model's `model_name`:
|
49
|
+
# parent category
|
41
50
|
def parent(*args)
|
42
51
|
return @parent if args.empty?
|
43
52
|
key = args.shift
|
data/lib/gretel/renderer.rb
CHANGED
@@ -8,9 +8,12 @@ module Gretel
|
|
8
8
|
autoroot: true,
|
9
9
|
display_single_fragment: false,
|
10
10
|
link_current: false,
|
11
|
+
link_current_to_request_path: true,
|
11
12
|
semantic: false,
|
12
13
|
class: "breadcrumbs",
|
13
14
|
current_class: "current",
|
15
|
+
pretext_class: "pretext",
|
16
|
+
posttext_class: "posttext",
|
14
17
|
id: nil
|
15
18
|
}
|
16
19
|
|
@@ -19,6 +22,7 @@ module Gretel
|
|
19
22
|
ol: { container_tag: :ol, fragment_tag: :li },
|
20
23
|
ul: { container_tag: :ul, fragment_tag: :li },
|
21
24
|
bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" },
|
25
|
+
bootstrap4: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" },
|
22
26
|
foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumbs", current_class: "current" }
|
23
27
|
}
|
24
28
|
|
@@ -36,11 +40,6 @@ module Gretel
|
|
36
40
|
LinkCollection.new(context, links, options)
|
37
41
|
end
|
38
42
|
|
39
|
-
# Yields links with applied options.
|
40
|
-
def yield_links(options = {})
|
41
|
-
yield render(options)
|
42
|
-
end
|
43
|
-
|
44
43
|
# Returns the parent breadcrumb.
|
45
44
|
def parent_breadcrumb(options = {})
|
46
45
|
render(options)[-2]
|
@@ -82,7 +81,7 @@ module Gretel
|
|
82
81
|
end
|
83
82
|
|
84
83
|
# Set current link to actual path
|
85
|
-
if out.any? && request
|
84
|
+
if options[:link_current_to_request_path] && out.any? && request
|
86
85
|
out.last.url = request.fullpath
|
87
86
|
end
|
88
87
|
|
@@ -109,7 +108,7 @@ module Gretel
|
|
109
108
|
|
110
109
|
# Links of first crumb
|
111
110
|
links = crumb.links.dup
|
112
|
-
|
111
|
+
|
113
112
|
# Get parent links
|
114
113
|
links.unshift *parent_links_for(crumb)
|
115
114
|
|
@@ -135,9 +134,9 @@ module Gretel
|
|
135
134
|
|
136
135
|
class << self
|
137
136
|
include Resettable
|
138
|
-
|
137
|
+
|
139
138
|
# Registers a style for later use.
|
140
|
-
#
|
139
|
+
#
|
141
140
|
# Gretel::Renderer.register_style :ul, { container_tag: :ul, fragment_tag: :li }
|
142
141
|
def register_style(style_key, options)
|
143
142
|
styles[style_key] = options
|
@@ -167,64 +166,79 @@ module Gretel
|
|
167
166
|
return "" if links.empty?
|
168
167
|
|
169
168
|
# Loop through all but the last (current) link and build HTML of the fragments
|
170
|
-
fragments = links[0..-2].map do |link|
|
171
|
-
render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic])
|
169
|
+
fragments = links[0..-2].map.with_index do |link, index|
|
170
|
+
render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic], index + 1, fragment_class: options[:fragment_class])
|
172
171
|
end
|
173
172
|
|
174
173
|
# The current link is handled a little differently, and is only linked if specified in the options
|
175
174
|
current_link = links.last
|
176
|
-
|
175
|
+
position = links.size
|
176
|
+
fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], position, fragment_class: options[:fragment_class], class: options[:current_class], current_link: current_link.url)
|
177
177
|
|
178
178
|
# Build the final HTML
|
179
179
|
html_fragments = []
|
180
180
|
|
181
181
|
if options[:pretext].present?
|
182
|
-
html_fragments << content_tag(:span, options[:pretext], class:
|
182
|
+
html_fragments << content_tag(:span, options[:pretext], class: options[:pretext_class])
|
183
183
|
end
|
184
184
|
|
185
185
|
html_fragments << fragments.join(options[:separator])
|
186
186
|
|
187
187
|
if options[:posttext].present?
|
188
|
-
html_fragments << content_tag(:span, options[:posttext], class:
|
188
|
+
html_fragments << content_tag(:span, options[:posttext], class: options[:posttext_class])
|
189
189
|
end
|
190
190
|
|
191
191
|
html = html_fragments.join(" ").html_safe
|
192
|
-
|
193
|
-
|
192
|
+
|
193
|
+
if options[:semantic]
|
194
|
+
content_tag(options[:container_tag], html, id: options[:id], class: options[:class], itemscope: "", itemtype: "https://schema.org/BreadcrumbList")
|
195
|
+
else
|
196
|
+
content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
194
200
|
|
195
201
|
alias :to_s :render
|
196
202
|
|
197
203
|
# Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
|
198
|
-
def render_fragment(fragment_tag, text, url, semantic, options = {})
|
204
|
+
def render_fragment(fragment_tag, text, url, semantic, position, options = {})
|
199
205
|
if semantic
|
200
|
-
render_semantic_fragment(fragment_tag, text, url, options)
|
206
|
+
render_semantic_fragment(fragment_tag, text, url, position, options)
|
201
207
|
else
|
202
208
|
render_nonsemantic_fragment(fragment_tag, text, url, options)
|
203
209
|
end
|
204
210
|
end
|
205
211
|
|
206
212
|
# Renders semantic fragment HTML.
|
207
|
-
def render_semantic_fragment(fragment_tag, text, url, options = {})
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
213
|
+
def render_semantic_fragment(fragment_tag, text, url, position, options = {})
|
214
|
+
fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
|
215
|
+
fragment_class = nil if fragment_class.blank?
|
216
|
+
fragment_tag = fragment_tag || 'span'
|
217
|
+
text = content_tag(:span, text, itemprop: "name")
|
218
|
+
|
219
|
+
if url.present?
|
220
|
+
text = breadcrumb_link_to(text, url, itemprop: "item")
|
221
|
+
elsif options[:current_link].present?
|
222
|
+
current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}"
|
223
|
+
text = text + tag(:meta, itemprop: "item", content: current_url)
|
216
224
|
end
|
225
|
+
|
226
|
+
text = text + tag(:meta, itemprop:"position", content: "#{position}")
|
227
|
+
content_tag(fragment_tag.to_sym, text, class: fragment_class, itemprop: "itemListElement", itemscope: "", itemtype: "https://schema.org/ListItem")
|
217
228
|
end
|
218
229
|
|
219
230
|
# Renders regular, non-semantic fragment HTML.
|
220
231
|
def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
|
232
|
+
fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
|
233
|
+
fragment_class = nil if fragment_class.blank?
|
234
|
+
|
221
235
|
if fragment_tag
|
222
236
|
text = breadcrumb_link_to(text, url) if url.present?
|
223
|
-
content_tag(fragment_tag, text, class:
|
237
|
+
content_tag(fragment_tag, text, class: fragment_class)
|
224
238
|
elsif url.present?
|
225
|
-
breadcrumb_link_to(text, url, class:
|
239
|
+
breadcrumb_link_to(text, url, class: fragment_class)
|
226
240
|
elsif options[:class].present?
|
227
|
-
content_tag(:span, text, class:
|
241
|
+
content_tag(:span, text, class: fragment_class)
|
228
242
|
else
|
229
243
|
text
|
230
244
|
end
|