Module: ExpressAdmin::Components::Presenters::Helper
- Included in:
- DefinitionList, SmartTable, SmartTable::Column
- Defined in:
- app/components/express_admin/helpers/presenters_helper.rb
Constant Summary collapse
- COLUMN_REGEX_LIST =
{ link: /(\w+)_link$/, checkmark: /(\w+)_checkmark/, in_words: /(\w+)_in_words/ }
Instance Method Summary collapse
- #accessor_match(accessor, regex) ⇒ Object
- #checkmark(accessor) ⇒ Object
- #checkmark?(accessor) ⇒ Boolean
- #link(accessor) ⇒ Object
- #link?(accessor) ⇒ Boolean
- #make_checkmark(item, accessor) ⇒ Object
- #make_in_words(item, accessor) ⇒ Object
- #make_link(item, accessor) ⇒ Object
- #words(accessor) ⇒ Object
- #words?(accessor) ⇒ Boolean
Instance Method Details
#accessor_match(accessor, regex) ⇒ Object
23 24 25 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 23 def accessor_match(accessor, regex) accessor.to_s.match(regex).try(:[], 1) end |
#checkmark(accessor) ⇒ Object
15 16 17 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 15 def checkmark(accessor) accessor_match(accessor, COLUMN_REGEX_LIST[:checkmark]) end |
#checkmark?(accessor) ⇒ Boolean
31 32 33 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 31 def checkmark?(accessor) checkmark(accessor).present? end |
#link(accessor) ⇒ Object
11 12 13 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 11 def link(accessor) accessor_match(accessor, COLUMN_REGEX_LIST[:link]) end |
#link?(accessor) ⇒ Boolean
27 28 29 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 27 def link?(accessor) link(accessor).present? end |
#make_checkmark(item, accessor) ⇒ Object
47 48 49 50 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 47 def make_checkmark(item, accessor) attrib = checkmark(accessor) "<i class='ion-checkmark-round'></i>".html_safe if item.send(attrib) end |
#make_in_words(item, accessor) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 52 def make_in_words(item, accessor) attrib = words(accessor) if item.send(attrib) if item.send(attrib) < DateTime.now "#{helpers.time_ago_in_words(item.send(attrib))} ago" else "in #{helpers.time_ago_in_words(item.send(attrib))}" end else 'never' end end |
#make_link(item, accessor) ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 39 def make_link(item, accessor) # TODO: only works with non-namespaced routes attrib = link(accessor) if item.send(attrib).present? helpers.link_to item.send(attrib), resource_path(item) end end |
#words(accessor) ⇒ Object
19 20 21 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 19 def words(accessor) accessor_match(accessor, COLUMN_REGEX_LIST[:in_words]) end |
#words?(accessor) ⇒ Boolean
35 36 37 |
# File 'app/components/express_admin/helpers/presenters_helper.rb', line 35 def words?(accessor) words(accessor).present? end |