Sha256: 6f806451ae65a60decf5f517fdcc4030d99edf9295a23565808fc70450b13016

Contents?: true

Size: 1.29 KB

Versions: 30

Compression:

Stored size: 1.29 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)
      current = @context.current_page?(compute_path(element)) || element.options&.dig(:current)

      html_class = 'active' if current

      @context.content_tag(: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

    private

    def element_label(element)
      @context.content_tag(:span) { compute_name(element) }
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
blacklight-spotlight-4.1.2 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-4.1.1 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-4.1.0 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-4.0.3 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-4.0.2 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-4.0.1 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-4.0.0 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta10 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta9 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta8 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.5.0.4 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta7 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.5.0.3 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta6 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta5 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta4 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta3 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.6.0.beta1 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.5.0.2 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
blacklight-spotlight-3.5.0.1 app/builders/spotlight/bootstrap_breadcrumbs_builder.rb