Module: Materialize::Helpers

Defined in:
lib/materialize-sass/helpers.rb

Instance Method Summary collapse

Instance Method Details

#toastObject



29
30
31
# File 'lib/materialize-sass/helpers.rb', line 29

def toast     
  jsReturn = javascript_tag(toaster)
end

#toast_nowObject



33
34
35
# File 'lib/materialize-sass/helpers.rb', line 33

def toast_now
  toaster
end

#toasterObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/materialize-sass/helpers.rb', line 4

def toaster
  valid_toast = ["error", "message", "success", "warning"]
  js_toast = ""
  queue = 0
  flash.each do |type, message|
    next if message.blank?
    type = type.to_s   
    case type   
    when "alert"
      type = "error"
    when "notice"
      type = "success"
    when "info"
      type = "message"
    end      
   next unless valid_toast.include?(type)         
    Array(message).each do |msg|
      js_toast << "setTimeout(function(){ M.toast({html: '#{j(msg)}'}) }, #{queue});"
    end
    queue += 100
  end    
  flash.clear
  return js_toast.html_safe()
end