Class: Arclight::BreadcrumbComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/arclight/breadcrumb_component.rb

Overview

Display the document hierarchy as “breadcrumbs”

Instance Method Summary collapse

Constructor Details

#initialize(document:, count: nil, offset: 0) ⇒ BreadcrumbComponent

Returns a new instance of BreadcrumbComponent.

Parameters:

  • count (Integer) (defaults to: nil)

    if provided the number of bookmarks is limited to this number



7
8
9
10
11
12
# File 'app/components/arclight/breadcrumb_component.rb', line 7

def initialize(document:, count: nil, offset: 0)
  @document = document
  @count = count
  @offset = offset
  super
end

Instance Method Details



36
37
38
# File 'app/components/arclight/breadcrumb_component.rb', line 36

def build_repository_link
  render Arclight::RepositoryBreadcrumbComponent.new(document: @document)
end

#callObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/arclight/breadcrumb_component.rb', line 14

def call
  breadcrumb_links = components.drop(@offset)

  if @count && breadcrumb_links.length > @count
    breadcrumb_links = breadcrumb_links.first(@count)
    breadcrumb_links << tag.li('&hellip;'.html_safe, class: 'breadcrumb-item')
  end
  tag.ol class: 'breadcrumb' do
    safe_join(breadcrumb_links)
  end
end

#components {|build_repository_link| ... } ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'app/components/arclight/breadcrumb_component.rb', line 26

def components
  return to_enum(:components) unless block_given?

  yield build_repository_link

  @document.parents.each do |parent|
    yield tag.li(class: 'breadcrumb-item') { link_to(parent.label, solr_document_path(parent.id)) }
  end
end