Sha256: 01299a6718c9f57f81def05f38948eac1755135c4048c781c489686c1c8dcd68

Contents?: true

Size: 756 Bytes

Versions: 35

Compression:

Stored size: 756 Bytes

Contents

# frozen_string_literal: true
module BootstrapFlashHelper
  ALERT_TYPES_MAP = {
    notice:  :success,
    alert:   :danger,
    error:   :danger,
    info:    :info,
    warning: :warning
  }.freeze

  def bootstrap_flash
    safe_join(flash.each_with_object([]) do |(type, message), messages|
      next if message.blank? || !message.respond_to?(:to_str)
      type = ALERT_TYPES_MAP.fetch(type.to_sym, type)
      messages << flash_container(type, message)
    end, "\n").presence
  end

  def flash_container(type, message)
    content_tag :div, class: "alert alert-#{type} alert-dismissable" do
      button_tag type: 'button', class: 'close', data: { dismiss: 'alert' } do
        '&times;'.html_safe
      end.safe_concat(message)
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
onotole-2.0.2 templates/bootstrap_flash_helper.rb
onotole-2.0.1 templates/bootstrap_flash_helper.rb
onotole-2.0.0 templates/bootstrap_flash_helper.rb
onotole-1.2.11 templates/bootstrap_flash_helper.rb
onotole-1.2.10 templates/bootstrap_flash_helper.rb
onotole-1.2.9 templates/bootstrap_flash_helper.rb
onotole-1.2.8 templates/bootstrap_flash_helper.rb
onotole-1.2.7 templates/bootstrap_flash_helper.rb
onotole-1.2.6 templates/bootstrap_flash_helper.rb
onotole-1.2.5 templates/bootstrap_flash_helper.rb
onotole-1.2.4 templates/bootstrap_flash_helper.rb
onotole-1.2.3 templates/bootstrap_flash_helper.rb
onotole-1.2.2 templates/bootstrap_flash_helper.rb
onotole-1.2.1 templates/bootstrap_flash_helper.rb
onotole-1.1.21 templates/bootstrap_flash_helper.rb
onotole-1.1.20 templates/bootstrap_flash_helper.rb
onotole-1.1.19 templates/bootstrap_flash_helper.rb
onotole-1.1.18 templates/bootstrap_flash_helper.rb
onotole-1.1.17 templates/bootstrap_flash_helper.rb
onotole-1.1.16 templates/bootstrap_flash_helper.rb