https://github.com/foca/migajas
Tiny breadcrumbs for your Rack apps.
https://github.com/foca/migajas
breadcrumbs cuba rack rails roda ruby
Last synced: 12 months ago
JSON representation
Tiny breadcrumbs for your Rack apps.
- Host: GitHub
- URL: https://github.com/foca/migajas
- Owner: foca
- License: mit
- Created: 2016-05-26T12:08:00.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-12-29T22:10:12.000Z (over 5 years ago)
- Last Synced: 2025-05-24T02:07:18.147Z (about 1 year ago)
- Topics: breadcrumbs, cuba, rack, rails, roda, ruby
- Language: Ruby
- Homepage:
- Size: 8.79 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Migajas
Migajas is a tiny library for adding breadcrumbs to any Rack application. It was
designed with routing tree frameworks like Cuba or Roda in mind, but works well
with any Rack-based framework, including Rails.
## Usage
First, build up your trail of crumbs as you match your routes:
``` ruby
Cuba.plugin Migajas
Cuba.define do
breacrumbs << "Home"
on "users" do
breadcrumbs << "Users"
on get do
# render the list of users
end
on ":id" do |id|
user = User[id]
breadcrumbs << user.name
on get do
# render the user profile page
end
end
end
end
```
Then, in the view, go over the `breadcrumbs` list:
``` erb
```
That's it :)
## Rails
Start by adding `Migajas::Rails` to your controllers:
``` ruby
class ApplicationController < ActionController::Base
include Migajas::Rails
end
```
This gives you a `breadcrumbs` method that you can access from your controllers
and views. The recommended approach is to use action callbacks to add
breadcrumbs:
``` ruby
class ApplicationController < ActionController::Base
include Migajas::Rails
before_action { breadcrumbs.add "Home", root_path }
end
class UsersController < ApplicationController
before_action { breadcrumbs.add "Users", users_path }
before_action(only: [:show, :edit, :update]) { breadcrumbs.add @user.name, user_path(@user) }
end
```
Then, in your layout, you can iterate over the Array:
``` erb
```
## Install
gem install migajas
## Do we need a gem for this?
Probably not, but after 2 years of using this code, I got bored of copying and
pasting it from [a gist](https://gist.github.com/foca/44c9f24a759238fba9fb).
## What's in a name?
`Migajas` is the Spanish word for `breadcrumbs`. It's pronounced like you'd
pronounce `me-gha-has` in English (`me` as in the word "me", `gha` as in
"ghast", and `has` as the word "has".)
## License
This project is shared under the MIT license. See the attached [LICENSE][] file
for details.
[LICENSE]: ./LICENSE