Class: Blacklight::Configuration::Field
- Inherits:
-
OpenStructWithHashAccess
- Object
- OpenStruct
- OpenStructWithHashAccess
- Blacklight::Configuration::Field
- Defined in:
- lib/blacklight/configuration/field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#field ⇒ String
The field name in the search response data from Solr.
-
#if ⇒ Proc, Symbol
A proc or the symbol name of a helper to test whether the field should be rendered.
-
#key ⇒ String
The field name as used in the application + user-facing HTML.
-
#label ⇒ String, Symbol
The label or i18n key to use for labeling data from this field.
-
#unless ⇒ Proc, Symbol
A proc or the symbol name of a helper to test whether the field should not be rendered.
Instance Method Summary collapse
- #default_label ⇒ Object
- #display_label(context = nil, **options) ⇒ Object
- #normalize!(_blacklight_config = nil) ⇒ Object
- #validate! ⇒ Object
Methods inherited from OpenStructWithHashAccess
#deep_dup, #merge, #merge!, #reverse_merge, #select, #sort_by, #sort_by!, #to_h
Instance Attribute Details
#field ⇒ String
Returns the field name in the search response data from Solr.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blacklight/configuration/field.rb', line 17 def normalize! _blacklight_config = nil self.field ||= key self.key ||= field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= field.to_s self end |
#if ⇒ Proc, Symbol
Returns a proc or the symbol name of a helper to test whether the field should be rendered. The helper or proc will receive this field configuration object as the first parameter. See Blacklight::Configuration::Context.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blacklight/configuration/field.rb', line 17 def normalize! _blacklight_config = nil self.field ||= key self.key ||= field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= field.to_s self end |
#key ⇒ String
Returns the field name as used in the application + user-facing HTML.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blacklight/configuration/field.rb', line 17 def normalize! _blacklight_config = nil self.field ||= key self.key ||= field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= field.to_s self end |
#label ⇒ String, Symbol
Returns the label or i18n key to use for labeling data from this field.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blacklight/configuration/field.rb', line 17 def normalize! _blacklight_config = nil self.field ||= key self.key ||= field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= field.to_s self end |
#unless ⇒ Proc, Symbol
Returns a proc or the symbol name of a helper to test whether the field should not be rendered. The helper or proc will receive this field configuration object as the first parameter. See Blacklight::Configuration::Context.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blacklight/configuration/field.rb', line 17 def normalize! _blacklight_config = nil self.field ||= key self.key ||= field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= field.to_s self end |
Instance Method Details
#default_label ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/blacklight/configuration/field.rb', line 45 def default_label if key.respond_to?(:titleize) key.titleize else key.to_s.titleize end end |
#display_label(context = nil, **options) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/blacklight/configuration/field.rb', line 35 def display_label(context = nil, **) field_label( (:"blacklight.search.fields.#{context}.#{key}" if context), :"blacklight.search.fields.#{key}", label, default_label, ** ) end |
#normalize!(_blacklight_config = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blacklight/configuration/field.rb', line 17 def normalize! _blacklight_config = nil self.field ||= key self.key ||= field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= field.to_s self end |
#validate! ⇒ Object
31 32 33 |
# File 'lib/blacklight/configuration/field.rb', line 31 def validate! raise ArgumentError, "Must supply a field name" if field.nil? end |