Sha256: 41da2a3d03021bc1a899b023526efc1547308b4a19d3ed54fd79e3ccd3d904a9

Contents?: true

Size: 1.23 KB

Versions: 18

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true
# 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.tag.nav(breadcrumbs_options) do
      @context.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.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: "navigation", "aria-label" => "Breadcrumb" }
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-4.0.0.rc2 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-4.0.0.rc1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.5.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-4.0.0.beta2 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.4.2 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-4.0.0.beta1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.4.1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.4.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.3.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.2.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.1.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.2 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.1 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.0 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.0.pre.rc4 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.0.pre.rc3 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb
hyrax-3.0.0.pre.rc2 app/builders/hyrax/bootstrap_breadcrumbs_builder.rb