Sha256: c31d05e1198e95b9649a700be53cbdc63a9ecc1d7bfc5bca71b06198767f2683

Contents?: true

Size: 1.18 KB

Versions: 54

Compression:

Stored size: 1.18 KB

Contents

module Para
  module FlashHelper
    def display_admin_flash
      # Render empty string if no flash
      return "" if flash.empty?

      # Make a div.alert for each message and join the whole
      messages = flash.map do |type, message|
        flash.delete(type)
        type = homogenize_flash_type(type)

        icon = content_tag(:div, class: "alert-icon-container pull-left") do
          content_tag(:i, "", class: "fa #{ icon_class_for(type) }") +
          ' '.html_safe
        end

        alert(type: type) do
          icon + content_tag(:p, message.html_safe)
        end
      end

      # Join the messages and make sure markup is correctly displayed
      messages.join.html_safe
    end

    private

    # Converts flash types to :success or :error to conform to what
    # twitter bootstrap can handle
    #
    def homogenize_flash_type type
      case type.to_sym
      when :notice then :success
      when :alert then :warning
      when :error then :danger
      else type
      end
    end

    def icon_class_for type
      case type
      when :success then "fa-check"
      when :error then "fa-warning"
      else "fa-exclamation-triangle"
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
para-0.11.4 app/helpers/para/flash_helper.rb
para-0.11.3 app/helpers/para/flash_helper.rb
para-0.11.2 app/helpers/para/flash_helper.rb
para-0.11.1 app/helpers/para/flash_helper.rb
para-0.11.0 app/helpers/para/flash_helper.rb
para-0.10.0 app/helpers/para/flash_helper.rb
para-0.9.4 app/helpers/para/flash_helper.rb
para-0.9.3.3 app/helpers/para/flash_helper.rb
para-0.9.3.2 app/helpers/para/flash_helper.rb
para-0.9.3.1 app/helpers/para/flash_helper.rb
para-0.9.2 app/helpers/para/flash_helper.rb
para-0.9.0 app/helpers/para/flash_helper.rb
para-0.8.15 app/helpers/para/flash_helper.rb
para-0.8.14 app/helpers/para/flash_helper.rb
para-0.8.13 app/helpers/para/flash_helper.rb
para-0.8.12 app/helpers/para/flash_helper.rb
para-0.8.11 app/helpers/para/flash_helper.rb
para-0.8.10 app/helpers/para/flash_helper.rb
para-0.8.9 app/helpers/para/flash_helper.rb
para-0.8.8 app/helpers/para/flash_helper.rb