gretel 4.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6b2a5d8a3fd0fbb357c690e1d0189c54ab90ad1619c6ea5910b59f9cf718e89
4
- data.tar.gz: d5c633b783445c773bb031dbd2377ca8af9265ced45f9aaafeabebc853c754d6
3
+ metadata.gz: 5738580a72561b3be8158c37561fa8f2b85b6438b127bc110d70aaac60ec16a8
4
+ data.tar.gz: 11cf40314f61f69ae51b1bb95c8c078ec3d35c325a3af34a75906d343163fb28
5
5
  SHA512:
6
- metadata.gz: 5816c2df05e992e54868150d8f6689af7c2d2cb0af33b588c9ef552d54771efcf81b29a9b9f2bca223e784644288caf24987f8b38f546ea0b3a4be1944a73b1e
7
- data.tar.gz: 80497833712a92ac207f663ab544761ebf65b7a93d8d5fd7712e3bb8b3c8785b72ee85020ead35cd2e118a03f09e81a3d844c7dbbd629a3cf6cfb1b3d78669ba
6
+ metadata.gz: a4c29b164147c61f5f5585782a0026af9f532ac45be4ad7822a7816ebbea8949c7e7b0448fc683df7e35d6a82a38817c592fd559560b43ac043e788b5585974f
7
+ data.tar.gz: c13b14cfa25d40d80e0cb615c01d90bd4d97ff68e8c08fc86245aa18818e3962abd3a111da36d6ee13908b8acd6489a45deeb11ec65406260f3114e2ba96290b
@@ -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](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417) (those used in Google results).
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](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417). | False
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
@@ -2,5 +2,4 @@
2
2
  Incomplete test coverage
3
3
  --------------------------------------------------------------------------------
4
4
 
5
- /lib/gretel/renderer.rb: 99.12% (missed: 45)
6
- /test/helper_methods_test.rb: 99.24% (missed: 17,196)
5
+ 100% test coverage. You're all set, friend!
@@ -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
- fragments << render_fragment(options[:fragment_tag], current_link.text, (options[:link_current] ? current_link.url : nil), options[:semantic], fragment_class: options[:fragment_class], class: options[:current_class], current_link: current_link.url)
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
- content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
197
- end
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
- if fragment_tag
216
- text = content_tag(:span, text, itemprop: "title")
217
-
218
- if url.present?
219
- text = breadcrumb_link_to(text, url, itemprop: "url")
220
- elsif options[:current_link].present?
221
- current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}"
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.
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "4.0.0"
2
+ VERSION = "4.0.1"
3
3
  end
@@ -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 %Q{<div class="breadcrumbs"><span itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></span> &rsaquo; <span itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><span class="current" itemprop="title">About</span></span></div>},
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> &rsaquo; <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
- breadcrumbs(style: :foundation5).to_s
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 %Q{<c class="breadcrumbs"><f itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" href="/"><span itemprop="title">Home</span></a></f> &rsaquo; <f class="current" itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">About</span><meta itemprop="url" content="http://test.host/about" /></f></c>},
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> &rsaquo; <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
 
@@ -9,7 +9,7 @@ SimpleCov.start do
9
9
  ])
10
10
  end
11
11
 
12
- SimpleCov.minimum_coverage 99 # TODO: Get to 100!
12
+ SimpleCov.minimum_coverage 100
13
13
 
14
14
  # Configure Rails Environment
15
15
  ENV["RAILS_ENV"] = "test"
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.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 00:00:00.000000000 Z
12
+ date: 2020-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails