gretel 4.0.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +52 -0
  3. data/.gitignore +7 -6
  4. data/CHANGELOG.md +20 -0
  5. data/Gemfile +3 -1
  6. data/README.md +46 -44
  7. data/Rakefile +3 -7
  8. data/coverage/coverage.txt +1 -2
  9. data/gretel.gemspec +9 -11
  10. data/lib/gretel.rb +1 -7
  11. data/lib/gretel/crumb.rb +5 -2
  12. data/lib/gretel/crumbs.rb +26 -7
  13. data/lib/gretel/railtie.rb +11 -0
  14. data/lib/gretel/renderer.rb +65 -33
  15. data/lib/gretel/version.rb +1 -1
  16. data/lib/gretel/view_helpers.rb +2 -0
  17. metadata +37 -112
  18. data/.travis.yml +0 -14
  19. data/test/dummy/Rakefile +0 -7
  20. data/test/dummy/app/assets/config/manifest.js +0 -0
  21. data/test/dummy/app/assets/javascripts/application.js +0 -15
  22. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  23. data/test/dummy/app/controllers/application_controller.rb +0 -3
  24. data/test/dummy/app/helpers/application_helper.rb +0 -5
  25. data/test/dummy/app/mailers/.gitkeep +0 -0
  26. data/test/dummy/app/models/.gitkeep +0 -0
  27. data/test/dummy/app/models/issue.rb +0 -3
  28. data/test/dummy/app/models/project.rb +0 -3
  29. data/test/dummy/app/views/breadcrumbs/site.rb +0 -3
  30. data/test/dummy/config.ru +0 -4
  31. data/test/dummy/config/application.rb +0 -14
  32. data/test/dummy/config/boot.rb +0 -10
  33. data/test/dummy/config/breadcrumbs.rb +0 -3
  34. data/test/dummy/config/breadcrumbs/test_crumbs.rb +0 -85
  35. data/test/dummy/config/database.yml +0 -25
  36. data/test/dummy/config/environment.rb +0 -5
  37. data/test/dummy/config/environments/development.rb +0 -2
  38. data/test/dummy/config/environments/production.rb +0 -2
  39. data/test/dummy/config/environments/test.rb +0 -2
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  41. data/test/dummy/config/initializers/inflections.rb +0 -15
  42. data/test/dummy/config/initializers/mime_types.rb +0 -5
  43. data/test/dummy/config/initializers/secret_token.rb +0 -7
  44. data/test/dummy/config/initializers/session_store.rb +0 -8
  45. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  46. data/test/dummy/config/locales/en.yml +0 -5
  47. data/test/dummy/config/routes.rb +0 -11
  48. data/test/dummy/db/migrate/20130122163007_create_projects.rb +0 -9
  49. data/test/dummy/db/migrate/20130122163051_create_issues.rb +0 -10
  50. data/test/dummy/db/schema.rb +0 -28
  51. data/test/dummy/lib/assets/.gitkeep +0 -0
  52. data/test/dummy/log/.gitkeep +0 -0
  53. data/test/dummy/public/404.html +0 -26
  54. data/test/dummy/public/422.html +0 -26
  55. data/test/dummy/public/500.html +0 -25
  56. data/test/dummy/public/favicon.ico +0 -0
  57. data/test/dummy/script/rails +0 -6
  58. data/test/fixtures/issues.yml +0 -4
  59. data/test/fixtures/projects.yml +0 -3
  60. data/test/gretel_test.rb +0 -23
  61. data/test/helper_methods_test.rb +0 -558
  62. data/test/test_helper.rb +0 -23
@@ -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,8 @@ module Gretel
14
17
  current_class: "current",
15
18
  pretext_class: "pretext",
16
19
  posttext_class: "posttext",
17
- id: nil
20
+ id: nil,
21
+ aria_current: nil
18
22
  }
19
23
 
20
24
  DEFAULT_STYLES = {
@@ -40,11 +44,6 @@ module Gretel
40
44
  LinkCollection.new(context, links, options)
41
45
  end
42
46
 
43
- # Yields links with applied options.
44
- def yield_links(options = {})
45
- yield render(options)
46
- end
47
-
48
47
  # Returns the parent breadcrumb.
49
48
  def parent_breadcrumb(options = {})
50
49
  render(options)[-2]
@@ -161,6 +160,27 @@ module Gretel
161
160
  concat links
162
161
  end
163
162
 
163
+ # Returns a hash matching the JSON-LD Structured Data schema
164
+ # https://developers.google.com/search/docs/data-types/breadcrumb#json-ld
165
+ def structured_data(url_base:)
166
+ url_base = url_base.chomp("/") # Remove trailing `/`, if present
167
+
168
+ items = @links.each_with_index.map do |link, i|
169
+ {
170
+ "@type": "ListItem",
171
+ "position": i + 1,
172
+ "name": link.text,
173
+ "item": "#{url_base}#{link.url}"
174
+ }
175
+ end
176
+
177
+ {
178
+ "@context": "https://schema.org",
179
+ "@type": "BreadcrumbList",
180
+ "itemListElement": items
181
+ }
182
+ end
183
+
164
184
  # Helper for returning all link keys to allow for simple testing.
165
185
  def keys
166
186
  map(&:key)
@@ -171,13 +191,14 @@ module Gretel
171
191
  return "" if links.empty?
172
192
 
173
193
  # 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])
194
+ 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])
176
196
  end
177
197
 
178
198
  # The current link is handled a little differently, and is only linked if specified in the options
179
199
  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)
200
+ 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])
181
202
 
182
203
  # Build the final HTML
183
204
  html_fragments = []
@@ -193,41 +214,43 @@ module Gretel
193
214
  end
194
215
 
195
216
  html = html_fragments.join(" ").html_safe
196
- content_tag(options[:container_tag], html, id: options[:id], class: options[:class])
217
+
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
197
223
  end
198
224
 
199
225
  alias :to_s :render
200
226
 
201
227
  # Renders HTML for a breadcrumb fragment, i.e. a breadcrumb link.
202
- def render_fragment(fragment_tag, text, url, semantic, options = {})
228
+ def render_fragment(fragment_tag, text, url, semantic, position, options = {})
203
229
  if semantic
204
- render_semantic_fragment(fragment_tag, text, url, options)
230
+ render_semantic_fragment(fragment_tag, text, url, position, options)
205
231
  else
206
232
  render_nonsemantic_fragment(fragment_tag, text, url, options)
207
233
  end
208
234
  end
209
235
 
210
236
  # Renders semantic fragment HTML.
211
- def render_semantic_fragment(fragment_tag, text, url, options = {})
237
+ def render_semantic_fragment(fragment_tag, text, url, position, options = {})
212
238
  fragment_class = [options[:fragment_class], options[:class]].join(' ').strip
213
239
  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")
240
+ fragment_tag = fragment_tag || 'span'
241
+ text = content_tag(:span, text, itemprop: "name")
242
+
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)
230
250
  end
251
+
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)
231
254
  end
232
255
 
233
256
  # Renders regular, non-semantic fragment HTML.
@@ -236,12 +259,16 @@ module Gretel
236
259
  fragment_class = nil if fragment_class.blank?
237
260
 
238
261
  if fragment_tag
239
- text = breadcrumb_link_to(text, url) if url.present?
240
- content_tag(fragment_tag, text, class: fragment_class)
262
+ if url.present?
263
+ text = breadcrumb_link_to(text, url, "aria-current": options[:aria_current])
264
+ content_tag(fragment_tag, text, class: fragment_class)
265
+ else
266
+ content_tag(fragment_tag, text, class: fragment_class, "aria-current": options[:aria_current])
267
+ end
241
268
  elsif url.present?
242
- breadcrumb_link_to(text, url, class: fragment_class)
269
+ breadcrumb_link_to(text, url, class: fragment_class, "aria-current": options[:aria_current])
243
270
  elsif options[:class].present?
244
- content_tag(:span, text, class: fragment_class)
271
+ content_tag(:span, text, class: fragment_class, "aria-current": options[:aria_current])
245
272
  else
246
273
  text
247
274
  end
@@ -256,6 +283,11 @@ module Gretel
256
283
  def method_missing(method, *args, &block)
257
284
  context.send(method, *args, &block)
258
285
  end
286
+
287
+ # Avoid unnecessary html escaping by template engines.
288
+ def html_safe?
289
+ true
290
+ end
259
291
  end
260
292
  end
261
293
  end
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "4.0.0"
2
+ VERSION = "4.3.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:
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.3.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-12 00:00:00.000000000 Z
12
+ date: 2021-07-01 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.0'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,22 +28,31 @@ dependencies:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: '5.1'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
28
34
  - !ruby/object:Gem::Dependency
29
- name: sqlite3
35
+ name: actionview
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
38
  - - ">="
33
39
  - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
40
+ version: '5.1'
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '7.0'
44
+ type: :runtime
36
45
  prerelease: false
37
46
  version_requirements: !ruby/object:Gem::Requirement
38
47
  requirements:
39
48
  - - ">="
40
49
  - !ruby/object:Gem::Version
41
- version: '0'
50
+ version: '5.1'
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '7.0'
42
54
  - !ruby/object:Gem::Dependency
43
- name: jquery-rails
55
+ name: sqlite3
44
56
  requirement: !ruby/object:Gem::Requirement
45
57
  requirements:
46
58
  - - ">="
@@ -54,47 +66,47 @@ dependencies:
54
66
  - !ruby/object:Gem::Version
55
67
  version: '0'
56
68
  - !ruby/object:Gem::Dependency
57
- name: test-unit
69
+ name: rspec-rails
58
70
  requirement: !ruby/object:Gem::Requirement
59
71
  requirements:
60
- - - "~>"
72
+ - - ">="
61
73
  - !ruby/object:Gem::Version
62
- version: '3.0'
74
+ version: '0'
63
75
  type: :development
64
76
  prerelease: false
65
77
  version_requirements: !ruby/object:Gem::Requirement
66
78
  requirements:
67
- - - "~>"
79
+ - - ">="
68
80
  - !ruby/object:Gem::Version
69
- version: '3.0'
81
+ version: '0'
70
82
  - !ruby/object:Gem::Dependency
71
83
  name: simplecov
72
84
  requirement: !ruby/object:Gem::Requirement
73
85
  requirements:
74
- - - "~>"
86
+ - - ">="
75
87
  - !ruby/object:Gem::Version
76
- version: 0.18.0
88
+ version: '0'
77
89
  type: :development
78
90
  prerelease: false
79
91
  version_requirements: !ruby/object:Gem::Requirement
80
92
  requirements:
81
- - - "~>"
93
+ - - ">="
82
94
  - !ruby/object:Gem::Version
83
- version: 0.18.0
95
+ version: '0'
84
96
  - !ruby/object:Gem::Dependency
85
97
  name: simplecov-erb
86
98
  requirement: !ruby/object:Gem::Requirement
87
99
  requirements:
88
- - - "~>"
100
+ - - ">="
89
101
  - !ruby/object:Gem::Version
90
- version: '0.1'
102
+ version: '0'
91
103
  type: :development
92
104
  prerelease: false
93
105
  version_requirements: !ruby/object:Gem::Requirement
94
106
  requirements:
95
- - - "~>"
107
+ - - ">="
96
108
  - !ruby/object:Gem::Version
97
- version: '0.1'
109
+ version: '0'
98
110
  description: Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create
99
111
  breadcrumbs.
100
112
  email:
@@ -103,8 +115,8 @@ executables: []
103
115
  extensions: []
104
116
  extra_rdoc_files: []
105
117
  files:
118
+ - ".github/workflows/ci.yml"
106
119
  - ".gitignore"
107
- - ".travis.yml"
108
120
  - CHANGELOG.md
109
121
  - Gemfile
110
122
  - LICENSE.txt
@@ -119,54 +131,11 @@ files:
119
131
  - lib/gretel/crumb.rb
120
132
  - lib/gretel/crumbs.rb
121
133
  - lib/gretel/link.rb
134
+ - lib/gretel/railtie.rb
122
135
  - lib/gretel/renderer.rb
123
136
  - lib/gretel/resettable.rb
124
137
  - lib/gretel/version.rb
125
138
  - lib/gretel/view_helpers.rb
126
- - test/dummy/Rakefile
127
- - test/dummy/app/assets/config/manifest.js
128
- - test/dummy/app/assets/javascripts/application.js
129
- - test/dummy/app/assets/stylesheets/application.css
130
- - test/dummy/app/controllers/application_controller.rb
131
- - test/dummy/app/helpers/application_helper.rb
132
- - test/dummy/app/mailers/.gitkeep
133
- - test/dummy/app/models/.gitkeep
134
- - test/dummy/app/models/issue.rb
135
- - test/dummy/app/models/project.rb
136
- - test/dummy/app/views/breadcrumbs/site.rb
137
- - test/dummy/config.ru
138
- - test/dummy/config/application.rb
139
- - test/dummy/config/boot.rb
140
- - test/dummy/config/breadcrumbs.rb
141
- - test/dummy/config/breadcrumbs/test_crumbs.rb
142
- - test/dummy/config/database.yml
143
- - test/dummy/config/environment.rb
144
- - test/dummy/config/environments/development.rb
145
- - test/dummy/config/environments/production.rb
146
- - test/dummy/config/environments/test.rb
147
- - test/dummy/config/initializers/backtrace_silencers.rb
148
- - test/dummy/config/initializers/inflections.rb
149
- - test/dummy/config/initializers/mime_types.rb
150
- - test/dummy/config/initializers/secret_token.rb
151
- - test/dummy/config/initializers/session_store.rb
152
- - test/dummy/config/initializers/wrap_parameters.rb
153
- - test/dummy/config/locales/en.yml
154
- - test/dummy/config/routes.rb
155
- - test/dummy/db/migrate/20130122163007_create_projects.rb
156
- - test/dummy/db/migrate/20130122163051_create_issues.rb
157
- - test/dummy/db/schema.rb
158
- - test/dummy/lib/assets/.gitkeep
159
- - test/dummy/log/.gitkeep
160
- - test/dummy/public/404.html
161
- - test/dummy/public/422.html
162
- - test/dummy/public/500.html
163
- - test/dummy/public/favicon.ico
164
- - test/dummy/script/rails
165
- - test/fixtures/issues.yml
166
- - test/fixtures/projects.yml
167
- - test/gretel_test.rb
168
- - test/helper_methods_test.rb
169
- - test/test_helper.rb
170
139
  homepage: http://github.com/kzkn/gretel
171
140
  licenses:
172
141
  - MIT
@@ -186,52 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
155
  - !ruby/object:Gem::Version
187
156
  version: '0'
188
157
  requirements: []
189
- rubygems_version: 3.0.3
158
+ rubygems_version: 3.2.15
190
159
  signing_key:
191
160
  specification_version: 4
192
161
  summary: Flexible Ruby on Rails breadcrumbs plugin.
193
- test_files:
194
- - test/dummy/Rakefile
195
- - test/dummy/app/assets/config/manifest.js
196
- - test/dummy/app/assets/javascripts/application.js
197
- - test/dummy/app/assets/stylesheets/application.css
198
- - test/dummy/app/controllers/application_controller.rb
199
- - test/dummy/app/helpers/application_helper.rb
200
- - test/dummy/app/mailers/.gitkeep
201
- - test/dummy/app/models/.gitkeep
202
- - test/dummy/app/models/issue.rb
203
- - test/dummy/app/models/project.rb
204
- - test/dummy/app/views/breadcrumbs/site.rb
205
- - test/dummy/config.ru
206
- - test/dummy/config/application.rb
207
- - test/dummy/config/boot.rb
208
- - test/dummy/config/breadcrumbs.rb
209
- - test/dummy/config/breadcrumbs/test_crumbs.rb
210
- - test/dummy/config/database.yml
211
- - test/dummy/config/environment.rb
212
- - test/dummy/config/environments/development.rb
213
- - test/dummy/config/environments/production.rb
214
- - test/dummy/config/environments/test.rb
215
- - test/dummy/config/initializers/backtrace_silencers.rb
216
- - test/dummy/config/initializers/inflections.rb
217
- - test/dummy/config/initializers/mime_types.rb
218
- - test/dummy/config/initializers/secret_token.rb
219
- - test/dummy/config/initializers/session_store.rb
220
- - test/dummy/config/initializers/wrap_parameters.rb
221
- - test/dummy/config/locales/en.yml
222
- - test/dummy/config/routes.rb
223
- - test/dummy/db/migrate/20130122163007_create_projects.rb
224
- - test/dummy/db/migrate/20130122163051_create_issues.rb
225
- - test/dummy/db/schema.rb
226
- - test/dummy/lib/assets/.gitkeep
227
- - test/dummy/log/.gitkeep
228
- - test/dummy/public/404.html
229
- - test/dummy/public/422.html
230
- - test/dummy/public/500.html
231
- - test/dummy/public/favicon.ico
232
- - test/dummy/script/rails
233
- - test/fixtures/issues.yml
234
- - test/fixtures/projects.yml
235
- - test/gretel_test.rb
236
- - test/helper_methods_test.rb
237
- - test/test_helper.rb
162
+ test_files: []
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 test/dummy; rake db:migrate; rake db:test:prepare; cd ../.."
13
- notifications:
14
- email: false