Module: ApplicationHelper
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.
-
#icon(fas, **opts) ⇒ String
Make an html structure for a bulma/awesome icon.
-
#icon_text(fas, text, **opts) ⇒ String
Make an html structure for a bulma/awesome text-icon.
-
#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.
-
#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.
Instance Method Details
#fas_icon(fa_style, span_style: nil, style: false, text: "", tooltip: false) ⇒ Object
make a div for the font-awesome icons
10 11 12 13 14 15 16 17 |
# File 'app/helpers/application_helper.rb', line 10 def fas_icon(fa_style, span_style: nil, style: false, text: "", tooltip: false) # "<span class='icon #{span_style}' #{"style='#{style}'" if style.present?} data-tooltip=\"#{tooltip if tooltip.present?}\" ><i class='fas fa-#{fa_style}' aria-hidden='true'></i></span> #{"<span>#{text}</span>" if text.present?}".html_safe tag_i = content_tag(:i, "", class: "fas fa-#{fa_style}", aria: { hidden: "true" }) span = content_tag(:span, tag_i, class: "icon #{span_style}", style:, data: { tooltip: }) return span if text.blank? span + content_tag(:span, text) end |
#icon(fas, **opts) ⇒ String
Make an html structure for a bulma/awesome icon
Example: icon(‘fas fa-home’) ‘<span class=“icon”><i class=“fas fa-home”></i></span>`
29 30 31 |
# File 'app/helpers/application_helper.rb', line 29 def icon(fas, **opts) content_tag :span, tag.i(class: fas), class: [ "icon", opts[:class] ] end |
#icon_text(fas, text, **opts) ⇒ String
Make an html structure for a bulma/awesome text-icon
Example: icon(‘fas fa-home’, ‘text’) ‘<span class=“text-icon”><span class=“icon”><i class=“fas fa-home”></i></span><span>text</span></span>`
45 46 47 48 49 50 51 |
# File 'app/helpers/application_helper.rb', line 45 def icon_text(fas, text, **opts) content_tag( :span, icon(fas, class: opts[:icon_class]) + content_tag(:span, text), class: [ "icon-text", opts[:class] ] ) end |
#l_date(obj = nil) ⇒ String
Localize a DateTime with format :date if #obj is present
99 100 101 |
# File 'app/helpers/application_helper.rb', line 99 def l_date(obj = nil) l(obj, format: :date) if obj.present? end |
#l_long(obj = nil) ⇒ String
Localize a DateTime with format :long if #obj is present
85 86 87 |
# File 'app/helpers/application_helper.rb', line 85 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
92 93 94 |
# File 'app/helpers/application_helper.rb', line 92 def l_time(obj = nil) l(obj, format: :time) if obj.present? end |
#notifications ⇒ Object
map of flash and rub notify() for each flash
54 55 56 |
# File 'app/helpers/application_helper.rb', line 54 def notifications flash.to_h.extract!("success", "notice", "warning", "alert").map { |type, text| notify(text, type:) }.join end |
#notify(text, type: "alert", timeout: 3000, hidden: true) ⇒ String
Returns Make a div with for the notification.
69 70 71 72 |
# File 'app/helpers/application_helper.rb', line 69 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
60 61 62 |
# File 'app/helpers/application_helper.rb', line 60 def notify_status(status = {}) status.map { |k, v| notify(v, type: k) }.join.html_safe if status.present? end |
#t_enum(list = {}, scope = "") ⇒ List
generate a list for a select from an enum
78 79 80 |
# File 'app/helpers/application_helper.rb', line 78 def t_enum(list = {}, scope = "") list.map { |k, _| [ t(k, scope:), k ] } end |