module FoundationRailsHelper::FlashHelper
Constants
- DEFAULT_KEY_MATCHING
<div class=“callout [success alert secondary]” data-closable>
This is an alert box. <button name="button" type="submit" class="close-button" data-close=""> <span>×</span> </button>
</div>
Public Instance Methods
display_flash_messages(closable: true, key_matching: {})
click to toggle source
Displays the flash messages found in ActionDispatch’s flash
hash using Foundation’s callout
component.
Parameters:
-
closable
- A boolean to determine whether the displayed flash messages
should be closable by the user. Defaults to true.
-
key_matching
- A Hash of key/value pairs mapping flash keys to the
corresponding class to use for the callout box.
# File lib/foundation_rails_helper/flash_helper.rb, line 31 def display_flash_messages(closable: true, key_matching: {}) key_matching = DEFAULT_KEY_MATCHING.merge(key_matching) key_matching.default = :primary capture do flash.each do |key, value| next if ignored_key?(key.to_sym) alert_class = key_matching[key.to_sym] concat alert_box(value, alert_class, closable) end end end
Private Instance Methods
alert_box(value, alert_class, closable)
click to toggle source
# File lib/foundation_rails_helper/flash_helper.rb, line 47 def alert_box(value, alert_class, closable) options = { class: "flash callout #{alert_class}" } options[:data] = { closable: '' } if closable content_tag(:div, options) do concat value concat close_link if closable end end
close_link()
click to toggle source
# File lib/foundation_rails_helper/flash_helper.rb, line 56 def close_link button_tag( class: 'close-button', type: 'button', data: { close: '' }, aria: { label: 'Dismiss alert' } ) do content_tag(:span, '×'.html_safe, aria: { hidden: true }) end end
ignored_key?(key)
click to toggle source
# File lib/foundation_rails_helper/flash_helper.rb, line 67 def ignored_key?(key) FoundationRailsHelper.configuration.ignored_flash_keys.include?(key) end