Class: Blacklight::FieldPresenter
- Inherits:
-
Object
- Object
- Blacklight::FieldPresenter
- 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
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#except_operations ⇒ Object
readonly
Returns the value of attribute except_operations.
-
#field_config ⇒ Object
readonly
Returns the value of attribute field_config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
-
#any? ⇒ Boolean
Check if a document has (or, might have, in the case of accessor methods) a value for the given solr field.
-
#initialize(view_context, document, field_config, options = {}) ⇒ FieldPresenter
constructor
A new instance of FieldPresenter.
- #label(context = nil, **options) ⇒ String
- #render ⇒ String
-
#render_field? ⇒ Boolean
Check to see if the given field should be rendered in this context.
- #values ⇒ Enumerable
Constructor Details
#initialize(view_context, document, field_config, options = {}) ⇒ FieldPresenter
Returns a new instance of FieldPresenter.
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, = {}) @view_context = view_context @document = document @field_config = field_config @options = @values = if .key?(:value) Array.wrap([:value]) else [:values] end @except_operations = [: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 .key? :value end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
32 33 34 |
# File 'app/presenters/blacklight/field_presenter.rb', line 32 def document @document end |
#except_operations ⇒ Object (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_config ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'app/presenters/blacklight/field_presenter.rb', line 32 def @options end |
#view_context ⇒ Object (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
63 64 65 |
# File 'app/presenters/blacklight/field_presenter.rb', line 63 def any? values.present? end |
#label(context = nil, **options) ⇒ String
48 49 50 |
# File 'app/presenters/blacklight/field_presenter.rb', line 48 def label(context = nil, **) field_config.display_label(context || .fetch(:context, 'index'), count: retrieve_values.count, **) end |
#render ⇒ 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, ).render end |
#render_field? ⇒ Boolean
Check to see if the given field should be rendered in this context
55 56 57 |
# File 'app/presenters/blacklight/field_presenter.rb', line 55 def render_field? view_context.should_render_field?(field_config, document) end |
#values ⇒ Enumerable
42 43 44 |
# File 'app/presenters/blacklight/field_presenter.rb', line 42 def values @values ||= retrieve_values end |