Class: ModsDisplay::Contents

Inherits:
Field
  • Object
show all
Defined in:
lib/mods_display/fields/contents.rb

Instance Method Summary collapse

Methods inherited from Field

#fields, #initialize, #label, #render_in

Constructor Details

This class inherits a constructor from ModsDisplay::Field

Instance Method Details

#to_html(view_context = ApplicationController.renderer) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mods_display/fields/contents.rb', line 5

def to_html(view_context = ApplicationController.renderer)
  f = fields.map do |field|
    ModsDisplay::Values.new(
      label: field.label,
      values: [field.values.join("\n\n")],
      field: self
    )
  end

  helpers = view_context.respond_to?(:simple_format) ? view_context : ApplicationController.new.view_context

  value_transformer = lambda do |value|
    text = ERB::Util.h(value.gsub('
', "\n"))
    helpers.simple_format(text, {}, sanitize: false)
  end

  component = ModsDisplay::FieldComponent.with_collection(f, value_transformer: value_transformer)

  view_context.render component, layout: false
end