notifiable 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +5 -0
 - data/MIT-LICENSE +20 -0
 - data/README.rdoc +3 -0
 - data/Rakefile +42 -0
 - data/app/controllers/notifiable/notifications_controller.rb +29 -0
 - data/app/models/notifiable/notification.rb +23 -0
 - data/app/views/notifiable/notifications/new.html.erb +16 -0
 - data/lib/generators/notifiable_install/notifiable_install_generator.rb +42 -0
 - data/lib/generators/notifiable_install/templates/README +23 -0
 - data/lib/generators/notifiable_install/templates/migration.rb +24 -0
 - data/lib/generators/notifiable_install/templates/sooner.rb +13 -0
 - data/lib/notifiable/helpers/notifiable_helper.rb +41 -0
 - data/lib/notifiable/rails.rb +5 -0
 - data/lib/notifiable/version.rb +3 -0
 - data/lib/notifiable.rb +5 -0
 - metadata +78 -0
 
    
        data/Gemfile
    ADDED
    
    
    
        data/MIT-LICENSE
    ADDED
    
    | 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright 2010 YOURNAME
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
      
 4 
     | 
    
         
            +
            a copy of this software and associated documentation files (the
         
     | 
| 
      
 5 
     | 
    
         
            +
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
      
 6 
     | 
    
         
            +
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
      
 7 
     | 
    
         
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
      
 8 
     | 
    
         
            +
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
      
 9 
     | 
    
         
            +
            the following conditions:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be
         
     | 
| 
      
 12 
     | 
    
         
            +
            included in all copies or substantial portions of the Software.
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
      
 15 
     | 
    
         
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 16 
     | 
    
         
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
      
 17 
     | 
    
         
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
      
 18 
     | 
    
         
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
      
 19 
     | 
    
         
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
      
 20 
     | 
    
         
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/README.rdoc
    ADDED
    
    
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: UTF-8
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rake'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rake/rdoctask'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rake/gempackagetask'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rake/testtask'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require File.join(File.dirname(__FILE__), 'lib', 'notifiable', 'version')
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            Rake::TestTask.new(:test) do |t|
         
     | 
| 
      
 9 
     | 
    
         
            +
              t.libs << 'lib'
         
     | 
| 
      
 10 
     | 
    
         
            +
              t.libs << 'test'
         
     | 
| 
      
 11 
     | 
    
         
            +
              t.pattern = 'test/**/*_test.rb'
         
     | 
| 
      
 12 
     | 
    
         
            +
              t.verbose = false
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            task :default => :test
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            Rake::RDocTask.new(:rdoc) do |rdoc|
         
     | 
| 
      
 18 
     | 
    
         
            +
              rdoc.rdoc_dir = 'rdoc'
         
     | 
| 
      
 19 
     | 
    
         
            +
              rdoc.title    = 'Notifiable'
         
     | 
| 
      
 20 
     | 
    
         
            +
              rdoc.options << '--line-numbers' << '--inline-source'
         
     | 
| 
      
 21 
     | 
    
         
            +
              rdoc.rdoc_files.include('README.rdoc')
         
     | 
| 
      
 22 
     | 
    
         
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            spec = Gem::Specification.new do |s|
         
     | 
| 
      
 26 
     | 
    
         
            +
              s.name = "notifiable"
         
     | 
| 
      
 27 
     | 
    
         
            +
              s.summary = "Insert Notifiable summary."
         
     | 
| 
      
 28 
     | 
    
         
            +
              s.description = "Insert Notifiable description."
         
     | 
| 
      
 29 
     | 
    
         
            +
              s.files =  FileList["[A-Z]*", "{app,config,lib}/**/*"]
         
     | 
| 
      
 30 
     | 
    
         
            +
              s.version = Notifiable::VERSION.dup
         
     | 
| 
      
 31 
     | 
    
         
            +
              s.email = "sbertel@mobithought.com"
         
     | 
| 
      
 32 
     | 
    
         
            +
              s.homepage = "http://github.com/shenoudab/notifiable"
         
     | 
| 
      
 33 
     | 
    
         
            +
              s.author = 'Shenouda Bertel'
         
     | 
| 
      
 34 
     | 
    
         
            +
            end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            Rake::GemPackageTask.new(spec) do |pkg|
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            desc "Install the gem #{spec.name}-#{spec.version}.gem"
         
     | 
| 
      
 40 
     | 
    
         
            +
            task :install do
         
     | 
| 
      
 41 
     | 
    
         
            +
              system("gem install pkg/#{spec.name}-#{spec.version}.gem --no-ri --no-rdoc")
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Notifiable
         
     | 
| 
      
 2 
     | 
    
         
            +
              class NotificationsController < ApplicationController
         
     | 
| 
      
 3 
     | 
    
         
            +
                
         
     | 
| 
      
 4 
     | 
    
         
            +
                unloadable
         
     | 
| 
      
 5 
     | 
    
         
            +
                
         
     | 
| 
      
 6 
     | 
    
         
            +
                def new
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @notification = Notification.new
         
     | 
| 
      
 8 
     | 
    
         
            +
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                def create
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @notification = Notification.new(params[:notifiable_notification])
         
     | 
| 
      
 12 
     | 
    
         
            +
                  if @notification.valid?
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @subscriber.save
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def dismiss
         
     | 
| 
      
 18 
     | 
    
         
            +
                  notification = Notification.find(params[:id])
         
     | 
| 
      
 19 
     | 
    
         
            +
                  notification.update_attribute('dismissed', true)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  respond_to do |format|
         
     | 
| 
      
 21 
     | 
    
         
            +
                    format.js {
         
     | 
| 
      
 22 
     | 
    
         
            +
                      render :update do |page|
         
     | 
| 
      
 23 
     | 
    
         
            +
                        page.remove "system_message_#{notification.id}"
         
     | 
| 
      
 24 
     | 
    
         
            +
                      end
         
     | 
| 
      
 25 
     | 
    
         
            +
                    }
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Notifiable
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Notification < ActiveRecord::Base
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                validates :level, :presence => true
         
     | 
| 
      
 5 
     | 
    
         
            +
                validates :header, :presence => true
         
     | 
| 
      
 6 
     | 
    
         
            +
                validates :message, :presence => true
         
     | 
| 
      
 7 
     | 
    
         
            +
                validates :expires, :presence => true
         
     | 
| 
      
 8 
     | 
    
         
            +
              
         
     | 
| 
      
 9 
     | 
    
         
            +
                named_scope :global,   :conditions => {:notifiable_id => nil}
         
     | 
| 
      
 10 
     | 
    
         
            +
                named_scope :viewable, lambda { {:conditions => ["dismissed = ? AND expires > ?", false, Time.now]} }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                belongs_to :notifiable, :polymorphic => true
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def viewable?
         
     | 
| 
      
 15 
     | 
    
         
            +
                  !dismissed? && !expired?
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def expired?
         
     | 
| 
      
 19 
     | 
    
         
            +
                  Time.now > expires
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
                
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <div id="notifiable_notification">
         
     | 
| 
      
 2 
     | 
    
         
            +
              <%= form_for @notification, :url => notifications_path, :remote => true do |f| %>
         
     | 
| 
      
 3 
     | 
    
         
            +
                <%= f.label :level %>
         
     | 
| 
      
 4 
     | 
    
         
            +
                <%= f.text_field :level %>
         
     | 
| 
      
 5 
     | 
    
         
            +
                <br/>
         
     | 
| 
      
 6 
     | 
    
         
            +
                <%= f.label :header %>
         
     | 
| 
      
 7 
     | 
    
         
            +
                <%= f.text_field :header %>
         
     | 
| 
      
 8 
     | 
    
         
            +
                <br />
         
     | 
| 
      
 9 
     | 
    
         
            +
                <%= f.label :message %>
         
     | 
| 
      
 10 
     | 
    
         
            +
                <%= f.text_field :message %>
         
     | 
| 
      
 11 
     | 
    
         
            +
                <br/>
         
     | 
| 
      
 12 
     | 
    
         
            +
                <%= f.label :expires %>
         
     | 
| 
      
 13 
     | 
    
         
            +
                <%= f.text_field :expires %>
         
     | 
| 
      
 14 
     | 
    
         
            +
                <%= f.submit "Send Notification" %>
         
     | 
| 
      
 15 
     | 
    
         
            +
              <% end %>
         
     | 
| 
      
 16 
     | 
    
         
            +
            </div>
         
     | 
| 
         @@ -0,0 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class NotifiableInstallGenerator < Rails::Generators::Base
         
     | 
| 
      
 2 
     | 
    
         
            +
              include Rails::Generators::Migration
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              desc "Creates a Notifibale Messages initializer and migration to your application."
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def self.source_root
         
     | 
| 
      
 7 
     | 
    
         
            +
                @_sooner_source_root ||= File.expand_path("../templates", __FILE__)
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def self.orm_has_migration?
         
     | 
| 
      
 11 
     | 
    
         
            +
                Rails::Generators.options[:rails][:orm] == :active_record
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              def self.next_migration_number(dirname)
         
     | 
| 
      
 15 
     | 
    
         
            +
                if ActiveRecord::Base.timestamped_migrations
         
     | 
| 
      
 16 
     | 
    
         
            +
                  Time.now.utc.strftime("%Y%m%d%H%M%S")
         
     | 
| 
      
 17 
     | 
    
         
            +
                else
         
     | 
| 
      
 18 
     | 
    
         
            +
                  "%.3d" % (current_migration_number(dirname) + 1)
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              class_option :orm
         
     | 
| 
      
 23 
     | 
    
         
            +
              class_option :migration, :type => :boolean, :default => orm_has_migration?
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def create_migration_file
         
     | 
| 
      
 26 
     | 
    
         
            +
                migration_template 'migration.rb', 'db/migrate/notifiable_create_notifications.rb'
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              #def copy_initializer
         
     | 
| 
      
 30 
     | 
    
         
            +
              #  template "sooner.rb", "config/initializers/sooner.rb"
         
     | 
| 
      
 31 
     | 
    
         
            +
              #end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def show_readme
         
     | 
| 
      
 34 
     | 
    
         
            +
                readme "README"
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              protected
         
     | 
| 
      
 38 
     | 
    
         
            +
              
         
     | 
| 
      
 39 
     | 
    
         
            +
              def readme(path)
         
     | 
| 
      
 40 
     | 
    
         
            +
                say File.read(File.expand_path(path, self.class.source_root))
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            ===============================================================================
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            Some setup you must do manually if you haven't yet:
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              1. Ensure you have defined root_url to *something* in your config/routes.rb.
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                   root :to => "sooner/subscribers#new"
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              2. Ensure you have defined javascript in app/views/layouts/application.html.erb
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                    <%= javascript_include_tag :defaults %>
         
     | 
| 
      
 13 
     | 
    
         
            +
                        <!-- or -->
         
     | 
| 
      
 14 
     | 
    
         
            +
                    <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "jquery.rails.js" %>
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    <%= csrf_meta_tag %>
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              3. Ensure you have flash messages in app/views/layouts/application.html.erb.
         
     | 
| 
      
 19 
     | 
    
         
            +
                 For example:
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                   <p class="notice"><%= notice %></p>
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            ===============================================================================
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class SoonerCreateSubscribers < ActiveRecord::Migration
         
     | 
| 
      
 2 
     | 
    
         
            +
              def self.up
         
     | 
| 
      
 3 
     | 
    
         
            +
                create_table :notifications do |t|
         
     | 
| 
      
 4 
     | 
    
         
            +
                  t.string        :header
         
     | 
| 
      
 5 
     | 
    
         
            +
                  t.string        :level
         
     | 
| 
      
 6 
     | 
    
         
            +
                  t.text          :message
         
     | 
| 
      
 7 
     | 
    
         
            +
                  t.boolean       :dismissed, :default => false
         
     | 
| 
      
 8 
     | 
    
         
            +
                  t.boolean       :dismissable, :default => false
         
     | 
| 
      
 9 
     | 
    
         
            +
                  t.datetime      :expires
         
     | 
| 
      
 10 
     | 
    
         
            +
                  t.references    :notifiable, :polymorphic => true
         
     | 
| 
      
 11 
     | 
    
         
            +
                  #Any additional fields here  
         
     | 
| 
      
 12 
     | 
    
         
            +
                  t.timestamps   
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                add_index :notifications, [:dismissed, :expires], :name => 'viewable_index'
         
     | 
| 
      
 16 
     | 
    
         
            +
                add_index :notifications, [:notifiable_type, :notifiable_id], :name => 'notifiable'
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
              
         
     | 
| 
      
 20 
     | 
    
         
            +
              def self.down
         
     | 
| 
      
 21 
     | 
    
         
            +
                drop_table :notifications 
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
              
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Sooner.setup do |config|
         
     | 
| 
      
 2 
     | 
    
         
            +
              # Configure the e-mail address which will be shown in SoonerMailer.
         
     | 
| 
      
 3 
     | 
    
         
            +
              config.mailer_sender = "info@sooner.com"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              config.db_store = true
         
     | 
| 
      
 6 
     | 
    
         
            +
              config.csv_store = true
         
     | 
| 
      
 7 
     | 
    
         
            +
              config.csv_file = "subscribers.csv"
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              # Messages.
         
     | 
| 
      
 10 
     | 
    
         
            +
              config.subscribed = 'Subscribed Successfully.'
         
     | 
| 
      
 11 
     | 
    
         
            +
              config.already_subscribed = 'Already Subscribed.'
         
     | 
| 
      
 12 
     | 
    
         
            +
              config.error_subscribed = 'Please Try to subscribe again.'
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,41 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Notifiable
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Helpers
         
     | 
| 
      
 3 
     | 
    
         
            +
                module NotificationHelper
         
     | 
| 
      
 4 
     | 
    
         
            +
                  def notify_msg(message, options={})
         
     | 
| 
      
 5 
     | 
    
         
            +
                    header = header_div(message.header, message.level)
         
     | 
| 
      
 6 
     | 
    
         
            +
                    body = message.message
         
     | 
| 
      
 7 
     | 
    
         
            +
                    base_options = {:class => "notify #{message.level}", :id => "notification_#{message.id}"}.merge(options)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    
         
     | 
| 
      
 9 
     | 
    
         
            +
                    if message.dismissable?
         
     | 
| 
      
 10 
     | 
    
         
            +
                      body += content_tag(:p, link_to_remote("Dismiss", :url => {:controller => 'notifiable/notifications', :action => 'dismiss',
         
     | 
| 
      
 11 
     | 
    
         
            +
                            :id => message.id}))
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
                    content_tag(:div, header + body, base_options)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
              
         
     | 
| 
      
 16 
     | 
    
         
            +
                  def notify_for(obj, options={})
         
     | 
| 
      
 17 
     | 
    
         
            +
                    messages = obj.notificaions.select(&:viewable?).
         
     | 
| 
      
 18 
     | 
    
         
            +
                      map {|msg| notify_msg(msg, options)}
         
     | 
| 
      
 19 
     | 
    
         
            +
                    messages.join("\n")
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
              
         
     | 
| 
      
 22 
     | 
    
         
            +
                  def notifications(options={})
         
     | 
| 
      
 23 
     | 
    
         
            +
                    Notification.global.viewable.map {|msg| notify_msg(msg, options)}.join("\n")
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
              
         
     | 
| 
      
 26 
     | 
    
         
            +
                  def static_notification(level, header, options={}, &block)
         
     | 
| 
      
 27 
     | 
    
         
            +
                    header = header_div(header, level)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    body   = capture(&block)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    
         
     | 
| 
      
 30 
     | 
    
         
            +
                    concat(content_tag(:div, header + body, {:class => "notify #{level}"}.merge(options)), block.binding)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                  
         
     | 
| 
      
 33 
     | 
    
         
            +
                  private
         
     | 
| 
      
 34 
     | 
    
         
            +
                  
         
     | 
| 
      
 35 
     | 
    
         
            +
                  def header_div(text, level)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    content_tag(:div, content_tag(:span, text, :class => level), :class => "notify-header #{level}")
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                  
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/notifiable.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,78 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: notifiable
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 5 
     | 
    
         
            +
              segments: 
         
     | 
| 
      
 6 
     | 
    
         
            +
              - 0
         
     | 
| 
      
 7 
     | 
    
         
            +
              - 0
         
     | 
| 
      
 8 
     | 
    
         
            +
              - 1
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 10 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 11 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 12 
     | 
    
         
            +
            - Shenouda Bertel
         
     | 
| 
      
 13 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 14 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 15 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            date: 2010-06-13 00:00:00 +03:00
         
     | 
| 
      
 18 
     | 
    
         
            +
            default_executable: 
         
     | 
| 
      
 19 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            description: Insert Notifiable description.
         
     | 
| 
      
 22 
     | 
    
         
            +
            email: sbertel@mobithought.com
         
     | 
| 
      
 23 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 30 
     | 
    
         
            +
            - MIT-LICENSE
         
     | 
| 
      
 31 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 32 
     | 
    
         
            +
            - README.rdoc
         
     | 
| 
      
 33 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 34 
     | 
    
         
            +
            - app/controllers/notifiable/notifications_controller.rb
         
     | 
| 
      
 35 
     | 
    
         
            +
            - app/models/notifiable/notification.rb
         
     | 
| 
      
 36 
     | 
    
         
            +
            - app/views/notifiable/notifications/new.html.erb
         
     | 
| 
      
 37 
     | 
    
         
            +
            - lib/notifiable/helpers/notifiable_helper.rb
         
     | 
| 
      
 38 
     | 
    
         
            +
            - lib/notifiable/version.rb
         
     | 
| 
      
 39 
     | 
    
         
            +
            - lib/notifiable/rails.rb
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/notifiable.rb
         
     | 
| 
      
 41 
     | 
    
         
            +
            - lib/generators/notifiable_install/templates/sooner.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - lib/generators/notifiable_install/templates/migration.rb
         
     | 
| 
      
 43 
     | 
    
         
            +
            - lib/generators/notifiable_install/templates/README
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib/generators/notifiable_install/notifiable_install_generator.rb
         
     | 
| 
      
 45 
     | 
    
         
            +
            has_rdoc: true
         
     | 
| 
      
 46 
     | 
    
         
            +
            homepage: http://github.com/shenoudab/notifiable
         
     | 
| 
      
 47 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 50 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 53 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 54 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 55 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 56 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 57 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 58 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 59 
     | 
    
         
            +
                  segments: 
         
     | 
| 
      
 60 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 61 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 62 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 63 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 64 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 65 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 66 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 67 
     | 
    
         
            +
                  segments: 
         
     | 
| 
      
 68 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 69 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 70 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 73 
     | 
    
         
            +
            rubygems_version: 1.3.7
         
     | 
| 
      
 74 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 75 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 76 
     | 
    
         
            +
            summary: Insert Notifiable summary.
         
     | 
| 
      
 77 
     | 
    
         
            +
            test_files: []
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     |