Module: Hyrax::PresentsAttributes

Included in:
CollectionPresenter, FileSetPresenter, WorkShowPresenter
Defined in:
app/presenters/hyrax/presents_attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute_to_html(field, options = {}) ⇒ Object

Present the attribute as an HTML table row or dl row.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :render_as (Symbol)

    use an alternate renderer (e.g., :linked or :linked_attribute to use LinkedAttributeRenderer)

  • :search_field (String)

    If the method_name of the attribute is different than how the attribute name should appear on the search URL, you can explicitly set the URL's search field name

  • :label (String)

    The default label for the field if no translation is found

  • :include_empty (TrueClass, FalseClass)

    should we display a row if there are no values?

  • :work_type (String)

    name of work type class (e.g., “GenericWork”)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/presenters/hyrax/presents_attributes.rb', line 15

def attribute_to_html(field, options = {})
  unless respond_to?(field)
    Rails.logger.warn("#{self.class} attempted to render #{field}, but no method exists with that name.")
    return
  end

  if options[:html_dl]
    renderer_for(field, options).new(field, send(field), options).render_dl_row
  else
    renderer_for(field, options).new(field, send(field), options).render
  end
end

#display_microdata?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/presenters/hyrax/presents_attributes.rb', line 36

def display_microdata?
  Hyrax.config.display_microdata?
end

#microdata_type_to_htmlObject


40
41
42
43
44
# File 'app/presenters/hyrax/presents_attributes.rb', line 40

def microdata_type_to_html
  return "" unless display_microdata?
  value = Microdata.fetch(microdata_type_key, default: Hyrax.config.microdata_default_type)
  " itemscope itemtype=\"#{value}\"".html_safe
end

#permission_badgeObject


28
29
30
# File 'app/presenters/hyrax/presents_attributes.rb', line 28

def permission_badge
  permission_badge_class.new(solr_document.visibility).render
end

#permission_badge_classObject


32
33
34
# File 'app/presenters/hyrax/presents_attributes.rb', line 32

def permission_badge_class
  PermissionBadge
end