gretel 4.3.0 → 4.5.0

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: c1fe62ed99bb8f03e6a00a782f55adc5f6b6fcf84a444d77aa1c771b41d148a9
4
- data.tar.gz: 1660db0b73ddbf77dac315c8d1466fb66958b9ebab59629c96f999536f17b824
3
+ metadata.gz: e11382c45e0cd902386dec63fccbfedbbfd7658bc03e2d22a70c8bc88b317431
4
+ data.tar.gz: fd662355346c8e056a71b8b4abc8d83b325b452ae2436339a15307a3355dffd9
5
5
  SHA512:
6
- metadata.gz: 4bddd221544196836669a1309c97d536ad2d2b11ef10c74a265e034d0a1463ba5b4955651235ad395b9c37249a9d5eff2ef9ec9b659ab896a8fbca959b199924
7
- data.tar.gz: ebd6e183dc3597f83c9ac8b22399d0ad52e345da6586b9de59c2386c8b5116d40199fcf494c44cd8d094a25ed543d5ee21397506d1979ebf851a973e23da3ced
6
+ metadata.gz: 141851ca991537082c0efaa5a7ca487d5a76ee46515f884cf4ced76cdf16df23c65c9472c2926c4962b68ab4f8cdb54ab720d43c51309b49bee19438ebbeffab
7
+ data.tar.gz: 74ad6b5a791c45b1c895f12bea6cb39e761775a99e7ff469ca98297f8ebada132484f6c40db2162cfa32a4f0f9c2defc294b1a516669b4c63b3072a187c4dbd2
@@ -11,39 +11,44 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
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]
14
+ rails_version: [5.1.0, 5.2.0, 6.0.0, 6.1.0, 7.0.0, master]
15
+ ruby_version: ['3.2', '3.1', '3.0', '2.7', '2.6']
16
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
17
+ - { ruby_version: '2.6', rails_version: 7.0.0 }
18
+ - { ruby_version: '2.6', rails_version: master }
19
+ - { ruby_version: '3.0', rails_version: 5.1.0 }
20
+ - { ruby_version: '3.0', rails_version: 5.2.0 }
21
+ - { ruby_version: '3.1', rails_version: 5.1.0 }
22
+ - { ruby_version: '3.1', rails_version: 5.2.0 }
23
+ - { ruby_version: '3.1', rails_version: 6.0.0 }
24
+ - { ruby_version: '3.1', rails_version: 6.1.0 }
25
+ - { ruby_version: '3.2', rails_version: 5.1.0 }
26
+ - { ruby_version: '3.2', rails_version: 5.2.0 }
27
+ - { ruby_version: '3.2', rails_version: 6.0.0 }
28
+ - { ruby_version: '3.2', rails_version: 6.1.0 }
25
29
 
26
30
  steps:
27
- - uses: actions/checkout@v2
31
+ - uses: actions/checkout@v3
28
32
 
29
33
  - name: Setup Ruby
30
34
  uses: ruby/setup-ruby@v1
31
35
  with:
32
- ruby-version: ${{ matrix.ruby_version }}
36
+ ruby-version: "${{ matrix.ruby_version }}"
33
37
 
34
38
  - name: Run test
35
39
  env:
36
- RAILS_VERSION: ${{ matrix.rails_version }}
40
+ RAILS_VERSION: "${{ matrix.rails_version }}"
37
41
  run: |
42
+ gem update --system
38
43
  bundle update
39
44
  cd spec/dummy; rake db:migrate db:test:prepare; cd ../..
40
45
  bundle exec rake
41
46
 
42
47
  - name: Upload coverage
43
- uses: actions/upload-artifact@v2
48
+ uses: actions/upload-artifact@v3
44
49
  if: always()
45
50
  with:
46
- name: coverage-ruby-${{ matrix.ruby_version }}-rails-${{ matrix.rails_version }}
51
+ name: "coverage-ruby-${{ matrix.ruby_version }}-rails-${{ matrix.rails_version }}"
47
52
  path: coverage
48
53
 
49
54
  - name: Show coverage
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## Version 4.5.0
6
+ * Use `link` element for link item in semantic markup instead of `meta` element (via #36, thanks @tkawa)
7
+ * Use `link_data` to set data attributes for link item (via #38, thanks @SpaYco)
8
+
9
+ ## Version 4.4.0
10
+ * Support Bootstrap 5. See the `:style` option in the readme for more info (via #30, thanks @tochi)
11
+ * Support Rails 7.0
12
+ * Link class is now customizable with `<%= breadcrumbs link_class: "some-class" %>`. (via #10)
13
+
3
14
  ## Version 4.3.0
4
15
  * Support generating `aria-current` attribute. It's disabled by default. See the readme for more info
5
16
 
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
- ![](https://github.com/kzkn/gretel/workflows/CI/badge.svg)
2
+ [![](https://github.com/kzkn/gretel/workflows/CI/badge.svg)](https://github.com/kzkn/gretel/actions/workflows/ci.yml)
3
3
 
4
4
  <img src="http://i.imgur.com/CAKEaBM.png" alt="Handle breadcrumb trails... like a boss :)" />
5
5
 
@@ -96,9 +96,11 @@ 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
101
102
  :aria_current | Value of `aria-current` attribute. | None
103
+ :link_data | Adds data attributes to breadcrumb | `nil`
102
104
 
103
105
  ### Styles
104
106
 
@@ -110,7 +112,8 @@ Style | Description
110
112
  `:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
111
113
  `:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
112
114
  `:bootstrap` | Renders the links for use in [Bootstrap v3](https://getbootstrap.com/docs/3.4/).
113
- `:bootstrap4` | Renders the links for use in [Bootstrap v4](https://getbootstrap.com/).
115
+ `:bootstrap4` | Renders the links for use in [Bootstrap v4](https://getbootstrap.com/docs/4.6/getting-started/introduction/).
116
+ `:bootstrap5` | Renders the links for use in [Bootstrap v5](https://getbootstrap.com/).
114
117
  `:foundation5` | Renders the links for use in [Foundation 5](https://get.foundation/).
115
118
 
116
119
  Or you can build the breadcrumbs manually for full customization; see below.
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,8 +15,12 @@ Gem::Specification.new do |gem|
15
15
  end
16
16
  gem.require_paths = ["lib"]
17
17
 
18
- gem.add_dependency "railties", [">= 5.1", "< 7.0"]
19
- gem.add_dependency "actionview", [">= 5.1", "< 7.0"]
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"]
20
24
  gem.add_development_dependency "sqlite3"
21
25
  gem.add_development_dependency "rspec-rails"
22
26
  gem.add_development_dependency "simplecov"
@@ -17,8 +17,10 @@ module Gretel
17
17
  current_class: "current",
18
18
  pretext_class: "pretext",
19
19
  posttext_class: "posttext",
20
+ link_class: nil,
20
21
  id: nil,
21
- aria_current: nil
22
+ aria_current: nil,
23
+ link_data: nil
22
24
  }
23
25
 
24
26
  DEFAULT_STYLES = {
@@ -27,6 +29,7 @@ module Gretel
27
29
  ul: { container_tag: :ul, fragment_tag: :li },
28
30
  bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" },
29
31
  bootstrap4: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" },
32
+ bootstrap5: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", fragment_class: "breadcrumb-item", current_class: "active" },
30
33
  foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumbs", current_class: "current" }
31
34
  }
32
35
 
@@ -85,7 +88,7 @@ module Gretel
85
88
  end
86
89
 
87
90
  # Set current link to actual path
88
- if options[:link_current_to_request_path] && out.any? && request
91
+ if options[:link_current_to_request_path] && out.any? && request&.fullpath.present?
89
92
  out.last.url = request.fullpath
90
93
  end
91
94
 
@@ -190,83 +193,111 @@ module Gretel
190
193
  def render
191
194
  return "" if links.empty?
192
195
 
196
+ renderer_class = options[:semantic] ? SemanticRenderer : NonSemanticRenderer
197
+ renderer = renderer_class.new(context, options)
193
198
  # Loop through all but the last (current) link and build HTML of the fragments
194
199
  fragments = links[0..-2].map.with_index do |link, index|
195
- render_fragment(options[:fragment_tag], link.text, link.url, options[:semantic], index + 1, fragment_class: options[:fragment_class])
200
+ renderer.render_fragment(link, index + 1)
196
201
  end
197
202
 
198
203
  # The current link is handled a little differently, and is only linked if specified in the options
199
204
  current_link = links.last
200
205
  position = links.size
201
- 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, aria_current: options[:aria_current])
206
+ fragments << renderer.render_current_fragment(current_link, position)
202
207
 
203
208
  # Build the final HTML
204
- html_fragments = []
209
+ html_fragments = [
210
+ renderer.render_pretext,
211
+ fragments.join(options[:separator]),
212
+ renderer.render_posttext
213
+ ]
214
+ html = html_fragments.compact.join(" ").html_safe
215
+ renderer.render_container(html)
216
+ end
217
+
218
+ alias :to_s :render
219
+
220
+ # Avoid unnecessary html escaping by template engines.
221
+ def html_safe?
222
+ true
223
+ end
224
+ end
225
+
226
+ class Base
227
+ attr_reader :context, :options
228
+
229
+ def initialize(context, options)
230
+ @context = context
231
+ @options = options
232
+ end
233
+
234
+ def render_fragment(link, position)
235
+ render_fragment_tag(fragment_tag, link.text, link.url, position, **fragment_options)
236
+ end
237
+
238
+ def render_current_fragment(link, position)
239
+ url = options[:link_current] ? link.url : nil
240
+ opts = fragment_options.merge(class: options[:current_class], current_link: link.url, aria_current: options[:aria_current])
241
+ render_fragment_tag(fragment_tag, link.text, url, position, **opts)
242
+ end
205
243
 
244
+ def render_fragment_tag(fragment_tag, text, url, position, options = {})
245
+ end
246
+
247
+ def render_container(html)
248
+ end
249
+
250
+ def render_pretext
206
251
  if options[:pretext].present?
207
- html_fragments << content_tag(:span, options[:pretext], class: options[:pretext_class])
252
+ content_tag(:span, options[:pretext], class: options[:pretext_class])
208
253
  end
254
+ end
209
255
 
210
- html_fragments << fragments.join(options[:separator])
211
-
256
+ def render_posttext
212
257
  if options[:posttext].present?
213
- html_fragments << content_tag(:span, options[:posttext], class: options[:posttext_class])
258
+ content_tag(:span, options[:posttext], class: options[:posttext_class])
214
259
  end
260
+ end
215
261
 
216
- html = html_fragments.join(" ").html_safe
262
+ private
217
263
 
218
- if options[:semantic]
219
- content_tag(options[:container_tag], html, id: options[:id], class: options[:class], itemscope: "", itemtype: "https://schema.org/BreadcrumbList")
220
- else
221
- content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
222
- end
264
+ def fragment_tag
265
+ options[:fragment_tag]
223
266
  end
224
267
 
225
- alias :to_s :render
226
-
227
- # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
228
- def render_fragment(fragment_tag, text, url, semantic, position, options = {})
229
- if semantic
230
- render_semantic_fragment(fragment_tag, text, url, position, options)
231
- else
232
- render_nonsemantic_fragment(fragment_tag, text, url, options)
233
- end
268
+ def fragment_options
269
+ options.slice(:fragment_class, :link_class, :link_data)
234
270
  end
235
271
 
236
- # Renders semantic fragment HTML.
237
- def render_semantic_fragment(fragment_tag, text, url, position, options = {})
238
- fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
239
- fragment_class = nil if fragment_class.blank?
240
- fragment_tag = fragment_tag || 'span'
241
- text = content_tag(:span, text, itemprop: "name")
272
+ def join_classes(*classes)
273
+ clazz = classes.join(' ').strip
274
+ clazz.blank? ? nil : clazz
275
+ end
242
276
 
243
- aria_current = options[:aria_current]
244
- if url.present?
245
- text = breadcrumb_link_to(text, url, itemprop: "item", "aria-current": aria_current)
246
- aria_current = nil
247
- elsif options[:current_link].present?
248
- current_url = "#{root_url}#{options[:current_link].gsub(/^\//, '')}"
249
- text = text + tag(:meta, itemprop: "item", content: current_url)
250
- end
277
+ # Proxy for +context.link_to+ that can be overridden by plugins.
278
+ def breadcrumb_link_to(name, url, options = {})
279
+ context.link_to(name, url, options)
280
+ end
251
281
 
252
- text = text + tag(:meta, itemprop:"position", content: "#{position}")
253
- content_tag(fragment_tag.to_sym, text, class: fragment_class, itemprop: "itemListElement", itemscope: "", itemtype: "https://schema.org/ListItem", "aria-current": aria_current)
282
+ # Proxy to view context.
283
+ def method_missing(method, *args, &block)
284
+ context.send(method, *args, &block)
254
285
  end
286
+ end
255
287
 
256
- # Renders regular, non-semantic fragment HTML.
257
- def render_nonsemantic_fragment(fragment_tag, text, url, options = {})
258
- fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
259
- fragment_class = nil if fragment_class.blank?
288
+ class NonSemanticRenderer < Base
289
+ def render_fragment_tag(fragment_tag, text, url, position, options = {})
290
+ fragment_class = join_classes(options[:fragment_class], options[:class])
260
291
 
261
292
  if fragment_tag
262
293
  if url.present?
263
- text = breadcrumb_link_to(text, url, "aria-current": options[:aria_current])
294
+ text = breadcrumb_link_to(text, url, "aria-current": options[:aria_current], data: options[:link_data])
264
295
  content_tag(fragment_tag, text, class: fragment_class)
265
296
  else
266
- content_tag(fragment_tag, text, class: fragment_class, "aria-current": options[:aria_current])
297
+ content_tag(fragment_tag, text, class: fragment_class, "aria-current": options[:aria_current], data: options[:link_data])
267
298
  end
268
299
  elsif url.present?
269
- breadcrumb_link_to(text, url, class: fragment_class, "aria-current": options[:aria_current])
300
+ breadcrumb_link_to(text, url, class: join_classes(fragment_class, options[:link_class]), "aria-current": options[:aria_current], data: options[:link_data])
270
301
  elsif options[:class].present?
271
302
  content_tag(:span, text, class: fragment_class, "aria-current": options[:aria_current])
272
303
  else
@@ -274,19 +305,31 @@ module Gretel
274
305
  end
275
306
  end
276
307
 
277
- # Proxy for +context.link_to+ that can be overridden by plugins.
278
- def breadcrumb_link_to(name, url, options = {})
279
- context.link_to(name, url, options)
308
+ def render_container(html)
309
+ content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
280
310
  end
311
+ end
281
312
 
282
- # Proxy to view context.
283
- def method_missing(method, *args, &block)
284
- context.send(method, *args, &block)
313
+ class SemanticRenderer < Base
314
+ def render_fragment_tag(fragment_tag, text, url, position, options = {})
315
+ fragment_class = join_classes(options[:fragment_class], options[:class])
316
+ fragment_tag = fragment_tag || 'span'
317
+ text = content_tag(:span, text, itemprop: "name")
318
+
319
+ aria_current = options[:aria_current]
320
+ if url.present?
321
+ text = breadcrumb_link_to(text, url, itemprop: "item", "aria-current": aria_current, class: options[:link_class], data: options[:link_data])
322
+ aria_current = nil
323
+ elsif options[:current_link].present?
324
+ text = text + tag(:link, itemprop: "item", href: options[:current_link])
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, data: options[:link_data])
285
329
  end
286
330
 
287
- # Avoid unnecessary html escaping by template engines.
288
- def html_safe?
289
- 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")
290
333
  end
291
334
  end
292
335
  end
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "4.3.0"
2
+ VERSION = "4.5.0"
3
3
  end
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.3.0
4
+ version: 4.5.0
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: 2021-07-01 00:00:00.000000000 Z
12
+ date: 2023-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '5.1'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '7.0'
23
+ version: '7.1'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '5.1'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '7.0'
33
+ version: '7.1'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: actionview
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: '5.1'
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '7.0'
43
+ version: '7.1'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: '5.1'
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '7.0'
53
+ version: '7.1'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: sqlite3
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -136,10 +136,11 @@ files:
136
136
  - lib/gretel/resettable.rb
137
137
  - lib/gretel/version.rb
138
138
  - lib/gretel/view_helpers.rb
139
- homepage: http://github.com/kzkn/gretel
139
+ homepage: https://github.com/kzkn/gretel
140
140
  licenses:
141
141
  - MIT
142
- metadata: {}
142
+ metadata:
143
+ changelog_uri: https://github.com/kzkn/gretel/blob/master/CHANGELOG.md
143
144
  post_install_message:
144
145
  rdoc_options: []
145
146
  require_paths:
@@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  - !ruby/object:Gem::Version
156
157
  version: '0'
157
158
  requirements: []
158
- rubygems_version: 3.2.15
159
+ rubygems_version: 3.4.6
159
160
  signing_key:
160
161
  specification_version: 4
161
162
  summary: Flexible Ruby on Rails breadcrumbs plugin.