Module: Facades::Helpers::Notifications
- Included in:
- Facades::Helpers
- Defined in:
- lib/facades/helpers/notifications.rb
Instance Method Summary collapse
-
#flash_messages(attrs = {}) ⇒ Object
Convenience method for outputting all current flash messages.
Instance Method Details
#flash_messages(attrs = {}) ⇒ Object
Convenience method for outputting all current flash messages. This allows you to avoid using things like “if flash” and so on, which is far from DRY
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/facades/helpers/notifications.rb', line 24 def (attrs = {}) return if flash.nil? or flash.empty? wrapper = attrs.delete(:wrapper) || :div closer = attrs.delete(:closer) unless closer === false closer ||= "<span class='close'>×</span>" end klasses = (attrs.delete(:class) || "").split(" ") klasses << "flash-message" content = "" flash.each do |key, value| next if value === true or value.to_s == 'true' # fix awkward devise message klasses << "notification" klasses << "flash-message-#{key.to_s.underscore}" msg_attrs = attrs.merge(:class => [key.to_s, klasses].flatten.join(' ')) content.concat content_tag(wrapper, "#{value} #{closer}".html_safe, msg_attrs).html_safe end content.html_safe end |