Module: Noventius::AlertsHelper
- Defined in:
- app/helpers/noventius/alerts_helper.rb
Constant Summary collapse
- ALERT_TYPES =
[:success, :info, :warning, :danger]
Instance Method Summary collapse
- #flash_alert(options = {}) ⇒ Object
- #options_for_type(options, type) ⇒ Object
- #transform_type(type) ⇒ Object
Instance Method Details
#flash_alert(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/noventius/alerts_helper.rb', line 7 def flash_alert( = {}) = [] flash.each do |type, | # Skip empty messages, e.g. for devise messages set to nothing in a locale file. next if .blank? type = transform_type(type) next unless ALERT_TYPES.include?(type) = (, type) = content_tag(:button, raw('×'), type: 'button', class: 'close', 'data-dismiss' => 'alert') Array().each do |msg| text = content_tag(:div, + msg, ) << text if msg end end .join("\n").html_safe end |
#options_for_type(options, type) ⇒ Object
40 41 42 43 44 |
# File 'app/helpers/noventius/alerts_helper.rb', line 40 def (, type) tag_class = .extract!(:class)[:class] { class: "alert fade in alert-#{type} #{tag_class}" }.merge() end |
#transform_type(type) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/helpers/noventius/alerts_helper.rb', line 32 def transform_type(type) case type when :notice then :success when :alert, :error then :danger else type end end |