gretel 4.0.2 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c9acb3e1bababfdec129ddf28041956e1d9cedab4168612403bc45e6f6be2ce
4
- data.tar.gz: 5d8a64b3af412616443a6f2fae688b3cff882cd4e39aebeb071c551a573fc2ca
3
+ metadata.gz: e903af36913aacbf98679ae5452d7269b9eba6abf5b2d75ff6a60277c2d64ad1
4
+ data.tar.gz: 56bcc5194372d75c357fcde07a542ffcd7440fa3ade06738124573d29d3cbf7b
5
5
  SHA512:
6
- metadata.gz: dfd59117fcad2e1459647cbf42bb52fb063fc49b49070ae5a8f7372b58f4f95317036597ca474f7c00fb17dcbd1809f9d503066495cd8d52d510342db6ad95a0
7
- data.tar.gz: 4466f946506b36678860eb17b922243fbcd4bc848f6c8fcd93ebb588dae02df4f9a78c934aa884d9a1dedf586fbc721128591696f887bafa9c88372859eb2877
6
+ metadata.gz: e20387223c47146510f79c77f3680ad3f76c8d703a455c7991fd68ec68d5011f79427fe39d56ccd8e0b8e942522632fc1cb448b12e02d6910214b8fe27eb65de
7
+ data.tar.gz: 9612998182b479f2e9f023e64ba8527897a8058a1c59268cb86583f3647b818be978e0c91b4f9740abbbd749c02ee03159fd4b8826377e03e6aef578375e9da3
@@ -0,0 +1,52 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ schedule:
7
+ - cron: '0 0 * * 0'
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ rails_version: [5.1.0, 5.2.0, 6.0.0, 6.1.0, master]
15
+ ruby_version: [3.0, 2.7, 2.6, 2.5]
16
+ exclude:
17
+ - ruby_version: 2.5
18
+ rails_version: master
19
+ - ruby_version: 2.6
20
+ rails_version: master
21
+ - ruby_version: 3.0
22
+ rails_version: 5.1.0
23
+ - ruby_version: 3.0
24
+ rails_version: 5.2.0
25
+
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+
29
+ - name: Setup Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby_version }}
33
+
34
+ - name: Run test
35
+ env:
36
+ RAILS_VERSION: ${{ matrix.rails_version }}
37
+ run: |
38
+ bundle update
39
+ cd spec/dummy; rake db:migrate db:test:prepare; cd ../..
40
+ bundle exec rake
41
+
42
+ - name: Upload coverage
43
+ uses: actions/upload-artifact@v2
44
+ if: always()
45
+ with:
46
+ name: coverage-ruby-${{ matrix.ruby_version }}-rails-${{ matrix.rails_version }}
47
+ path: coverage
48
+
49
+ - name: Show coverage
50
+ if: always()
51
+ run: |
52
+ cat coverage/coverage.txt
data/.gitignore CHANGED
@@ -26,3 +26,4 @@ spec/dummy/.sass-cache
26
26
  /coverage/assets
27
27
  /coverage/*.json
28
28
  /coverage/*.json.lock
29
+ /.ruby-version
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## Version 4.4.0
6
+ * Support Bootstrap 5. See the `:style` option in the readme for more info (via #30, thanks @tochi)
7
+ * Support Rails 7.0
8
+ * Link class is now customizable with `<%= breadcrumbs link_class: "some-class" %>`. (via #10)
9
+
10
+ ## Version 4.3.0
11
+ * Support generating `aria-current` attribute. It's disabled by default. See the readme for more info
12
+
13
+ ## Version 4.2.0
14
+ * Support generating JSON-LD structured data. See the readme for more info (via #26, thanks @dkniffin)
15
+
16
+ ## Version 4.1.0
17
+ * Depends only `railties` and `actionview`, not `rails` (via #7)
18
+ * Include `Gretel::ViewHelpers` module in `ActiveSupport.on_load(:action_view)` block
19
+ * Fix ruby 2.7 keywords warning (via #24, thanks @aki77)
20
+ * Fix multithreaded environment issue (via #13)
21
+ * `breadcrumbs.rb` is now evaluated in a instance of `Gretel::Crumbs::Builder`. If you want to call methods from `breadcrumbs.rb` other than `crumb`, `crumbs` and `crumb_defined?`, you need to call it via full reference like `Gretel::Crumbs.xxxx`
22
+
3
23
  ## Version 4.0.2
4
24
  * The return value of `breadcrumbs` is `html_safe` now (via #22)
5
25
  * For the slim template engine users: You don't need to use `==` instead of `=` for `breadcrumbs`
data/Gemfile CHANGED
@@ -3,4 +3,6 @@ source "http://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  rails_version = ENV['RAILS_VERSION'] || '>= 0'
6
- gem 'rails', rails_version
6
+ rails_version = "~> #{rails_version}" if rails_version =~ /^\d/
7
+
8
+ gem 'rails', rails_version == 'master' ? { github: 'rails/rails' } : rails_version
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/gretel.svg)](http://badge.fury.io/rb/gretel)
2
- [![Build Status](https://travis-ci.org/kzkn/gretel.svg?branch=master)](https://travis-ci.org/kzkn/gretel)
2
+ ![](https://github.com/kzkn/gretel/workflows/CI/badge.svg)
3
3
 
4
4
  <img src="http://i.imgur.com/CAKEaBM.png" alt="Handle breadcrumb trails... like a boss :)" />
5
5
 
@@ -96,8 +96,10 @@ Option | Description
96
96
  :current_class | CSS class for the current link or span. Can be set to `nil` for no class. | `"current"`
97
97
  :pretext_class | CSS class for the pretext, if given. Can be set to `nil` for no class. | `"pretext"`
98
98
  :posttext_class | CSS class for the posttext, if given. Can be set to `nil` for no class. | `"posttext"`
99
+ :link_class | CSS class for the link, if given. Can be set to `nil` for no class. | None
99
100
  :container_tag | Tag type that contains the breadcrumbs. | `:div`
100
101
  :fragment_tag | Tag type to contain each breadcrumb fragment/link. | None
102
+ :aria_current | Value of `aria-current` attribute. | None
101
103
 
102
104
  ### Styles
103
105
 
@@ -109,7 +111,8 @@ Style | Description
109
111
  `:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
110
112
  `:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
111
113
  `:bootstrap` | Renders the links for use in [Bootstrap v3](https://getbootstrap.com/docs/3.4/).
112
- `:bootstrap4` | Renders the links for use in [Bootstrap v4](https://getbootstrap.com/).
114
+ `:bootstrap4` | Renders the links for use in [Bootstrap v4](https://getbootstrap.com/docs/4.6/getting-started/introduction/).
115
+ `:bootstrap5` | Renders the links for use in [Bootstrap v5](https://getbootstrap.com/).
113
116
  `:foundation5` | Renders the links for use in [Foundation 5](https://get.foundation/).
114
117
 
115
118
  Or you can build the breadcrumbs manually for full customization; see below.
@@ -202,6 +205,11 @@ end
202
205
  crumb :user do |user|
203
206
  link user_name_for(user), user
204
207
  end
208
+
209
+ # I18n
210
+ crumb :home do
211
+ link t("breadcrumbs.home"), root_path
212
+ end
205
213
  ```
206
214
 
207
215
  ## Building the breadcrumbs manually
@@ -219,6 +227,23 @@ You can use the `breadcrumbs` method directly as an array. It will return an arr
219
227
  <% end %>
220
228
  ```
221
229
 
230
+ If you use this approach, you lose the built-in semantic breadcrumb functionality. One way to
231
+ add them back is to use JSON-LD structured data:
232
+
233
+ ```erb
234
+ <script type="application/ld+json">
235
+ <%= breadcrumbs.structured_data(url_base: "https://example.com") %>
236
+ </script>
237
+ ```
238
+
239
+ Or, you can infer `url_base` from `request`:
240
+
241
+ ```erb
242
+ <script type="application/ld+json">
243
+ <%= breadcrumbs.structured_data(url_base: "#{request.protocol}#{request.host_with_port}") %>
244
+ </script>
245
+ ```
246
+
222
247
  ## Getting the parent breadcrumb
223
248
 
224
249
  If you want to add a link to the parent breadcrumb, you can use the `parent_breadcrumb` view helper.
@@ -292,6 +317,25 @@ breadcrumbs do |links|
292
317
  end
293
318
  ```
294
319
 
320
+ ### ARIA support
321
+
322
+ You can improve the accessibility of your page with the markup that specified in [ARIA](https://www.w3.org/TR/wai-aria-practices/examples/breadcrumb/index.html). Gretel supports generating `aria-current` attribute:
323
+
324
+ ```erb
325
+ <% breadcrumb :issue, @issue %>
326
+ <%= breadcrumbs aria_current: "page" %>
327
+ ```
328
+
329
+ This will generate the following HTML (indented for readability):
330
+
331
+ ```html
332
+ <div class="breadcrumbs">
333
+ <a href="/">Home</a> &rsaquo;
334
+ <a href="/issues">All issues</a> &rsaquo;
335
+ <span class="current" aria-current="page">My Issue</span>
336
+ </div>
337
+ ```
338
+
295
339
  ## Documentation
296
340
 
297
341
  * [Full documentation](https://rubydoc.info/gems/gretel)
data/gretel.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.email = ["kzkn@users.noreply.github.com"]
8
8
  gem.description = %q{Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create breadcrumbs.}
9
9
  gem.summary = %q{Flexible Ruby on Rails breadcrumbs plugin.}
10
- gem.homepage = "http://github.com/kzkn/gretel"
10
+ gem.homepage = "https://github.com/kzkn/gretel"
11
11
  gem.license = "MIT"
12
12
 
13
13
  gem.files = Dir.chdir(File.expand_path('..', __FILE__)) do
@@ -15,7 +15,12 @@ Gem::Specification.new do |gem|
15
15
  end
16
16
  gem.require_paths = ["lib"]
17
17
 
18
- gem.add_dependency "rails", ">= 5.1"
18
+ gem.metadata = {
19
+ "changelog_uri" => "https://github.com/kzkn/gretel/blob/master/CHANGELOG.md",
20
+ }
21
+
22
+ gem.add_dependency "railties", [">= 5.1", "< 7.1"]
23
+ gem.add_dependency "actionview", [">= 5.1", "< 7.1"]
19
24
  gem.add_development_dependency "sqlite3"
20
25
  gem.add_development_dependency "rspec-rails"
21
26
  gem.add_development_dependency "simplecov"
data/lib/gretel/crumb.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'gretel/link'
2
+
1
3
  module Gretel
2
4
  class Crumb
3
5
  # Initializes a new crumb from the given +key+.
@@ -13,7 +15,7 @@ module Gretel
13
15
  raise ArgumentError, "Breadcrumb :#{key} not found." unless block
14
16
  @key = key
15
17
  @context = context
16
- instance_exec *args, &block
18
+ instance_exec(*args, &block)
17
19
  end
18
20
 
19
21
  # Sets link of the breadcrumb.
@@ -29,7 +31,7 @@ module Gretel
29
31
 
30
32
  # Transform objects to real paths.
31
33
  url = url_for(url) if url
32
-
34
+
33
35
  links << Gretel::Link.new(key, text, url, options)
34
36
  end
35
37
 
@@ -64,5 +66,6 @@ module Gretel
64
66
  def method_missing(method, *args, &block)
65
67
  context.send(method, *args, &block)
66
68
  end
69
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
67
70
  end
68
71
  end
data/lib/gretel/crumbs.rb CHANGED
@@ -3,11 +3,6 @@ module Gretel
3
3
  class << self
4
4
  include Resettable
5
5
 
6
- # Stores the supplied block for later use.
7
- def crumb(key, &block)
8
- crumbs[key] = block
9
- end
10
-
11
6
  # Returns a hash of all stored crumb blocks.
12
7
  def crumbs
13
8
  @crumbs ||= {}
@@ -20,14 +15,15 @@ module Gretel
20
15
 
21
16
  # Loads the breadcrumb configuration files.
22
17
  def load_breadcrumbs
23
- @crumbs = {}
18
+ builder = Builder.new
24
19
 
25
20
  loaded_file_mtimes.clear
26
21
  breadcrumb_files.each do |file|
27
- instance_eval open(file).read, file
22
+ builder.instance_eval open(file).read, file
28
23
  loaded_file_mtimes << File.mtime(file)
29
24
  end
30
25
 
26
+ @crumbs = builder.crumbs
31
27
  @loaded = true
32
28
  end
33
29
 
@@ -59,6 +55,29 @@ module Gretel
59
55
  def loaded_file_mtimes
60
56
  @loaded_file_mtimes ||= []
61
57
  end
58
+
59
+ class Builder
60
+ attr_reader :crumbs
61
+
62
+ def initialize
63
+ @crumbs = {}
64
+ end
65
+
66
+ # Stores the supplied block for later use.
67
+ def crumb(key, &block)
68
+ crumbs[key] = block
69
+ end
70
+
71
+ # Returns a hash of all stored crumb blocks.
72
+ def crumbs
73
+ @crumbs ||= {}
74
+ end
75
+
76
+ # Returns true if a crumb with the given key has been set.
77
+ def crumb_defined?(key)
78
+ crumbs.has_key?(key)
79
+ end
80
+ end
62
81
  end
63
82
  end
64
83
  end
@@ -0,0 +1,11 @@
1
+ require 'gretel/view_helpers'
2
+
3
+ module Gretel
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'gretel.view_helpers' do
6
+ ActiveSupport.on_load(:action_view) do
7
+ include ViewHelpers
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,6 @@
1
+ require 'gretel/crumbs'
2
+ require 'gretel/crumb'
3
+
1
4
  module Gretel
2
5
  class Renderer
3
6
  DEFAULT_OPTIONS = {
@@ -14,7 +17,9 @@ module Gretel
14
17
  current_class: "current",
15
18
  pretext_class: "pretext",
16
19
  posttext_class: "posttext",
17
- id: nil
20
+ link_class: nil,
21
+ id: nil,
22
+ aria_current: nil
18
23
  }
19
24
 
20
25
  DEFAULT_STYLES = {
@@ -23,6 +28,7 @@ module Gretel
23
28
  ul: { container_tag: :ul, fragment_tag: :li },
24
29
  bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" },
25
30
  bootstrap4: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" },
31
+ bootstrap5: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" },
26
32
  foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumbs", current_class: "current" }
27
33
  }
28
34
 
@@ -156,6 +162,27 @@ module Gretel
156
162
  concat links
157
163
  end
158
164
 
165
+ # Returns a hash matching the JSON-LD Structured Data schema
166
+ # https://developers.google.com/search/docs/data-types/breadcrumb#json-ld
167
+ def structured_data(url_base:)
168
+ url_base = url_base.chomp("/") # Remove trailing `/`, if present
169
+
170
+ items = @links.each_with_index.map do |link, i|
171
+ {
172
+ "@type": "ListItem",
173
+ "position": i + 1,
174
+ "name": link.text,
175
+ "item": "#{url_base}#{link.url}"
176
+ }
177
+ end
178
+
179
+ {
180
+ "@context": "https://schema.org",
181
+ "@type": "BreadcrumbList",
182
+ "itemListElement": items
183
+ }
184
+ end
185
+
159
186
  # Helper for returning all link keys to allow for simple testing.
160
187
  def keys
161
188
  map(&:key)
@@ -165,97 +192,144 @@ module Gretel
165
192
  def render
166
193
  return "" if links.empty?
167
194
 
195
+ renderer_class = options[:semantic] ? SemanticRenderer : NonSemanticRenderer
196
+ renderer = renderer_class.new(context, options)
168
197
  # Loop through all but the last (current) link and build HTML of the fragments
169
198
  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])
199
+ renderer.render_fragment(link, index + 1)
171
200
  end
172
201
 
173
202
  # The current link is handled a little differently, and is only linked if specified in the options
174
203
  current_link = links.last
175
204
  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)
205
+ fragments << renderer.render_current_fragment(current_link, position)
177
206
 
178
207
  # Build the final HTML
179
- html_fragments = []
208
+ html_fragments = [
209
+ renderer.render_pretext,
210
+ fragments.join(options[:separator]),
211
+ renderer.render_posttext
212
+ ]
213
+ html = html_fragments.compact.join(" ").html_safe
214
+ renderer.render_container(html)
215
+ end
180
216
 
181
- if options[:pretext].present?
182
- html_fragments << content_tag(:span, options[:pretext], class: options[:pretext_class])
183
- end
217
+ alias :to_s :render
184
218
 
185
- html_fragments << fragments.join(options[:separator])
219
+ # Avoid unnecessary html escaping by template engines.
220
+ def html_safe?
221
+ true
222
+ end
223
+ end
186
224
 
187
- if options[:posttext].present?
188
- html_fragments << content_tag(:span, options[:posttext], class: options[:posttext_class])
225
+ class Base
226
+ attr_reader :context, :options
227
+
228
+ def initialize(context, options)
229
+ @context = context
230
+ @options = options
231
+ end
232
+
233
+ def render_fragment(link, position)
234
+ render_fragment_tag(fragment_tag, link.text, link.url, position, **fragment_options)
235
+ end
236
+
237
+ def render_current_fragment(link, position)
238
+ url = options[:link_current] ? link.url : nil
239
+ opts = fragment_options.merge(class: options[:current_class], current_link: link.url, aria_current: options[:aria_current])
240
+ render_fragment_tag(fragment_tag, link.text, url, position, **opts)
241
+ end
242
+
243
+ def render_fragment_tag(fragment_tag, text, url, position, options = {})
244
+ end
245
+
246
+ def render_container(html)
247
+ end
248
+
249
+ def render_pretext
250
+ if options[:pretext].present?
251
+ content_tag(:span, options[:pretext], class: options[:pretext_class])
189
252
  end
253
+ end
190
254
 
191
- html = html_fragments.join(" ").html_safe
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])
255
+ def render_posttext
256
+ if options[:posttext].present?
257
+ content_tag(:span, options[:posttext], class: options[:posttext_class])
197
258
  end
198
259
  end
199
260
 
200
- alias :to_s :render
261
+ private
201
262
 
202
- # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
203
- def render_fragment(fragment_tag, text, url, semantic, position, options = {})
204
- if semantic
205
- render_semantic_fragment(fragment_tag, text, url, position, options)
206
- else
207
- render_nonsemantic_fragment(fragment_tag, text, url, options)
208
- end
263
+ def fragment_tag
264
+ options[:fragment_tag]
209
265
  end
210
266
 
211
- # Renders semantic fragment HTML.
212
- def render_semantic_fragment(fragment_tag, text, url, position, options = {})
213
- fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
214
- fragment_class = nil if fragment_class.blank?
215
- fragment_tag = fragment_tag || 'span'
216
- text = content_tag(:span, text, itemprop: "name")
267
+ def fragment_options
268
+ options.slice(:fragment_class, :link_class)
269
+ end
217
270
 
218
- if url.present?
219
- text = breadcrumb_link_to(text, url, itemprop: "item")
220
- elsif options[:current_link].present?
221
- current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}"
222
- text = text + tag(:meta, itemprop: "item", content: current_url)
223
- end
271
+ def join_classes(*classes)
272
+ clazz = classes.join(' ').strip
273
+ clazz.blank? ? nil : clazz
274
+ end
224
275
 
225
- text = text + tag(:meta, itemprop:"position", content: "#{position}")
226
- content_tag(fragment_tag.to_sym, text, class: fragment_class, itemprop: "itemListElement", itemscope: "", itemtype: "https://schema.org/ListItem")
276
+ # Proxy for +context.link_to+ that can be overridden by plugins.
277
+ def breadcrumb_link_to(name, url, options = {})
278
+ context.link_to(name, url, options)
227
279
  end
228
280
 
229
- # Renders regular, non-semantic fragment HTML.
230
- def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
231
- fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
232
- fragment_class = nil if fragment_class.blank?
281
+ # Proxy to view context.
282
+ def method_missing(method, *args, &block)
283
+ context.send(method, *args, &block)
284
+ end
285
+ end
286
+
287
+ class NonSemanticRenderer < Base
288
+ def render_fragment_tag(fragment_tag, text, url, position, options = {})
289
+ fragment_class = join_classes(options[:fragment_class], options[:class])
233
290
 
234
291
  if fragment_tag
235
- text = breadcrumb_link_to(text, url) if url.present?
236
- content_tag(fragment_tag, text, class: fragment_class)
292
+ if url.present?
293
+ text = breadcrumb_link_to(text, url, "aria-current": options[:aria_current])
294
+ content_tag(fragment_tag, text, class: fragment_class)
295
+ else
296
+ content_tag(fragment_tag, text, class: fragment_class, "aria-current": options[:aria_current])
297
+ end
237
298
  elsif url.present?
238
- breadcrumb_link_to(text, url, class: fragment_class)
299
+ breadcrumb_link_to(text, url, class: join_classes(fragment_class, options[:link_class]), "aria-current": options[:aria_current])
239
300
  elsif options[:class].present?
240
- content_tag(:span, text, class: fragment_class)
301
+ content_tag(:span, text, class: fragment_class, "aria-current": options[:aria_current])
241
302
  else
242
303
  text
243
304
  end
244
305
  end
245
306
 
246
- # Proxy for +context.link_to+ that can be overridden by plugins.
247
- def breadcrumb_link_to(name, url, options = {})
248
- context.link_to(name, url, options)
307
+ def render_container(html)
308
+ content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
249
309
  end
310
+ end
250
311
 
251
- # Proxy to view context.
252
- def method_missing(method, *args, &block)
253
- context.send(method, *args, &block)
312
+ class SemanticRenderer < Base
313
+ def render_fragment_tag(fragment_tag, text, url, position, options = {})
314
+ fragment_class = join_classes(options[:fragment_class], options[:class])
315
+ fragment_tag = fragment_tag || 'span'
316
+ text = content_tag(:span, text, itemprop: "name")
317
+
318
+ aria_current = options[:aria_current]
319
+ if url.present?
320
+ text = breadcrumb_link_to(text, url, itemprop: "item", "aria-current": aria_current, class: options[:link_class])
321
+ aria_current = nil
322
+ elsif options[:current_link].present?
323
+ current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}"
324
+ text = text + tag(:meta, itemprop: "item", content: current_url)
325
+ end
326
+
327
+ text = text + tag(:meta, itemprop:"position", content: "#{position}")
328
+ content_tag(fragment_tag.to_sym, text, class: fragment_class, itemprop: "itemListElement", itemscope: "", itemtype: "https://schema.org/ListItem", "aria-current": aria_current)
254
329
  end
255
330
 
256
- # Avoid unnecessary html escaping by template engines.
257
- def html_safe?
258
- true
331
+ def render_container(html)
332
+ content_tag(options[:container_tag], html, id: options[:id], class: options[:class], itemscope: "", itemtype: "https://schema.org/BreadcrumbList")
259
333
  end
260
334
  end
261
335
  end
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "4.0.2"
2
+ VERSION = "4.4.0"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'gretel/renderer'
2
+
1
3
  module Gretel
2
4
  module ViewHelpers
3
5
  # Sets the current breadcrumb to be rendered elsewhere. Put it somewhere in the view, preferably in the top, before you render any breadcrumbs HTML:
data/lib/gretel.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  require 'gretel/version'
2
2
  require 'gretel/resettable'
3
- require 'gretel/crumbs'
4
- require 'gretel/crumb'
5
- require 'gretel/link'
6
- require 'gretel/renderer'
7
- require 'gretel/view_helpers'
3
+ require 'gretel/railtie'
8
4
 
9
5
  module Gretel
10
6
  class << self
@@ -57,5 +53,3 @@ module Gretel
57
53
  end
58
54
  end
59
55
  end
60
-
61
- ActionView::Base.send :include, Gretel::ViewHelpers
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.2
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Bunk
@@ -9,15 +9,18 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-08-25 00:00:00.000000000 Z
12
+ date: 2021-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rails
15
+ name: railties
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '5.1'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '7.1'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,6 +28,29 @@ dependencies:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: '5.1'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.1'
34
+ - !ruby/object:Gem::Dependency
35
+ name: actionview
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.1'
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '7.1'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '5.1'
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '7.1'
28
54
  - !ruby/object:Gem::Dependency
29
55
  name: sqlite3
30
56
  requirement: !ruby/object:Gem::Requirement
@@ -89,8 +115,8 @@ executables: []
89
115
  extensions: []
90
116
  extra_rdoc_files: []
91
117
  files:
118
+ - ".github/workflows/ci.yml"
92
119
  - ".gitignore"
93
- - ".travis.yml"
94
120
  - CHANGELOG.md
95
121
  - Gemfile
96
122
  - LICENSE.txt
@@ -105,14 +131,16 @@ files:
105
131
  - lib/gretel/crumb.rb
106
132
  - lib/gretel/crumbs.rb
107
133
  - lib/gretel/link.rb
134
+ - lib/gretel/railtie.rb
108
135
  - lib/gretel/renderer.rb
109
136
  - lib/gretel/resettable.rb
110
137
  - lib/gretel/version.rb
111
138
  - lib/gretel/view_helpers.rb
112
- homepage: http://github.com/kzkn/gretel
139
+ homepage: https://github.com/kzkn/gretel
113
140
  licenses:
114
141
  - MIT
115
- metadata: {}
142
+ metadata:
143
+ changelog_uri: https://github.com/kzkn/gretel/blob/master/CHANGELOG.md
116
144
  post_install_message:
117
145
  rdoc_options: []
118
146
  require_paths:
@@ -128,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
156
  - !ruby/object:Gem::Version
129
157
  version: '0'
130
158
  requirements: []
131
- rubygems_version: 3.0.3
159
+ rubygems_version: 3.2.15
132
160
  signing_key:
133
161
  specification_version: 4
134
162
  summary: Flexible Ruby on Rails breadcrumbs plugin.
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
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'"
11
- before_script:
12
- - "cd spec/dummy; rake db:migrate; rake db:test:prepare; cd ../.."
13
- notifications:
14
- email: false