Class: ExpressAdmin::Components::Presenters::DefinitionList

Inherits:
ExpressTemplates::Components::Configurable
  • Object
show all
Includes:
Helper, ExpressTemplates::Components::Capabilities::Resourceful
Defined in:
app/components/express_admin/definition_list.rb

Direct Known Subclasses

DefinitionTable

Constant Summary

Constants included from Helper

Helper::COLUMN_REGEX_LIST

Instance Method Summary collapse

Methods included from Helper

#accessor_match, #checkmark, #checkmark?, #link, #link?, #make_checkmark, #make_in_words, #make_link, #words, #words?

Instance Method Details

#definitionsObject



25
26
27
28
29
30
31
# File 'app/components/express_admin/definition_list.rb', line 25

def definitions
  if config[:list].kind_of?(Array)
    definitions_from_array(config[:list])
  elsif config[:list].kind_of?(Hash)
    definitions_from_hash(config[:list])
  end
end

#definitions_from_array(fields) ⇒ Object



50
51
52
# File 'app/components/express_admin/definition_list.rb', line 50

def definitions_from_array(fields)
  Hash[fields.map {|field| ["#{field.to_s.titleize}:", "{{resource.#{field}}}"]}]
end

#definitions_from_hash(hash) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/components/express_admin/definition_list.rb', line 33

def definitions_from_hash(hash)
  processed = hash.map do |k,v|
    value =
      if words?(v)
        make_in_words(resource, v)
      elsif v.kind_of? Symbol
        resource.send(v)
      elsif v.respond_to?(:call)
        v.call(resource).to_s.html_safe
      else
        v
      end
    [promptify(k), value]
  end
  Hash[processed]
end