Sha256: 1a052f24be3afd8cc2520733d546be1220ef1bc33f07f63aecbe563fa25299e3

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

module FlashMessageHelper
  ALERTS = [:success, :info, :warning, :danger]

  def flash_messages
    messages = []

    flash.each do |type, message|
      next if message.is_a?(String) && message == "" 
      next if message.is_a?(Hash) && message[:msg] == ""
      next unless ALERTS.include?(type)
      
      dismissable = message[:dismissable] || false if message.is_a?(Hash)
      dismissable = message.match(/\[\s*(x|X)\s*\]\s*(.*)/) if message.is_a?(String)

      message = dismissable[2] if message.is_a?(String) && dismissable
      message = message[:msg] if message.is_a?(Hash)
      
      if dismissable
        text = "<div class='alert alert-#{type} alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>#{message.html_safe}</div>"
      else
        text = "<div class='alert alert-#{type}'>#{message.html_safe}</div>"
      end
      
      messages << text
    end

    messages.join("\n").html_safe
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
strappy-0.0.02 app/helpers/flash_message_helper.rb