Open richardonrails opened 3 years ago
Hi there 👋
I'm in favour of making loaf
to be more compatible.
As far as making the breadcrumb work with only the string, I have small reservations. Why is that? All the code is currently built on the assumption that a crumb instance has a valid url. From a functional standpoint, this is a rather strong guarantee that simplifies things internally and externally. Since this gem enumerates breadcrumbs and leaves it up to you to decide about markup, you can detect the last breadcrumb and display only the title. Alternatively, I'd consider extending the crumb instance with the last?
as suggested in the https://github.com/piotrmurach/loaf/issues/41. These are my quick thoughts and I'd encourage you to submit PR.
In my case it's about backwards compatibility to avoid having to modify a bunch of existing code beyond what otherwise would be a simple find/replaceall of the method name.
But perhaps there are general cases... e.g. when you know you'll never try to hyperlink the final breadcrumb anyway (or only link it if there is a URL), and some pages (e.g. a POST confirmation page) may not even have a valid URL that brings you to the same place. Just seems reasonable (like the other 2 libraries) that a URL shouldn't be required when you know it'll never be used, either because you just don't want to link the last item, or because sometimes a valid URL may not even exist for the last item.
Do the gem internals really need to require a URL even if the URL will never be used? Seems like that should only matter when a link is being created on the display side.
Both crummy (which I'm trying to migrate from) and breadcrumbs_on_rails support similar syntax as
loaf
for adding breadcrumbs by passing a string followed by a path:However the other 2 libraries also support passing only a string for the last item, such as:
It would aid in the migration of large applications from one of those gems to
loaf
if it supported the string-only syntax for the final crumb rather than throwingArgumentError (wrong number of arguments (given 1, expected 2..3))
In particular, excluding a path for the final item would be common given Bootstrap 4's template which doesn't even want the last item linked.