gretel 4.3.0 → 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: c1fe62ed99bb8f03e6a00a782f55adc5f6b6fcf84a444d77aa1c771b41d148a9
4
- data.tar.gz: 1660db0b73ddbf77dac315c8d1466fb66958b9ebab59629c96f999536f17b824
3
+ metadata.gz: e903af36913aacbf98679ae5452d7269b9eba6abf5b2d75ff6a60277c2d64ad1
4
+ data.tar.gz: 56bcc5194372d75c357fcde07a542ffcd7440fa3ade06738124573d29d3cbf7b
5
5
  SHA512:
6
- metadata.gz: 4bddd221544196836669a1309c97d536ad2d2b11ef10c74a265e034d0a1463ba5b4955651235ad395b9c37249a9d5eff2ef9ec9b659ab896a8fbca959b199924
7
- data.tar.gz: ebd6e183dc3597f83c9ac8b22399d0ad52e345da6586b9de59c2386c8b5116d40199fcf494c44cd8d094a25ed543d5ee21397506d1979ebf851a973e23da3ced
6
+ metadata.gz: e20387223c47146510f79c77f3680ad3f76c8d703a455c7991fd68ec68d5011f79427fe39d56ccd8e0b8e942522632fc1cb448b12e02d6910214b8fe27eb65de
7
+ data.tar.gz: 9612998182b479f2e9f023e64ba8527897a8058a1c59268cb86583f3647b818be978e0c91b4f9740abbbd749c02ee03159fd4b8826377e03e6aef578375e9da3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## Version 4.3.0
4
11
  * Support generating `aria-current` attribute. It's disabled by default. See the readme for more info
5
12
 
data/README.md CHANGED
@@ -96,6 +96,7 @@ 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
@@ -110,7 +111,8 @@ Style | Description
110
111
  `:ol` | Renders the links in `<li>` elements contained in an outer `<ol>`.
111
112
  `:ul` | Renders the links in `<li>` elements contained in an outer `<ul>`.
112
113
  `: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/).
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/).
114
116
  `:foundation5` | Renders the links for use in [Foundation 5](https://get.foundation/).
115
117
 
116
118
  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,6 +17,7 @@ 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
22
  aria_current: nil
22
23
  }
@@ -27,6 +28,7 @@ module Gretel
27
28
  ul: { container_tag: :ul, fragment_tag: :li },
28
29
  bootstrap: { container_tag: :ol, fragment_tag: :li, class: "breadcrumb", current_class: "active" },
29
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" },
30
32
  foundation5: { container_tag: :ul, fragment_tag: :li, class: "breadcrumbs", current_class: "current" }
31
33
  }
32
34
 
@@ -190,73 +192,101 @@ module Gretel
190
192
  def render
191
193
  return "" if links.empty?
192
194
 
195
+ renderer_class = options[:semantic] ? SemanticRenderer : NonSemanticRenderer
196
+ renderer = renderer_class.new(context, options)
193
197
  # Loop through all but the last (current) link and build HTML of the fragments
194
198
  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])
199
+ renderer.render_fragment(link, index + 1)
196
200
  end
197
201
 
198
202
  # The current link is handled a little differently, and is only linked if specified in the options
199
203
  current_link = links.last
200
204
  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])
205
+ fragments << renderer.render_current_fragment(current_link, position)
202
206
 
203
207
  # Build the final HTML
204
- 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
216
+
217
+ alias :to_s :render
218
+
219
+ # Avoid unnecessary html escaping by template engines.
220
+ def html_safe?
221
+ true
222
+ end
223
+ end
224
+
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
205
245
 
246
+ def render_container(html)
247
+ end
248
+
249
+ def render_pretext
206
250
  if options[:pretext].present?
207
- html_fragments << content_tag(:span, options[:pretext], class: options[:pretext_class])
251
+ content_tag(:span, options[:pretext], class: options[:pretext_class])
208
252
  end
253
+ end
209
254
 
210
- html_fragments << fragments.join(options[:separator])
211
-
255
+ def render_posttext
212
256
  if options[:posttext].present?
213
- html_fragments << content_tag(:span, options[:posttext], class: options[:posttext_class])
257
+ content_tag(:span, options[:posttext], class: options[:posttext_class])
214
258
  end
259
+ end
215
260
 
216
- html = html_fragments.join(" ").html_safe
261
+ private
217
262
 
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
263
+ def fragment_tag
264
+ options[:fragment_tag]
223
265
  end
224
266
 
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
267
+ def fragment_options
268
+ options.slice(:fragment_class, :link_class)
234
269
  end
235
270
 
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")
271
+ def join_classes(*classes)
272
+ clazz = classes.join(' ').strip
273
+ clazz.blank? ? nil : clazz
274
+ end
242
275
 
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
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)
279
+ end
251
280
 
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)
281
+ # Proxy to view context.
282
+ def method_missing(method, *args, &block)
283
+ context.send(method, *args, &block)
254
284
  end
285
+ end
255
286
 
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?
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])
260
290
 
261
291
  if fragment_tag
262
292
  if url.present?
@@ -266,7 +296,7 @@ module Gretel
266
296
  content_tag(fragment_tag, text, class: fragment_class, "aria-current": options[:aria_current])
267
297
  end
268
298
  elsif url.present?
269
- breadcrumb_link_to(text, url, class: fragment_class, "aria-current": options[:aria_current])
299
+ breadcrumb_link_to(text, url, class: join_classes(fragment_class, options[:link_class]), "aria-current": options[:aria_current])
270
300
  elsif options[:class].present?
271
301
  content_tag(:span, text, class: fragment_class, "aria-current": options[:aria_current])
272
302
  else
@@ -274,19 +304,32 @@ module Gretel
274
304
  end
275
305
  end
276
306
 
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)
307
+ def render_container(html)
308
+ content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
280
309
  end
310
+ end
281
311
 
282
- # Proxy to view context.
283
- def method_missing(method, *args, &block)
284
- 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)
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.4.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.4.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: 2021-12-16 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: