Module: Twitter::Bootswatch::FlashHelper

Defined in:
app/helpers/twitter/bootswatch/flash_helper.rb

Instance Method Summary collapse

Instance Method Details

#bootswatch_alert_types(alert_type) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'app/helpers/twitter/bootswatch/flash_helper.rb', line 48

def bootswatch_alert_types(alert_type)
  #Rails 4.1 started using Strings instead of Symbol.
  case alert_type
    when :info, 'info' then 'alert-info'
    when :notice, :success, 'notice', 'success' then 'alert-success'
    when :alert, :error, 'alert', 'error' then 'alert-danger'
    else 'alert-warning' # warning
  end
end

#bootswatch_flash(alert_dismissable = true) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/twitter/bootswatch/flash_helper.rb', line 5

def bootswatch_flash(alert_dismissable=true)
  alert_dismissable_class = alert_dismissable ? ' alert-dismissable' : ''
  flash_messages = ''
  flash.each do |type, message|
    alert_type_class = bootswatch_alert_types(type)
    if alert_dismissable
    alert_div = (:div, raw('<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>') + message, :class => "alert #{alert_type_class}#{alert_dismissable_class}")
    else
      alert_div = (:div, raw(message), :class => "alert #{alert_type_class}")
    end
    flash_messages << alert_div if message
  end
  raw(flash_messages)
end

#bootswatch_flash_block(alert_dismissable = true) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/twitter/bootswatch/flash_helper.rb', line 20

def bootswatch_flash_block(alert_dismissable=true)
  output = ''
  flash.each do |type, message|
    output << bootswatch_flash_container(type, alert_dismissable) do
        message
    end
  end

  raw(output)
end

#bootswatch_flash_container(type, alert_dismissable = true, &message) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/twitter/bootswatch/flash_helper.rb', line 31

def bootswatch_flash_container(type, alert_dismissable=true, &message)
  alert_dismissable_class = alert_dismissable ? ' alert-dismissable' : ''
  alert_type_class = bootswatch_alert_types(type)
  message_html = capture(&message)
  if alert_dismissable
    output = (:div, :class => "alert #{alert_type_class}#{alert_dismissable_class}") do
      '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'.html_safe.safe_concat(message_html)
    end
  else
    output = (:div, :class => "alert #{alert_type_class}") do
      message_html.html_safe
    end
  end

  raw(output)
end