Class: Dbla::DocumentPresenter

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

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)


10
11
12
13
14
# File 'lib/dbla/document_presenter.rb', line 10

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)


21
22
23
# File 'lib/dbla/document_presenter.rb', line 21

def document_heading
  @document['sourceResource']['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:



30
31
32
# File 'lib/dbla/document_presenter.rb', line 30

def document_show_html_title
  @document['sourceResource']['title']
end

#field_value_separatorString

Default separator to use in #render_field_value

Returns:

  • (String)


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

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
# File 'lib/dbla/document_presenter.rb', line 96

def get_field_values field, field_config, options = {}
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



49
50
51
52
53
54
55
56
57
58
# File 'lib/dbla/document_presenter.rb', line 49

def render_document_index_label field, opts ={}
  if Symbol === field
    # these are shenanigans to find a nested field
    field.to_s.split('/').inject(@document) {|m,v| m[v]}
  elsif Proc === field
    field.call
  else
    field
  end
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


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

def render_document_show_field_value field, options={}
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)


39
40
# File 'lib/dbla/document_presenter.rb', line 39

def render_field_value value=nil, field_config=nil
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


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

def render_index_field_value field, options = {}

end