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, #deep_transform_values, #merge, #merge!, #reverse_merge, #select, #sort_by, #sort_by!, #to_h, #try
Instance Attribute Details
#field ⇒ String
Returns the field name in the search response data from Solr.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blacklight/configuration/field.rb', line 18 def normalize! _blacklight_config = nil self.field ||= key self.key ||= self.field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= self.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.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blacklight/configuration/field.rb', line 18 def normalize! _blacklight_config = nil self.field ||= key self.key ||= self.field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= self.field.to_s self end |
#key ⇒ String
Returns the field name as used in the application + user-facing HTML.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blacklight/configuration/field.rb', line 18 def normalize! _blacklight_config = nil self.field ||= key self.key ||= self.field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= self.field.to_s self end |
#label ⇒ String, Symbol
Returns the label or i18n key to use for labeling data from this field.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blacklight/configuration/field.rb', line 18 def normalize! _blacklight_config = nil self.field ||= key self.key ||= self.field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= self.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.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blacklight/configuration/field.rb', line 18 def normalize! _blacklight_config = nil self.field ||= key self.key ||= self.field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= self.field.to_s self end |
Instance Method Details
#default_label ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/blacklight/configuration/field.rb', line 46 def default_label if self.key.respond_to?(:titleize) self.key.titleize else self.key.to_s.titleize end end |
#display_label(context = nil, **options) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/blacklight/configuration/field.rb', line 36 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
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blacklight/configuration/field.rb', line 18 def normalize! _blacklight_config = nil self.field ||= key self.key ||= self.field self.label ||= default_label self.if = true if self.if.nil? self.unless = false if self.unless.nil? self.field &&= self.field.to_s self end |
#validate! ⇒ Object
32 33 34 |
# File 'lib/blacklight/configuration/field.rb', line 32 def validate! raise ArgumentError, "Must supply a field name" if self.field.nil? end |