Class: Blacklight::Facets::ItemComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/facets/item_component.rb

Direct Known Subclasses

Blacklight::FacetItemComponent

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

reset_compiler!, sidecar_files, upstream_sidecar_files

Constructor Details

#initialize(facet_item:, wrapping_element: 'li', suppress_link: false) ⇒ ItemComponent

Returns a new instance of ItemComponent.



10
11
12
13
14
15
16
17
18
# File 'app/components/blacklight/facets/item_component.rb', line 10

def initialize(facet_item:, wrapping_element: 'li', suppress_link: false)
  @facet_item = facet_item
  @label = facet_item.label
  @hits = facet_item.hits
  @href = facet_item.href
  @selected = facet_item.selected?
  @wrapping_element = wrapping_element
  @suppress_link = suppress_link
end

Instance Attribute Details

#hitsObject (readonly)

Returns the value of attribute hits.



6
7
8
# File 'app/components/blacklight/facets/item_component.rb', line 6

def hits
  @hits
end

#hrefObject (readonly)

Returns the value of attribute href.



6
7
8
# File 'app/components/blacklight/facets/item_component.rb', line 6

def href
  @href
end

#labelObject (readonly)

Returns the value of attribute label.



6
7
8
# File 'app/components/blacklight/facets/item_component.rb', line 6

def label
  @label
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/blacklight/facets/item_component.rb', line 20

def call
  # if the downstream app has overridden the helper methods we'd usually call,
  # use the helpers to preserve compatibility
  content = if @selected
              render_selected_facet_value
            else
              render_facet_value
            end

  return '' if content.blank?
  return content unless @wrapping_element

   @wrapping_element, content
end

#render_facet_count(options = {}) ⇒ String

Renders a count value for facet limits. Can be over-ridden locally to change style. And can be called by plugins to get consistent display.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • an (Array<String>)

    array of classes to add to count span.

Returns:

  • (String)


66
67
68
69
70
# File 'app/components/blacklight/facets/item_component.rb', line 66

def render_facet_count(options = {})
  classes = (options[:classes] || []) << "facet-count"

  render Blacklight::Facets::CountComponent.new(hits: hits, classes: classes)
end

#render_facet_valueString

Standard display of a facet value in a list. Used in both _facets sidebar partial and catalog/facet expanded list. Will output facet value name as a link to add that to your restrictions, with count in parens.

Returns:

  • (String)


42
43
44
45
46
# File 'app/components/blacklight/facets/item_component.rb', line 42

def render_facet_value
  tag.span(class: "facet-label") do
    link_to_unless(@suppress_link, label, href, class: "facet-select", rel: "nofollow")
  end + render_facet_count
end

#render_selected_facet_valueObject

Standard display of a SELECTED facet value (e.g. without a link and with a remove button)



53
54
55
56
# File 'app/components/blacklight/facets/item_component.rb', line 53

def render_selected_facet_value
  concat render(Blacklight::Facets::SelectedValueComponent.new(label: label, href: href))
  concat render_facet_count(classes: ["selected"])
end