notify_on 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +37 -0
- data/app/assets/config/notify_on_manifest.js +2 -0
- data/app/assets/javascripts/notify_on/application.js +13 -0
- data/app/assets/stylesheets/notify_on/application.css +15 -0
- data/app/controllers/notify_on/application_controller.rb +5 -0
- data/app/helpers/notify_on/application_helper.rb +4 -0
- data/app/helpers/notify_on/mailer_helper.rb +9 -0
- data/app/jobs/notify_on/application_job.rb +4 -0
- data/app/mailers/notify_on/application_mailer.rb +6 -0
- data/app/mailers/notify_on/notification_mailer.rb +26 -0
- data/app/models/concerns/notify_on/email_support.rb +97 -0
- data/app/models/concerns/notify_on/pusher_support.rb +66 -0
- data/app/models/concerns/notify_on/string_interpolation.rb +39 -0
- data/app/models/notify_on/application_record.rb +5 -0
- data/app/models/notify_on/notification.rb +86 -0
- data/app/views/layouts/notify_on/application.html.erb +17 -0
- data/app/views/notifications/notify.html.erb +9 -0
- data/config/database.travis.yml +4 -0
- data/config/routes.rb +2 -0
- data/lib/generators/notify_on/install_generator.rb +29 -0
- data/lib/generators/templates/notifications.yml +19 -0
- data/lib/generators/templates/notify_on.rb +64 -0
- data/lib/notify_on.rb +29 -0
- data/lib/notify_on/bulk_config.rb +36 -0
- data/lib/notify_on/configuration.rb +22 -0
- data/lib/notify_on/creator.rb +85 -0
- data/lib/notify_on/engine.rb +19 -0
- data/lib/notify_on/notify_on.rb +36 -0
- data/lib/notify_on/receives_notifications.rb +11 -0
- data/lib/notify_on/utilities.rb +13 -0
- data/lib/notify_on/version.rb +3 -0
- data/lib/tasks/notify_on_tasks.rake +4 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +5 -0
- data/spec/dummy/app/assets/javascripts/application.js +7 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.scss +28 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +7 -0
- data/spec/dummy/app/controllers/messages_controller.rb +31 -0
- data/spec/dummy/app/helpers/application_helper.rb +8 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/mailers/notification_mailer.rb +15 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/comment.rb +10 -0
- data/spec/dummy/app/models/message.rb +45 -0
- data/spec/dummy/app/models/post.rb +11 -0
- data/spec/dummy/app/models/user.rb +21 -0
- data/spec/dummy/app/views/application/_header.html.erb +44 -0
- data/spec/dummy/app/views/application/home.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +19 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/app/views/messages/_message.html.erb +6 -0
- data/spec/dummy/app/views/messages/index.html.erb +33 -0
- data/spec/dummy/app/views/messages/new.html.erb +5 -0
- data/spec/dummy/app/views/messages/show.html.erb +7 -0
- data/spec/dummy/app/views/notifications/new_message.html.erb +9 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +35 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +9 -0
- data/spec/dummy/config/database.yml +12 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +58 -0
- data/spec/dummy/config/environments/production.rb +86 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/devise.rb +274 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
- data/spec/dummy/config/initializers/notify_on.rb +64 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/simple_form.rb +165 -0
- data/spec/dummy/config/initializers/simple_form_bootstrap.rb +149 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +62 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/locales/simple_form.en.yml +31 -0
- data/spec/dummy/config/notifications.yml +20 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/routes.rb +14 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/db/migrate/20160801112429_devise_create_users.rb +42 -0
- data/spec/dummy/db/migrate/20160801130804_create_messages.rb +11 -0
- data/spec/dummy/db/migrate/20160823102904_create_notify_on_notifications.rb +20 -0
- data/spec/dummy/db/migrate/20161021100707_create_comments.rb +11 -0
- data/spec/dummy/db/migrate/20161021100842_create_posts.rb +11 -0
- data/spec/dummy/db/schema.rb +77 -0
- data/spec/dummy/db/seeds.rb +4 -0
- data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/controllers/messages_controller_spec.rb +5 -0
- data/spec/dummy/spec/factories/comments.rb +7 -0
- data/spec/dummy/spec/factories/messages.rb +7 -0
- data/spec/dummy/spec/factories/posts.rb +6 -0
- data/spec/dummy/spec/factories/users.rb +6 -0
- data/spec/dummy/spec/features/send_message_spec.rb +25 -0
- data/spec/dummy/spec/mailers/notify_on/notification_mailer_spec.rb +30 -0
- data/spec/dummy/spec/mailers/previews/notification_mailer_preview.rb +4 -0
- data/spec/dummy/spec/models/comment_spec.rb +22 -0
- data/spec/dummy/spec/models/message_spec.rb +60 -0
- data/spec/dummy/spec/models/post_spec.rb +23 -0
- data/spec/dummy/spec/models/user_spec.rb +21 -0
- data/spec/factories/notify_on_notifications.rb +10 -0
- data/spec/lib/notify_on/configuration_spec.rb +53 -0
- data/spec/mailers/notify_on/notification_mailer_spec.rb +6 -0
- data/spec/mailers/previews/notify_on/notification_mailer_preview.rb +6 -0
- data/spec/models/notify_on/notification_spec.rb +335 -0
- data/spec/rails_helper.rb +95 -0
- data/spec/spec_helper.rb +103 -0
- data/spec/support/feature_helpers.rb +19 -0
- data/spec/support/general_helpers.rb +19 -0
- metadata +543 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
// Action Cable provides the framework to deal with WebSockets in Rails.
|
2
|
+
// You can generate new channels where WebSocket features live using the rails generate channel command.
|
3
|
+
//
|
4
|
+
//= require action_cable
|
5
|
+
//= require_self
|
6
|
+
//= require_tree ./channels
|
7
|
+
|
8
|
+
(function() {
|
9
|
+
this.App || (this.App = {});
|
10
|
+
|
11
|
+
App.cable = ActionCable.createConsumer();
|
12
|
+
|
13
|
+
}).call(this);
|
@@ -0,0 +1,28 @@
|
|
1
|
+
@import 'bootstrap-sprockets';
|
2
|
+
@import 'bootstrap';
|
3
|
+
|
4
|
+
#container {
|
5
|
+
padding: 10px 25px;
|
6
|
+
}
|
7
|
+
|
8
|
+
#notifications-menu {
|
9
|
+
.dropdown-menu > li > a {
|
10
|
+
min-width: 350px;
|
11
|
+
white-space: normal;
|
12
|
+
}
|
13
|
+
img {
|
14
|
+
float: left;
|
15
|
+
width: 50px;
|
16
|
+
}
|
17
|
+
.time {
|
18
|
+
display: block;
|
19
|
+
float: left;
|
20
|
+
margin-left: 15px;
|
21
|
+
font-size: 80%;
|
22
|
+
font-weight: 600;
|
23
|
+
}
|
24
|
+
.desc {
|
25
|
+
display: block;
|
26
|
+
margin: 20px 0px 0px 65px;
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class MessagesController < ApplicationController
|
2
|
+
|
3
|
+
def index
|
4
|
+
@inbox = current_user.messages.includes(:user, :author)
|
5
|
+
@sent = current_user.sent_messages.includes(:user, :author)
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@message = Message.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@message = Message.new(message_params.merge(:author => current_user))
|
14
|
+
if @message.save
|
15
|
+
redirect_to messages_path, :notice => 'Message created successfully!'
|
16
|
+
else
|
17
|
+
render 'new'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
@message = current_user.messages.find_by_id(params[:id])
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def message_params
|
28
|
+
params.require(:message).permit(:user_id, :content)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class NotificationMailer < NotifyOn::NotificationMailer
|
2
|
+
|
3
|
+
def notify(notification_id, template = 'notify')
|
4
|
+
@notification = NotifyOn::Notification.find_by_id(notification_id)
|
5
|
+
@recipient = @notification.recipient
|
6
|
+
@sender = @notification.sender
|
7
|
+
@trigger = @notification.trigger
|
8
|
+
mail :to => @recipient.email,
|
9
|
+
:from => 'Bob Ross <admin@bobross.com>',
|
10
|
+
:subject => @notification.description,
|
11
|
+
:template_path => 'notifications',
|
12
|
+
:template_name => template
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Message < ApplicationRecord
|
2
|
+
|
3
|
+
# ---------------------------------------- Plugins
|
4
|
+
|
5
|
+
# Test that the basics work with the model config. All other features and
|
6
|
+
# variations are tested using the bulk config.
|
7
|
+
notify_on :create,
|
8
|
+
:to => :user,
|
9
|
+
:from => :author,
|
10
|
+
:message => '{author.email} sent you a message.',
|
11
|
+
:link => 'message_path(:self)',
|
12
|
+
:email => true
|
13
|
+
|
14
|
+
# ---------------------------------------- Attributes
|
15
|
+
|
16
|
+
attr_accessor :delayed
|
17
|
+
|
18
|
+
# ---------------------------------------- Associations
|
19
|
+
|
20
|
+
belongs_to :user
|
21
|
+
belongs_to :author, :class_name => User
|
22
|
+
|
23
|
+
# ---------------------------------------- Validations
|
24
|
+
|
25
|
+
validates :user, :author, :content, :presence => true
|
26
|
+
|
27
|
+
# ---------------------------------------- Instance Methods
|
28
|
+
|
29
|
+
def delayed?
|
30
|
+
content.start_with?('[DELAYED]')
|
31
|
+
end
|
32
|
+
|
33
|
+
def skip?
|
34
|
+
content.start_with?('[SKIP]')
|
35
|
+
end
|
36
|
+
|
37
|
+
def pdf_filename
|
38
|
+
'myfile.pdf'
|
39
|
+
end
|
40
|
+
|
41
|
+
def pdf_file
|
42
|
+
@pdf_file ||= open('http://loremflickr.com/200/200')
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Post < ApplicationRecord
|
2
|
+
|
3
|
+
# ---------------------------------------- Associations
|
4
|
+
|
5
|
+
belongs_to :author, :class_name => User
|
6
|
+
|
7
|
+
# ---------------------------------------- Attributes
|
8
|
+
|
9
|
+
enum :state => { :draft => 0, :pending => 1, :published => 2 }
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class User < ApplicationRecord
|
2
|
+
|
3
|
+
# ---------------------------------------- Plugins
|
4
|
+
|
5
|
+
devise :database_authenticatable, :registerable,
|
6
|
+
:recoverable, :rememberable, :trackable, :validatable
|
7
|
+
|
8
|
+
receives_notifications
|
9
|
+
|
10
|
+
# ---------------------------------------- Associations
|
11
|
+
|
12
|
+
has_many :messages
|
13
|
+
has_many :sent_messages, :class_name => 'Message', :foreign_key => :author_id
|
14
|
+
|
15
|
+
# ---------------------------------------- Instance Methods
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
email
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<header class="navbar navbar-default">
|
2
|
+
<ul class="nav navbar-nav">
|
3
|
+
<li class="nav-item <%= 'active' if request.path == root_path %>">
|
4
|
+
<a class="nav-link" href="/">Home</a>
|
5
|
+
</li>
|
6
|
+
<li class="nav-item">
|
7
|
+
<a class="nav-link <%= 'active' if controller_name == 'messages' %>"
|
8
|
+
href="<%= messages_path %>">Messages</a>
|
9
|
+
</li>
|
10
|
+
</ul>
|
11
|
+
<div class="links pull-right">
|
12
|
+
<ul class="nav navbar-nav">
|
13
|
+
<% if user_signed_in? %>
|
14
|
+
<li class="nav-item dropdown" id="notifications-menu">
|
15
|
+
<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">
|
16
|
+
<i class="glyphicon glyphicon-bell"></i>
|
17
|
+
</a>
|
18
|
+
<ul class="dropdown-menu pull-right">
|
19
|
+
<% current_user.notifications.each do |n| %>
|
20
|
+
<li>
|
21
|
+
<a href="<%= n.link %>" class="dropdown-item">
|
22
|
+
<img src="<%= avatar(n.recipient) %>" alt="">
|
23
|
+
<span class="time">
|
24
|
+
<%= time_ago_in_words n.created_at %> ago
|
25
|
+
</span>
|
26
|
+
<span class="desc"><%= n.description %></span>
|
27
|
+
</a>
|
28
|
+
</li>
|
29
|
+
<% end %>
|
30
|
+
</ul>
|
31
|
+
</li>
|
32
|
+
<% end %>
|
33
|
+
<li class="nav-item">
|
34
|
+
<% if user_signed_in? %>
|
35
|
+
<%= link_to 'Sign Out', destroy_user_session_path,
|
36
|
+
:class => 'nav-link', :method => :delete %>
|
37
|
+
<% else %>
|
38
|
+
<%= link_to 'Sign In', new_user_session_path,
|
39
|
+
:class => 'nav-link' %>
|
40
|
+
<% end %>
|
41
|
+
</li>
|
42
|
+
</ul>
|
43
|
+
</div>
|
44
|
+
</header>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Home</h1>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
|
7
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
8
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
|
9
|
+
</head>
|
10
|
+
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<%= render 'header' %>
|
14
|
+
|
15
|
+
<div id="container">
|
16
|
+
<%= yield %>
|
17
|
+
</div>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<h1>Messages</h1>
|
2
|
+
|
3
|
+
<%= link_to 'New Message', new_message_path %>
|
4
|
+
|
5
|
+
<hr>
|
6
|
+
|
7
|
+
<h2>Inbox</h2>
|
8
|
+
<div class="row">
|
9
|
+
<div class="col-sm-4">
|
10
|
+
<% if @inbox.present? %>
|
11
|
+
<ul class="list-group"><%= render @inbox %></ul>
|
12
|
+
<% else %>
|
13
|
+
<div class="alert alert-warning">
|
14
|
+
No messages yet!
|
15
|
+
</div>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<hr>
|
21
|
+
|
22
|
+
<h2>Sent</h2>
|
23
|
+
<div class="row">
|
24
|
+
<div class="col-sm-4">
|
25
|
+
<% if @sent.present? %>
|
26
|
+
<ul class="list-group"><%= render @sent %></ul>
|
27
|
+
<% else %>
|
28
|
+
<div class="alert alert-warning">
|
29
|
+
No messages yet!
|
30
|
+
</div>
|
31
|
+
<% end %>
|
32
|
+
</div>
|
33
|
+
</div>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a starting point to setup your application.
|
15
|
+
# Add necessary setup steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
# puts "\n== Copying sample files =="
|
22
|
+
# unless File.exist?('config/database.yml')
|
23
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
24
|
+
# end
|
25
|
+
|
26
|
+
puts "\n== Preparing database =="
|
27
|
+
system! 'bin/rails db:setup'
|
28
|
+
|
29
|
+
puts "\n== Removing old logs and tempfiles =="
|
30
|
+
system! 'bin/rails log:clear tmp:clear'
|
31
|
+
|
32
|
+
puts "\n== Restarting application server =="
|
33
|
+
system! 'bin/rails restart'
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a way to update your development environment automatically.
|
15
|
+
# Add necessary update steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
puts "\n== Updating database =="
|
22
|
+
system! 'bin/rails db:migrate'
|
23
|
+
|
24
|
+
puts "\n== Removing old logs and tempfiles =="
|
25
|
+
system! 'bin/rails log:clear tmp:clear'
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system! 'bin/rails restart'
|
29
|
+
end
|