Class: Hyrax::Renderers::AttributeRenderer
- Inherits:
-
Object
- Object
- Hyrax::Renderers::AttributeRenderer
- Includes:
- ActionView::Helpers::TextHelper, ActionView::Helpers::TranslationHelper, ActionView::Helpers::UrlHelper, ConfiguredMicrodata
- Defined in:
- app/renderers/hyrax/renderers/attribute_renderer.rb
Overview
Direct Known Subclasses
DateAttributeRenderer, ExternalLinkAttributeRenderer, FacetedAttributeRenderer, LicenseAttributeRenderer, LinkedAttributeRenderer, RightsStatementAttributeRenderer
Instance Attribute Summary collapse
- #field ⇒ Object readonly
- #options ⇒ Object readonly
- #values ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(field, values, options = {}) ⇒ AttributeRenderer
constructor
A new instance of AttributeRenderer.
-
#label ⇒ Object
Defaults to the label provided in the options, otherwise, it fallsback to the inner logic of the method.
-
#render ⇒ Object
Draw the table row for the attribute.
-
#render_dl_row ⇒ Object
Draw the dl row for the attribute.
Methods included from ConfiguredMicrodata
#microdata?, #microdata_object?, #microdata_object_attributes, #microdata_property, #microdata_type, #microdata_value_attributes
Constructor Details
#initialize(field, values, options = {}) ⇒ AttributeRenderer
Returns a new instance of AttributeRenderer.
22 23 24 25 26 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 22 def initialize(field, values, = {}) @field = field @values = values @options = end |
Instance Attribute Details
#field ⇒ Object (readonly)
12 13 14 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 12 def field @field end |
#options ⇒ Object (readonly)
12 13 14 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 12 def @options end |
#values ⇒ Object (readonly)
12 13 14 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 12 def values @values end |
Instance Method Details
#label ⇒ Object
This is a central location for determining the label of a field name. Can be overridden if more complicated logic is needed.
Defaults to the label provided in the options, otherwise, it fallsback to the inner logic of the method.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 73 def label if &.key?(:label) .fetch(:label) else translate( :"blacklight.search.fields.#{work_type_label_key}.show.#{field}", default: [:"blacklight.search.fields.show.#{field}", :"blacklight.search.fields.#{field}", field.to_s.humanize] ) end end |
#render ⇒ Object
Draw the table row for the attribute
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 29 def render return '' if values.blank? && ![:include_empty] markup = %(<tr><th>#{label}</th>\n<td><ul class='tabular'>) attributes = microdata_object_attributes(field).merge(class: "attribute attribute-#{field}") values_array = Array(values) values_array = values_array.sort if [:sort] markup += values_array.map do |value| "<li#{html_attributes(attributes)}>#{attribute_value_to_html(value.to_s)}</li>" end.join markup += %(</ul></td></tr>) markup.html_safe end |
#render_dl_row ⇒ Object
Draw the dl row for the attribute
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 49 def render_dl_row return '' if values.blank? && ![:include_empty] markup = %(<dt>#{label}</dt>\n<dd><ul class='tabular'>) attributes = microdata_object_attributes(field).merge(class: "attribute attribute-#{field}") values_array = Array(values) values_array.sort! if [:sort] markup += values_array.map do |value| "<li#{html_attributes(attributes)}>#{attribute_value_to_html(value.to_s)}</li>" end.join markup += %(</ul></dd>) markup.html_safe end |