Class: BootstrapBreadcrumbsBuilder

Inherits:
BreadcrumbsOnRails::Breadcrumbs::Builder
  • Object
show all
Defined in:
lib/bootstrap_breadcrumbs_builder.rb

Overview

CREDIT: gist.github.com/1933884

The BootstrapBreadcrumbsBuilder is a Bootstrap compatible breadcrumb builder. It provides basic functionalities to render a breadcrumb navigation according to Bootstrap’s conventions.

BootstrapBreadcrumbsBuilder accepts a limited set of options:

  • separator: what should be displayed as a separator between elements

You can use it with the :builder option on render_breadcrumbs:

<%= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder, :separator => "&raquo;" %>

Note: You may need to adjust the autoload_paths in your config/application.rb file for rails to load this class:

config.autoload_paths += Dir["#{config.root}/lib/"]

Instance Method Summary collapse

Instance Method Details

#renderObject



16
17
18
19
20
21
22
# File 'lib/bootstrap_breadcrumbs_builder.rb', line 16

def render
  @context.(:ul, class: 'breadcrumb') do
    @elements.collect do |element|
      render_element(element)
    end.join.html_safe
  end
end

#render_element(element) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/bootstrap_breadcrumbs_builder.rb', line 24

def render_element(element)
  current = @context.current_page?(compute_path(element))

  @context.(:li, class: ('active' if current)) do
    link_or_text = @context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
    divider = @context.(:span, (@options[:separator]  || '/').html_safe, class: 'divider') unless current

    link_or_text + (divider || '')
  end
end