Module: ApplicationHelper
- Includes:
- Pagy::Frontend
- Defined in:
- app/helpers/application_helper.rb
Overview
This helper contain the methods shared for all views
-
include Pagy::Frontend
Instance Method Summary collapse
-
#fas_icon(fa_style, span_style: nil, style: false, text: '', tooltip: false) ⇒ Object
make a div for the font-awesome icons.
-
#l_date(obj = nil) ⇒ String
Localize a DateTime with format :date if #obj is present.
-
#l_long(obj = nil) ⇒ String
Localize a DateTime with format :long if #obj is present.
-
#l_time(obj = nil) ⇒ String
Localize a DateTime with format :time if #obj is present.
-
#loader(url) ⇒ String
Write a content tag for load a remote page.
-
#notifications ⇒ Object
map of flash and rub notify() for each flash.
-
#notify(text, type: 'alert', timeout: 3000, hidden: true) ⇒ String
Make a div with for the notification.
-
#notify_status(status = {}) ⇒ Object
map of status and run notify() for each status.
-
#t_enum(list = {}, scope = '') ⇒ List
generate a list for a select from an enum.
-
#t_field(field_label = nil, obj = '') ⇒ String
Localize a fieldName if #obj is present.
Instance Method Details
#fas_icon(fa_style, span_style: nil, style: false, text: '', tooltip: false) ⇒ Object
make a div for the font-awesome icons
17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/application_helper.rb', line 17 def fas_icon(fa_style, span_style: nil, style: false, text: '', tooltip: false) content_tag_i = tag.i('', class: "fas fa-#{fa_style}", aria: { hidden: 'true' }) span = if tooltip.present? tag.span(content_tag_i, class: "icon #{span_style}", style: style, data: { tooltip: tooltip }) else tag.span(content_tag_i, class: "icon #{span_style}", style: style) end return span if text.blank? span + tag.span(text) end |
#l_date(obj = nil) ⇒ String
Localize a DateTime with format :date if #obj is present
74 75 76 |
# File 'app/helpers/application_helper.rb', line 74 def l_date(obj = nil) l(obj.try(:to_date), format: :date) if obj.present? end |
#l_long(obj = nil) ⇒ String
Localize a DateTime with format :long if #obj is present
60 61 62 |
# File 'app/helpers/application_helper.rb', line 60 def l_long(obj = nil) l(obj, format: :long) if obj.present? end |
#l_time(obj = nil) ⇒ String
Localize a DateTime with format :time if #obj is present
67 68 69 |
# File 'app/helpers/application_helper.rb', line 67 def l_time(obj = nil) l(obj, format: :time) if obj.present? end |
#loader(url) ⇒ String
Returns write a content tag for load a remote page.
11 12 13 14 |
# File 'app/helpers/application_helper.rb', line 11 def loader(url) # "<div data-target='page.loader', url='#{url}'>Sto caricando</div>".html_safe content_tag(:div, 'Sto caricando', url: url, data: { target: 'page.loader' }) end |
#notifications ⇒ Object
map of flash and rub notify() for each flash
30 31 32 |
# File 'app/helpers/application_helper.rb', line 30 def notifications flash.map { |type, text| notify(text, type: type) }.join end |
#notify(text, type: 'alert', timeout: 3000, hidden: true) ⇒ String
Returns Make a div with for the notification.
45 46 47 |
# File 'app/helpers/application_helper.rb', line 45 def notify(text, type: 'alert', timeout: 3000, hidden: true) content_tag(:div, text.to_s, class: "notification is-#{type} #{'is-hidden' if hidden}", data: { controller: 'noty', noty_type: type, noty_timeout: timeout }) end |
#notify_status(status = {}) ⇒ Object
map of status and run notify() for each status
36 37 38 |
# File 'app/helpers/application_helper.rb', line 36 def notify_status(status = {}) status.map { |k, v| notify(v, type: k) }.join end |
#t_enum(list = {}, scope = '') ⇒ List
generate a list for a select from an enum
53 54 55 |
# File 'app/helpers/application_helper.rb', line 53 def t_enum(list = {}, scope = '') list.map { |k, _| [t(k, scope: scope), k] } end |
#t_field(field_label = nil, obj = '') ⇒ String
Localize a fieldName if #obj is present
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/application_helper.rb', line 82 def t_field(field_label = nil, obj = '') return '' if field_label.blank? case obj when Class t(field_label, scope: "activerecord.attributes.#{obj.class}") when String t(field_label, scope: "activerecord.attributes.#{obj}") else t(field_label, default: field_label) end end |