Sha256: d0abe2530e7df69c64c4a5d0ebe3a1d1d4b4e36e223812468f83b60cd1d3f776

Contents?: true

Size: 1.23 KB

Versions: 29

Compression:

Stored size: 1.23 KB

Contents

# 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: Hyrax::BootstrapBreadcrumbsBuilder %>
#
class Hyrax::BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
  include ActionView::Helpers::OutputSafetyHelper
  def render
    return "" if @elements.blank?

    @context.content_tag(:nav, breadcrumbs_options) do
      @context.content_tag(:ol) do
        safe_join(@elements.uniq.collect { |e| render_element(e) })
      end
    end
  end

  def render_element(element)
    html_class = 'active' if @context.current_page?(compute_path(element)) || element.options["aria-current"] == "page"

    @context.content_tag(:li, class: html_class) do
      @context.link_to_unless(html_class == 'active', @context.truncate(compute_name(element), length: 30, separator: ' '), compute_path(element), element.options)
    end
  end

  def breadcrumbs_options
    { class: 'breadcrumb', role: "region", "aria-label" => "Breadcrumb" }
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.9.5 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.9.4 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.9.3 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.9.2 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.9.1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.9.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.8.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.7.2 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.7.1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.7.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.6.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.0.pre.rc1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.0.pre.beta3 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.5.1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.5.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.0.pre.beta2 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.4.1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.0.pre.beta1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-2.4.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb