Class: ExpressAdmin::Components::Presenters::DefinitionList
- Inherits:
-
ExpressTemplates::Components::Configurable
- Object
- ExpressTemplates::Components::Configurable
- ExpressAdmin::Components::Presenters::DefinitionList
- Includes:
- ExpressTemplates::Components::Capabilities::Resourceful
- Defined in:
- app/components/express_admin/definition_list.rb
Direct Known Subclasses
Constant Summary collapse
- COLUMN_REGEX_LIST =
{ in_words: /(\w+)_in_words/ }
Instance Method Summary collapse
- #definitions ⇒ Object
- #definitions_from_array(fields) ⇒ Object
- #definitions_from_hash(hash) ⇒ Object
Instance Method Details
#definitions ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/components/express_admin/definition_list.rb', line 28 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
61 62 63 |
# File 'app/components/express_admin/definition_list.rb', line 61 def definitions_from_array(fields) Hash[fields.map {|field| ["#{field.to_s.titleize}:", "{{resource.#{field}}}"]}] end |
#definitions_from_hash(hash) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/components/express_admin/definition_list.rb', line 36 def definitions_from_hash(hash) processed = hash.map do |k,v| value = if attrib = v.to_s.match(COLUMN_REGEX_LIST[:in_words]).try(:[], 1) if resource.send(attrib) if resource.send(attrib) < DateTime.now "#{helpers.time_ago_in_words(resource.send(attrib))} ago" else "in #{helpers.time_ago_in_words(resource.send(attrib))}" end else 'never' end 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 |