commontator 4.1.2 → 4.2.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: 871a16d73340c7eb75bc49f2329432bf6dcbc679
4
- data.tar.gz: 13c27ed2620146b5d6d48ef386c723e67d5a2249
3
+ metadata.gz: 62ff7e0ae14f2179de8ad2f079f27c5647a253bb
4
+ data.tar.gz: 205e1137acfdea70a5d0ded9c7714b0e85d494dd
5
5
  SHA512:
6
- metadata.gz: 401a0f8fc62eb0e88c340a96bf7b766bc8be6ac79b551d5944ce1beb1939272a1083b08da5f12e00a50077630515298c7f5dc5b469a73d21fa052d7d824210c3
7
- data.tar.gz: 6dd7959ccca36945f04bc219b9f1cf4fc08cc951eacd1e912b8e19dfde7019122f565f087a4ca190980104fd4fefccf05852a9ef0487ce9445970bd500c8cfc8
6
+ metadata.gz: 60f0a5755fa8b1f143a4e492463d017c37effc7c5d5e3fb7a327d15e78b4f1077df459e04f0e25849a0fbeded4197009f96fc0195c59608e969d0a35afca5be5
7
+ data.tar.gz: 401709696330a73aba059e47dfc40ca35324ee3a0909ac306f01b819c69bcfea50b37fa4ed5862942585f79b42afed4d7dff59fd78faca02f561a24999f32395
data/README.md CHANGED
@@ -13,7 +13,7 @@ There are 4 steps you must follow to install commontator:
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'commontator', '~> 4.1.2'
16
+ gem 'commontator', '~> 4.2.0'
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -6,7 +6,7 @@ module Commontator
6
6
  def comment_created(comment, recipients)
7
7
  setup_variables(comment, recipients)
8
8
 
9
- mail :to => 'Undisclosed Recipients',
9
+ mail :to => @to,
10
10
  :bcc => @bcc,
11
11
  :from => @from,
12
12
  :subject => @subject
@@ -18,17 +18,17 @@ module Commontator
18
18
  @comment = comment
19
19
  @thread = @comment.thread
20
20
  @creator = @comment.creator
21
-
21
+
22
22
  @commontable = @thread.commontable
23
23
  @config = @thread.config
24
-
24
+
25
25
  @creator_name = commontator_name(@creator)
26
26
  @comment_created_timestamp = @comment.created_timestamp
27
-
27
+
28
28
  @commontable_name = commontable_name(@thread)
29
-
29
+
30
30
  @commontable_url = ApplicationController.commontable_url
31
-
31
+
32
32
  params = Hash.new
33
33
  params[:comment] = @comment
34
34
  params[:thread] = @thread
@@ -39,7 +39,8 @@ module Commontator
39
39
  params[:comment_created_timestamp] = @comment_created_timestamp
40
40
  params[:commontable_name] = @commontable_name
41
41
  params[:commontable_url] = @commontable_url
42
-
42
+
43
+ @to = @config.subscription_email_to_proc.call(params)
43
44
  @bcc = recipients.collect{|s| commontator_email(s)}
44
45
  @from = @config.subscription_email_from_proc.call(params)
45
46
  @subject = @config.subscription_email_subject_proc.call(params)
@@ -6,7 +6,7 @@ module Commontator
6
6
  def comment_created(comment, recipients)
7
7
  setup_variables(comment, recipients)
8
8
 
9
- mail :to => 'Undisclosed Recipients',
9
+ mail :to => @to
10
10
  :bcc => @bcc,
11
11
  :from => @from,
12
12
  :subject => @subject
@@ -18,18 +18,17 @@ module Commontator
18
18
  @comment = comment
19
19
  @thread = @comment.thread
20
20
  @creator = @comment.creator
21
-
21
+
22
22
  @commontable = @thread.commontable
23
23
  @config = @thread.config
24
-
24
+
25
25
  @creator_name = commontator_name(@creator)
26
26
  @comment_created_timestamp = @comment.created_timestamp
27
-
27
+
28
28
  @commontable_name = commontable_name(@thread)
29
- @commontable_id = commontable_id(@thread).to_s
30
-
29
+
31
30
  @commontable_url = ApplicationController.commontable_url
32
-
31
+
33
32
  params = Hash.new
34
33
  params[:comment] = @comment
35
34
  params[:thread] = @thread
@@ -39,9 +38,9 @@ module Commontator
39
38
  params[:creator_name] = @creator_name
40
39
  params[:comment_created_timestamp] = @comment_created_timestamp
41
40
  params[:commontable_name] = @commontable_name
42
- params[:commontable_id] = @commontable_id
43
41
  params[:commontable_url] = @commontable_url
44
-
42
+
43
+ @to = @config.subscription_email_to_proc.call(params)
45
44
  @bcc = recipients.collect{|s| commontator_email(s)}
46
45
  @from = @config.subscription_email_from_proc.call(params)
47
46
  @subject = @config.subscription_email_subject_proc.call(params)
@@ -20,6 +20,14 @@ module Commontator
20
20
 
21
21
  public
22
22
 
23
+ def is_modified?
24
+ !editor.nil?
25
+ end
26
+
27
+ def is_latest?
28
+ thread.comments.last == self
29
+ end
30
+
23
31
  def is_votable?
24
32
  return true if acts_as_votable_initialized
25
33
  return false unless self.class.respond_to?(:acts_as_votable)
@@ -32,10 +40,6 @@ module Commontator
32
40
  votes.where(:voter_type => user.class.name, :voter_id => user.id).first
33
41
  end
34
42
 
35
- def is_modified?
36
- !editor.nil?
37
- end
38
-
39
43
  def is_deleted?
40
44
  !deleted_at.blank?
41
45
  end
@@ -82,14 +86,14 @@ module Commontator
82
86
 
83
87
  def can_be_edited_by?(user)
84
88
  (!thread.is_closed? && !is_deleted? &&\
85
- (thread.comments.last == self || thread.config.can_edit_old_comments) &&\
89
+ (is_latest? || thread.config.can_edit_old_comments) &&\
86
90
  user == creator && thread.config.can_edit_own_comments && thread.can_be_read_by?(user)) ||\
87
91
  (thread.config.admin_can_edit_comments && thread.can_be_edited_by?(user))
88
92
  end
89
93
 
90
94
  def can_be_deleted_by?(user)
91
95
  (!thread.is_closed? && (!is_deleted? || editor == user) &&\
92
- (thread.comments.last == self || thread.config.can_delete_old_comments) &&\
96
+ (is_latest? || thread.config.can_delete_old_comments) &&\
93
97
  user == creator && thread.config.can_delete_own_comments &&\
94
98
  thread.can_be_read_by?(user)) ||\
95
99
  thread.can_be_edited_by?(user)
@@ -20,6 +20,14 @@ module Commontator
20
20
 
21
21
  public
22
22
 
23
+ def is_modified?
24
+ !editor.nil?
25
+ end
26
+
27
+ def is_latest?
28
+ thread.comments.last == self
29
+ end
30
+
23
31
  def is_votable?
24
32
  return true if acts_as_votable_initialized
25
33
  return false unless self.class.respond_to?(:acts_as_votable)
@@ -28,14 +36,10 @@ module Commontator
28
36
  end
29
37
 
30
38
  def get_vote_by(user)
31
- return nil unless is_votable?
39
+ return nil unless is_votable? && user && user.is_commontator
32
40
  votes.where(:voter_type => user.class.name, :voter_id => user.id).first
33
41
  end
34
42
 
35
- def is_modified?
36
- !editor.nil?
37
- end
38
-
39
43
  def is_deleted?
40
44
  !deleted_at.blank?
41
45
  end
@@ -82,7 +86,7 @@ module Commontator
82
86
 
83
87
  def can_be_edited_by?(user)
84
88
  (!thread.is_closed? && !is_deleted? &&\
85
- (thread.comments.last == self || thread.config.can_edit_old_comments) &&\
89
+ (is_latest? || thread.config.can_edit_old_comments) &&\
86
90
  user == creator && thread.config.can_edit_own_comments && thread.can_be_read_by?(user)) ||\
87
91
  (thread.config.admin_can_edit_comments && thread.can_be_edited_by?(user))
88
92
  end
@@ -14,8 +14,12 @@ module Commontator
14
14
  end
15
15
 
16
16
  def ordered_comments
17
- (config.can_vote_on_comments && config.comments_ordered_by_votes) ? \
18
- comments.order("cached_votes_down - cached_votes_up") : comments
17
+ case config.comments_order
18
+ when :l then comments.order('id DESC')
19
+ when :ve then comments.order('cached_votes_down - cached_votes_up')
20
+ when :vl then comments.order('cached_votes_down - cached_votes_up', 'id DESC')
21
+ else comments
22
+ end
19
23
  end
20
24
 
21
25
  def is_closed?
@@ -14,8 +14,12 @@ module Commontator
14
14
  end
15
15
 
16
16
  def ordered_comments
17
- (config.can_vote_on_comments && config.comments_ordered_by_votes) ? \
18
- comments.order("cached_votes_down - cached_votes_up") : comments
17
+ case config.comments_order
18
+ when :l then comments.order('id DESC')
19
+ when :ve then comments.order('cached_votes_down - cached_votes_up')
20
+ when :vl then comments.order('cached_votes_down - cached_votes_up', '')
21
+ else comments
22
+ end
19
23
  end
20
24
 
21
25
  def is_closed?
@@ -32,7 +36,6 @@ module Commontator
32
36
 
33
37
  def subscription_for(subscriber)
34
38
  return nil if !subscriber || !subscriber.is_commontator
35
- return nil if !subscriber.is_commontator
36
39
  subscriber.subscriptions.where(:thread_id => self.id).first
37
40
  end
38
41
 
@@ -0,0 +1,11 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # comments
3
+ # user
4
+ %>
5
+
6
+ <% comments.each do |comment| %>
7
+ <% next unless comment.can_be_read_by?(user) %>
8
+ <%= render :partial => 'commontator/comments/show',
9
+ :locals => {:comment => comment,
10
+ :user => user} %>
11
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # comments
3
+ # user
4
+ %>
5
+
6
+ <% thread.ordered_comments.each do |comment| %>
7
+ <% next unless comment.can_be_read_by?(user) %>
8
+ <%= render :partial => 'commontator/comments/show',
9
+ :locals => {:comment => comment,
10
+ :user => user} %>
11
+ <% end %>
@@ -1,17 +1,12 @@
1
- <% @thread.comments.each do |comment| %>
2
- $("#comment_<%= comment.id.to_s %>_actions_span").html("<%= escape_javascript(
3
- render :partial => 'actions',
4
- :locals => {:comment => comment,
1
+ $("#thread_<%= @thread.id %>_comment_list_div").html("<%= escape_javascript(
2
+ render :partial => 'list',
3
+ :locals => {:comments => @thread.ordered_comments,
5
4
  :user => @user}) %>");
6
- <% end %>
7
-
8
- $("#thread_<%= @thread.id %>_comment_list_div").append("<%= escape_javascript(
9
- render :partial => 'show',
10
- :locals => {:comment => @comment,
11
- :user => @user}) %>");
12
5
 
13
6
  $("#thread_<%= @thread.id %>_new_comment_div").hide();
14
7
 
15
- $("#thread_<%= @thread.id %>_new_comment_link_span").show();
8
+ $("#thread_<%= @thread.id %>_new_comment_link_span").fadeIn();
9
+
10
+ $("#comment_<%= @comment.id.to_s %>_div").hide().fadeIn()[0].scrollIntoView();
16
11
 
17
12
  <%= javascript_proc %>
@@ -0,0 +1,12 @@
1
+ $("#thread_<%= @thread.id %>_comment_list_div").html("<%= escape_javascript(
2
+ render :partial => 'list',
3
+ :locals => {:comments => @thread.ordered_comments,
4
+ :user => @user}) %>");
5
+
6
+ $("#thread_<%= @thread.id %>_new_comment_div").hide();
7
+
8
+ $("#thread_<%= @thread.id %>_new_comment_link_span").fadeIn();
9
+
10
+ $("#comment_<%= @comment.id.to_s %>_div").hide().fadeIn()[0].scrollIntoView();
11
+
12
+ $("#error_explanation").remove();
@@ -2,7 +2,7 @@ $("#comment_<%= @comment.id.to_s %>_body_div").html("<%= escape_javascript(
2
2
  render :partial => 'body', :locals => {:comment => @comment}) %>");
3
3
 
4
4
  $("#comment_<%= @comment.id.to_s %>_updated_timestamp_span").html("<%= escape_javascript(
5
- "#{@comment.updated_timestamp} by #{commontator_name(comment.editor)}") %>");
5
+ "#{@comment.updated_timestamp} by #{commontator_name(@comment.editor)}") %>");
6
6
 
7
7
  $("#comment_<%= @comment.id.to_s %>_actions_span").html("<%= escape_javascript(
8
8
  render :partial => 'actions',
@@ -14,4 +14,4 @@ $("#comment_<%= @comment.id %>_votes_span").html("<%= escape_javascript(
14
14
  :locals => {:comment => @comment,
15
15
  :user => @user}) %>");
16
16
 
17
- <%= javascript_proc %>
17
+ $("#error_explanation").remove();
@@ -0,0 +1,5 @@
1
+ $("#comment_<%= @comment.id.to_s %>_body_div").html("<%= escape_javascript(
2
+ render :partial => 'form',
3
+ :locals => {:comment => @comment}) %>");
4
+
5
+ $("#error_explanation").remove();
@@ -5,7 +5,7 @@ $("#thread_<%= @thread.id %>_new_comment_div").html("<%= escape_javascript(
5
5
  :thread => @thread
6
6
  }) %>");
7
7
 
8
- $("#thread_<%= @thread.id %>_new_comment_div").show();
8
+ $("#thread_<%= @thread.id %>_new_comment_div").fadeIn()[0].scrollIntoView();
9
9
 
10
10
  $("#thread_<%= @thread.id %>_new_comment_link_span").hide();
11
11
 
@@ -0,0 +1,12 @@
1
+ $("#thread_<%= @thread.id %>_new_comment_div").html("<%= escape_javascript(
2
+ render :partial => 'form',
3
+ :locals => {
4
+ :comment => @comment,
5
+ :thread => @thread
6
+ }) %>");
7
+
8
+ $("#thread_<%= @thread.id %>_new_comment_div").fadeIn()[0].scrollIntoView();
9
+
10
+ $("#thread_<%= @thread.id %>_new_comment_link_span").hide();
11
+
12
+ $("#error_explanation").remove();
@@ -2,6 +2,6 @@ $("#comment_<%= @comment.id.to_s %>_body_div").html("<%= escape_javascript(
2
2
  render :partial => 'body', :locals => {:comment => @comment}) %>");
3
3
 
4
4
  $("#comment_<%= @comment.id.to_s %>_updated_timestamp_span").html("<%= escape_javascript(
5
- @comment.updated_timestamp) %>");
5
+ "#{@comment.updated_timestamp} by #{commontator_name(@comment.editor)}") %>");
6
6
 
7
- <%= javascript_proc %>
7
+ $("#error_explanation").remove();
@@ -36,12 +36,9 @@
36
36
  </span>
37
37
 
38
38
  <div id="thread_<%= thread.id.to_s %>_comment_list_div" class="thread_comment_list">
39
- <% thread.ordered_comments.each do |comment| %>
40
- <% next unless comment.can_be_read_by?(user) %>
41
- <%= render :partial => 'commontator/comments/show',
42
- :locals => {:comment => comment,
43
- :user => user} %>
44
- <% end %>
39
+ <%= render :partial => 'commontator/comments/list',
40
+ :locals => {:comments => thread.ordered_comments,
41
+ :user => user} %>
45
42
  </div>
46
43
 
47
44
  <% if thread.is_closed? %>
@@ -36,6 +36,9 @@
36
36
  </span>
37
37
 
38
38
  <div id="thread_<%= thread.id.to_s %>_comment_list_div" class="thread_comment_list">
39
+ <%= render :partial => 'commontator/comments/list',
40
+ :locals => {:comments => thread.ordered_comments,
41
+ :user => user} %>
39
42
  <% thread.ordered_comments.each do |comment| %>
40
43
  <% next unless comment.can_be_read_by?(user) %>
41
44
  <%= render :partial => 'commontator/comments/show',
@@ -47,7 +50,7 @@
47
50
  <% if thread.is_closed? %>
48
51
  <p><%= thread.config.comment_name.capitalize.pluralize %> cannot be <%= thread.config.comment_create_verb_past %> at this time.</p>
49
52
  <% elsif !user %>
50
- <p>You must log in before you can <%= thread.config.comment_create_verb_present %> a <%= thread.config.comment_name %> to this thread.</p>
53
+ <p>You must log in before you can <%= thread.config.comment_create_verb_present %> a <%= thread.config.comment_name %>.</p>
51
54
  <% else %>
52
55
  <div id="thread_<%= thread.id %>_new_comment_div" class="thread_new_comment"></div>
53
56
 
@@ -8,13 +8,14 @@ Commontator.configure do |config|
8
8
  # Default: lambda { |controller| controller.current_user }
9
9
  config.current_user_proc = lambda { |controller| controller.current_user }
10
10
 
11
- # Proc that is called after any javascript runs (e.g. to display/clear flash messages)
12
- # It is passed the view_context object (self from the view template), so you should be able to
13
- # access anything you normally could in a view template (by using, e.g. view.flash)
14
- # However, be aware that it does not have access to the main application's helpers
15
- # Should return a string containing JS to be appended to all Commontator JS responses
16
- # Default: lambda { |view| '$("#error_explanation").remove();' }
17
- config.javascript_proc = lambda { |view| '$("#error_explanation").remove();' }
11
+ # Proc called with the view_context object as argument
12
+ # Returns a string to be appended to all JavaScript responses from commontator
13
+ # Can be used, for example, to display/clear Rails error messages
14
+ # Objects visible in view templates can be accessed through
15
+ # the view_context object (for example, view_context.flash)
16
+ # However, the view_context does not include the main application's helpers
17
+ # Default: lambda { |view_context| '$("#error_explanation").remove();' }
18
+ config.javascript_proc = lambda { |view_context| '$("#error_explanation").remove();' }
18
19
 
19
20
 
20
21
  # User (acts_as_commontator) Configuration
@@ -109,15 +110,14 @@ Commontator.configure do |config|
109
110
  # Default: false
110
111
  config.can_vote_on_comments = false
111
112
 
112
- # Whether to display upvotes and downvotes
113
- # combined or separately
114
- # Default: true
115
- config.combine_upvotes_and_downvotes = true
116
-
117
- # Whether comments should be ordered by vote score
118
- # instead of by order posted
119
- # Default: false
120
- config.comments_ordered_by_votes = false
113
+ # What order to use for comments
114
+ # Valid values:
115
+ # :e (earliest comment first)
116
+ # :l (latest comment first)
117
+ # :ve (highest voted first; earliest first if tied)
118
+ # :vl (highest voted first; latest first if tied)
119
+ # Default: :e (earliest comment first)
120
+ config.comments_order = :e
121
121
 
122
122
  # Whether users can read threads closed by moderators
123
123
  # Default: true
@@ -153,6 +153,14 @@ Commontator.configure do |config|
153
153
  # Default: lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
154
154
  # (defaults to the commontable's show url)
155
155
  config.commontable_url_proc = lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
156
+
157
+ # Proc called with params from the subscription mailer as arguments
158
+ # Returns the subscription email 'to' addresses
159
+ # Available params can be seen in the subscription mailer
160
+ # Note that the actual addresses are already set in the BCC field
161
+ # Default:
162
+ # lambda { |params| 'Undisclosed Recipients' }
163
+ config.subscription_email_to_proc = lambda { |params| 'Undisclosed Recipients' }
156
164
 
157
165
  # Proc called with params from the subscription mailer as arguments
158
166
  # Returns the subscription email 'from' address
@@ -5,14 +5,14 @@ Commontator.configure do |config|
5
5
 
6
6
  # Proc that is passed the current controller as argument
7
7
  # Returns the current user
8
- # Default: 'current_user'
8
+ # Default: lambda { |controller| controller.current_user }
9
9
  config.current_user_proc = lambda { |controller| controller.current_user }
10
10
 
11
- # Proc that is called after any javascript runs (e.g. to display/clear flash messages)
12
- # It is passed the view_context object (self from the view template), so you should be able to
13
- # access anything you normally could in a view template (by using, e.g. view.flash)
14
- # However, be aware that it does not have access to the main application's helpers
15
- # Should return a string containing JS to be appended to all Commontator JS responses
11
+ # Proc called with the view_context object as argument
12
+ # Returns a string to be appended to all JavaScript responses from commontator
13
+ # Can be used, for example, to display/clear Rails error messages
14
+ # Objects visible in view templates can be accessed through the view_context object
15
+ # However, the view_context does not include the main application's helpers
16
16
  # Default: lambda { |view| '$("#error_explanation").remove();' }
17
17
  config.javascript_proc = lambda { |view| '$("#error_explanation").remove();' }
18
18
 
@@ -109,15 +109,14 @@ Commontator.configure do |config|
109
109
  # Default: false
110
110
  config.can_vote_on_comments = false
111
111
 
112
- # Whether to display upvotes and downvotes
113
- # combined or separately
114
- # Default: true
115
- config.combine_upvotes_and_downvotes = true
116
-
117
- # Whether comments should be ordered by vote score
118
- # instead of by order posted
119
- # Default: false
120
- config.comments_ordered_by_votes = false
112
+ # What order to use for comments
113
+ # Valid values:
114
+ # :e (earliest comment first)
115
+ # :l (latest comment first)
116
+ # :ve (highest voted first; earliest first if tied)
117
+ # :vl (highest voted first; latest first if tied)
118
+ # Default: :e (earliest comment first)
119
+ config.comments_order = :e
121
120
 
122
121
  # Whether users can read threads closed by moderators
123
122
  # Default: true
@@ -153,6 +152,14 @@ Commontator.configure do |config|
153
152
  # Default: lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
154
153
  # (defaults to the commontable's show url)
155
154
  config.commontable_url_proc = lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
155
+
156
+ # Proc called with params from the subscription mailer as arguments
157
+ # Returns the subscription email 'to' addresses
158
+ # Available params can be seen in the subscription mailer
159
+ # Note that the actual addresses are already set in the BCC field
160
+ # Default:
161
+ # lambda { |params| 'Undisclosed Recipients' }
162
+ config.subscription_email_to_proc = lambda { |params| 'Undisclosed Recipients' }
156
163
 
157
164
  # Proc called with params from the subscription mailer as arguments
158
165
  # Returns the subscription email 'from' address