Class: Dbla::DocumentPresenter

Inherits:
Blacklight::DocumentPresenter
  • Object
show all
Extended by:
Deprecation
Includes:
ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper
Defined in:
lib/dbla/document_presenter.rb

Constant Summary collapse

DESCRIPTIVE_METADATA_KEY =
'sourceResource'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(document, controller, configuration = controller.blacklight_config) ⇒ DocumentPresenter

Returns a new instance of DocumentPresenter.

Parameters:

  • document (Item or Collection)
  • controller (ActionController::Base)

    scope for linking and generating urls

  • configuration (Blacklight::Configuration) (defaults to: controller.blacklight_config)


12
13
14
15
16
# File 'lib/dbla/document_presenter.rb', line 12

def initialize(document, controller, configuration = controller.blacklight_config)
  @document = document
  @configuration = configuration
  @controller = controller
end

Instance Method Details

#document_headingString

Get the value of the document’s “title” field, or a placeholder value (if empty)

Parameters:

  • document (SolrDocument)

Returns:

  • (String)


26
27
28
# File 'lib/dbla/document_presenter.rb', line 26

def document_heading
  source_resource_title
end

#document_show_html_titleString

Get the document’s “title” to display in the <title> element. (by default, use the #document_heading)

Returns:

  • (String)

See Also:



35
36
37
# File 'lib/dbla/document_presenter.rb', line 35

def document_show_html_title
  source_resource_title
end

#field_value_separatorString

Default separator to use in #render_field_value

Returns:

  • (String)


104
105
106
# File 'lib/dbla/document_presenter.rb', line 104

def field_value_separator
  ', '
end

#get_field_values(field, field_config, options = {}) ⇒ Object

Get the value for a document’s field, and prepare to render it.

  • highlight_field

  • accessor

  • solr field

Rendering:

- helper_method
- link_to_search

TODO : maybe this should be merged with render_field_value, and the ugly signature simplified by pushing some of this logic into the “model”

Parameters:

  • document (SolrDocument)
  • field (String)

    name

  • solr (Blacklight::Solr::Configuration::Field)

    field configuration

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

    additional options to pass to the rendering helpers



96
97
98
# File 'lib/dbla/document_presenter.rb', line 96

def get_field_values field, field_config, options = {}
    super
end

#render_document_index_label(field, opts = {}) ⇒ Object

Render the document index heading

Parameters:

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

    (Deprecated)

  • field (Symbol, Proc, String)

    Render the given field or evaluate the proc or render the given string

Options Hash (opts):

  • :label (Symbol)

    Render the given field from the document

  • :label (Proc)

    Evaluate the given proc

  • :label (String)

    Render the given string



55
56
57
# File 'lib/dbla/document_presenter.rb', line 55

def render_document_index_label field, opts ={}
  super
end

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

Render the show field value for a document

Allow an extention point where information in the document
may drive the value of the field
@param [String] field
@param [Hash] options
@options opts [String] :value


77
78
79
# File 'lib/dbla/document_presenter.rb', line 77

def render_document_show_field_value field, options={}
    super
end

#render_field_value(value = nil, field_config = nil) ⇒ String

Render a value (or array of values) from a field

Parameters:

  • value (String) (defaults to: nil)

    or list of values to display

  • solr (Blacklight::Solr::Configuration::Field)

    field configuration

Returns:

  • (String)


44
45
46
# File 'lib/dbla/document_presenter.rb', line 44

def render_field_value value=nil, field_config=nil
    super
end

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

Render the index field label for a document

Allow an extention point where information in the document
may drive the value of the field
@param [String] field
@param [Hash] opts
@options opts [String] :value


66
67
68
# File 'lib/dbla/document_presenter.rb', line 66

def render_index_field_value field, options = {}
    super
end

#source_resource_titleObject



17
18
19
# File 'lib/dbla/document_presenter.rb', line 17

def source_resource_title
  @document[DESCRIPTIVE_METADATA_KEY] ? (@document[DESCRIPTIVE_METADATA_KEY]['title'] || @document['id']) : @document['id']
end