notify_with 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +30 -0
  4. data/app/controllers/concerns/notify_with/notifications_api.rb +38 -0
  5. data/app/mailers/notify_with/notifications_mailer.rb +29 -0
  6. data/app/models/concerns/notify_with/notification.rb +47 -0
  7. data/app/models/concerns/notify_with/notification_receiver.rb +9 -0
  8. data/app/models/concerns/notify_with/notification_type.rb +23 -0
  9. data/config/routes.rb +2 -0
  10. data/lib/generators/notify_with/install/USAGE +15 -0
  11. data/lib/generators/notify_with/install/install_generator.rb +62 -0
  12. data/lib/generators/notify_with/install/templates/create_notification.rb +13 -0
  13. data/lib/generators/notify_with/install/templates/index.json.jbuilder +9 -0
  14. data/lib/generators/notify_with/install/templates/notification.rb +3 -0
  15. data/lib/generators/notify_with/install/templates/notification_type.rb +6 -0
  16. data/lib/generators/notify_with/install/templates/notifications_controller.rb +3 -0
  17. data/lib/generators/notify_with/install/templates/notifications_mailer.rb +4 -0
  18. data/lib/generators/notify_with/install/templates/notify_with.rb +1 -0
  19. data/lib/generators/notify_with/install/templates/show.json.jbuilder +5 -0
  20. data/lib/generators/notify_with/notification/USAGE +11 -0
  21. data/lib/generators/notify_with/notification/notification_generator.rb +33 -0
  22. data/lib/notify_with/engine.rb +12 -0
  23. data/lib/notify_with/version.rb +3 -0
  24. data/lib/notify_with.rb +5 -0
  25. data/lib/tasks/notify_with_tasks.rake +4 -0
  26. data/spec/controllers/notifications_controller_spec.rb +57 -0
  27. data/spec/dummy/README.rdoc +28 -0
  28. data/spec/dummy/Rakefile +6 -0
  29. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  30. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  31. data/spec/dummy/app/controllers/api/notifications_controller.rb +6 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  34. data/spec/dummy/app/mailers/notifications_mailer.rb +4 -0
  35. data/spec/dummy/app/models/message.rb +2 -0
  36. data/spec/dummy/app/models/notification.rb +3 -0
  37. data/spec/dummy/app/models/notification_type.rb +7 -0
  38. data/spec/dummy/app/models/user.rb +3 -0
  39. data/spec/dummy/app/views/api/notifications/_notify_new_message.json.jbuilder +3 -0
  40. data/spec/dummy/app/views/api/notifications/index.json.jbuilder +9 -0
  41. data/spec/dummy/app/views/api/notifications/show.json.jbuilder +5 -0
  42. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  43. data/spec/dummy/app/views/notifications_mailer/notify_new_message.html.erb +2 -0
  44. data/spec/dummy/bin/bundle +3 -0
  45. data/spec/dummy/bin/rails +4 -0
  46. data/spec/dummy/bin/rake +4 -0
  47. data/spec/dummy/bin/setup +29 -0
  48. data/spec/dummy/config/application.rb +34 -0
  49. data/spec/dummy/config/boot.rb +5 -0
  50. data/spec/dummy/config/database.yml +25 -0
  51. data/spec/dummy/config/environment.rb +5 -0
  52. data/spec/dummy/config/environments/development.rb +41 -0
  53. data/spec/dummy/config/environments/production.rb +79 -0
  54. data/spec/dummy/config/environments/test.rb +42 -0
  55. data/spec/dummy/config/initializers/assets.rb +11 -0
  56. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  59. data/spec/dummy/config/initializers/inflections.rb +16 -0
  60. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  61. data/spec/dummy/config/initializers/notify_with.rb +1 -0
  62. data/spec/dummy/config/initializers/session_store.rb +3 -0
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/spec/dummy/config/locales/en.yml +4 -0
  65. data/spec/dummy/config/routes.rb +10 -0
  66. data/spec/dummy/config/secrets.yml +22 -0
  67. data/spec/dummy/config.ru +4 -0
  68. data/spec/dummy/db/development.sqlite3 +0 -0
  69. data/spec/dummy/db/migrate/20150213150625_create_users.rb +10 -0
  70. data/spec/dummy/db/migrate/20150213152846_create_messages.rb +9 -0
  71. data/spec/dummy/db/migrate/20150216115438_create_notification.rb +13 -0
  72. data/spec/dummy/db/schema.rb +41 -0
  73. data/spec/dummy/db/test.sqlite3 +0 -0
  74. data/spec/dummy/log/development.log +2402 -0
  75. data/spec/dummy/log/test.log +37779 -0
  76. data/spec/dummy/public/404.html +67 -0
  77. data/spec/dummy/public/422.html +67 -0
  78. data/spec/dummy/public/500.html +66 -0
  79. data/spec/dummy/public/favicon.ico +0 -0
  80. data/spec/factories/message.rb +5 -0
  81. data/spec/factories/notification.rb +7 -0
  82. data/spec/factories/user.rb +9 -0
  83. data/spec/mailers/notifications_mailer_spec.rb +32 -0
  84. data/spec/models/notification_spec.rb +69 -0
  85. data/spec/notify_with_spec.rb +11 -0
  86. data/spec/rails_helper.rb +52 -0
  87. data/spec/spec_helper.rb +87 -0
  88. data/spec/support/factory_girl.rb +3 -0
  89. metadata +278 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3173ecd1a4779e09c8fbfcaca08042117de9b342
4
+ data.tar.gz: 7348cc427713287bf0b640590dd4523ab035e9dc
5
+ SHA512:
6
+ metadata.gz: 076d6743c70272b6df0077e83c5ca887de3ce84d5f7a1f263a225792f87d38956063cfca9541519c77a50e6d82c40b0623fb6d7a5f41a2806c8764c075cf49c2
7
+ data.tar.gz: 1880410b455978697059f4c20d804f15008c75d37f1e58d3139043385c7acc5c4d8ccb3b4cdf1d7620857dbb2d012776efbb3aa16f1e64eec970fc37e73f2b83
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Peng DU
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/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'NotifyWith'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
23
+
24
+ require 'rspec/core'
25
+ require 'rspec/core/rake_task'
26
+
27
+ desc "Run all specs in spec directory (excluding plugin specs)"
28
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
29
+
30
+ task :default => :spec
@@ -0,0 +1,38 @@
1
+ module NotifyWith
2
+ module NotificationsApi
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ respond_to :json
7
+ before_action :set_notification, only: [:show, :update]
8
+
9
+ def index
10
+ if params[:is_read]
11
+ @notifications = current_user.notifications.where(is_read: params[:is_read] == "true")
12
+ else
13
+ @notifications = current_user.notifications
14
+ end
15
+ end
16
+
17
+ def show
18
+ end
19
+
20
+ def update
21
+ @notification.mark_as_read
22
+ render :show
23
+ end
24
+
25
+ def update_all
26
+ current_user.notifications.where(is_read: false).find_each do |n|
27
+ n.mark_as_read
28
+ end
29
+ head :no_content
30
+ end
31
+
32
+ private
33
+ def set_notification
34
+ @notification = current_user.notifications.find(params[:id])
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ module NotifyWith
2
+ class NotificationsMailer < ActionMailer::Base
3
+ after_action :mark_notification_as_send
4
+
5
+ def send_mail_by(notification)
6
+ @notification = notification
7
+ @recipient = notification.receiver
8
+ @attached_object = notification.attached_object
9
+
10
+ if !respond_to?(notification.notification_type)
11
+ class_eval %Q{
12
+ def #{notification.notification_type}
13
+ mail to: @recipient.email,
14
+ subject: t('.subject_#{notification.notification_type}'),
15
+ template_name: '#{notification.notification_type}',
16
+ content_type: 'text/html'
17
+ end
18
+ }
19
+ end
20
+
21
+ send(notification.notification_type)
22
+ end
23
+
24
+ private
25
+ def mark_notification_as_send
26
+ @notification.mark_as_send unless @notification.is_send
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,47 @@
1
+ module NotifyWith
2
+ module Notification
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ belongs_to :receiver, polymorphic: true
7
+ belongs_to :attached_object, polymorphic: true
8
+
9
+ validates_presence_of :receiver_id,
10
+ :receiver_type,
11
+ :attached_object_id,
12
+ :attached_object_type,
13
+ :notification_type_id
14
+
15
+ def send_notification(type: nil, attached_object: nil)
16
+ self.notification_type_id = ::NotificationType.find_by_name(type)
17
+ self.attached_object = attached_object
18
+ self
19
+ end
20
+
21
+ def to(receiver)
22
+ self.receiver = receiver
23
+ self
24
+ end
25
+
26
+ def notification_type
27
+ ::NotificationType.find(notification_type_id)
28
+ end
29
+
30
+ def mark_as_read
31
+ update_columns(is_read: true)
32
+ end
33
+
34
+ def mark_as_send
35
+ update_columns(is_send: true)
36
+ end
37
+
38
+ def deliver_now
39
+ NotifyWith.mailer.send_mail_by(self).deliver_now if save
40
+ end
41
+
42
+ def deliver_later
43
+ NotifyWith.mailer.send_mail_by(self).deliver_later if save
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,9 @@
1
+ module NotifyWith
2
+ module NotificationReceiver
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :notifications, as: :receiver, dependent: :destroy
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module NotifyWith
2
+ module NotificationType
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ NAMES = []
7
+
8
+ def self.notification_type_names(names)
9
+ NAMES.concat names
10
+ end
11
+
12
+ def self.find(id)
13
+ return nil if id.nil?
14
+ NAMES[id-1]
15
+ end
16
+
17
+ def self.find_by_name(name)
18
+ return nil if name.nil? or NAMES.empty?
19
+ NAMES.index(name.to_s)+1
20
+ end
21
+ end
22
+ end
23
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ NotifyWith::Engine.routes.draw do
2
+ end
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Generates model notification and notification_type, a mailer, an initializer
3
+
4
+ Example:
5
+ rails generate notify_with:install
6
+
7
+ This will create:
8
+ db/migrate/created_notifcation.rb
9
+ app/models/notification.rb
10
+ app/models/notification_type.rb
11
+ app/mailers/notifications_mailer.rb
12
+ config/initializers/notify_with.rb
13
+
14
+ this will update:
15
+ config/locales/{local}.yml
@@ -0,0 +1,62 @@
1
+ class NotifyWith::InstallGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def self.next_migration_number path
6
+ unless @prev_migration_nr
7
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
8
+ else
9
+ @prev_migration_nr += 1
10
+ end
11
+ @prev_migration_nr.to_s
12
+ end
13
+
14
+ def copy_notification_migration
15
+ migration_template "create_notification.rb", "db/migrate/create_notification.rb"
16
+ end
17
+
18
+ def copy_notification_model
19
+ template "notification.rb", "app/models/notification.rb"
20
+ end
21
+
22
+ def copy_notification_type_model
23
+ template "notification_type.rb", "app/models/notification_type.rb"
24
+ end
25
+
26
+ def copy_notifications_mailer
27
+ template "notifications_mailer.rb", "app/mailers/notifications_mailer.rb"
28
+ end
29
+
30
+ def copy_api_notifications_controller
31
+ template "notifications_controller.rb", "app/controllers/api/notifications_controller.rb"
32
+ end
33
+
34
+ def copy_api_notifications_views
35
+ template "index.json.jbuilder", "app/views/api/notifications/index.json.jbuilder"
36
+ template "show.json.jbuilder", "app/views/api/notifications/show.json.jbuilder"
37
+ end
38
+
39
+ def add_notifications_route
40
+ route \
41
+ <<-CODE
42
+ namespace :api, defaults: { format: :json } do
43
+ resources :notifications, only: [:index, :show, :update] do
44
+ match :update_all, path: '/', via: [:put, :patch], on: :collection
45
+ end
46
+ end
47
+ CODE
48
+ end
49
+
50
+ def copy_initializer
51
+ template "notify_with.rb", "config/initializers/notify_with.rb"
52
+ end
53
+
54
+ def add_subject_locale
55
+ append_file "config/locales/#{I18n.locale.to_s}.yml" do
56
+ <<-CODE
57
+ notifications_mailer:
58
+ send_mail_by:
59
+ CODE
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,13 @@
1
+ class CreateNotification < ActiveRecord::Migration
2
+ def change
3
+ create_table :notify_with_notifications do |t|
4
+ t.references :receiver, polymorphic: true
5
+ t.references :attached_object, polymorphic: true
6
+ t.integer :notification_type_id
7
+ t.boolean :is_read, default: false
8
+ t.boolean :is_send, default: false
9
+
10
+ t.timestamps null: false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ json.array!(@notifications) do |notification|
2
+ if notification.attached_object
3
+ json.extract! notification, :id, :notification_type_id, :notification_type, :created_at, :is_read
4
+ json.attached_object notification.attached_object
5
+ json.message do
6
+ json.partial! "/api/notifications/#{notification.notification_type}", notification: notification
7
+ end
8
+ end
9
+ end.delete_if {|n| n['id'] == nil }
@@ -0,0 +1,3 @@
1
+ class Notification < ActiveRecord::Base
2
+ include NotifyWith::Notification
3
+ end
@@ -0,0 +1,6 @@
1
+ class NotificationType
2
+ include NotifyWith::NotificationType
3
+
4
+ notification_type_names %w(
5
+ )
6
+ end
@@ -0,0 +1,3 @@
1
+ class API::NotificationsController < ApplicationController
2
+ include NotifyWith::NotificationsApi
3
+ end
@@ -0,0 +1,4 @@
1
+ class NotificationsMailer < NotifyWith::NotificationsMailer
2
+ default from: 'contact@sleede.com'
3
+ layout false
4
+ end
@@ -0,0 +1 @@
1
+ NotifyWith.mailer = NotificationsMailer
@@ -0,0 +1,5 @@
1
+ json.extract! @notification, :id, :notification_type_id, :notification_type, :created_at, :is_read
2
+ json.attached_object @notification.attached_object
3
+ json.message do
4
+ json.partial! "/api/notifications/#{@notification.notification_type}", notification: @notification
5
+ end
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Add a notification by name
3
+
4
+ Example:
5
+ rails generate notification name
6
+
7
+ This will create or modify:
8
+ insert app/models/notification_type.rb
9
+ create app/views/notifications_mailer/name.html.erb
10
+ insert app/mailers/notifications_mailer.rb
11
+ insert config/locales/en.yml
@@ -0,0 +1,33 @@
1
+ class NotifyWith::NotificationGenerator < Rails::Generators::NamedBase
2
+ def add_notification_type
3
+ inject_into_file 'app/models/notification_type.rb', before: / \)/ do
4
+ <<-CODE
5
+ #{file_name}
6
+ CODE
7
+ end
8
+ end
9
+
10
+ def create_notification_mail_template_file
11
+ create_file "app/views/notifications_mailer/#{file_name}.html.erb", <<-FILE
12
+ <%# this is a mail template of notifcation #{file_name} %>
13
+ <p><%= @recipient.name %></p>
14
+ <p><%= @attached_object.body %></p>
15
+ FILE
16
+ end
17
+
18
+ def add_notification_subject
19
+ inject_into_file "config/locales/#{I18n.locale.to_s}.yml", after: /send_mail_by:\n/ do
20
+ <<-CODE
21
+ subject_#{file_name}: "#{file_name}"
22
+ CODE
23
+ end
24
+ end
25
+
26
+ def create_notification_json_template_file
27
+ create_file "app/views/api/notifications/_#{file_name}.json.jbuilder", <<-FILE
28
+ json.title notification.notification_type
29
+ json.description 'a notification description'
30
+ json.url 'a url for redirect to attached_object'
31
+ FILE
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ module NotifyWith
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace NotifyWith
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, fixture: false
7
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
8
+ g.assets false
9
+ g.helper false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module NotifyWith
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "notify_with/engine"
2
+
3
+ module NotifyWith
4
+ mattr_accessor :mailer
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :notify_with do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,57 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe API::NotificationsController, type: :controller do
4
+ let(:notification) { create :notification }
5
+
6
+ before :each do
7
+ allow_any_instance_of(API::NotificationsController).to receive(:current_user).and_return(notification.receiver)
8
+ end
9
+
10
+ it 'should get current user' do
11
+ expect(subject).to receive(:current_user).and_return(notification.receiver)
12
+ get :index, format: :json
13
+ end
14
+
15
+ describe 'GET index json' do
16
+ render_views
17
+
18
+ it "should returns a notification from a rendered template" do
19
+ get :index, format: :json
20
+ expect(json.size).to eq 1
21
+ expect(json[0]['id']).to eq notification.id
22
+ expect(json[0]['message']['title']).to eq notification.notification_type
23
+ end
24
+ end
25
+
26
+ describe 'GET show json' do
27
+ render_views
28
+
29
+ it "should returns a notification from a rendered template" do
30
+ get :show, format: :json, id: notification.id
31
+ expect(json['id']).to eq notification.id
32
+ expect(json['message']['title']).to eq notification.notification_type
33
+ end
34
+ end
35
+
36
+ describe 'PUT update' do
37
+ render_views
38
+
39
+ it "should mark as read" do
40
+ put :update, format: :json, id: notification.id
41
+ expect(json['is_read']).to eq true
42
+ end
43
+ end
44
+
45
+ describe 'PUT update_all' do
46
+ render_views
47
+
48
+ it "should all notification of user mark as read" do
49
+ put :update_all, format: :json
50
+ expect(notification.reload.is_read).to eq true
51
+ end
52
+ end
53
+
54
+ def json
55
+ ActiveSupport::JSON.decode(response.body)
56
+ end
57
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,6 @@
1
+ class API::NotificationsController < ApplicationController
2
+ include NotifyWith::NotificationsApi
3
+
4
+ def current_user
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class NotificationsMailer < NotifyWith::NotificationsMailer
2
+ default from: 'contact@sleede.com'
3
+ layout false
4
+ end
@@ -0,0 +1,2 @@
1
+ class Message < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ class Notification < ActiveRecord::Base
2
+ include NotifyWith::Notification
3
+ end
@@ -0,0 +1,7 @@
1
+ class NotificationType
2
+ include NotifyWith::NotificationType
3
+
4
+ notification_type_names %w(
5
+ notify_new_message
6
+ )
7
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ include NotifyWith::NotificationReceiver
3
+ end
@@ -0,0 +1,3 @@
1
+ json.title notification.notification_type
2
+ json.description "description"
3
+ json.url 'url'
@@ -0,0 +1,9 @@
1
+ json.array!(@notifications) do |notification|
2
+ if notification.attached_object
3
+ json.extract! notification, :id, :notification_type_id, :notification_type, :created_at, :is_read
4
+ json.attached_object notification.attached_object
5
+ json.message do
6
+ json.partial! "/api/notifications/#{notification.notification_type}", notification: notification
7
+ end
8
+ end
9
+ end.delete_if {|n| n['id'] == nil }
@@ -0,0 +1,5 @@
1
+ json.extract! @notification, :id, :notification_type_id, :notification_type, :created_at, :is_read
2
+ json.attached_object @notification.attached_object
3
+ json.message do
4
+ json.partial! "/api/notifications/#{@notification.notification_type}", notification: @notification
5
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,2 @@
1
+ <p><%= @recipient.name %></p>
2
+ <p><%= @attached_object.body %></p>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')