Module: Shipyard::Rails::AlertHelper

Defined in:
lib/shipyard-framework/rails/alert_helper.rb

Instance Method Summary collapse

Instance Method Details

#flash_alert(*args, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shipyard-framework/rails/alert_helper.rb', line 4

def flash_alert(*args, &block)
  alert_txt = capture(&block) if block_given?
  options = {}
  options[:role] ||= 'alert'
  options[:data] ||= {}
  options[:data][:shipyard] = 'alert'
  options['v-show'] = 'visible'
  class_list = ['alert']

  args.each do |arg|
    if arg.is_a? Symbol
      class_list << "alert-#{alert_type(arg)}"
    elsif arg.is_a? Hash
      options = options.merge(arg) if arg.is_a?(Hash)
    else
      alert_txt = arg
    end
  end

  options[:class] = "#{class_list.join(' ')} #{options[:class]}"

   :div, options do
    concat (:p, raw(alert_txt), class: 'alert-txt')
    concat (:button,
                       icon('x', class: 'alert-close-icon icon-outline-inverse center'),
                       class: 'alert-close v-center',
                       '@click': 'close')
  end
end