Sha256: 09ad7fec9fb3cd95b94212c9a7751dfd29488cb2985a8e25147581b1bde5e12d

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

module Notifiable
  module Helpers
    module NotificationHelper
      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 += content_tag(:p, link_to_remote("Dismiss", :url => {:controller => 'notifiable/notifications', :action => 'dismiss',
                :id => message.id}))
        end
        content_tag(:div, header + body, base_options)
      end
  
      def notify_for(obj, options={})
        messages = obj.notificaions.select(&:viewable?).
          map {|msg| notify_msg(msg, options)}
        messages.join("\n")
      end
  
      def notifications(options={})
        Notification.global.viewable.map {|msg| notify_msg(msg, options)}.join("\n")
      end
  
      def static_notification(level, header, options={}, &block)
        header = header_div(header, level)
        body   = capture(&block)
        
        concat(content_tag(:div, header + body, {:class => "notify #{level}"}.merge(options)), block.binding)
      end
      
      private
      
      def header_div(text, level)
        content_tag(:div, content_tag(:span, text, :class => level), :class => "notify-header #{level}")
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
notifiable-0.0.2 lib/notifiable/helpers/notifiable_helper.rb
notifiable-0.0.1 lib/notifiable/helpers/notifiable_helper.rb