Provides an easy_breadcrumbs
view helper for automatically generating bootstrap breadcrumbs for your Sinatra Application.
- It's able to properly generate the html for many different types of complex routes (See Below).
- It only generates breadcrumbs for the routes you've defined, so if you have a route
/categories/10/contacts/5
, but haven't defined an index view route for/categories
, that item will be left out. - It can automatically detect certain name attributes for specific resources.
Add this line to your application's Gemfile:
gem 'easy_breadcrumbs'
And then execute:
$ bundle
Or install it yourself as:
$ gem install easy_breadcrumbs
If you're building a classic style Sinatra app, simply add this line to your sinatra application file:
require "easy_breadcrumbs"
If you're building a modular style Sinatra app, you'll also need to explicitly register the module within your application.
class HelloApp < Sinatra::Base
helpers Sinatra::EasyBreadcrumbs
get "/hello" do
h "1 < 2"
end
end
And then use the helper method in your layout or view:
<%= easy_breadcrumbs %>
And last but not least, make sure you have bootstrap installed. You can install bootstrap's css by adding this line to your applications layout template.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
NEW: Auto Name Detection
Easy Breadcrumbs can now detect names for specific resources.
Path: /contacts/10
Old Breadcrumb Format: Home > Contacts > Contact
New Breadcrumb Format: Home > Contacts > Ada Lovelace
It's able to detect the name with the following limitations:
- The resource is either a Hash or a Custom object
- The resource has a key (Hash) or accessor method (custom object) of one of the following 3 commonly used name attributes:
- :name
- :title
- :subject
If this condition fails, it will default to the old format.
Easy Breadcrumbs is able to handle a variety of complex routes.
Here are some examples:
Path: /about
Breadcrumb: Home > About
Path: /contacts
Breadcrumb: Home > Contacts
###Path to specific resource
Path: /contacts/28
Breadcrumb: Home > Contacts > Contact
Path: /contacts/new
Breadcrumb: Home > Contacts > New Contact
Path: /contacts/28/edit
Breadcrumb: Home > Contacts > Contact > Edit Contact
Path: /categories/5/contacts
Breadcrumb: Home > Categories > Category > Contacts
Path: /categories/5/contacts/10
Breadcrumb: Home > Categories > Category > Contacts > Contact
Path: /categories/5/contacts/new
Breadcrumb: Home > Categories > Category > Contacts > New Contact
Path: /categories/5/contacts/10/edit
Breadcrumb: Home > Categories > Category > Contacts > Contact > Edit Contact
- Don't render breadcrumbs if current page is home
- Allow for manual turning off of breadcrumbs for specific routes or sets of routes
- Allow for custom configuration of name attributes for resources
- Should be able to do something like
set :easy_breadcrumbs, user: :name, post: :title
- Should be able to do something like
- More robust spec suite
- Explore more edge cases for both unit and integration tests
- Eliminate repetition in specs
- Other development gems that would help with this?
- Update gemspec with depencency version restrictions and bump gem version to 1.0
Bug reports and pull requests are welcome on GitHub at https://github.com/nerboda/easy_breadcrumbs.
The gem is available as open source under the terms of the MIT License.