commontator 0.2.4 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/app/assets/stylesheets/commontator/threads.css +4 -0
  2. data/app/assets/stylesheets/commontator/threads.css~ +1 -1
  3. data/app/controllers/commontator/application_controller.rb +5 -0
  4. data/app/controllers/commontator/application_controller.rb~ +8 -1
  5. data/app/controllers/commontator/comments_controller.rb +24 -31
  6. data/app/controllers/commontator/comments_controller.rb~ +25 -32
  7. data/app/controllers/commontator/subscriptions_controller.rb +8 -18
  8. data/app/controllers/commontator/subscriptions_controller.rb~ +10 -16
  9. data/app/controllers/commontator/threads_controller.rb +3 -5
  10. data/app/controllers/commontator/threads_controller.rb~ +3 -6
  11. data/app/helpers/commontator/application_helper.rb +2 -6
  12. data/app/helpers/commontator/application_helper.rb~ +4 -4
  13. data/app/helpers/commontator/commontator_helper.rb +2 -2
  14. data/app/helpers/commontator/commontator_helper.rb~ +2 -2
  15. data/app/helpers/commontator/threads_helper.rb +1 -1
  16. data/app/helpers/commontator/threads_helper.rb~ +5 -12
  17. data/app/mailers/commontator/subscriptions_mailer.rb +15 -11
  18. data/app/mailers/commontator/subscriptions_mailer.rb~ +15 -12
  19. data/app/models/commontator/comment.rb +2 -2
  20. data/app/models/commontator/thread.rb +11 -11
  21. data/app/models/commontator/thread.rb~ +7 -9
  22. data/app/views/commontator/comments/_actions.html.erb +13 -16
  23. data/app/views/commontator/comments/_actions.html.erb~ +13 -17
  24. data/app/views/commontator/comments/create.js.erb +1 -1
  25. data/app/views/commontator/comments/create.js.erb~ +2 -2
  26. data/app/views/commontator/comments/delete.js.erb +1 -1
  27. data/app/views/commontator/comments/delete.js.erb~ +2 -2
  28. data/app/views/commontator/comments/edit.js.erb +1 -1
  29. data/app/views/commontator/comments/edit.js.erb~ +2 -2
  30. data/app/views/commontator/comments/new.js.erb +1 -1
  31. data/app/views/commontator/comments/new.js.erb~ +2 -2
  32. data/app/views/commontator/comments/update.js.erb +1 -1
  33. data/app/views/commontator/comments/update.js.erb~ +2 -2
  34. data/app/views/commontator/comments/vote.js.erb +1 -1
  35. data/app/views/commontator/comments/vote.js.erb~ +2 -2
  36. data/app/views/commontator/{commontator/_thread.html.erb~ → shared/_thread_link.html.erb} +1 -3
  37. data/app/views/commontator/subscriptions/{index.html.erb → _index.html.erb~} +0 -0
  38. data/app/views/commontator/subscriptions/_link.html.erb +15 -0
  39. data/app/views/commontator/subscriptions/_link.html.erb~ +15 -0
  40. data/app/views/commontator/subscriptions/_subscription_link.html.erb~ +8 -7
  41. data/app/views/commontator/subscriptions/create.js.erb~ +4 -2
  42. data/app/views/commontator/subscriptions/subscribe.js.erb +5 -0
  43. data/app/views/commontator/subscriptions/subscribe.js.erb~ +5 -0
  44. data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb +4 -12
  45. data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb~ +4 -12
  46. data/app/views/commontator/threads/_actions.html.erb~ +28 -0
  47. data/app/views/commontator/{commontator/_thread.html.erb → threads/_link.html.erb~} +1 -1
  48. data/app/views/commontator/threads/_show.html.erb +30 -2
  49. data/app/views/commontator/threads/_show.html.erb~ +31 -3
  50. data/app/views/commontator/threads/close.js.erb~ +5 -0
  51. data/app/views/commontator/threads/{show.html.erb → show.html.erb~} +0 -0
  52. data/app/views/commontator/threads/show.js.erb +1 -1
  53. data/app/views/commontator/threads/show.js.erb~ +6 -0
  54. data/config/initializers/commontator.rb +17 -11
  55. data/config/initializers/commontator.rb~ +16 -11
  56. data/config/routes.rb +2 -4
  57. data/config/routes.rb~ +4 -2
  58. data/lib/commontator.rb +1 -1
  59. data/lib/commontator.rb~ +2 -2
  60. data/lib/commontator/version.rb +1 -1
  61. data/lib/commontator/version.rb~ +1 -1
  62. data/test/dummy/config/initializers/commontator.rb +23 -12
  63. data/test/dummy/config/initializers/commontator.rb~ +174 -0
  64. data/test/dummy/log/development.log +6 -0
  65. metadata +15 -11
  66. data/app/views/commontator/comments/edit.html.erb +0 -6
  67. data/app/views/commontator/comments/new.html.erb +0 -8
  68. data/app/views/commontator/subscriptions/_subscription_link.html.erb +0 -12
  69. data/app/views/commontator/subscriptions/create.js.erb +0 -5
  70. data/app/views/commontator/subscriptions/destroy.js.erb +0 -5
@@ -1,11 +1,7 @@
1
1
  module Commontator
2
2
  module ApplicationHelper
3
- def heading(string)
4
- Commontator.heading_proc.call(string) unless Commontator.heading_proc.blank?
5
- end
6
-
7
- def javascript_callback
8
- Commontator.javascript_proc.call unless Commontator.javascript_proc.blank?
3
+ def javascript_proc
4
+ Commontator.javascript_proc.call(self).html_safe
9
5
  end
10
6
  end
11
7
  end
@@ -1,11 +1,11 @@
1
1
  module Commontator
2
2
  module ApplicationHelper
3
- def heading(string)
4
- Commontator.heading_proc.call unless Commontator.heading_proc.blank?
3
+ def commontable_url(thread)
4
+ thread.config.commontable_url_proc.call(main_app, thread.commontable)
5
5
  end
6
6
 
7
- def javascript_callback
8
- Commontator.javascript_proc.call unless Commontator.javascript_proc.blank?
7
+ def javascript_proc
8
+ Commontator.javascript_proc.call(self).html_safe
9
9
  end
10
10
  end
11
11
  end
@@ -1,8 +1,8 @@
1
1
  module Commontator
2
2
  module CommontatorHelper
3
3
  def commontator_thread_link(commontable)
4
- render(:partial => 'commontator/commontator/thread',
5
- :locals => {:commontable => commontable}).html_safe
4
+ render(:partial => 'commontator/shared/thread_link',
5
+ :locals => {:thread => commontable.thread}).html_safe
6
6
  end
7
7
  end
8
8
  end
@@ -1,8 +1,8 @@
1
1
  module Commontator
2
2
  module CommontatorHelper
3
3
  def commontator_thread_link(commontable)
4
- render(:partial => 'commontator/shared/thread',
5
- :locals => {:commontable => commontable}).html_safe
4
+ render(:partial => 'commontator/shared/link',
5
+ :locals => {:thread => commontable.thread}).html_safe
6
6
  end
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Commontator
2
- module ThreadsHelper
2
+ module ThreadsHelper
3
3
  def commontable_name(thread)
4
4
  config = thread.config
5
5
  config.commontable_name.blank? ? \
@@ -1,5 +1,9 @@
1
1
  module Commontator
2
- module ThreadsHelper
2
+ module ThreadsHelper
3
+ def commontable_url(thread)
4
+ thread.config.commontable_url_proc.call(main_app, thread.commontable)
5
+ end
6
+
3
7
  def commontable_name(thread)
4
8
  config = thread.config
5
9
  config.commontable_name.blank? ? \
@@ -17,16 +21,5 @@ module Commontator
17
21
  config.commontator_name_method.blank? ? config.anonymous_name : \
18
22
  closer.send(config.commontator_name_method)
19
23
  end
20
-
21
- def refresh_thread_actions(thread)
22
- output = ""
23
- thread.comments.each do |comment|
24
- output << "$('#comment_#{comment.id.to_s}_actions_span').html('" + \
25
- escape_javascript(
26
- render :partial => :actions,
27
- :locals => { :comment => comment }) + "');\n\n"
28
- end
29
- output.slice(0..-3).html_safe
30
- end
31
24
  end
32
25
  end
@@ -1,35 +1,39 @@
1
1
  module Commontator
2
2
  class SubscriptionsMailer < ActionMailer::Base
3
-
4
3
  include CommentsHelper
5
4
  include ThreadsHelper
6
5
 
7
- def comment_created_email(comment)
8
- setup_variables(comment)
6
+ def comment_created_email(comment, commontable_url)
7
+ setup_variables(comment, commontable_url)
9
8
 
10
- mail(:bcc => @bcc,
11
- :subject => @subject)
9
+ mail(:bcc => @bcc, :subject => @subject) \
10
+ unless @bcc.empty?
12
11
  end
13
12
 
14
13
  protected
15
14
 
16
- def setup_variables(comment)
15
+ def setup_variables(comment, commontable_url)
17
16
 
18
17
  @comment = comment
19
18
  @thread = @comment.thread
20
-
21
19
  @commontator = @comment.commontator
20
+
21
+ @bcc = @thread.subscribers.reject{|s| s == @commontator}\
22
+ .collect{|s| email(s)}
23
+
24
+ return if @bcc.empty?
25
+
22
26
  @commontable = @thread.commontable
23
27
  @config = @thread.config
24
- @bcc = @thread.subscribers.reject{|s| s == @commontator}\
25
- .collect{|s| email(s)}
26
-
28
+
27
29
  @commontator_name = commontator_name(@comment)
28
30
  @comment_timestamp = comment_timestamp(@comment)
29
31
 
30
32
  @commontable_name = commontable_name(@thread)
31
33
  @commontable_id = commontable_id(@thread).to_s
32
34
 
35
+ @commontable_url = commontable_url
36
+
33
37
  params = Hash.new
34
38
  params[:comment] = @comment
35
39
  params[:thread] = @thread
@@ -40,9 +44,9 @@ protected
40
44
  params[:comment_timestamp] = @comment_timestamp
41
45
  params[:commontable_name] = @commontable_name
42
46
  params[:commontable_id] = @commontable_id
47
+ params[:commontable_url] = @commontable_url
43
48
 
44
49
  @subject = @config.subscription_email_subject_proc.call(params)
45
50
  end
46
-
47
51
  end
48
52
  end
@@ -1,36 +1,39 @@
1
1
  module Commontator
2
2
  class SubscriptionsMailer < ActionMailer::Base
3
-
4
3
  include CommentsHelper
5
4
  include ThreadsHelper
6
5
 
7
- def comment_created_email(comment)
8
- setup_variables(comment)
6
+ def comment_created_email(comment, commontable_url)
7
+ setup_variables(comment, commontable_url)
9
8
 
10
- mail(:bcc => @bcc,
11
- :subject => @subject,
12
- :body => @body)
9
+ mail(:bcc => @bcc, :subject => @subject) \
10
+ unless @bcc.empty?
13
11
  end
14
12
 
15
13
  protected
16
14
 
17
- def setup_variables(comment)
15
+ def setup_variables(comment, commontable_url)
18
16
 
19
17
  @comment = comment
20
18
  @thread = @comment.thread
21
-
22
19
  @commontator = @comment.commontator
20
+
21
+ @bcc = @thread.subscribers.reject{|s| s == @commontator}\
22
+ .collect{|s| email(s)}
23
+
24
+ return if @bcc.empty?
25
+
23
26
  @commontable = @thread.commontable
24
27
  @config = @thread.config
25
- @bcc = @thread.subscribers.reject{|s| s == @commontator}\
26
- .collect{|s| email(s)}
27
-
28
+
28
29
  @commontator_name = commontator_name(@comment)
29
30
  @comment_timestamp = comment_timestamp(@comment)
30
31
 
31
32
  @commontable_name = commontable_name(@thread)
32
33
  @commontable_id = commontable_id(@thread).to_s
33
34
 
35
+ @commontable_url = commontable_url
36
+
34
37
  params = Hash.new
35
38
  params[:comment] = @comment
36
39
  params[:thread] = @thread
@@ -39,11 +42,11 @@ protected
39
42
  params[:config] = @config
40
43
  params[:commontator_name] = @commontator_name
41
44
  params[:comment_timestamp] = @comment_timestamp
45
+ params[:commontable_url] = @commontable_url
42
46
  params[:commontable_name] = @commontable_name
43
47
  params[:commontable_id] = @commontable_id
44
48
 
45
49
  @subject = @config.subscription_email_subject_proc.call(params)
46
50
  end
47
-
48
51
  end
49
52
  end
@@ -64,9 +64,9 @@ module Commontator
64
64
  end
65
65
 
66
66
  def can_be_deleted_by?(user)
67
- !thread.is_closed? &&\
67
+ (!thread.is_closed? &&\
68
68
  ((user == commontator && thread.config.can_delete_own_comments) &&\
69
- (thread.comments.last == self || thread.config.can_delete_old_comments)) ||\
69
+ (thread.comments.last == self || thread.config.can_delete_old_comments))) ||\
70
70
  thread.can_be_edited_by?(user)
71
71
  end
72
72
 
@@ -23,20 +23,20 @@ module Commontator
23
23
  subscriptions.collect{|s| s.subscriber}
24
24
  end
25
25
 
26
- def subscription_for(user)
27
- Subscription.find_by_thread_id_and_subscriber_id_and_subscriber_type(self.id, user.id, user.class.name)
26
+ def subscription_for(subscriber)
27
+ Subscription.find_by_thread_id_and_subscriber_id_and_subscriber_type(self.id, subscriber.id, subscriber.class.name)
28
28
  end
29
29
 
30
30
  def is_closed?
31
31
  !closed_at.blank?
32
32
  end
33
33
 
34
- def is_subscribed?(user)
34
+ def is_subscribed?(subscriber)
35
35
  !subscription_for(subscriber).blank?
36
36
  end
37
37
 
38
38
  def subscribe(subscriber)
39
- return false if is_subscribed?(user)
39
+ return false if is_subscribed?(subscriber)
40
40
  subscription = Subscription.create(
41
41
  :subscriber => subscriber, :thread => self)
42
42
  subscribe_callback(subscriber)
@@ -97,27 +97,27 @@ module Commontator
97
97
  ####################
98
98
 
99
99
  def comment_created_callback(user, comment)
100
- commontable.send(config.comment_created_callback, user, comment) unless commontable.blank? || config.comment_created_callback.blank?
100
+ commontable.blank? || config.comment_created_callback.blank? || commontable.send(config.comment_created_callback, user, comment)
101
101
  end
102
102
 
103
103
  def comment_edited_callback(user, comment)
104
- commontable.send(config.comment_edited_callback, user, comment) unless commontable.blank? || config.comment_edited_callback.blank?
104
+ commontable.blank? || config.comment_edited_callback.blank? || commontable.send(config.comment_edited_callback, user, comment)
105
105
  end
106
106
 
107
107
  def comment_deleted_callback(user, comment)
108
- commontable.send(config.comment_deleted_callback, user, comment) unless commontable.blank? || config.comment_deleted_callback.blank?
108
+ commontable.blank? || config.comment_deleted_callback.blank? || commontable.send(config.comment_deleted_callback, user, comment)
109
109
  end
110
110
 
111
111
  def thread_closed_callback(user)
112
- commontable.send(config.thread_closed_callback, user) unless commontable.blank? || config.thread_closed_callback.blank?
112
+ commontable.blank? || config.thread_closed_callback.blank? || commontable.send(config.thread_closed_callback, user)
113
113
  end
114
114
 
115
115
  def subscribe_callback(user)
116
- commontable.send(config.subscribe_callback, user) unless commontable.blank? || config.subscribe_callback.blank?
116
+ commontable.blank? || config.subscribe_callback.blank? || commontable.send(config.subscribe_callback, user)
117
117
  end
118
118
 
119
119
  def unsubscribe_callback(user)
120
- commontable.send(config.unsubscribe_callback, user) unless commontable.blank? || config.unsubscribe_callback.blank?
120
+ commontable.blank? || config.unsubscribe_callback.blank? || commontable.send(config.unsubscribe_callback, user)
121
121
  end
122
122
 
123
123
  ##########################
@@ -137,7 +137,7 @@ module Commontator
137
137
  end
138
138
 
139
139
  def can_subscribe?(user)
140
- !commontable.blank? && config.can_subscribe_to_thread && can_be_read_by?(user)
140
+ !commontable.blank? && config.can_subscribe_to_thread && !is_closed? && can_be_read_by?(user)
141
141
  end
142
142
  end
143
143
  end
@@ -10,35 +10,33 @@ module Commontator
10
10
 
11
11
  attr_accessible :is_closed
12
12
 
13
- alias_method :default_comments, :comments
14
-
15
13
  def config
16
14
  commontable.try(:commontable_config)
17
15
  end
18
16
 
19
17
  def ordered_comments
20
18
  (!commontable.blank? && config.comments_can_be_voted_on && config.comments_ordered_by_votes) ? \
21
- default_comments.order("cached_votes_down - cached_votes_up") : default_comments
19
+ comments.order("cached_votes_down - cached_votes_up") : comments
22
20
  end
23
21
 
24
22
  def subscribers
25
23
  subscriptions.collect{|s| s.subscriber}
26
24
  end
27
25
 
28
- def subscription_for(user)
29
- Subscription.find_by_thread_id_and_subscriber_id_and_subscriber_type(self.id, user.id, user.class.name)
26
+ def subscription_for(subscriber)
27
+ Subscription.find_by_thread_id_and_subscriber_id_and_subscriber_type(self.id, subscriber.id, subscriber.class.name)
30
28
  end
31
29
 
32
30
  def is_closed?
33
31
  !closed_at.blank?
34
32
  end
35
33
 
36
- def is_subscribed?(user)
34
+ def is_subscribed?(subscriber)
37
35
  !subscription_for(subscriber).blank?
38
36
  end
39
37
 
40
38
  def subscribe(subscriber)
41
- return false if is_subscribed?(user)
39
+ return false if is_subscribed?(subscriber)
42
40
  subscription = Subscription.create(
43
41
  :subscriber => subscriber, :thread => self)
44
42
  subscribe_callback(subscriber)
@@ -99,7 +97,7 @@ module Commontator
99
97
  ####################
100
98
 
101
99
  def comment_created_callback(user, comment)
102
- commontable.send(config.comment_created_callback, user, comment) unless commontable.blank? || config.comment_created_callback.blank?
100
+ commontable.blank? || config.comment_created_callback.blank? || commontable.send(config.comment_created_callback, user, comment)
103
101
  end
104
102
 
105
103
  def comment_edited_callback(user, comment)
@@ -139,7 +137,7 @@ module Commontator
139
137
  end
140
138
 
141
139
  def can_subscribe?(user)
142
- !commontable.blank? && config.can_subscribe_to_thread && can_be_read_by?(user)
140
+ !commontable.blank? && config.can_subscribe_to_thread && !is_closed? && can_be_read_by?(user)
143
141
  end
144
142
  end
145
143
  end
@@ -7,26 +7,23 @@
7
7
 
8
8
  <% if can_edit %>
9
9
  <%= link_to 'Edit', edit_comment_path(comment),
10
- :id => "edit_comment_#{comment.id.to_s}_link",
11
- :class => "edit_comment_link",
10
+ :id => "comment_#{comment.id.to_s}_edit_link",
11
+ :class => "comment_edit_link",
12
12
  :remote => true %>
13
13
  <% end %>
14
14
 
15
15
  &nbsp;
16
16
 
17
17
  <% if can_delete %>
18
- <% if !comment.is_deleted? %>
19
- <%= link_to('Delete', delete_comment_path(comment),
20
- :confirm => 'Are you sure you want to delete this ' + @thread.config.comment_name + '?',
21
- :method => :put,
22
- :id => "delete_comment_#{comment.id.to_s}_link",
23
- :class => "delete_comment_link",
24
- :remote => true) %>
25
- <% else %>
26
- <%= link_to('Undelete', undelete_comment_path(comment),
27
- :method => :put,
28
- :id => "undelete_comment_#{comment.id.to_s}_link",
29
- :class => "undelete_comment_link",
30
- :remote => true) %>
31
- <% end %>
18
+ <% is_deleted = comment.is_deleted? %>
19
+ <% del_string = is_deleted ? "undelete" : "delete" %>
20
+ <%= link_to del_string.capitalize,
21
+ polymorphic_path([del_string, comment]),
22
+ :confirm => (!is_deleted ? \
23
+ "Are you sure you want to delete this " + \
24
+ "#{@thread.config.comment_name}?" : nil),
25
+ :method => :put,
26
+ :id => "comment_#{comment.id.to_s}_#{del_string}_link",
27
+ :class => "comment_#{del_string}_link",
28
+ :remote => true %>
32
29
  <% end %>
@@ -7,27 +7,23 @@
7
7
 
8
8
  <% if can_edit %>
9
9
  <%= link_to 'Edit', edit_comment_path(comment),
10
- :id => "edit_comment_#{comment.id.to_s}_link",
11
- :class => "edit_comment_link",
10
+ :id => "comment_#{comment.id.to_s}_edit_link",
11
+ :class => "comment_edit_link",
12
12
  :remote => true %>
13
13
  <% end %>
14
14
 
15
15
  &nbsp;
16
16
 
17
17
  <% if can_delete %>
18
- <% if !comment.is_deleted? %>
19
- <%= link_to('Delete', delete_comment_path(comment),
20
- :confirm => 'Are you sure you want to delete this ' + @thread.config.comment_name + '?',
21
- :method => :put,
22
- :id => "delete_comment_#{comment.id.to_s}_link",
23
- :class => "delete_comment_link",
24
- :remote => true) %>
25
- <% else %>
26
- <%= link_to('Undelete', undelete_comment_path(comment),
27
- :confirm => 'Are you sure you want to delete this ' + @thread.config.comment_name + '?',
28
- :method => :put,
29
- :id => "delete_comment_#{comment.id.to_s}_link",
30
- :class => "delete_comment_link",
31
- :remote => true) %>
32
- <% end %>
18
+ <% is_deleted = comment.is_deleted?
19
+ <% del_string = is_deleted ? "undelete" : "delete" %>
20
+ <%= link_to del_string.capitalize,
21
+ polymorphic_path([del_string, comment]),
22
+ :confirm => (!is_deleted ? \
23
+ "Are you sure you want to delete this " + \
24
+ "#{@thread.config.comment_name}?" : nil),
25
+ :method => :put,
26
+ :id => "comment_#{comment.id.to_s}_#{del_string}_link",
27
+ :class => "comment_#{del_string}_link",
28
+ :remote => true %>
33
29
  <% end %>
@@ -12,4 +12,4 @@ $("#thread_<%= @thread.id %>_new_comment_div").hide();
12
12
 
13
13
  $("#thread_<%= @thread.id %>_new_comment_link_span").show();
14
14
 
15
- <%= javascript_callback %>
15
+ <%= javascript_proc %>