notifications 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4db6d361624d9bc1d23d47a7ccc2972a72c2b7db
4
- data.tar.gz: 9997b74887d08320e258d170c726e20a5f7b5196
3
+ metadata.gz: 19fdfc6600364423b916ac5ceb8f6f392a3f069d
4
+ data.tar.gz: b771f33617dab12b562c6b737495f7cfee80fc1a
5
5
  SHA512:
6
- metadata.gz: 3c0c36018c209e2b50b02b856880f4170b2ce33df7322a3a766c27c1b0461cc98c6b4670b25ad9d143d4d29df1441e48499d898b4bed929270ab1a88fb0fec9c
7
- data.tar.gz: ec47e9eb45a4bfa1e158f478191dc3b5fb78bc327f25c7205c32aca71df454418ae4fd3a17c01f279c372ead7ed3ff55ab8040a649c52f8e134440bfe4baa32e
6
+ metadata.gz: cddce6321db0f1a954ff3e2816b8c3cf858f4893d995788abfd8b3e9a150acc4667440c6c11450b780ff6b302e9357f715b8620cbe869b9b7d0a267149337205
7
+ data.tar.gz: f072bd94cd7509e33193bd8dd40953dd9bd4e0fdea9b0b34c933f2bc33be44b66276350275e947ccd03c880323e4302a74277b6d0e118374df2470ba120ebbb1
data/README.md CHANGED
@@ -6,7 +6,7 @@ Rails mountable Notification for any applications.
6
6
 
7
7
  ## Example:
8
8
 
9
- <img width="650" alt="2016-03-29 10 48 16" src="https://cloud.githubusercontent.com/assets/5518/14096499/d7555aaa-f59b-11e5-87f0-e4728db903c8.png">
9
+ <img width="800" alt="2016-03-29 10 48 16" src="https://cloud.githubusercontent.com/assets/5518/16578955/eb59e472-42cf-11e6-825e-8fc9ecf58a8b.png">
10
10
 
11
11
  ## Installation
12
12
 
@@ -97,7 +97,7 @@ You app must be have:
97
97
 
98
98
  ### About Notification template N+1 performance
99
99
 
100
- We suggest use [second_level_cached](https://github.com/hooopo/second_level_cache) for solve N+1 performance issue.
100
+ Suggest you to use [second_level_cache](https://github.com/hooopo/second_level_cache) for solve N+1 performance issue.
101
101
 
102
102
  ## Contributing
103
103
 
@@ -3,7 +3,9 @@ module Notifications
3
3
  helper_method :current_user
4
4
 
5
5
  alias_method :origin_current_user, Notifications.config.current_user_method.to_sym
6
- alias_method :origin_authenticate_user!, Notifications.config.authenticate_user_method.to_sym
6
+ if Notifications.config.authenticate_user_method
7
+ alias_method :origin_authenticate_user!, Notifications.config.authenticate_user_method.to_sym
8
+ end
7
9
 
8
10
  before_action :authenticate_user!
9
11
 
@@ -12,7 +14,7 @@ module Notifications
12
14
  end
13
15
 
14
16
  def authenticate_user!
15
- origin_authenticate_user!
17
+ origin_authenticate_user! if Notifications.config.authenticate_user_method
16
18
  end
17
19
  end
18
20
  end
@@ -1,7 +1,7 @@
1
1
  module Notifications
2
2
  class NotificationsController < Notifications::ApplicationController
3
3
  def index
4
- @notifications = current_user.notifications.includes(:actor).order('id desc').page(params[:page])
4
+ @notifications = notifications.includes(:actor).order('id desc').page(params[:page])
5
5
 
6
6
  unread_ids = []
7
7
  @notifications.each do |n|
@@ -13,8 +13,14 @@ module Notifications
13
13
  end
14
14
 
15
15
  def clean
16
- Notification.where(user_id: current_user.id).delete_all
16
+ notifications.delete_all
17
17
  redirect_to notifications_path
18
18
  end
19
+
20
+ private
21
+
22
+ def notifications
23
+ Notification.where(user_id: current_user.id)
24
+ end
19
25
  end
20
26
  end
@@ -3,7 +3,9 @@
3
3
  data-id="<%= notification.id %>"
4
4
  class="media notification notification-<%= notification.notify_type %><%= ' unread' if !notification.read? %>">
5
5
  <div class="media-left">
6
- <%= link_to image_tag(notification.actor_avatar_url), notification.actor_profile_url, title: notification.actor_name, class: 'user-avatar' %>
6
+ <% if notification.actor_profile_url && notification.actor_avatar_url %>
7
+ <%= link_to image_tag(notification.actor_avatar_url), notification.actor_profile_url, title: notification.actor_name, class: 'user-avatar' %>
8
+ <% end %>
7
9
  </div>
8
10
  <div class="media-body">
9
11
  <%= render partial: "/notifications/#{notification.notify_type}", locals: { notification: notification } %>
@@ -9,10 +9,10 @@ Notifications.configure do
9
9
  # Method of user avatar in User model, default: nil
10
10
  # self.user_avatar_url_method = nil
11
11
 
12
- # Method name of user profile page path, in User model, default: 'profile_url'
12
+ # Method name of user profile page path, in User model, default: nil
13
13
  # self.user_profile_url_method = 'profile_url'
14
14
 
15
- # authenticate_user method in your Controller, default: 'authenticate_user!'
15
+ # authenticate_user method in your Controller, default: nil
16
16
  # If you use Devise, authenticate_user! is correct
17
17
  # self.authenticate_user_method = 'authenticate_user!'
18
18
 
@@ -10,7 +10,7 @@ module Notifications
10
10
  if File.exist?(path)
11
11
  puts 'Skipping config/initializers/notifications.rb creation, as file already exists!'
12
12
  else
13
- puts 'Adding Homeland initializer (config/initializers/notifications.rb)...'
13
+ puts 'Adding Notifications initializer (config/initializers/notifications.rb)...'
14
14
  template 'config/initializers/notifications.rb', path
15
15
  end
16
16
  end
data/lib/notifications.rb CHANGED
@@ -14,8 +14,8 @@ module Notifications
14
14
  @config.user_class = 'User'
15
15
  @config.user_name_method = 'name'
16
16
  @config.user_avatar_url_method = nil
17
- @config.user_profile_url_method = 'profile_url'
18
- @config.authenticate_user_method = 'authenticate_user!'
17
+ @config.user_profile_url_method = nil
18
+ @config.authenticate_user_method = nil
19
19
  @config.current_user_method = 'current_user'
20
20
  @config
21
21
  end
@@ -22,7 +22,7 @@ module Notifications
22
22
  #
23
23
  attr_accessor :user_avatar_url_method
24
24
 
25
- # method name of user profile page path, in User model, default: 'profile_url'
25
+ # method name of user profile page path, in User model, default: nil
26
26
  # Example:
27
27
  #
28
28
  # class User
@@ -37,7 +37,7 @@ module Notifications
37
37
  # current_user method name in your Controller, default: 'current_user'
38
38
  attr_accessor :current_user_method
39
39
 
40
- # authenticate_user method in your Controller, default: 'authenticate_user!'
40
+ # authenticate_user method in your Controller, default: nil
41
41
  attr_accessor :authenticate_user_method
42
42
 
43
43
  # pagination size, default: 32
@@ -31,7 +31,8 @@ module Notifications
31
31
  end
32
32
 
33
33
  def actor_profile_url
34
- return '#' if self.actor.blank?
34
+ return nil if Notifications.config.user_profile_url_method.blank?
35
+ return nil if self.actor.blank?
35
36
  self.actor.send(Notifications.config.user_profile_url_method)
36
37
  end
37
38
 
@@ -1,3 +1,3 @@
1
1
  module Notifications
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-26 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,16 +34,16 @@ dependencies:
34
34
  name: will_paginate
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 3.0.0
39
+ version: '3'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 3.0.0
46
+ version: '3'
47
47
  description: Rails mountable Notification for any applications.
48
48
  email:
49
49
  - huacnlee@gmail.com
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.4.8
98
+ rubygems_version: 2.5.2
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Rails mountable Notification for any applications.