Project

breadcrumb

0.0
No commit activity in last 3 years
No release in over 3 years
Breadcrumb Helper
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 5.0.0, ~> 3.2.0
 Project Readme

Breadcrumb

Build Status Coverage Status Code Climate Dependency Status Gem Version

Instalation

Put the following line in your Gemfile

gem 'breadcrumb'

And then execute:

$ bundle

Usage

Layout: <%= breadcrumb %>

You can add a root path by doing this

<%= breadcrumb.prepend("Home","/") %>

In your view (say the uri path is /books/religion/the-holly-bible):

  <%
  breadcrumb.add("Books","/books")
  breadcrumb.add("Religion", books_category_path(@book.category))
  breadcrumb.add(@book.title)
  %>

It will render

  <div class="breadcrumb">
    <a href="/books">Books</a>
    <span class="separator"> » </span>
    <a href="/books/religion">Religion</a>
    <span class="separator"> » </span>
    <span>The Holly Bible</span>
  </div>

You can change the separator

<% breadcrumb.separator = '<span class="separator"> &gt; </span>' %>

Titleizing You can use breadcrumb for creating the page title:

  <title><%= breadcrumb.titleize %></title>

which will ouput

  <title>Books :: Religion :: The Holly Bible</title>

Titleize accepts block. When using blocks, returning false removes the title part. Returing nil, won't change the behavior. Returning String changes the title part.

  <title><%= breadcrumb.titleize {|part| "Our Awesome Books" if parts == 'Books' } %></title>

Ouputs

  <title>Our Awesome Books :: Religion :: The Holly Bible</title>

Removing the title part

  <title><%= breadcrumb.titleize {|part| false if part == "Religion" } %></title>
<!-- or -->
  <title><%= breadcrumb.titleize {|part, order| false if order == 1 } %></title>

Outputs

  <title>Books :: The Holly Bible</title>

And you can change the title separator:

<% breadcrumb.title_separator = '-' %>

Authors

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature) Do not forget to write tests
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request