Class: Blacklight::FacetItemComponent
- Extended by:
- Deprecation
- Defined in:
- app/components/blacklight/facet_item_component.rb
Instance Attribute Summary collapse
-
#hits ⇒ Object
readonly
Returns the value of attribute hits.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #call ⇒ Object
- #content_from_legacy_view_helper ⇒ Object deprecated Deprecated.
-
#initialize(facet_item:, wrapping_element: 'li', suppress_link: false) ⇒ FacetItemComponent
constructor
A new instance of FacetItemComponent.
- #overridden_helper_methods? ⇒ Boolean deprecated Deprecated.
-
#render_facet_count(options = {}) ⇒ String
Renders a count value for facet limits.
-
#render_facet_value ⇒ String
Standard display of a facet value in a list.
-
#render_selected_facet_value ⇒ Object
Standard display of a SELECTED facet value (e.g. without a link and with a remove button).
- #with_view_context(view_context) ⇒ Object deprecated Deprecated.
Methods inherited from Component
reset_compiler!, sidecar_files, upstream_sidecar_files
Constructor Details
#initialize(facet_item:, wrapping_element: 'li', suppress_link: false) ⇒ FacetItemComponent
Returns a new instance of FacetItemComponent.
11 12 13 14 15 16 17 18 19 |
# File 'app/components/blacklight/facet_item_component.rb', line 11 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
#hits ⇒ Object (readonly)
Returns the value of attribute hits.
7 8 9 |
# File 'app/components/blacklight/facet_item_component.rb', line 7 def hits @hits end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
7 8 9 |
# File 'app/components/blacklight/facet_item_component.rb', line 7 def href @href end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'app/components/blacklight/facet_item_component.rb', line 7 def label @label end |
Instance Method Details
#call ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/blacklight/facet_item_component.rb', line 21 def call # if the downstream app has overridden the helper methods we'd usually call, # use the helpers to preserve compatibility content = if overridden_helper_methods? content_from_legacy_view_helper elsif @selected render_selected_facet_value else render_facet_value end return '' if content.blank? return content unless @wrapping_element content_tag @wrapping_element, content end |
#content_from_legacy_view_helper ⇒ Object
Call out to the helper method equivalent of this component
61 62 63 64 65 66 |
# File 'app/components/blacklight/facet_item_component.rb', line 61 def content_from_legacy_view_helper Deprecation.warn(self.class, 'Calling out to the #render_facet_item helper for backwards compatibility.') Deprecation.silence(Blacklight::FacetsHelperBehavior) do @view_context.render_facet_item(@facet_item.facet_field, @facet_item.facet_item) end end |
#overridden_helper_methods? ⇒ Boolean
Check if the downstream application has overridden these methods
50 51 52 53 54 55 56 |
# File 'app/components/blacklight/facet_item_component.rb', line 50 def overridden_helper_methods? return false if explicit_component_configuration? helpers.method(:render_facet_item).owner != Blacklight::FacetsHelperBehavior || helpers.method(:render_facet_value).owner != Blacklight::FacetsHelperBehavior || helpers.method(:render_selected_facet_value).owner != Blacklight::FacetsHelperBehavior 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.
105 106 107 108 109 110 111 112 |
# File 'app/components/blacklight/facet_item_component.rb', line 105 def render_facet_count( = {}) return helpers.render_facet_count(hits, ) unless helpers.method(:render_facet_count).owner == Blacklight::FacetsHelperBehavior || explicit_component_configuration? return '' if hits.blank? classes = ([:classes] || []) << "facet-count" tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(hits)), class: classes) end |
#render_facet_value ⇒ String
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.
75 76 77 78 79 |
# File 'app/components/blacklight/facet_item_component.rb', line 75 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_value ⇒ Object
Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
86 87 88 89 90 91 92 93 94 95 |
# File 'app/components/blacklight/facet_item_component.rb', line 86 def render_selected_facet_value tag.span(class: "facet-label") do tag.span(label, class: "selected") + # remove link link_to(href, class: "remove", rel: "nofollow") do tag.span('✖', class: "remove-icon", aria: { hidden: true }) + tag.span(helpers.t(:'blacklight.search.facets.selected.remove'), class: 'sr-only visually-hidden') end end + render_facet_count(classes: ["selected"]) end |
#with_view_context(view_context) ⇒ Object
This is a little shim to let us call the render methods below outside the usual component rendering cycle (for backward compatibility)
42 43 44 45 |
# File 'app/components/blacklight/facet_item_component.rb', line 42 def with_view_context(view_context) @view_context = view_context self end |