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.

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



65
66
67
# File 'app/presenters/blacklight/field_presenter.rb', line 65

def any?
  values.present?
end

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



50
51
52
# File 'app/presenters/blacklight/field_presenter.rb', line 50

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

#renderArray<String>



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

def render
  Array.wrap(
    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



57
58
59
# File 'app/presenters/blacklight/field_presenter.rb', line 57

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

#valuesEnumerable



44
45
46
# File 'app/presenters/blacklight/field_presenter.rb', line 44

def values
  @values ||= retrieve_values
end