commontator 1.1.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/app/controllers/commontator/comments_controller.rb +3 -2
  2. data/app/controllers/commontator/comments_controller.rb~ +136 -0
  3. data/app/models/commontator/comment.rb +53 -36
  4. data/app/models/commontator/comment.rb~ +108 -0
  5. data/app/models/commontator/subscription.rb +8 -6
  6. data/app/models/commontator/subscription.rb~ +21 -0
  7. data/app/models/commontator/thread.rb +48 -44
  8. data/app/models/commontator/thread.rb~ +48 -47
  9. data/app/views/commontator/comments/_body.html.erb +1 -1
  10. data/app/views/commontator/comments/_body.html.erb~ +8 -0
  11. data/app/views/commontator/comments/_form.html.erb +1 -1
  12. data/app/views/commontator/comments/_form.html.erb~ +38 -0
  13. data/app/views/commontator/comments/_show.html.erb +1 -1
  14. data/app/views/commontator/comments/_show.html.erb~ +44 -0
  15. data/app/views/commontator/comments/_votes.html.erb +1 -1
  16. data/app/views/commontator/comments/_votes.html.erb~ +57 -0
  17. data/app/views/commontator/comments/delete.js.erb +1 -1
  18. data/app/views/commontator/comments/delete.js.erb~ +17 -0
  19. data/config/initializers/commontator.rb +11 -4
  20. data/config/initializers/commontator.rb~ +171 -0
  21. data/db/migrate/0_install.rb +23 -21
  22. data/db/migrate/0_install.rb~ +23 -21
  23. data/lib/commontator.rb +2 -0
  24. data/lib/commontator.rb~ +1 -1
  25. data/lib/commontator/acts_as_commontable.rb +7 -6
  26. data/lib/commontator/acts_as_commontable.rb~ +8 -6
  27. data/lib/commontator/acts_as_commontator.rb +4 -3
  28. data/lib/commontator/acts_as_commontator.rb~ +31 -0
  29. data/lib/commontator/version.rb +1 -1
  30. data/lib/commontator/version.rb~ +1 -1
  31. data/spec/app/controllers/commontator/comments_controller_spec.rb +61 -20
  32. data/spec/app/controllers/commontator/comments_controller_spec.rb~ +58 -21
  33. data/spec/app/models/commontator/comment_spec.rb +8 -7
  34. data/spec/app/models/commontator/comment_spec.rb~ +9 -8
  35. data/spec/app/models/commontator/thread_spec.rb +1 -1
  36. data/spec/app/models/commontator/thread_spec.rb~ +1 -1
  37. data/spec/dummy/db/development.sqlite3 +0 -0
  38. data/spec/dummy/db/schema.rb +16 -16
  39. data/spec/dummy/db/test.sqlite3 +0 -0
  40. data/spec/dummy/log/development.log +724 -0
  41. data/spec/dummy/log/test.log +41005 -0
  42. metadata +12 -2
@@ -5,7 +5,7 @@
5
5
 
6
6
  <% if comment.can_be_voted_on? %>
7
7
  <% can_vote = comment.can_be_voted_on_by?(user) %>
8
- <% vote = comment.votes.find_by_voter_id_and_voter_type(user.id, user.class.name) %>
8
+ <% vote = comment.get_vote_by(user) %>
9
9
 
10
10
  <span id="comment_<%= comment.id %>_upvote_span" class="comment_upvote">
11
11
  <% if can_vote && (vote.blank? || !vote.vote_flag) %>
@@ -0,0 +1,57 @@
1
+ <% # Clients of this partial must provide the following variable:
2
+ # comment
3
+ # user
4
+ %>
5
+
6
+ <% if comment.can_be_voted_on? %>
7
+ <% can_vote = comment.can_be_voted_on_by?(user) %>
8
+ <% vote = comment.get_vote_from(user) %>
9
+
10
+ <span id="comment_<%= comment.id %>_upvote_span" class="comment_upvote">
11
+ <% if can_vote && (vote.blank? || !vote.vote_flag) %>
12
+ <%= form_tag commontator.upvote_comment_path(comment),
13
+ :method => :put,
14
+ :remote => true do %>
15
+ <%= image_submit_tag "commontator/upvote.png",
16
+ :onmouseover => "this.src='/assets/commontator/upvote_hover.png'",
17
+ :onmouseout => "this.src='/assets/commontator/upvote.png'" %>
18
+ <% end %>
19
+ <% elsif can_vote %>
20
+ <%= form_tag commontator.unvote_comment_path(comment),
21
+ :method => :put,
22
+ :remote => true do %>
23
+ <%= image_submit_tag "commontator/upvote_hover.png",
24
+ :onmouseover => "this.src='/assets/commontator/upvote.png'",
25
+ :onmouseout => "this.src='/assets/commontator/upvote_hover.png'" %>
26
+ <% end %>
27
+ <% else %>
28
+ <%= image_tag "commontator/upvote_hover.png" %>
29
+ <% end %>
30
+ </span>
31
+
32
+ <span id="comment_<%= comment.id %>_vote_count_span" class="comment_vote_count">
33
+ <p>+ <%= comment.upvotes.size %><br><br>- <%= comment.downvotes.size %></p>
34
+ </span>
35
+
36
+ <span id="comment_<%= comment.id %>_downvote_span" class="comment_downvote">
37
+ <% if can_vote && (vote.blank? || vote.vote_flag) %>
38
+ <%= form_tag commontator.downvote_comment_path(comment),
39
+ :method => :put,
40
+ :remote => true do %>
41
+ <%= image_submit_tag "commontator/downvote.png",
42
+ :onmouseover => "this.src='/assets/commontator/downvote_hover.png'",
43
+ :onmouseout => "this.src='/assets/commontator/downvote.png'" %>
44
+ <% end %>
45
+ <% elsif can_vote %>
46
+ <%= form_tag commontator.unvote_comment_path(comment),
47
+ :method => :put,
48
+ :remote => true do %>
49
+ <%= image_submit_tag "commontator/downvote_hover.png",
50
+ :onmouseover => "this.src='/assets/commontator/downvote.png'",
51
+ :onmouseout => "this.src='/assets/commontator/downvote_hover.png'" %>
52
+ <% end %>
53
+ <% else %>
54
+ <%= image_tag "commontator/downvote_hover.png" %>
55
+ <% end %>
56
+ </span>
57
+ <% end %>
@@ -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 %>_timestamp_span").html("<%= escape_javascript(
5
- @comment.timestamp) %>");
5
+ @comment.timestamp + (@comment.is_modified? ? " by #{commontator_name(@comment.editor)}" : '')) %>");
6
6
 
7
7
  $("#comment_<%= @comment.id.to_s %>_actions_span").html("<%= escape_javascript(
8
8
  render :partial => 'actions',
@@ -0,0 +1,17 @@
1
+ $("#comment_<%= @comment.id.to_s %>_body_div").html("<%= escape_javascript(
2
+ render :partial => 'body', :locals => {:comment => @comment}) %>");
3
+
4
+ $("#comment_<%= @comment.id.to_s %>_timestamp_span").html("<%= escape_javascript(
5
+ @comment.timestamp + (@comment.is_modified? ? " by #{commontator_name(comment.editor)}" : '')) %>");
6
+
7
+ $("#comment_<%= @comment.id.to_s %>_actions_span").html("<%= escape_javascript(
8
+ render :partial => 'actions',
9
+ :locals => {:comment => @comment,
10
+ :user => @user}) %>");
11
+
12
+ $("#comment_<%= @comment.id %>_votes_span").html("<%= escape_javascript(
13
+ render :partial => 'votes',
14
+ :locals => {:comment => @comment,
15
+ :user => @user}) %>");
16
+
17
+ <%= javascript_proc %>
@@ -1,7 +1,6 @@
1
1
  # Change the settings below to suit your needs
2
2
  # All settings are initially set to their default values
3
3
  Commontator.configure do |config|
4
-
5
4
  # Engine Configuration
6
5
 
7
6
  # Name of the ApplicationController helper method that returns the current user
@@ -62,9 +61,17 @@ Commontator.configure do |config|
62
61
  # Default: 'posted'
63
62
  config.comment_create_verb_past = 'posted'
64
63
 
64
+ # Verb used when editing comments (present)
65
+ # Default: 'modify'
66
+ config.comment_edit_verb_present = 'modify'
67
+
68
+ # Verb used when editing comments (past)
69
+ # Default: 'modified'
70
+ config.comment_edit_verb_past = 'modified'
71
+
65
72
  # What a commontable is called in your application
66
73
  # If you have multiple commontable models,
67
- # you might want to pass this configuration value
74
+ # you will want to pass this configuration value
68
75
  # as an argument to acts_as_commontable in each one
69
76
  # Default: 'commontable'
70
77
  config.commontable_name = 'commontable'
@@ -114,11 +121,11 @@ Commontator.configure do |config|
114
121
  # Default: false
115
122
  config.comments_ordered_by_votes = false
116
123
 
117
- # Whether users can read threads closed by admins
124
+ # Whether users can read threads closed by moderators
118
125
  # Default: true
119
126
  config.closed_threads_are_readable = true
120
127
 
121
- # Whether comments deleted by admins can be seen
128
+ # Whether comments deleted by moderators can be seen
122
129
  # (the content will still be hidden)
123
130
  # Default: true
124
131
  config.deleted_comments_are_visible = true
@@ -0,0 +1,171 @@
1
+ # Change the settings below to suit your needs
2
+ # All settings are initially set to their default values
3
+ Commontator.configure do |config|
4
+ # Engine Configuration
5
+
6
+ # Name of the ApplicationController helper method that returns the current user
7
+ # Default: 'current_user'
8
+ config.current_user_method = 'current_user'
9
+
10
+ # Proc that is called after any javascript runs (e.g. to display/clear flash messages)
11
+ # It is passed the view_context object (self from the view template), so you should be able to
12
+ # access anything you normally could in a view template (by using, e.g. view.flash)
13
+ # However, be aware that it does not have access to the main application's helpers
14
+ # Should return a string containing JS to be appended to all Commontator JS responses
15
+ # Default: lambda { |view| '$("#error_explanation").remove();' }
16
+ config.javascript_proc = lambda { |view| '$("#error_explanation").remove();' }
17
+
18
+
19
+ # User (acts_as_commontator) Configuration
20
+
21
+ # The name used if the user's name cannot be retrieved
22
+ # Default: 'Anonymous'
23
+ config.user_missing_name = 'Anonymous'
24
+
25
+ # Whether the comment creator's name is clickable in the comment view
26
+ # If enabled, the link will point to the comment creator's show page
27
+ # Default: false
28
+ config.user_name_clickable = false
29
+
30
+ # The method that returns the user's email address
31
+ # Default: 'email'
32
+ config.user_email_method = 'email'
33
+
34
+ # The method that returns the user's name
35
+ # Default: '' (use user_missing_name)
36
+ config.user_name_method = ''
37
+
38
+ # Proc called with user as argument that returns true if the user is an admin
39
+ # Admins can always delete other users' comments and close threads
40
+ # Note: user can be nil
41
+ # Default: lambda { |user| false } (no admins)
42
+ config.user_admin_proc = lambda { |user| false }
43
+
44
+ # Proc called with user as argument that returns true
45
+ # if the user should receive subscription emails
46
+ # Default: lambda { |user| true } (always receive subscription emails)
47
+ config.subscription_email_enable_proc = lambda { |user| true }
48
+
49
+
50
+ # Commontable (acts_as_commontable) Configuration
51
+
52
+ # What a comment is called in your application
53
+ # Default: 'comment'
54
+ config.comment_name = 'comment'
55
+
56
+ # Verb used when creating comments (present)
57
+ # Default: 'post'
58
+ config.comment_create_verb_present = 'post'
59
+
60
+ # Verb used when creating comments (past)
61
+ # Default: 'posted'
62
+ config.comment_create_verb_past = 'posted'
63
+
64
+ # Verb used when editing comments (present)
65
+ # Default: 'edit'
66
+ config.comment_edit_verb_present = 'modify'
67
+
68
+ # Verb used when editing comments (past)
69
+ # Default: 'modified'
70
+ config.comment_edit_verb_past = 'modified'
71
+
72
+ # What a commontable is called in your application
73
+ # If you have multiple commontable models,
74
+ # you will want to pass this configuration value
75
+ # as an argument to acts_as_commontable in each one
76
+ # Default: 'commontable'
77
+ config.commontable_name = 'commontable'
78
+
79
+ # The format of the timestamps used by Commontator
80
+ # Default: '%b %d %Y, %I:%M %p'
81
+ config.timestamp_format = '%b %d %Y, %I:%M %p'
82
+
83
+ # Whether admins can edit other users' comments
84
+ # Default: false
85
+ config.admin_can_edit_comments = false
86
+
87
+ # Whether users automatically subscribe to a thread when commenting
88
+ # Default: false
89
+ config.auto_subscribe_on_comment = false
90
+
91
+ # Whether users can edit their own comments
92
+ # Default: true
93
+ config.can_edit_own_comments = true
94
+
95
+ # Whether users can edit their own comments
96
+ # after someone posted a newer comment
97
+ # Default: false
98
+ config.can_edit_old_comments = false
99
+
100
+ # Whether users can delete their own comments
101
+ # Default: true
102
+ config.can_delete_own_comments = true
103
+
104
+ # Whether users can delete their own comments
105
+ # after someone posted a newer comment
106
+ # Default: false
107
+ config.can_delete_old_comments = false
108
+
109
+ # Whether users can manually subscribe or unsubscribe to threads
110
+ # Default: true
111
+ config.can_subscribe_to_thread = true
112
+
113
+ # Whether users can vote on other users' comments
114
+ # Note: requires acts_as_votable gem installed
115
+ # and configured for your application
116
+ # Default: false
117
+ config.can_vote_on_comments = false
118
+
119
+ # Whether comments should be ordered by vote score
120
+ # instead of by order posted
121
+ # Default: false
122
+ config.comments_ordered_by_votes = false
123
+
124
+ # Whether users can read threads closed by moderators
125
+ # Default: true
126
+ config.closed_threads_are_readable = true
127
+
128
+ # Whether comments deleted by moderators can be seen
129
+ # (the content will still be hidden)
130
+ # Default: true
131
+ config.deleted_comments_are_visible = true
132
+
133
+ # The method which returns the commontable's id, sent to users in email messages
134
+ # Default: 'id'
135
+ config.commontable_id_method = 'id'
136
+
137
+ # Proc called with thread and user as arguments
138
+ # If it returns true, that user is a moderator for that particular thread
139
+ # and is given admin-like capabilities for that thread only
140
+ # Note: user can be nil
141
+ # Default: lambda { |thread, user| false } (no thread-specific moderators)
142
+ config.can_edit_thread_proc = lambda { |thread, user| false }
143
+
144
+ # Proc called with thread and user as arguments
145
+ # If it returns true, that user is allowed to read that thread
146
+ # Note: user can be nil
147
+ # Default: lambda { |thread, user| true } (no read restrictions)
148
+ config.can_read_thread_proc = lambda { |thread, user| true }
149
+
150
+ # Proc that returns the commontable url that contains the thread
151
+ # (defaults to the commontable show url)
152
+ # Main application's routes can be accessed using main_app object
153
+ # Default: lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
154
+ config.commontable_url_proc = lambda { |main_app, commontable| main_app.polymorphic_url(commontable) }
155
+
156
+ # Proc that returns the subscription email 'from' address
157
+ # Default:
158
+ # lambda { |params| 'no-reply@example.com' }
159
+ config.subscription_email_from_proc = lambda { |params| 'no-reply@example.com' }
160
+
161
+ # Proc that returns the subscription email 'subject' string
162
+ # Default:
163
+ # lambda do |params|
164
+ # "#{params[:creator_name]} #{params[:config].comment_create_verb_past} a " + \
165
+ # "#{params[:config].comment_name} on #{params[:commontable_name]} #{params[:commontable_id]}"
166
+ # end
167
+ config.subscription_email_subject_proc = lambda do |params|
168
+ "#{params[:creator_name]} #{params[:config].comment_create_verb_past} a " + \
169
+ "#{params[:config].comment_name} on #{params[:commontable_name]} #{params[:commontable_id]}"
170
+ end
171
+ end
@@ -1,13 +1,13 @@
1
1
  class Install < ActiveRecord::Migration
2
2
  def change
3
3
  create_table "commontator_comments" do |t|
4
- t.text "body"
5
- t.integer "creator_id"
6
4
  t.string "creator_type"
5
+ t.integer "creator_id"
6
+ t.string "editor_type"
7
+ t.integer "editor_id"
8
+ t.integer "thread_id", :null => false
9
+ t.text "body", :null => false, :default => ''
7
10
  t.datetime "deleted_at"
8
- t.integer "deleter_id"
9
- t.string "deleter_type"
10
- t.integer "thread_id"
11
11
 
12
12
  t.integer "cached_votes_total", :default => 0
13
13
  t.integer "cached_votes_up", :default => 0
@@ -15,34 +15,36 @@ class Install < ActiveRecord::Migration
15
15
 
16
16
  t.timestamps
17
17
  end
18
+
19
+ add_index :commontator_comments, [:creator_type, :creator_id, :thread_id], :name => "index_c_c_on_c_type_and_c_id_and_t_id"
20
+ add_index :commontator_comments, :thread_id
21
+
22
+ add_index :commontator_comments, :cached_votes_total
23
+ add_index :commontator_comments, :cached_votes_up
24
+ add_index :commontator_comments, :cached_votes_down
18
25
 
19
26
  create_table "commontator_subscriptions" do |t|
20
- t.integer "subscriber_id"
21
- t.string "subscriber_type"
22
- t.integer "thread_id"
23
- t.integer "unread", :default => 0
27
+ t.string "subscriber_type", :null => false
28
+ t.integer "subscriber_id", :null => false
29
+ t.integer "thread_id", :null => false
30
+ t.integer "unread", :null => false, :default => 0
24
31
 
25
32
  t.timestamps
26
33
  end
27
34
 
35
+ add_index :commontator_subscriptions, [:subscriber_type, :subscriber_id, :thread_id], :unique => true, :name => "index_c_s_on_s_type_and_s_id_and_t_id"
36
+ add_index :commontator_subscriptions, :thread_id
37
+
28
38
  create_table "commontator_threads" do |t|
29
- t.integer "commontable_id"
30
39
  t.string "commontable_type"
40
+ t.integer "commontable_id"
31
41
  t.datetime "closed_at"
32
- t.integer "closer_id"
33
42
  t.string "closer_type"
43
+ t.integer "closer_id"
34
44
 
35
45
  t.timestamps
36
46
  end
37
-
38
- add_index :commontator_comments, [:creator_id, :creator_type, :thread_id], :name => "index_c_c_on_c_id_and_c_type_and_t_id"
39
- add_index :commontator_comments, :thread_id
40
- add_index :commontator_subscriptions, [:subscriber_id, :subscriber_type, :thread_id], :unique => true, :name => "index_c_s_on_s_id_and_s_type_and_t_id"
41
- add_index :commontator_subscriptions, :thread_id
42
- add_index :commontator_threads, [:commontable_id, :commontable_type]
43
-
44
- add_index :commontator_comments, :cached_votes_total
45
- add_index :commontator_comments, :cached_votes_up
46
- add_index :commontator_comments, :cached_votes_down
47
+
48
+ add_index :commontator_threads, [:commontable_type, :commontable_id], :unique => true
47
49
  end
48
50
  end
@@ -1,13 +1,13 @@
1
- class InstallCommontator < ActiveRecord::Migration
1
+ class Install < ActiveRecord::Migration
2
2
  def change
3
3
  create_table "commontator_comments" do |t|
4
- t.text "body"
5
- t.integer "creator_id"
6
4
  t.string "creator_type"
5
+ t.integer "creator_id"
6
+ t.string "editor_type"
7
+ t.integer "editor_id"
8
+ t.integer "thread_id", :null => false
9
+ t.text "body", :null => false, :default => ''
7
10
  t.datetime "deleted_at"
8
- t.integer "deleter_id"
9
- t.string "deleter_type"
10
- t.integer "thread_id"
11
11
 
12
12
  t.integer "cached_votes_total", :default => 0
13
13
  t.integer "cached_votes_up", :default => 0
@@ -15,34 +15,36 @@ class InstallCommontator < ActiveRecord::Migration
15
15
 
16
16
  t.timestamps
17
17
  end
18
+
19
+ add_index :commontator_comments, [:creator_type, :creator_id, :thread_id], :name => "index_c_c_on_c_type_and_c_id_and_t_id"
20
+ add_index :commontator_comments, :thread_id
21
+
22
+ add_index :commontator_comments, :cached_votes_total
23
+ add_index :commontator_comments, :cached_votes_up
24
+ add_index :commontator_comments, :cached_votes_down
18
25
 
19
26
  create_table "commontator_subscriptions" do |t|
20
- t.integer "subscriber_id"
21
- t.string "subscriber_type"
22
- t.integer "thread_id"
27
+ t.string "subscriber_type", :null => false
28
+ t.integer "subscriber_id", :null => false
29
+ t.integer "thread_id", :null => false
23
30
  t.integer "unread", :default => 0
24
31
 
25
32
  t.timestamps
26
33
  end
27
34
 
35
+ add_index :commontator_subscriptions, [:subscriber_type, :subscriber_id, :thread_id], :unique => true, :name => "index_c_s_on_s_type_and_s_id_and_t_id"
36
+ add_index :commontator_subscriptions, :thread_id
37
+
28
38
  create_table "commontator_threads" do |t|
29
- t.integer "commontable_id"
30
39
  t.string "commontable_type"
40
+ t.integer "commontable_id"
31
41
  t.datetime "closed_at"
32
- t.integer "closer_id"
33
42
  t.string "closer_type"
43
+ t.integer "closer_id"
34
44
 
35
45
  t.timestamps
36
46
  end
37
-
38
- add_index :commontator_comments, [:creator_id, :creator_type, :thread_id], :name => "index_c_c_on_c_id_and_c_type_and_t_id"
39
- add_index :commontator_comments, :thread_id
40
- add_index :commontator_subscriptions, [:subscriber_id, :subscriber_type, :thread_id], :unique => true, :name => "index_c_s_on_s_id_and_s_type_and_t_id"
41
- add_index :commontator_subscriptions, :thread_id
42
- add_index :commontator_threads, [:commontable_id, :commontable_type]
43
-
44
- add_index :commontator_comments, :cached_votes_total
45
- add_index :commontator_comments, :cached_votes_up
46
- add_index :commontator_comments, :cached_votes_down
47
+
48
+ add_index :commontator_threads, [:commontable_type, :commontable_id], :unique => true
47
49
  end
48
50
  end