Project

gretel-erb

0.0
No commit activity in last 3 years
No release in over 3 years
EOS This is a significant fork of Lasse Bunk's rails gem 'gretel' (http://github.com/lassebunk/gretel) that retains the convenient page hierarchy specification DSL of the original gem, but does all rendering using a user-specifiable partial template.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

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.