Flexible Ruby on Rails breadcrumbs plugin.
Switch branches/tags
Clone or download
Pull request Compare This branch is 19 commits ahead, 342 commits behind lassebunk:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
MIT-LICENSE
README.md
Rakefile
gretel-erb.gemspec
init.rb

README.md

Gretel-ERB

Gretel-ERB is a a fork of Lasse Bunk's 'gretel' that gives you much more control over your breadcrumb's layout by using ERB templates for rendering. This fork was authored by Nicholas Zaillian (Washington Square Interactive) to resolve issues encountered during the ongoing development of GoodTix.

Note: this is a significant fork of gretel and usage is, accordingly, different from that of the original gem. Most of the 'breadcrumb' method options from the original plugin (such as the :pretext and :separator options) are not relevant when you're using a template to specify the layout of your breadcrumb. We'll attempt to keep version numbers in sync with those of the original project.

Installation

In your Gemfile:

gem 'gretel-erb', :git => 'git@github.com:nzaillian/gretel-erb.git'

And run:

bundle install

Example

Start by generating the initializer, (default) partial, and assets:

$ rails generate gretel:new breadcrumbs

This creates the following files:

config/initializers/breadcrumbs.rb
app/views/common/_gretel_breadcrumb.html.erb
app/assets/stylesheets/common/breadcrumb.css.erb
app/assets/images/common/breadcrumb/breadcrumb_separator.png
app/assets/images/common/breadcrumb/breadcrumb_bg.png

You'll need to link the stylesheet in the header of the layout for any pages where you want to display the breadcrumb (assuming you want it styled -- and you almost certainly do). You can do that either by including a

stylesheet_link_tag('common/breadcrumb')
directly to the header or adding
*= require './common/breadcrumb'
(or appropriate relative path) to an asset manifest file that you've linked to.

Finally, use Gretel's DSL (nearly unchanged in this fork) to declare your page hierarchies and template partial path in config/initializers/breadcrumbs.rb:

Gretel::Crumbs.layout do
	
  # Declare the path to your custom breadcrumb partial template (optional;
  # defaults to the path below...)
  template 'common/gretel_breadcrumb.html.erb'

  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/xx/xx.html.erb:

<%= breadcrumb :issue, @issue %>

options for <%= breadcrumb %>:

: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  

The 'breadcrumb' helper method passes an array of 'Crumb' objects (see lib/gretel-erb/crumb.rb) sorted oldest to newest to your partial for rendering. You may do whatever you please with this array. The default template created by the generator I've included with this gem (see lib/generators/templates/_gretel_breadcrumb.html.erb) renders the breadcrumb as a ul wrapped in a div.

The original Gretel gem was written by Lasse Bunk and released under the MIT license. This gem retains that license.