Class: ModsDisplay::NestedRelatedItem
- Includes:
- RelatedItemConcerns
- Defined in:
- lib/mods_display/fields/nested_related_item.rb
Overview
This class will hopefully take over for related item support more broadly. Currently there is behavior in RelatedItem and Collection that would need to be accounted for when adding nested metadata support.
Defined Under Namespace
Classes: ValueRenderer
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize(related_item_elements, value_renderer: ValueRenderer) ⇒ NestedRelatedItem
constructor
A new instance of NestedRelatedItem.
-
#to_html(view_context = ApplicationController.renderer) ⇒ Object
Used by exhibits.
Methods inherited from Field
Constructor Details
#initialize(related_item_elements, value_renderer: ValueRenderer) ⇒ NestedRelatedItem
Returns a new instance of NestedRelatedItem.
11 12 13 14 |
# File 'lib/mods_display/fields/nested_related_item.rb', line 11 def initialize(, value_renderer: ValueRenderer) super() @value_renderer = value_renderer end |
Instance Method Details
#fields ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mods_display/fields/nested_related_item.rb', line 16 def fields @fields ||= begin return_fields = RelatedItemValue.for_stanford_mods_elements(@stanford_mods_elements).map do || next if .collection? next unless () = @value_renderer.new().render ModsDisplay::Values.new( label: (), values: [] ) end.compact collapse_fields(return_fields) end end |
#to_html(view_context = ApplicationController.renderer) ⇒ Object
Used by exhibits
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mods_display/fields/nested_related_item.rb', line 34 def to_html(view_context = ApplicationController.renderer) helpers = view_context.respond_to?(:simple_format) ? view_context : ApplicationController.new.view_context component = ModsDisplay::ListFieldComponent.with_collection( fields, value_transformer: ->(value) { helpers.format_mods_html(value.to_s) }, list_html_attributes: { class: 'mods_display_nested_related_items' }, list_item_html_attributes: { class: 'mods_display_nested_related_item open' } ) view_context.render component, layout: false end |