Class: Blacklight::DocumentPresenter
- Inherits:
-
Object
- Object
- Blacklight::DocumentPresenter
- Defined in:
- app/presenters/blacklight/document_presenter.rb
Overview
An abstract class that the view presenters for SolrDocuments descend from
Direct Known Subclasses
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #display_type(base_name = nil, default: nil) ⇒ Object
- #field_presenters ⇒ Object
-
#field_value(field_config, options = {}) ⇒ Object
Render the field label for a document.
-
#fields_to_render ⇒ Hash<String,Configuration::Field>
All the fields for this index view that should be rendered.
-
#heading ⇒ String
Get the value of the document's “title” field, or a placeholder value (if empty).
-
#html_title ⇒ String
Get the document's “title” to display in the <title> element.
-
#initialize(document, view_context, configuration = view_context.blacklight_config) ⇒ DocumentPresenter
constructor
A new instance of DocumentPresenter.
- #inspect ⇒ Object
-
#link_rel_alternates(options = {}) ⇒ Object
Create <link rel=“alternate”> links from a documents dynamically provided export formats.
- #show_view_config ⇒ Object
- #thumbnail ⇒ Object
- #thumbnail_presenter_class ⇒ Object
- #view_config ⇒ Object
Constructor Details
#initialize(document, view_context, configuration = view_context.blacklight_config) ⇒ DocumentPresenter
Returns a new instance of DocumentPresenter.
14 15 16 17 18 |
# File 'app/presenters/blacklight/document_presenter.rb', line 14 def initialize(document, view_context, configuration = view_context.blacklight_config) @document = document @view_context = view_context @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'app/presenters/blacklight/document_presenter.rb', line 6 def configuration @configuration end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
6 7 8 |
# File 'app/presenters/blacklight/document_presenter.rb', line 6 def document @document end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
6 7 8 |
# File 'app/presenters/blacklight/document_presenter.rb', line 6 def view_context @view_context end |
Instance Method Details
#display_type(base_name = nil, default: nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/presenters/blacklight/document_presenter.rb', line 70 def display_type(base_name = nil, default: nil) fields = [] fields += Array.wrap(view_config[:"#{base_name}_display_type_field"]) if base_name && view_config.key?(:"#{base_name}_display_type_field") fields += Array.wrap(view_config.display_type_field) if fields.empty? && show_view_config != view_config fields += Array.wrap(show_view_config[:"#{base_name}_display_type_field"]) if base_name && show_view_config.key?(:"#{base_name}_display_type_field") fields += Array.wrap(show_view_config.display_type_field) end fields += ['format'] if fields.empty? # backwards compatibility with the old default value for display_type_field display_type = fields.lazy.map { |field| field_presenter(display_fields[field] || Configuration::NullDisplayField.new(field)) }.detect(&:any?)&.values display_type || Array(default) end |
#field_presenters ⇒ Object
33 34 35 36 37 |
# File 'app/presenters/blacklight/document_presenter.rb', line 33 def field_presenters return to_enum(:field_presenters) unless block_given? fields_to_render.each { |_, _, config| yield config } end |
#field_value(field_config, options = {}) ⇒ Object
Render the field label for a document
Allow an extention point where information in the document may drive the value of the field
94 95 96 |
# File 'app/presenters/blacklight/document_presenter.rb', line 94 def field_value field_config, = {} field_presenter(field_config, ).render end |
#fields_to_render ⇒ Hash<String,Configuration::Field>
Returns all the fields for this index view that should be rendered.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/presenters/blacklight/document_presenter.rb', line 21 def fields_to_render return to_enum(:fields_to_render) unless block_given? fields.each do |name, field_config| field_presenter = field_presenter(field_config) next unless field_presenter.render_field? && field_presenter.any? yield name, field_config, field_presenter end end |
#heading ⇒ String
Get the value of the document's “title” field, or a placeholder value (if empty)
44 45 46 47 48 49 50 |
# File 'app/presenters/blacklight/document_presenter.rb', line 44 def heading return field_value(view_config.title_field) if view_config.title_field.is_a? Blacklight::Configuration::Field fields = Array.wrap(view_config.title_field) + [configuration.document_model.unique_key] f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| field_presenter(field_config).any? } f ? field_value(f, except_operations: [Rendering::HelperMethod]) : "" end |
#html_title ⇒ String
Get the document's “title” to display in the <title> element. (by default, use the #document_heading)
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/presenters/blacklight/document_presenter.rb', line 58 def html_title return field_value(view_config.html_title_field) if view_config.html_title_field.is_a? Blacklight::Configuration::Field if view_config.html_title_field fields = Array.wrap(view_config.html_title_field) + [configuration.document_model.unique_key] f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| field_presenter(field_config).any? } field_value(f) else heading end end |
#inspect ⇒ Object
126 127 128 129 |
# File 'app/presenters/blacklight/document_presenter.rb', line 126 def inspect fields = "document:#{document.inspect}" "#<#{self.class.name}:#{object_id} #{fields}>" end |
#link_rel_alternates(options = {}) ⇒ Object
Create <link rel=“alternate”> links from a documents dynamically provided export formats. Returns empty string if no links available.
114 115 116 |
# File 'app/presenters/blacklight/document_presenter.rb', line 114 def link_rel_alternates( = {}) LinkAlternatePresenter.new(view_context, document, ).render end |
#show_view_config ⇒ Object
122 123 124 |
# File 'app/presenters/blacklight/document_presenter.rb', line 122 def show_view_config configuration.view_config(:show) end |
#thumbnail ⇒ Object
102 103 104 |
# File 'app/presenters/blacklight/document_presenter.rb', line 102 def thumbnail @thumbnail ||= thumbnail_presenter_class.new(document, view_context, view_config) end |
#thumbnail_presenter_class ⇒ Object
98 99 100 |
# File 'app/presenters/blacklight/document_presenter.rb', line 98 def thumbnail_presenter_class view_config.thumbnail_presenter || thumbnail_presenter end |
#view_config ⇒ Object
118 119 120 |
# File 'app/presenters/blacklight/document_presenter.rb', line 118 def view_config show_view_config end |