crumbly 2.1.0 → 2.3.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: 79dd182434d2559579a926dc460606527bea5ab63bda1e1c00bcef7ecd3e221d
4
- data.tar.gz: 265c0a56aa5ad03ee08d9d825b31432af7569dab24cd8d80974ed1a1e2fd2bb9
3
+ metadata.gz: 5bf3918dd4b7fcbadd1730b66e44af7449e2185eb7e18967a25bf6c1363b1700
4
+ data.tar.gz: 0e372c5825ba04c4fb71287af76ebca3b8522959b7f80877d83f137b6a03e32b
5
5
  SHA512:
6
- metadata.gz: b465f51629faefb7bfce68edeb9c8c01cb4a5b9099ecc942add8fa9ff753f3d2bccc972c6d1b19c5ef34435121b2fca127c723c5297e10343298ed389c269920
7
- data.tar.gz: 39682d63dc8464e7fc3881ec95d3834f34fa1c9a1975682fa53c016e6fe105611d92d2b4f3ce784fa2792500b46e6bf59f46453c4d2fd9a71584b34ca8b8a6b3
6
+ metadata.gz: f05b3347e70dc154bca5ce217428c3b8559c1834404c328c47fbfd8166b923306eeba2b2f7679659774259838671ed177ce7fc9b9d5e023c8ceda02186650621
7
+ data.tar.gz: 347c7fa50a57807fc4fb404d8e4f4c11a3c37d2b60649135e3067738a39b1def40e8e78ac7f6586a5afde88d4799e494b9b2c70030098fb30da14d4c7916f30d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [2.3.0] — 2026-11-28
6
+
7
+ Crumbly boots without loading Prism, and the trails it works out give valid JSON-LD, singular resources and namespaced models included.
8
+
9
+ **Faster**
10
+ - `require "crumbly"` no longer loads Prism: only `Crumbly.verify!` does. About 65 ms and 5 MB less per boot on Ruby 3.3 without JIT.
11
+
12
+ **Fixed**
13
+ - `breadcrumb_json_ld` gives full URLs to the levels Crumbly works out for a trail, instead of raising `Crumbly::RelativeUrl` outside production and dropping the structured data in production.
14
+ - A singular resource with a show route (`resource :account`) links to that route, with no made-up "Accounts" level above it, and sits under its parent record when nested.
15
+ - A `javascript:` URL spelled with character references in an `html_safe` string (`javascript:`, `javascript:`) is refused like any other script URL.
16
+ - `Crumbly.verify!` no longer reports a namespaced model's crumb (`billing_invoice` for `Billing::Invoice`) as dead.
17
+ - `Crumbly.verify!` checks crumbs called on `self` (`parent: self.orders`, as crumbly-convert writes them): they no longer count as dead, and a misspelled name or wrong argument count is reported.
18
+ - `crumbly-convert --views` lists `breadcrumb` calls closed with `-%>`.
19
+
20
+ ## [2.2.0] — 2026-11-06
21
+
22
+ A trail class can turn off derived trails with `derive_trails false`, and a derived level labels a record without its own `to_s` "Invoice 12" instead of `#<Invoice:0x…>`.
23
+
24
+ **New**
25
+ - `derive_trails false` in a trail class, for apps that want only the trails they write, as with gretel: a view without a `breadcrumb` call gets an empty `breadcrumb_trail` and a nil `breadcrumb_json_ld`. Subclasses inherit it and `derive_trails true` turns it back on. In such a class, `Crumbly.verify!` reports a crumb that only a derived trail would read as unused, and `Crumbly::Oracle.redundant_calls` lists nothing.
26
+
27
+ **Fixed**
28
+ - A derived level whose record's model doesn't define `to_s` is labelled with the translated model name and id, "Invoice 12", instead of Ruby's `#<Invoice:0x000…>`. A model's own `to_s` still wins.
29
+
5
30
  ## [2.1.0] — 2026-11-06
6
31
 
7
32
  Crumbs refuse `javascript:`, `vbscript:` and `data:` URLs, and a nil record, odd bytes or `=begin` comments no longer break Crumbly.
@@ -76,7 +101,9 @@ tests. Replaces gretel: `crumbly-convert` turns its breadcrumbs files into Crumb
76
101
  `breadcrumb` calls a derived trail may now cover.
77
102
  - `Crumbly::Oracle.compare` draws trails with gretel and with Crumbly, from a test of an app migrating.
78
103
 
79
- [Unreleased]: https://github.com/levups/crumbly/compare/v2.1.0...HEAD
104
+ [Unreleased]: https://github.com/levups/crumbly/compare/v2.3.0...HEAD
105
+ [2.3.0]: https://github.com/levups/crumbly/compare/v2.2.0...v2.3.0
106
+ [2.2.0]: https://github.com/levups/crumbly/compare/v2.1.0...v2.2.0
80
107
  [2.1.0]: https://github.com/levups/crumbly/compare/v2.0.0...v2.1.0
81
108
  [2.0.0]: https://github.com/levups/crumbly/compare/v1.1.0...v2.0.0
82
109
  [1.1.0]: https://github.com/levups/crumbly/compare/v1.0.0...v1.1.0
data/README.md CHANGED
@@ -13,6 +13,9 @@ checks every trail in the app, so a broken one fails CI before anyone opens the
13
13
 
14
14
  The guide, the migration notes and the benchmarks are also on the website: <https://levups.github.io/crumbly/>.
15
15
 
16
+ Coding agents can start from <https://levups.github.io/crumbly/llms.txt>, or read this README and the
17
+ website's pages as one Markdown file: <https://levups.github.io/crumbly/llms-full.txt>.
18
+
16
19
  ## Why Crumbly
17
20
 
18
21
  Crumbly was written to replace [gretel](https://github.com/kzkn/gretel) in a back office with 265 crumbs, in one
@@ -122,7 +125,8 @@ A crumb calls `crumb label, url = nil, parent: nil, links: []`.
122
125
 
123
126
  `url` can be a string, a record or a polymorphic array such as `[:admin, owner, :returns]`. Leave it out for a
124
127
  level without a link. A `javascript:`, `vbscript:` or `data:` URL would run a script once your layout links it,
125
- so Crumbly refuses it, however it is spelled (`" JavaScript:"`, `"java\tscript:"`): see
128
+ so Crumbly refuses it, however it is spelled (`" JavaScript:"`, `"java\tscript:"`, or `"javascript&colon;"` in an
129
+ `html_safe` string, which the browser decodes): see
126
130
  [Mistakes in development and in production](#mistakes-in-development-and-in-production).
127
131
 
128
132
  `links:` is for a level that points to more than one page. It takes extra `link(label, url)` entries, which your
@@ -169,20 +173,38 @@ When a view doesn't call `breadcrumb`, Crumbly builds the trail from the action:
169
173
  | Action | Trail |
170
174
  |---|---|
171
175
  | `index` | the collection: your `posts` crumb if you wrote one, or else the model's plural name linked to the `index` route |
172
- | `show` | the record: your `post` crumb, or else its `to_s` linked to the `show` route, under the collection |
176
+ | `show` | the record: your `post` crumb, or else its label linked to the `show` route, under the collection |
173
177
  | `new`, `create` | "New" under the collection |
174
178
  | `edit`, `update` | "Edit" under the record |
175
179
 
176
180
  The record is the one the controller has already loaded, `@post` in `PostsController`. Crumbly never runs a query
177
181
  to find it. "New" and "Edit" come from the `crumbly.new` and `crumbly.edit` translations, so you can translate
178
- them.
182
+ them. A record's label is its `to_s`. A model without a `to_s` of its own gets its translated model name and id
183
+ instead ("Post 5"), not `#<Post:0x000...>`.
179
184
 
180
185
  Nested routes work too. On `/admin/posts/5/comments`, the trail is Posts › Post 5 › Comments, and the post is
181
186
  the `@post` the controller loaded. If the controller didn't load it, Crumbly skips that level and keeps Posts.
182
187
 
188
+ A singular resource with a `show` route (`resource :account`) has no collection: its record links to that route,
189
+ under its parent record when the route is nested, so the profile on `/admin/customers/7/profile` sits under its
190
+ customer. A crumb named after the controller or the nesting (`customer_profiles`) still comes first.
191
+
183
192
  To change how these trails are built, override the private methods `collection_crumb`, `record_crumb`,
184
193
  `new_record_crumb` or `edit_record_crumb` in your trail class.
185
194
 
195
+ To turn them off, set `derive_trails false` in the trail class. A view that doesn't call `breadcrumb` then has no
196
+ trail, as with gretel: `breadcrumb_trail` returns `[]` and `breadcrumb_json_ld` returns `nil`.
197
+
198
+ ```ruby
199
+ module Admin
200
+ class Breadcrumbs < Crumbly::Trail
201
+ derive_trails false
202
+ end
203
+ end
204
+ ```
205
+
206
+ Subclasses inherit the setting, and `derive_trails true` turns it back on in one of them.
207
+
186
208
  ### Which crumb wins
187
209
 
188
210
  Crumbly takes the first of these that applies:
@@ -194,6 +216,8 @@ Crumbly takes the first of these that applies:
194
216
  3. The trail Crumbly works out. Its parent levels follow the same rule: your crumb for the parent's model if there
195
217
  is one, or else a level Crumbly builds.
196
218
 
219
+ With `derive_trails false`, only the first applies.
220
+
197
221
  ## Testing your trails
198
222
 
199
223
  Add one test:
@@ -218,7 +242,7 @@ fails when:
218
242
  - a view or another crumb calls a crumb with the wrong number of arguments (calls spread over several lines, or
219
243
  with a splat, are skipped);
220
244
  - a crumb is never used. A crumb is used when another crumb, a view or a controller calls it, when a trail
221
- Crumbly works out reads it, or when it is named after a model.
245
+ Crumbly works out reads it (unless its class sets `derive_trails false`), or when it is named after a model.
222
246
 
223
247
  A crumb defined twice in the same class is caught even earlier: the class raises `Crumbly::DuplicateCrumb` when it
224
248
  loads.
@@ -267,6 +291,9 @@ module Storefront
267
291
  end
268
292
  ```
269
293
 
294
+ The levels Crumbly builds for a trail it works out get full URLs in the JSON-LD on their own, and keep paths in
295
+ the page. Your own crumbs, `root` included, still need `_url` helpers.
296
+
270
297
  A relative URL raises `Crumbly::RelativeUrl` in development and test. In production it is reported to
271
298
  `Rails.error` and the page has no structured data. `Crumbly.raise_on_relative_url` changes this.
272
299
 
@@ -296,6 +323,7 @@ It prints each line it left out or couldn't convert exactly, and with `--views`,
296
323
  Crumbly may now make unnecessary. It needs Prism 1.2 or later: Ruby 3.4 comes with it, and on Ruby 3.3 you add
297
324
  `gem "prism"` to the development group. While gretel is still installed on the migration branch,
298
325
  `Crumbly::Oracle` draws each trail your tests render with both gems and lists where the labels or URLs differ.
326
+ To keep gretel's empty trail on pages whose views name no crumb, set `derive_trails false` in the trail class.
299
327
 
300
328
  The [migration guide](https://levups.github.io/crumbly/migration.html) has every step: what the converter maps to
301
329
  what, what it leaves to you, the comparison in your tests, and the same walk-through for loaf and
@@ -342,6 +370,7 @@ bundle exec rake test # latest Rails
342
370
  BUNDLE_GEMFILE=gemfiles/rails_8_0.gemfile bundle exec rake test # Rails 8.0
343
371
  bundle exec rubocop
344
372
  bundle exec rake docs:highlight # after editing a code block in docs/
373
+ bundle exec rake docs:llms # after editing the README or docs/
345
374
  ```
346
375
 
347
376
  [CONTRIBUTING.md](CONTRIBUTING.md) says what a pull request needs.
@@ -356,10 +385,11 @@ bin/release minor --dry-run # shows the notes and the changes, writes nothing
356
385
  bin/release minor # or patch, major, or an exact version such as 1.2.0
357
386
  ```
358
387
 
359
- `bin/release` bumps the version on a `release/vX.Y.Z` branch, opens its pull request, waits for it to merge
360
- itself once CI is green, and pushes a signed tag `vX.Y.Z` on the merge commit (`bin/release --tag X.Y.Z` resumes
361
- this step if you stopped it). The tag starts the Release workflow, which publishes the gem to RubyGems through
362
- trusted publishing and creates the GitHub release.
388
+ `main` takes no direct push, so `bin/release` dates the notes and bumps the version on a `release/vX.Y.Z` branch,
389
+ opens a pull request that merges itself once CI is green, and waits for it (`bin/release --wait X.Y.Z` if you
390
+ stopped it). The merge starts the Release workflow, which waits for a maintainer's approval, tags the merge commit
391
+ `vX.Y.Z`, publishes the gem to RubyGems through trusted publishing and creates the GitHub release with the notes
392
+ and the `.gem`.
363
393
 
364
394
  ## License
365
395
 
@@ -12,7 +12,8 @@ module Crumbly
12
12
  end
13
13
  end
14
14
 
15
- BREADCRUMB_CALL = /\bbreadcrumb[ (]\s*(?<target>:\w+|@\w+)(?<arguments>[^\n%}]*)/
15
+ # The call ends before the tag closes, `-%>` (ERB's trim mode) included.
16
+ BREADCRUMB_CALL = /\bbreadcrumb[ (]\s*(?<target>:\w+|@\w+)(?<arguments>[^\n%}]*?)(?=\s*(?:-?%|\}|$))/
16
17
  VIEW_GLOB = "**/*.{erb,haml,slim,ruby}"
17
18
  FORM_CRUMBS = %w[generic_form new edit].freeze
18
19
 
data/lib/crumbly/trail.rb CHANGED
@@ -37,6 +37,18 @@ module Crumbly
37
37
  raise DuplicateCrumb, "#{self}##{name} is defined twice: the second definition would replace the first"
38
38
  end
39
39
 
40
+ def derive_trails(derive)
41
+ raise ArgumentError, "derive_trails takes true or false, not #{derive.inspect}" unless derive in true | false
42
+
43
+ @derive_trails = derive
44
+ end
45
+
46
+ def derive_trails?
47
+ return @derive_trails unless @derive_trails.nil?
48
+
49
+ self == Trail || superclass.derive_trails?
50
+ end
51
+
40
52
  def crumb?(name)
41
53
  trail_class = self
42
54
  while trail_class < Trail
@@ -51,8 +63,12 @@ module Crumbly
51
63
  new(helpers).send(:levels_for, target, arguments)
52
64
  end
53
65
 
54
- def derive(helpers)
55
- new(helpers).send(:derived_levels)
66
+ def derive(helpers, full_urls: false)
67
+ return [] unless derive_trails?
68
+
69
+ trail = new(helpers)
70
+ trail.instance_variable_set(:@full_urls, true) if full_urls
71
+ trail.send(:derived_levels)
56
72
  end
57
73
  end
58
74
 
@@ -103,17 +119,25 @@ module Crumbly
103
119
 
104
120
  # A URL built from user input can run a script once a layout links it: the level keeps its label, not the link.
105
121
  def safe_url(url)
106
- return url if url.start_with?("/", "https://", "http://") || !url.include?(":")
107
- return url unless UNSAFE_URL_SCHEME.match?(url.gsub(IGNORED_URL_CHARACTERS, ""))
122
+ href = (url.html_safe? && url.include?("&")) ? decoded_attribute(url) : url
123
+ return url if href.start_with?("/", "https://", "http://") || !href.include?(":")
124
+ return url unless UNSAFE_URL_SCHEME.match?(href.gsub(IGNORED_URL_CHARACTERS, ""))
108
125
 
109
126
  exception = UnsafeUrl.new("#{self.class} links to #{url.inspect}, which a browser runs as a script: " \
110
127
  "check its scheme before passing it to a crumb")
111
128
  raise exception if Crumbly.raise_on_unsafe_url?
112
129
 
113
- ActiveSupport.error_reporter.report(exception, handled: true)
130
+ # breadcrumb_json_ld derives again, with full URLs, a trail the page has just derived and reported.
131
+ ActiveSupport.error_reporter.report(exception, handled: true) unless @full_urls
114
132
  nil
115
133
  end
116
134
 
135
+ # link_to writes an html_safe URL into href as is, and the browser decodes its character references first:
136
+ # "javascript&colon;" runs too.
137
+ def decoded_attribute(url)
138
+ Loofah.html5_fragment(%(<a href="#{url.gsub('"', "&quot;")}">)).children.first["href"]
139
+ end
140
+
117
141
  def levels_for(target, arguments)
118
142
  levels(target_crumb(target, arguments))
119
143
  end
@@ -166,7 +190,8 @@ module Crumbly
166
190
  exception = UnknownCrumb.new(message)
167
191
  raise exception if Crumbly.raise_on_unknown_crumb?
168
192
 
169
- ActiveSupport.error_reporter.report(exception, handled: true)
193
+ # breadcrumb_json_ld derives again, with full URLs, a trail the page has just derived and reported.
194
+ ActiveSupport.error_reporter.report(exception, handled: true) unless @full_urls
170
195
  nil
171
196
  end
172
197
 
@@ -190,13 +215,26 @@ module Crumbly
190
215
 
191
216
  # The four crumbs below build a derived trail; override any of them as a private method.
192
217
  def collection_crumb
193
- nested_collection_crumb(controller.controller_name, route_parents)
218
+ parents = route_parents
219
+ if singular_show_location && !(parents.all?(&:record) && nesting_crumb?(parents))
220
+ return singular_resource_parent_crumb(parents)
221
+ end
222
+
223
+ nested_collection_crumb(controller.controller_name, parents)
194
224
  end
195
225
 
196
226
  def record_crumb(record)
197
227
  return crumb_for(record) if crumb_name_for(record)
198
228
 
199
- crumb(record.to_s, route_path(action: "show", id: record), parent: collection_crumb)
229
+ url = singular_show_location || route_path(action: "show", id: record)
230
+ crumb(record_label(record), url, parent: collection_crumb)
231
+ end
232
+
233
+ # Kernel#to_s would label the level "#<Invoice:0x000...>".
234
+ def record_label(record)
235
+ return record.to_s unless record.class.instance_method(:to_s).owner == Kernel && record.class.respond_to?(:model_name)
236
+
237
+ "#{record.model_name.human} #{record.to_param}"
200
238
  end
201
239
 
202
240
  def new_record_crumb
@@ -207,6 +245,41 @@ module Crumbly
207
245
  crumb(I18n.t("crumbly.edit", default: "Edit"), parent: record_crumb(record))
208
246
  end
209
247
 
248
+ def singular_show_location
249
+ return @singular_show_location if defined?(@singular_show_location)
250
+
251
+ @singular_show_location = (route_path(action: "show") if singular_resource?)
252
+ end
253
+
254
+ # A singular resource (resource :account) has no index route, and each of its show routes ends with a static
255
+ # segment (/account), where a plural one ends with its member key (/orders/:id, /tags/:slug).
256
+ def singular_resource?
257
+ return false if controller.action_name == "index" || controller.request.path_parameters.key?(:id)
258
+ return false if route_path(action: "index")
259
+
260
+ show_paths = controller._routes.routes.filter_map do |route|
261
+ next unless route.defaults[:controller] == controller.controller_path && route.defaults[:action] == "show"
262
+
263
+ route.path.spec.to_s.delete_suffix("(.:format)")
264
+ end
265
+ show_paths.any? && show_paths.none? { |path| path.split("/").last.to_s.match?(/[:*]/) }
266
+ end
267
+
268
+ def nesting_crumb?(parents)
269
+ self.class.crumb?([*parents.map(&:name), controller.controller_name].join("_").to_sym)
270
+ end
271
+
272
+ # Under a nested route (/customers/7/profile), the level above a singular resource is its parent record, or
273
+ # the collection of the first parent the controller didn't load.
274
+ def singular_resource_parent_crumb(parents)
275
+ return if parents.empty?
276
+
277
+ loaded_parents = parents.take_while(&:record)
278
+ return parent_record_crumb(parents) if loaded_parents.size == parents.size
279
+
280
+ nested_collection_crumb(parents[loaded_parents.size].name.pluralize, loaded_parents)
281
+ end
282
+
210
283
  # Under a nested route (/orders/42/messages), a crumb named after the whole nesting (order_messages) is
211
284
  # called with the parents' records; otherwise the collection is derived under its parent record.
212
285
  def nested_collection_crumb(name, parents)
@@ -235,7 +308,7 @@ module Crumbly
235
308
  return crumb_for(parent.record) if crumb_name_for(parent.record)
236
309
 
237
310
  name = parent.name.pluralize
238
- crumb(parent.record.to_s, route_path(resources: name, action: "show", id: parent.id, **route_parent_ids(ancestors)),
311
+ crumb(record_label(parent.record), route_path(resources: name, action: "show", id: parent.id, **route_parent_ids(ancestors)),
239
312
  parent: nested_collection_crumb(name, ancestors))
240
313
  end
241
314
 
@@ -256,7 +329,7 @@ module Crumbly
256
329
  # A controller without an index or show route still gets its level, without a link.
257
330
  def route_path(resources: controller.controller_name, **options)
258
331
  namespace = controller.controller_path.delete_suffix(controller.controller_name)
259
- helpers.url_for(controller: "/#{namespace}#{resources}", only_path: true, **options)
332
+ helpers.url_for(controller: "/#{namespace}#{resources}", only_path: !@full_urls, **options)
260
333
  rescue ActionController::UrlGenerationError
261
334
  nil
262
335
  end
@@ -41,9 +41,9 @@ module Crumbly
41
41
  definition = definition_of(method)
42
42
  return unless definition
43
43
 
44
- receiverless_calls(definition).each do |call|
44
+ calls_on_self(definition).each do |call|
45
45
  name = call.name
46
- location = "#{method.source_location.first}:#{call.location.start_line}"
46
+ location = "#{method.source_location.first}:#{(call.message_loc || call.location).start_line}"
47
47
  if trail_class.crumb?(name)
48
48
  arity_problem = arity_problem(trail_class, name, call)
49
49
  problems << "#{trail_class}##{method.name} calls #{name} #{arity_problem} (#{location})" if arity_problem
@@ -74,9 +74,10 @@ module Crumbly
74
74
  definitions
75
75
  end
76
76
 
77
- def receiverless_calls(definition)
77
+ # crumbly-convert writes `self.orders` when a local of the crumb is also named orders.
78
+ def calls_on_self(definition)
78
79
  calls = []
79
- each_node(definition) { |node| calls << node if node in Prism::CallNode[receiver: nil] }
80
+ each_node(definition) { |node| calls << node if node in Prism::CallNode[receiver: nil | Prism::SelfNode] }
80
81
  calls
81
82
  end
82
83
 
@@ -165,8 +166,9 @@ module Crumbly
165
166
  end
166
167
 
167
168
  def dead_crumbs
168
- reachable_names = called_names + derived_names
169
+ reachable_names_with_derivation = called_names + derived_names
169
170
  trail_classes.flat_map do |trail_class|
171
+ reachable_names = trail_class.derive_trails? ? reachable_names_with_derivation : called_names
170
172
  dead_names = crumb_names(trail_class).reject do |name|
171
173
  reachable_names.include?(name) || model_name?(name)
172
174
  end
@@ -191,9 +193,27 @@ module Crumbly
191
193
  [*nesting_names, controller_name.singularize.to_sym]
192
194
  end
193
195
 
194
- # A crumb named after a model is reachable from any `breadcrumb @record` or `crumb_for(record)`.
196
+ # A crumb named after a model is reachable from any `breadcrumb @record` or `crumb_for(record)`. Its name is
197
+ # the model's `model_name.singular`, where each underscore may stand for a namespace: billing_invoice is
198
+ # the crumb of Billing::Invoice.
195
199
  def model_name?(name)
196
- name.to_s.camelize.safe_constantize.respond_to?(:model_name)
200
+ model_named?(name.to_s, name.to_s.split("_"), Object)
201
+ end
202
+
203
+ # Only a prefix that names a module is searched further, so `settings_profile` never reads inside a
204
+ # Settings object.
205
+ def model_named?(name, words, namespace)
206
+ (1..words.size).any? do |count|
207
+ constant_name = words.first(count).join("_").camelize
208
+ next false unless constant_name.match?(/\A[A-Z]\w*\z/) && namespace.const_defined?(constant_name, false)
209
+
210
+ constant = namespace.const_get(constant_name, false)
211
+ if count == words.size
212
+ constant.respond_to?(:model_name) && constant.model_name.try(:singular) == name
213
+ else
214
+ constant.is_a?(Module) && model_named?(name, words.drop(count), constant)
215
+ end
216
+ end
197
217
  end
198
218
 
199
219
  def crumb_names(trail_class)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Crumbly
4
- VERSION = "2.1.0"
4
+ VERSION = "2.3.0"
5
5
  end
@@ -2,7 +2,8 @@
2
2
 
3
3
  module Crumbly
4
4
  module ViewHelpers
5
- # The view names its crumb; a view that says nothing gets the trail derived from its controller and action.
5
+ # The view names its crumb; a view that says nothing gets the trail derived from its controller and action,
6
+ # or none under `derive_trails false`.
6
7
  def breadcrumb(target, *arguments)
7
8
  @crumbly_breadcrumb = [target, arguments]
8
9
  @crumbly_trail = nil
@@ -21,10 +22,21 @@ module Crumbly
21
22
  end
22
23
 
23
24
  def breadcrumb_json_ld
24
- breadcrumb_list = JsonLd.call(breadcrumb_trail)
25
+ breadcrumb_list = JsonLd.call(crumbly_json_ld_trail)
25
26
  return unless breadcrumb_list
26
27
 
27
28
  content_tag(:script, ERB::Util.json_escape(JSON.generate(breadcrumb_list)).html_safe, type: "application/ld+json")
28
29
  end
30
+
31
+ private
32
+
33
+ # Google needs full URLs and the page keeps paths: a derived trail that links a path is derived again, with
34
+ # full URLs, for the JSON-LD.
35
+ def crumbly_json_ld_trail
36
+ levels = breadcrumb_trail
37
+ return levels if @crumbly_breadcrumb || levels.all? { |level| level.url.nil? || JsonLd::ABSOLUTE_URL.match?(level.url) }
38
+
39
+ @crumbly_json_ld_trail ||= Crumbly.trail_class_for(controller.class).derive(self, full_urls: true)
40
+ end
29
41
  end
30
42
  end
data/lib/crumbly.rb CHANGED
@@ -15,10 +15,12 @@ require_relative "crumbly/trail"
15
15
  require_relative "crumbly/json_ld"
16
16
  require_relative "crumbly/controller"
17
17
  require_relative "crumbly/view_helpers"
18
- require_relative "crumbly/verifier"
19
18
  require_relative "crumbly/railtie" if defined?(Rails::Railtie)
20
19
 
21
20
  module Crumbly
21
+ # Prism, which the verifier parses crumbs with, is only loaded by verify!: production never runs it.
22
+ autoload :Verifier, File.expand_path("crumbly/verifier", __dir__)
23
+
22
24
  class << self
23
25
  attr_writer :routes, :raise_on_unknown_crumb, :raise_on_relative_url, :raise_on_unsafe_url
24
26
 
metadata CHANGED
@@ -1,111 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crumbly
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Level UP Solutions
7
+ - Level UP Solutions
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: actionpack
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: '8.0'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: '8.0'
26
- - !ruby/object:Gem::Dependency
27
- name: activesupport
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: '8.0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '8.0'
40
- - !ruby/object:Gem::Dependency
41
- name: loofah
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 2.25.3
47
- type: :runtime
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 2.25.3
54
- description: Each level of a breadcrumb trail is a Ruby method that names its parent.
55
- When a view names no crumb, Crumbly works the trail out from the controller and
56
- the routes, and one test checks every trail in the app. The trail comes back as
57
- data, so your layout writes the HTML.
12
+ - !ruby/object:Gem::Dependency
13
+ name: actionpack
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "8.0"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: "8.0"
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ -
33
+ - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "8.0"
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ -
41
+ - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "8.0"
44
+ - !ruby/object:Gem::Dependency
45
+ name: loofah
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ -
49
+ - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.25.3
52
+ type: :runtime
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ -
57
+ - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.25.3
60
+ description: "Each level of a breadcrumb trail is a Ruby method that names its parent. When a view names no crumb, Crumbly works the trail out from the controller and the routes, and one test checks every trail in the app. The trail comes back as data, so your layout writes the HTML."
58
61
  executables:
59
- - crumbly-convert
62
+ - crumbly-convert
60
63
  extensions: []
61
64
  extra_rdoc_files: []
62
65
  files:
63
- - CHANGELOG.md
64
- - LICENSE
65
- - README.md
66
- - exe/crumbly-convert
67
- - lib/crumbly.rb
68
- - lib/crumbly/controller.rb
69
- - lib/crumbly/converter.rb
70
- - lib/crumbly/converter/crumb_definition.rb
71
- - lib/crumbly/converter/source.rb
72
- - lib/crumbly/crumb.rb
73
- - lib/crumbly/derived_call_sites.rb
74
- - lib/crumbly/errors.rb
75
- - lib/crumbly/json_ld.rb
76
- - lib/crumbly/level.rb
77
- - lib/crumbly/oracle.rb
78
- - lib/crumbly/railtie.rb
79
- - lib/crumbly/test_helper.rb
80
- - lib/crumbly/trail.rb
81
- - lib/crumbly/verifier.rb
82
- - lib/crumbly/version.rb
83
- - lib/crumbly/view_helpers.rb
84
- homepage: https://github.com/levups/crumbly
66
+ - CHANGELOG.md
67
+ - LICENSE
68
+ - README.md
69
+ - exe/crumbly-convert
70
+ - lib/crumbly.rb
71
+ - lib/crumbly/controller.rb
72
+ - lib/crumbly/converter.rb
73
+ - lib/crumbly/converter/crumb_definition.rb
74
+ - lib/crumbly/converter/source.rb
75
+ - lib/crumbly/crumb.rb
76
+ - lib/crumbly/derived_call_sites.rb
77
+ - lib/crumbly/errors.rb
78
+ - lib/crumbly/json_ld.rb
79
+ - lib/crumbly/level.rb
80
+ - lib/crumbly/oracle.rb
81
+ - lib/crumbly/railtie.rb
82
+ - lib/crumbly/test_helper.rb
83
+ - lib/crumbly/trail.rb
84
+ - lib/crumbly/verifier.rb
85
+ - lib/crumbly/version.rb
86
+ - lib/crumbly/view_helpers.rb
87
+ homepage: "https://github.com/levups/crumbly"
85
88
  licenses:
86
- - MIT
89
+ - MIT
87
90
  metadata:
88
- source_code_uri: https://github.com/levups/crumbly
89
- changelog_uri: https://github.com/levups/crumbly/blob/main/CHANGELOG.md
90
- documentation_uri: https://levups.github.io/crumbly/
91
- bug_tracker_uri: https://github.com/levups/crumbly/issues
92
- rubygems_mfa_required: 'true'
91
+ source_code_uri: "https://github.com/levups/crumbly"
92
+ changelog_uri: "https://github.com/levups/crumbly/blob/main/CHANGELOG.md"
93
+ documentation_uri: "https://levups.github.io/crumbly/"
94
+ bug_tracker_uri: "https://github.com/levups/crumbly/issues"
95
+ rubygems_mfa_required: "true"
93
96
  rdoc_options: []
94
97
  require_paths:
95
- - lib
98
+ - lib
96
99
  required_ruby_version: !ruby/object:Gem::Requirement
97
100
  requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: '3.3'
101
+ -
102
+ - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "3.3"
101
105
  required_rubygems_version: !ruby/object:Gem::Requirement
102
106
  requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
107
+ -
108
+ - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
106
111
  requirements: []
107
- rubygems_version: 4.0.20
112
+ rubygems_version: 4.1.1
108
113
  specification_version: 4
109
- summary: Breadcrumb trails for Rails, written as plain Ruby methods and checked in
110
- tests
114
+ summary: "Breadcrumb trails for Rails, written as plain Ruby methods and checked in tests"
111
115
  test_files: []