Sha256: 5a3c89e2c1e95deff4b597f993d96352aa6a43272563783cb745478dde2f6214

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Spotlight
  # 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 %>
  #
  class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
    include ActionView::Helpers::OutputSafetyHelper

    def render
      return '' if @elements.blank?

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

    def render_element(element)
      html_class = 'active' if @context.current_page?(compute_path(element))

      @context.content_tag(:li, class: "breadcrumb-item #{html_class}") do
        @context.link_to_unless_current(element_label(element), compute_path(element), element.options)
      end
    end

    private

    def element_label(element)
      label = compute_name(element)
      @context.truncate(label, escape: !label.html_safe?, length: 30, separator: ' ')
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc2 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.rc1 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.10 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.9 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.8 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.7 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.6 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.5 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.4 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.3 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.2 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.0.0.alpha.1 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb