Sha256: a8329529e17262e2af0f7cbc2724ad21ab44d8a58b6384440e16502fb7d603ce

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

module Notifiable
  module Helpers
    module NotifiableHelpers
      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.4 lib/notifiable/helpers/notifiable_helpers.rb
notifiable-0.0.3 lib/notifiable/helpers/notifiable_helpers.rb