Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Flexible Ruby on Rails breadcrumbs plugin.
Ruby
branch: master

This branch is 2 commits ahead, 325 commits behind lassebunk:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
MIT-LICENSE
README.rdoc
Rakefile
gretel.gemspec
init.rb

README.rdoc

Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create breadcrumbs.

Installation

In your Gemfile:

gem 'gretel'

And run bundle install.

Example

Start by generating initializer:

$ rails generate gretel breadcrumbs

In config/initializers/breadcrumbs.rb:

Gretel::Crumbs.layout do

  crumb :root do
    link "Home", root_path
  end

  crumb :projects do
    link "Projects", projects_path, :class => "breadcrumb", :style => "font-weight: bold;"
    link "Projects", projects_path, { :class => 'breadcrumb', :style => 'font-weight: bold;' }
  end

  crumb :project do |project|
    link lambda { |project| "#{project.name} (#{project.id.to_s})" }, project_path(project)
    parent :projects
  end

  crumb :project_issues do |project|
    link "Issues", project_issues_path(project)
    parent :project, project
  end

  crumb :issue do |issue|
    link issue.name, issue_path(issue)
    parent :project_issues, issue.project
  end

end

In app/views/layouts/application.html.erb:

<%= breadcrumb :pretext => "You are here:",
               :separator => ">",
               :autoroot => true,
               :show_root_alone => true,
               :link_last => false %>

In app/views/xx/xx.html.erb:

<% breadcrumb :issue, @issue %>

This could also be done in the controller, if you prefer:

def show
  @project = Project.find(params[:id])
  breadcrumb :project, @project
end

Options for <%= breadcrumb %>:

:pretext          Text to be rendered before breadcrumb, if any. Default: none
:separator        Separator between links. Default: &gt;
:autoroot         Whether it should automatically link to :root if no root parent is given. Default: false
:show_root_alone  Whether it should show :root if this is the only link. Default: false
:link_last        Whether the last crumb should be linked to. Default: false

Contributors

  • Alan Larkin

  • David Doan

Copyright © 2010 Lasse Bunk, released under the MIT license

Something went wrong with that request. Please try again.