Giter VIP home page Giter VIP logo

gretel's Introduction

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;' }
  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

Copyright © 2010 Lasse Bunk, released under the MIT license

gretel's People

Contributors

lassebunk avatar al avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.