gretel 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +2 -2
- data/coverage/coverage.txt +1 -2
- data/lib/gretel/renderer.rb +26 -29
- data/lib/gretel/version.rb +1 -1
- data/test/helper_methods_test.rb +5 -8
- data/test/test_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
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
|
+
|
3
6
|
## Version 4.0.0
|
4
7
|
* Support Bootstrap 4. See the `:style` option in the readme for more info
|
5
8
|
* CSS class for fragment link or span is now customizable. See the `:fragment_class` option in the readme for more info
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
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
9
|
Have fun!
|
10
10
|
|
@@ -88,7 +88,7 @@ Option | Description
|
|
88
88
|
:display_single_fragment | Whether it should display the breadcrumb if it includes only one link. | False
|
89
89
|
:link_current | Whether the current crumb should be linked to. | False
|
90
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](
|
91
|
+
:semantic | Whether it should generate [semantic breadcrumbs](https://developers.google.com/search/docs/data-types/breadcrumb). | False
|
92
92
|
:id | ID for the breadcrumbs container. | None
|
93
93
|
:class | CSS class for the breadcrumbs container. Can be set to `nil` for no class. | `"breadcrumbs"`
|
94
94
|
:fragment_class | CSS class for the fragment link or span. Can be set to `nil` for no class. | None
|
data/coverage/coverage.txt
CHANGED
data/lib/gretel/renderer.rb
CHANGED
@@ -40,11 +40,6 @@ module Gretel
|
|
40
40
|
LinkCollection.new(context, links, options)
|
41
41
|
end
|
42
42
|
|
43
|
-
# Yields links with applied options.
|
44
|
-
def yield_links(options = {})
|
45
|
-
yield render(options)
|
46
|
-
end
|
47
|
-
|
48
43
|
# Returns the parent breadcrumb.
|
49
44
|
def parent_breadcrumb(options = {})
|
50
45
|
render(options)[-2]
|
@@ -171,13 +166,14 @@ module Gretel
|
|
171
166
|
return "" if links.empty?
|
172
167
|
|
173
168
|
# Loop through all but the last (current) link and build HTML of the fragments
|
174
|
-
fragments = links[0..-2].map do |link|
|
175
|
-
render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic], fragment_class: options[:fragment_class])
|
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])
|
176
171
|
end
|
177
172
|
|
178
173
|
# The current link is handled a little differently, and is only linked if specified in the options
|
179
174
|
current_link = links.last
|
180
|
-
|
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)
|
181
177
|
|
182
178
|
# Build the final HTML
|
183
179
|
html_fragments = []
|
@@ -193,41 +189,42 @@ module Gretel
|
|
193
189
|
end
|
194
190
|
|
195
191
|
html = html_fragments.join(" ").html_safe
|
196
|
-
|
197
|
-
|
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
|
198
200
|
|
199
201
|
alias :to_s :render
|
200
202
|
|
201
203
|
# Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
|
202
|
-
def render_fragment(fragment_tag, text, url, semantic, options = {})
|
204
|
+
def render_fragment(fragment_tag, text, url, semantic, position, options = {})
|
203
205
|
if semantic
|
204
|
-
render_semantic_fragment(fragment_tag, text, url, options)
|
206
|
+
render_semantic_fragment(fragment_tag, text, url, position, options)
|
205
207
|
else
|
206
208
|
render_nonsemantic_fragment(fragment_tag, text, url, options)
|
207
209
|
end
|
208
210
|
end
|
209
211
|
|
210
212
|
# Renders semantic fragment HTML.
|
211
|
-
def render_semantic_fragment(fragment_tag, text, url, options = {})
|
213
|
+
def render_semantic_fragment(fragment_tag, text, url, position, options = {})
|
212
214
|
fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
|
213
215
|
fragment_class = nil if fragment_class.blank?
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
text = text + tag(:meta, itemprop: "url", content: current_url)
|
223
|
-
end
|
224
|
-
|
225
|
-
content_tag(fragment_tag, text, class: fragment_class, itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
|
226
|
-
elsif url.present?
|
227
|
-
content_tag(:span, breadcrumb_link_to(content_tag(:span, text, itemprop: "title"), url, class: fragment_class, itemprop: "url"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
|
228
|
-
else
|
229
|
-
content_tag(:span, content_tag(:span, text, class: fragment_class, itemprop: "title"), itemscope: "", itemtype: "http://data-vocabulary.org/Breadcrumb")
|
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)
|
230
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")
|
231
228
|
end
|
232
229
|
|
233
230
|
# Renders regular, non-semantic fragment HTML.
|
data/lib/gretel/version.rb
CHANGED
data/test/helper_methods_test.rb
CHANGED
@@ -12,11 +12,6 @@ class HelperMethodsTest < ActionView::TestCase
|
|
12
12
|
Gretel.reset!
|
13
13
|
end
|
14
14
|
|
15
|
-
def itemscope_value
|
16
|
-
ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES.include?("itemscope") ?
|
17
|
-
"itemscope" : ""
|
18
|
-
end
|
19
|
-
|
20
15
|
# Breadcrumb generation
|
21
16
|
|
22
17
|
test "basic breadcrumb" do
|
@@ -63,7 +58,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
63
58
|
|
64
59
|
test "semantic breadcrumb" do
|
65
60
|
breadcrumb :with_root
|
66
|
-
assert_dom_equal %
|
61
|
+
assert_dom_equal %{<div class="breadcrumbs" itemscope="itemscope" itemtype="https://schema.org/BreadcrumbList"><span itemprop="itemListElement" itemscope="itemscope" itemtype="https://schema.org/ListItem"><a itemprop="item" href="/"><span itemprop="name">Home</span></a><meta itemprop="position" content="1" /></span> › <span class="current" itemprop="itemListElement" itemscope="itemscope" itemtype="https://schema.org/ListItem"><span itemprop="name">About</span><meta itemprop="item" content="http://test.host/about" /><meta itemprop="position" content="2" /></span></div>},
|
67
62
|
breadcrumbs(semantic: true).to_s
|
68
63
|
end
|
69
64
|
|
@@ -193,7 +188,9 @@ class HelperMethodsTest < ActionView::TestCase
|
|
193
188
|
breadcrumb :basic
|
194
189
|
|
195
190
|
out = parent_breadcrumb(autoroot: false) do
|
191
|
+
# :nocov:
|
196
192
|
"yielded"
|
193
|
+
# :nocov:
|
197
194
|
end
|
198
195
|
|
199
196
|
assert_nil out
|
@@ -373,7 +370,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
373
370
|
test "foundation5 style" do
|
374
371
|
breadcrumb :basic
|
375
372
|
assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
|
376
|
-
|
373
|
+
breadcrumbs(style: :foundation5).to_s
|
377
374
|
end
|
378
375
|
|
379
376
|
test "custom container and fragment tags" do
|
@@ -384,7 +381,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
384
381
|
|
385
382
|
test "custom semantic container and fragment tags" do
|
386
383
|
breadcrumb :basic
|
387
|
-
assert_dom_equal %
|
384
|
+
assert_dom_equal %{<c class="breadcrumbs" itemscope="itemscope" itemtype="https://schema.org/BreadcrumbList"><f itemprop="itemListElement" itemscope="itemscope" itemtype="https://schema.org/ListItem"><a itemprop="item" href="/"><span itemprop="name">Home</span></a><meta itemprop="position" content="1" /></f> › <f class="current" itemprop="itemListElement" itemscope="itemscope" itemtype="https://schema.org/ListItem"><span itemprop="name">About</span><meta itemprop="item" content="http://test.host/about" /><meta itemprop="position" content="2" /></f></c>},
|
388
385
|
breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true).to_s
|
389
386
|
end
|
390
387
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gretel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lasse Bunk
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-08-
|
12
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|