Module: Notifiable::Helpers::NotifiableHelpers

Defined in:
lib/notifiable/helpers/notifiable_helpers.rb

Instance Method Summary collapse

Instance Method Details

#notifications(options = {}) ⇒ Object



22
23
24
# File 'lib/notifiable/helpers/notifiable_helpers.rb', line 22

def notifications(options={})
  Notification.global.viewable.map {|msg| notify_msg(msg, options)}.join("\n")
end

#notify_for(obj, options = {}) ⇒ Object



16
17
18
19
20
# File 'lib/notifiable/helpers/notifiable_helpers.rb', line 16

def notify_for(obj, options={})
  messages = obj.notificaions.select(&:viewable?).
    map {|msg| notify_msg(msg, options)}
  messages.join("\n")
end

#notify_msg(message, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/notifiable/helpers/notifiable_helpers.rb', line 4

def notify_msg(message, options={})
  header = header_div(message.header, message.level)
  body = message.message
  base_options = {:class => "notify #{message.level}", :id => "notification_#{message.id}"}.merge(options)

  if message.dismissable?
    body += (:p, link_to_remote("Dismiss", :url => {:controller => 'notifiable/notifications', :action => 'dismiss',
          :id => message.id}))
  end
  (:div, header + body, base_options)
end

#static_notification(level, header, options = {}, &block) ⇒ Object



26
27
28
29
30
31
# File 'lib/notifiable/helpers/notifiable_helpers.rb', line 26

def static_notification(level, header, options={}, &block)
  header = header_div(header, level)
  body   = capture(&block)

  concat((:div, header + body, {:class => "notify #{level}"}.merge(options)), block.binding)
end