Class: CurationConcerns::Renderers::AttributeRenderer
- Inherits:
-
Object
- Object
- CurationConcerns::Renderers::AttributeRenderer
- Includes:
- ActionView::Helpers::TextHelper, ActionView::Helpers::TranslationHelper, ActionView::Helpers::UrlHelper, ConfiguredMicrodata
- Defined in:
- app/renderers/curation_concerns/renderers/attribute_renderer.rb
Overview
Direct Known Subclasses
DateAttributeRenderer, ExternalLinkAttributeRenderer, FacetedAttributeRenderer, LinkedAttributeRenderer, RightsAttributeRenderer
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
The human-readable label for this field.
-
#render ⇒ Object
Draw the table 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.
16 17 18 19 20 |
# File 'app/renderers/curation_concerns/renderers/attribute_renderer.rb', line 16 def initialize(field, values, = {}) @field = field @values = values @options = end |
Instance Attribute Details
#field ⇒ Object (readonly)
11 12 13 |
# File 'app/renderers/curation_concerns/renderers/attribute_renderer.rb', line 11 def field @field end |
#options ⇒ Object (readonly)
11 12 13 |
# File 'app/renderers/curation_concerns/renderers/attribute_renderer.rb', line 11 def @options end |
#values ⇒ Object (readonly)
11 12 13 |
# File 'app/renderers/curation_concerns/renderers/attribute_renderer.rb', line 11 def values @values end |
Instance Method Details
#label ⇒ Object
Note:
This is a central location for determining the label of a field name. Can be overridden if more complicated logic is needed.
Returns The human-readable label for this field.
39 40 41 42 43 |
# File 'app/renderers/curation_concerns/renderers/attribute_renderer.rb', line 39 def label translate( :"blacklight.search.fields.show.#{field}", default: [:"blacklight.search.fields.#{field}", .fetch(:label, field.to_s.humanize)]) end |
#render ⇒ Object
Draw the table row for the attribute
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/renderers/curation_concerns/renderers/attribute_renderer.rb', line 23 def render markup = '' return markup if !values.present? && ![:include_empty] markup << %(<tr><th>#{label}</th>\n<td><ul class='tabular'>) attributes = microdata_object_attributes(field).merge(class: "attribute #{field}") Array(values).each do |value| markup << "<li#{html_attributes(attributes)}>#{attribute_value_to_html(value.to_s)}</li>" end markup << %(</ul></td></tr>) markup.html_safe end |