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.
20 21 22 23 24 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 20 def initialize(field, values, = {}) @field = field @values = values = 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 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.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 65 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 27 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}") markup += Array(values).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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 44 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}") markup += Array(values).map do |value| "<li#{html_attributes(attributes)}>#{attribute_value_to_html(value.to_s)}</li>" end.join markup += %(</ul></dd>) markup.html_safe end |