Class: Hyrax::Renderers::AttributeRenderer

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TextHelper, ActionView::Helpers::TranslationHelper, ActionView::Helpers::UrlHelper, ConfiguredMicrodata
Defined in:
app/renderers/hyrax/renderers/attribute_renderer.rb

Overview

Since:

  • 0.14.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • field (Symbol)
  • values (Array)
  • options (Hash) (defaults to: {})

Since:

  • 0.14.0



16
17
18
19
20
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 16

def initialize(field, values, options = {})
  @field = field
  @values = values
  @options = options
end

Instance Attribute Details

#fieldObject (readonly)

Since:

  • 0.14.0



11
12
13
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 11

def field
  @field
end

#optionsObject (readonly)

Since:

  • 0.14.0



11
12
13
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 11

def options
  @options
end

#valuesObject (readonly)

Since:

  • 0.14.0



11
12
13
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 11

def values
  @values
end

Instance Method Details

#labelObject

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.

Returns:

  • The human-readable label for this field.

Since:

  • 0.14.0



39
40
41
42
43
44
45
46
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 39

def label
  translate(
    :"blacklight.search.fields.#{work_type_label_key}.show.#{field}",
    default: [:"blacklight.search.fields.show.#{field}",
              :"blacklight.search.fields.#{field}",
              options.fetch(:label, field.to_s.humanize)]
  )
end

#renderObject

Draw the table row for the attribute

Since:

  • 0.14.0



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/renderers/hyrax/renderers/attribute_renderer.rb', line 23

def render
  markup = ''

  return markup if values.blank? && !options[: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