Class: Spotlight::BootstrapBreadcrumbsBuilder

Inherits:
BreadcrumbsOnRails::Breadcrumbs::Builder
  • Object
show all
Includes:
ActionView::Helpers::OutputSafetyHelper
Defined in:
app/builders/spotlight/bootstrap_breadcrumbs_builder.rb

Overview

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:

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

<%= render_breadcrumbs :builder => Spotlight::BootstrapBreadcrumbsBuilder %>

Instance Method Summary collapse

Instance Method Details

#renderObject



15
16
17
18
19
20
21
# File 'app/builders/spotlight/bootstrap_breadcrumbs_builder.rb', line 15

def render
  return '' if @elements.blank?

  @context.(:ul, class: 'breadcrumb') do
    safe_join(@elements.uniq.map { |e| render_element(e) })
  end
end

#render_element(element) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'app/builders/spotlight/bootstrap_breadcrumbs_builder.rb', line 23

def render_element(element)
  current = @context.current_page?(compute_path(element)) || element.options&.dig(:current)

  html_class = 'active' if current

  @context.(:li, class: "breadcrumb-item truncated-value #{html_class}") do
    @context.link_to_unless(current, element_label(element), compute_path(element), element.options&.except(:current))
  end
end