Class: Blacklight::FieldPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/blacklight/field_presenter.rb

Overview

Renders a field and handles link_to_facet or helper_method if supplied

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_context, document, field_config, options = {}) ⇒ FieldPresenter

Returns a new instance of FieldPresenter.

Parameters:

  • view_context (Object)

    the context in which to execute helper methods

  • document (SolrDocument)

    the document

  • field_config (Blacklight::Configuration::Field)

    the field’s configuration

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

Options Hash (options):

  • :values (Object)
  • :except_operations (Array)
  • :value (Object)
  • :steps (Array)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/presenters/blacklight/field_presenter.rb', line 14

def initialize(view_context, document, field_config, options = {})
  @view_context = view_context
  @document = document
  @field_config = field_config
  @options = options

  @values = if options.key?(:value)
              Array.wrap(options[:value])
            else
              options[:values]
            end

  @except_operations = options[:except_operations] || []
  @except_operations += field_config.except_operations || []
  # Implicitly prevent helper methods from drawing when drawing the label for the document
  @except_operations += [Rendering::HelperMethod] if options.key? :value
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



32
33
34
# File 'app/presenters/blacklight/field_presenter.rb', line 32

def document
  @document
end

#except_operationsObject (readonly)

Returns the value of attribute except_operations.



32
33
34
# File 'app/presenters/blacklight/field_presenter.rb', line 32

def except_operations
  @except_operations
end

#field_configObject (readonly)

Returns the value of attribute field_config.



32
33
34
# File 'app/presenters/blacklight/field_presenter.rb', line 32

def field_config
  @field_config
end

#optionsObject (readonly)

Returns the value of attribute options.



32
33
34
# File 'app/presenters/blacklight/field_presenter.rb', line 32

def options
  @options
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



32
33
34
# File 'app/presenters/blacklight/field_presenter.rb', line 32

def view_context
  @view_context
end

Instance Method Details

#any?Boolean

Check if a document has (or, might have, in the case of accessor methods) a value for the given solr field

Returns:

  • (Boolean)


63
64
65
# File 'app/presenters/blacklight/field_presenter.rb', line 63

def any?
  values.present?
end

#label(context = nil, **options) ⇒ String

Parameters:

  • context (String) (defaults to: nil)

Returns:

  • (String)


48
49
50
# File 'app/presenters/blacklight/field_presenter.rb', line 48

def label(context = nil, **options)
  field_config.display_label(context || options.fetch(:context, 'index'), count: retrieve_values.count, **options)
end

#renderString

Returns:

  • (String)


37
38
39
# File 'app/presenters/blacklight/field_presenter.rb', line 37

def render
  Rendering::Pipeline.new(values, field_config, document, view_context, pipeline_steps, options).render
end

#render_field?Boolean

Check to see if the given field should be rendered in this context

Returns:

  • (Boolean)


55
56
57
# File 'app/presenters/blacklight/field_presenter.rb', line 55

def render_field?
  view_context.should_render_field?(field_config, document)
end

#valuesEnumerable

Returns:

  • (Enumerable)


42
43
44
# File 'app/presenters/blacklight/field_presenter.rb', line 42

def values
  @values ||= retrieve_values
end