Class: Blacklight::IndexPresenter

Inherits:
Object
  • Object
show all
Extended by:
Deprecation
Defined in:
app/presenters/blacklight/index_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, view_context, configuration = view_context.blacklight_config) ⇒ IndexPresenter

Returns a new instance of IndexPresenter.

Parameters:

  • document (SolrDocument)
  • view_context (ActionView::Base)

    scope for linking and generating urls

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


12
13
14
15
16
# File 'app/presenters/blacklight/index_presenter.rb', line 12

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

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



7
8
9
# File 'app/presenters/blacklight/index_presenter.rb', line 7

def configuration
  @configuration
end

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'app/presenters/blacklight/index_presenter.rb', line 7

def document
  @document
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



7
8
9
# File 'app/presenters/blacklight/index_presenter.rb', line 7

def view_context
  @view_context
end

Instance Method Details

#field_value(field_or_name, 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

Parameters:

Options Hash (options):

  • :value (String)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/presenters/blacklight/index_presenter.rb', line 54

def field_value field_or_name, options = {}
  field = case field_or_name
          when Blacklight::Configuration::Field
            field_or_name
          when String, Symbol
            Deprecation.warn(self, "You provided a #{field_or_name.class} value to IndexPresenter#field_value " \
            "Provide a Blacklight::Configuration::Field instead. This behavior is deprecated in Blacklight 7")
            field_config(field_or_name)
          else
            Deprecation.warn(self, "You provided a #{field_or_name.class} value to IndexPresenter#field_value. " \
            "This will be silently ignored and will be an error in Blacklight 7.")

            Configuration::NullField.new
          end
  field_values(field, options)
end

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

Deprecated.


78
79
80
# File 'app/presenters/blacklight/index_presenter.rb', line 78

def get_field_values(field_config, options={})
  field_values(field_config, options)
end

#label(field_or_string_or_proc, opts = {}) ⇒ Object

Render the document index heading

TODO: the default field should be `document_show_link_field(doc)'

Parameters:

  • field_or_string_or_proc (Symbol, Proc, String)

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

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


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/presenters/blacklight/index_presenter.rb', line 24

def label(field_or_string_or_proc, opts = {})
  config = Configuration::NullField.new
  value = case field_or_string_or_proc
  when Symbol
    config = field_config(field_or_string_or_proc)
    document[field_or_string_or_proc]
  when Proc
    field_or_string_or_proc.call(document, opts)
  when String
    field_or_string_or_proc
  end

  value ||= document.id
  field_values(config, value: value)
end

#render_document_index_label(*args) ⇒ Object

Deprecated.


41
42
43
# File 'app/presenters/blacklight/index_presenter.rb', line 41

def render_document_index_label(*args)
  label(*args)
end

#render_field_values(values, field_config = Configuration::NullField.new) ⇒ Object

Deprecated.


84
85
86
# File 'app/presenters/blacklight/index_presenter.rb', line 84

def render_field_values(values, field_config = Configuration::NullField.new)
  field_values(field_config, value: Array(values))
end

#render_index_field_value(*args) ⇒ Object

Deprecated.


72
73
74
# File 'app/presenters/blacklight/index_presenter.rb', line 72

def render_index_field_value(*args)
  field_value(*args)
end

#render_values(values, field_config = Configuration::NullField.new) ⇒ Object

Deprecated.


90
91
92
# File 'app/presenters/blacklight/index_presenter.rb', line 90

def render_values(values, field_config = Configuration::NullField.new)
  field_values(field_config, value: Array(values))
end