Module: AlertBoxHelper

Includes:
ActionView::Helpers
Defined in:
app/helpers/alert_box_helper.rb

Instance Method Summary collapse

Instance Method Details

#alert_box(content_or_options = nil, options = {}, &block) ⇒ Object



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

def alert_box(content_or_options=nil, options={}, &block)
  if content_or_options.is_a?(Hash)
    options = content_or_options
  else
    content = content_or_options
  end

  dismissible = options.delete(:dismiss).present?
  klass       = options.delete(:class)
  type        = alert_type(options.delete(:type))

  prepend_class(options, 'alert', type, klass)
  options[:role] = 'alert'

  render_alert_box(options, dismissible, content, &block)
end

#alert_type(type) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/alert_box_helper.rb', line 21

def alert_type(type)
  case type.try(:to_sym)
  when :info
    'alert-info'
  when :success
    'alert-success'
  when :warning
    'alert-warning'
  when :danger
    'alert-danger'
  else
    'alert-info'
  end
end

#dismiss_buttonObject



36
37
38
39
# File 'app/helpers/alert_box_helper.rb', line 36

def dismiss_button
  "<button type='button' class='close' data-dismiss='alert'" \
  "aria-label='Close'><span aria-hidden='true'>&times;</span></button>"
end

#render_alert_box(options, dismissible, content, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'app/helpers/alert_box_helper.rb', line 41

def render_alert_box(options, dismissible, content, &block)
   :div, options do
    if dismissible
      (dismiss_button + (content.presence || capture(&block))).html_safe
    else
      content.presence || capture(&block)
    end
  end
end