Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fnando/breadcrumbs
Breadcrumbs is a simple Rails plugin that adds a breadcrumbs object to controllers and views.
https://github.com/fnando/breadcrumbs
breadcrumbs rails ruby ruby-on-rails
Last synced: 3 days ago
JSON representation
Breadcrumbs is a simple Rails plugin that adds a breadcrumbs object to controllers and views.
- Host: GitHub
- URL: https://github.com/fnando/breadcrumbs
- Owner: fnando
- License: mit
- Created: 2010-03-25T00:12:31.000Z (almost 15 years ago)
- Default Branch: main
- Last Pushed: 2023-09-05T09:37:23.000Z (over 1 year ago)
- Last Synced: 2025-01-01T04:09:51.177Z (10 days ago)
- Topics: breadcrumbs, rails, ruby, ruby-on-rails
- Language: Ruby
- Homepage:
- Size: 78.1 KB
- Stars: 63
- Watchers: 2
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Breadcrumbs
[![ruby-tests](https://github.com/fnando/breadcrumbs/actions/workflows/ruby-tests.yml/badge.svg)](https://github.com/fnando/breadcrumbs/actions/workflows/ruby-tests.yml)
[![Gem](https://img.shields.io/gem/v/breadcrumbs.svg)](https://rubygems.org/gems/breadcrumbs)
[![Gem](https://img.shields.io/gem/dt/breadcrumbs.svg)](https://rubygems.org/gems/breadcrumbs)Breadcrumbs is a simple plugin that adds a `breadcrumbs` object to controllers
and views.## Instalation
Just run `gem install breadcrumbs`. Or add `gem "breadcrumbs"` to your Gemfile.
## Usage
On your controller (optional):
```ruby
class ApplicationController < ActionController::Base
before_action :add_initial_breadcrumbsprivate
def add_initial_breadcrumbs
breadcrumbs.add "Home", root_path
end
endclass ThingsController < ApplicationController
def index
breadcrumbs.add "Things", things_path
end
end
```You don't need to provide an URL; in that case, a span will be generated instead
of a link:```ruby
breadcrumbs.add "Some page"
```You can set additional HTML attributes if you need to:
```ruby
breadcrumbs.add "Home", root_path, id: "home", title: "Go to the home page"
```On your view (possibly application.html.erb):
```erb
<%= breadcrumbs.render %>
```You can render as ordered list.
```erb
<%= breadcrumbs.render(format: :ordered_list) %>
```You can render as inline links.
```erb
<%= breadcrumbs.render(format: :inline) %>
```You can set your own separator:
```erb
You are here: <%= breadcrumbs.render(format: :inline, separator: "|") %>
```You can also define your own formatter. Just create a class that implements a
`render` instance method and you're good to go.```ruby
class Breadcrumbs::Render::Dl
def render
# return breadcrumbs wrapped in a
- tag
end
end
```
To use your new format, just provide the `:format` option.
```ruby
breadcrumbs.render(format: :dl)
```
### I18n
Breadcrumbs is integrated with I18n. You can set translations like:
```yaml
en:
breadcrumbs:
home: "Home"
```
And then you just call
```ruby
breadcrumbs.add :home
```
In fact, you can provide any scope you want.
```ruby
breadcrumbs.add :"titles.home"
```
If you don't want to translate a label, just pass the option `:i18n` as `false`.
```ruby
breadcrumbs.add :home, nil, i18n: false
```
## Maintainer
- [Nando Vieira](https://github.com/fnando)
## Contributors
- https://github.com/fnando/breadcrumbs/contributors
## Contributing
For more details about how to contribute, please read
https://github.com/fnando/breadcrumbs/blob/main/CONTRIBUTING.md.
## License
The gem is available as open source under the terms of the
[MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
found at https://github.com/fnando/breadcrumbs/blob/main/LICENSE.md.
## Code of Conduct
Everyone interacting in the breadcrumbs project's codebases, issue trackers,
chat rooms and mailing lists is expected to follow the
[code of conduct](https://github.com/fnando/breadcrumbs/blob/main/CODE_OF_CONDUCT.md).