Class: Blacklight::Configuration::Field

Inherits:
OpenStructWithHashAccess show all
Defined in:
lib/blacklight/configuration/field.rb

Direct Known Subclasses

DisplayField, FacetField, NullField, SearchField, SortField

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OpenStructWithHashAccess

#deep_dup, #deep_transform_values, #merge, #merge!, #reverse_merge, #select, #sort_by, #sort_by!, #to_h, #try

Instance Attribute Details

#fieldString

Returns the field name in the search response data from Solr.

Returns:

  • (String)

    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

#ifProc, 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.

Returns:

  • (Proc, Symbol)

    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

#keyString

Returns the field name as used in the application + user-facing HTML.

Returns:

  • (String)

    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

#labelString, Symbol

Returns the label or i18n key to use for labeling data from this field.

Returns:

  • (String, Symbol)

    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

#unlessProc, 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.

Returns:

  • (Proc, Symbol)

    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_labelObject



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, **options)
  field_label(
    (:"blacklight.search.fields.#{context}.#{key}" if context),
    :"blacklight.search.fields.#{key}",
    label,
    default_label,
    **options
  )
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

Raises:

  • (ArgumentError)


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