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


== Installation

In your <em>Gemfile</em>:

  gem 'gretel'

And run <code>bundle install</code>.


== Example

Start by generating initializer:

  $ rails generate gretel breadcrumbs

In <code>config/initializers/breadcrumbs.rb</code>:

  Gretel::Crumbs.layout do
    
    # root crumb
    crumb :root do
      link "Home", root_path
    end
    
    # custom styles
    crumb :projects do
      link "Projects", projects_path, :class => "breadcrumb", :style => "font-weight: bold;"
    end
 
    # lambdas
    crumb :project do |project|
      link lambda { |project| "#{project.name} (#{project.id.to_s})" }, project_path(project)
      parent :projects
    end
    
    # parent crumbs
    crumb :project_issues do |project|
      link "Issues", project_issues_path(project)
      parent :project, project
    end
    
    # child 
    crumb :issue do |issue|
      link issue.name, issue_path(issue)
      parent :project_issues, issue.project
    end
    
    # multiple links per crumb (recursive links for parent categories)
    crumb :category do |category|
      parents = [category]
    
      parent_category = category
      while parent_category = parent_category.parent_category
        parents.unshift parent_category
      end
    
      parents.each do |category|
        link category.name, category
      end

      parent :categories
    end
    
    # product crumb with recursive parent categories
    crumb :product do |product|
      link product.name, product
      parent :category, product.category
    end
  end

In <code>app/views/xx/xx.html.erb</code>:

  <% breadcrumb :issue, @issue %>

In <code>app/views/layouts/application.html.erb</code>:

  <%= breadcrumb :pretext => "You are here: ",
                 :posttext => " &laquo; that was the breadcrumbs!",
                 :separator => " &rsaquo; ",
                 :autoroot => true,
                 :show_root_alone => true,
                 :link_current => false,
                 :semantic => true
                 %>

Or, if you want to customize your breadcrumbs:

  <% breadcrumbs(:autoroot => true, :show_root_alone => false).each_with_index do |crumb, index| %>
    <% if index > 0 %> &gt;<% end %>
    <% if crumb.current? %>
      <span class="current"><%= crumb.text %></span>
    <% else %>
      <%= link_to crumb.text, crumb.url %>
    <% end %>
  <% end %>

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

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

Options for <code><%= breadcrumb %></code>:

  :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_current     Whether the current crumb should be linked to. Default: false


== Todo's

* Make sure that you in your development environment can update breadcrumbs without having to restart the server<commit_msg>update todos<commit_after>Gretel is a Ruby on Rails plugin that makes it easy yet flexible to create breadcrumbs.


== Installation

In your <em>Gemfile</em>:

  gem 'gretel'

And run <code>bundle install</code>.


== Example

Start by generating initializer:

  $ rails generate gretel breadcrumbs

In <code>config/initializers/breadcrumbs.rb</code>:

  Gretel::Crumbs.layout do
    
    # root crumb
    crumb :root do
      link "Home", root_path
    end
    
    # custom styles
    crumb :projects do
      link "Projects", projects_path, :class => "breadcrumb", :style => "font-weight: bold;"
    end
 
    # lambdas
    crumb :project do |project|
      link lambda { |project| "#{project.name} (#{project.id.to_s})" }, project_path(project)
      parent :projects
    end
    
    # parent crumbs
    crumb :project_issues do |project|
      link "Issues", project_issues_path(project)
      parent :project, project
    end
    
    # child 
    crumb :issue do |issue|
      link issue.name, issue_path(issue)
      parent :project_issues, issue.project
    end
    
    # multiple links per crumb (recursive links for parent categories)
    crumb :category do |category|
      parents = [category]
    
      parent_category = category
      while parent_category = parent_category.parent_category
        parents.unshift parent_category
      end
    
      parents.each do |category|
        link category.name, category
      end

      parent :categories
    end
    
    # product crumb with recursive parent categories
    crumb :product do |product|
      link product.name, product
      parent :category, product.category
    end
  end

In <code>app/views/xx/xx.html.erb</code>:

  <% breadcrumb :issue, @issue %>

In <code>app/views/layouts/application.html.erb</code>:

  <%= breadcrumb :pretext => "You are here: ",
                 :posttext => " &laquo; that was the breadcrumbs!",
                 :separator => " &rsaquo; ",
                 :autoroot => true,
                 :show_root_alone => true,
                 :link_current => false,
                 :semantic => true
                 %>

Or, if you want to customize your breadcrumbs:

  <% breadcrumbs(:autoroot => true, :show_root_alone => false).each_with_index do |crumb, index| %>
    <% if index > 0 %> &gt;<% end %>
    <% if crumb.current? %>
      <span class="current"><%= crumb.text %></span>
    <% else %>
      <%= link_to crumb.text, crumb.url %>
    <% end %>
  <% end %>

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

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

Options for <code><%= breadcrumb %></code>:

  :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_current     Whether the current crumb should be linked to. Default: false


== Todo's

* Do it so that you in your development environment can update breadcrumbs without having to restart the server – can anybody help me fix this?
{'fraction_non_alphanumeric': 0.1012970969734404, 'fraction_numerical': 0.00030883261272390367, 'mean_word_length': 2.6023359288097887, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3565194', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1906, 'n_words': 632}