Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to pass only a string to breadcrumb #47

Open
richardonrails opened this issue Apr 9, 2021 · 2 comments
Open

Ability to pass only a string to breadcrumb #47

richardonrails opened this issue Apr 9, 2021 · 2 comments

Comments

@richardonrails
Copy link

richardonrails commented Apr 9, 2021

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:

breadcrumb "Categories", blog_categories_path

However the other 2 libraries also support passing only a string for the last item, such as:

def show
  # ...
  breadcrumb "Categories", blog_categories_path
  breadcrumb @category.title
end

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 throwing ArgumentError (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.

@piotrmurach
Copy link
Owner

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 #41. These are my quick thoughts and I'd encourage you to submit PR.

@richardonrails
Copy link
Author

richardonrails commented Apr 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants