Module: AlertBoxHelper
- Includes:
- ActionView::Helpers, FormatHelper
- Defined in:
- app/helpers/alert_box_helper.rb
Instance Method Summary
collapse
#parse_content_or_options, #prepend_class, #squeeze_n_strip
Instance Method Details
#alert_box(content_or_options = nil, options = {}, &block) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'app/helpers/alert_box_helper.rb', line 5
def alert_box(content_or_options=nil, options={}, &block)
content, options = parse_content_or_options(content_or_options, options)
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/helpers/alert_box_helper.rb', line 17
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
|
32
33
34
35
|
# File 'app/helpers/alert_box_helper.rb', line 32
def dismiss_button
"<button type='button' class='close' data-dismiss='alert'" \
"aria-label='Close'><span aria-hidden='true'>×</span></button>"
end
|
#render_alert_box(options, dismissible, content, &block) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'app/helpers/alert_box_helper.rb', line 37
def render_alert_box(options, dismissible, content, &block)
content_tag :div, options do
if dismissible
(dismiss_button + (content.presence || capture(&block))).html_safe
else
content.presence || capture(&block)
end
end
end
|