commontator 0.1.46 → 0.2.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.
@@ -0,0 +1,164 @@
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
+
5
+ # Engine Configuration
6
+
7
+ # Method called on ApplicationController to return the current user
8
+ # Default: 'current_user'
9
+ config.current_user_method = 'current_user'
10
+
11
+ # Proc that is called when a view wants to set the page heading.
12
+ # Default: Proc.new {}
13
+ config.heading_proc = nil
14
+
15
+ # Proc that is called after any javascript runs (e.g. to clear flash notices)
16
+ # Default: Proc.new {}
17
+ config.javascript_proc = nil
18
+
19
+
20
+ # Commontator (User model) Configuration
21
+
22
+ # Whether the commontator's name is clickable in the comment view
23
+ # Default: false
24
+ config.commontator_name_clickable = false
25
+
26
+ # The method that return the commontator's email address
27
+ # Default: 'email'
28
+ config.commontator_email_method = 'email'
29
+
30
+ # The method that return the commontator's name
31
+ # Default: '' (Anonymous)
32
+ config.commontator_name_method = ''
33
+
34
+ # Method that returns true if the commontator is an admin for all threads
35
+ # Admins can always delete other users' comments and close threads
36
+ # Default: '' (no admins)
37
+ config.is_admin_method = ''
38
+
39
+
40
+ # Commontable (Commentable model) Configuration
41
+
42
+ # What a comment is called in your application
43
+ # Default: 'comment'
44
+ config.comment_name = 'comment'
45
+
46
+ # Verb used when creating comments (present)
47
+ # Default: 'post'
48
+ config.comment_create_verb_present = 'post'
49
+
50
+ # Verb used when creating comments (past)
51
+ # Default: 'posted'
52
+ config.comment_create_verb_past = 'posted'
53
+
54
+ # What a commontable is called in your application
55
+ # If you have multiple commontable models,
56
+ # you might want to pass this configuration value
57
+ # as an argument to acts_as_commontable in each one
58
+ # Default: 'commontable'
59
+ config.commontable_name = 'commontable'
60
+
61
+ # Proc that returns the subscription email subject
62
+ # Default: Proc.new {}
63
+ config.subscription_email_subject_proc = Proc.new {|params| \
64
+ "#{params[:commontator_name]} #{params[:config].comment_create_verb_past} a " + \
65
+ "#{params[:config].comment_name} on #{params[:commontable_name]} ##{params[:commontable_id]}"}
66
+
67
+ # The format of the timestamps used by Commontator
68
+ # Default: '%b %d %Y, %I:%M %p'
69
+ config.timestamp_format = '%b %d %Y, %I:%M %p'
70
+
71
+ # Whether admins can edit other users' comments
72
+ # Default: false
73
+ config.admin_can_edit_comments = false
74
+
75
+ # Whether users automatically subscribe to a thread when commenting
76
+ # Default: false
77
+ config.auto_subscribe_on_comment = false
78
+
79
+ # Whether users can edit their own comments
80
+ # Default: true
81
+ config.can_edit_own_comments = true
82
+
83
+ # Whether users can edit their own comments
84
+ # after someone posted a newer comment
85
+ # Default: false
86
+ config.can_edit_old_comments = false
87
+
88
+ # Whether users can delete their own comments
89
+ # Default: false
90
+ config.can_delete_own_comments = false
91
+
92
+ # Whether users can delete their own comments
93
+ # after someone posted a newer comment
94
+ # Default: false
95
+ config.can_delete_old_comments = false
96
+
97
+ # Whether users can manually subscribe or unsubscribe to threads
98
+ # Default: true
99
+ config.can_subscribe_to_thread = true
100
+
101
+ # Whether users can vote on other users' comments
102
+ # Note: requires acts_as_votable gem installed
103
+ # and configured for your application
104
+ # Default: false
105
+ config.comments_can_be_voted_on = false
106
+
107
+ # Whether comments should be ordered by vote score
108
+ # instead of by order posted
109
+ # Default: false
110
+ config.comments_order_by_votes = false
111
+
112
+ # Whether users can read threads closed by admins
113
+ # Default: true
114
+ config.closed_threads_are_readable = true
115
+
116
+ # Whether comments deleted by admins can be seen
117
+ # (the content will still be hidden)
118
+ # Default: true
119
+ config.deleted_comments_are_visible = true
120
+
121
+ # Method called on commontable to return its id
122
+ # Default: 'id'
123
+ config.commontable_id_method = 'id'
124
+
125
+ # Method called on commontable and passed user as argument
126
+ # If true, that user is an admin for that particular commontable's thread
127
+ # Default: '' (no thread-specific admins)
128
+ config.can_edit_thread_method = ''
129
+
130
+ # Method called on commontable and passed user as argument
131
+ # If true, that user is allowed to read that commontable's thread
132
+ # Default: '' (no read restrictions)
133
+ config.can_read_thread_method = ''
134
+
135
+ # Method called on commontable when a comment is created
136
+ # Passed user, comment as arguments
137
+ # Default: '' (no callback)
138
+ config.comment_created_callback = ''
139
+
140
+ # Method called on commontable when a comment is edited
141
+ # Passed user, comment as arguments
142
+ # Default: '' (no callback)
143
+ config.comment_edited_callback = ''
144
+
145
+ # Method called on commontable when a comment is deleted
146
+ # Passed user, comment as arguments
147
+ # Default: '' (no callback)
148
+ config.comment_deleted_callback = ''
149
+
150
+ # Method called on commontable when a thread is closed
151
+ # Passed user as argument
152
+ # Default: '' (no callback)
153
+ config.thread_closed_callback = ''
154
+
155
+ # Method called on commontable when a thread is subscribed to
156
+ # Passed user as argument
157
+ # Default: '' (no callback)
158
+ config.subscribe_callback = ''
159
+
160
+ # Method called on commontable when a thread is unsubscribed to
161
+ # Passed user as argument
162
+ # Default: '' (no callback)
163
+ config.unsubscribe_callback = ''
164
+ end
@@ -8,6 +8,10 @@ class InstallCommontator < ActiveRecord::Migration
8
8
  t.integer "deleter_id"
9
9
  t.string "deleter_type"
10
10
  t.integer "thread_id"
11
+
12
+ t.integer "cached_votes_total", :default => 0
13
+ t.integer "cached_votes_up", :default => 0
14
+ t.integer "cached_votes_down", :default => 0
11
15
 
12
16
  t.timestamps
13
17
  end
@@ -36,5 +40,9 @@ class InstallCommontator < ActiveRecord::Migration
36
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"
37
41
  add_index :commontator_subscriptions, :thread_id
38
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
39
47
  end
40
48
  end
@@ -8,6 +8,10 @@ class InstallCommontator < ActiveRecord::Migration
8
8
  t.integer "deleter_id"
9
9
  t.string "deleter_type"
10
10
  t.integer "thread_id"
11
+
12
+ t.integer "cached_votes_total", :default => 0
13
+ t.integer "cached_votes_up", :default => 0
14
+ t.integer "cached_votes_down", :default => 0
11
15
 
12
16
  t.timestamps
13
17
  end
@@ -33,8 +37,12 @@ class InstallCommontator < ActiveRecord::Migration
33
37
 
34
38
  add_index :commontator_comments, [:commontator_id, :commontator_type, :thread_id], :name => "index_c_c_on_c_id_and_c_type_and_t_id"
35
39
  add_index :commontator_comments, :thread_id
36
- add_index :commontator_subscriptions, [:subscriber_id, :subscriber_type, :thread_id], :unique => true
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"
37
41
  add_index :commontator_subscriptions, :thread_id
38
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
39
47
  end
40
48
  end
data/lib/commontator.rb CHANGED
@@ -1,57 +1,54 @@
1
1
  module Commontator
2
- # Attributes and default values
2
+ # Attributes
3
3
 
4
- # Can be overriden in initializer only
5
- ENGINE_CONFIG = {
6
- :current_user_method => 'current_user',
7
- :heading_proc => nil,
8
- :javascript_proc => nil,
9
- }
4
+ # Can be set in initializer only
5
+ ENGINE_ATTRIBUTES = [
6
+ :current_user_method,
7
+ :heading_proc,
8
+ :javascript_proc
9
+ ]
10
10
 
11
- # Can be overriden in initializer and acts_as_commontator
12
- COMMONTATOR_CONFIG = {
13
- :commontator_name_clickable => false,
14
- :commontator_email_method => 'email',
15
- :commontator_name_method => '',
16
- :is_admin_method => ''
17
- }
11
+ # Can be set in initializer or passed as an option to acts_as_commontator
12
+ COMMONTATOR_ATTRIBUTES = [
13
+ :commontator_name_clickable,
14
+ :commontator_email_method,
15
+ :commontator_name_method,
16
+ :is_admin_method
17
+ ]
18
18
 
19
- # Can be overriden in initializer and acts_as_commontable
20
- COMMONTABLE_CONFIG = {
21
- :comment_name => 'comment',
22
- :comment_create_verb_present => 'post',
23
- :comment_create_verb_past => 'posted',
24
- :commontable_name => 'commontable',
25
- :subscription_email_subject_proc => Proc.new {|params| \
26
- "#{params[:commontator_name]} #{params[:config].comment_create_verb_past} a " + \
27
- "#{params[:config].comment_name} on #{params[:commontable_name]} ##{params[:commontable_id]}"},
28
- :subscription_email_body_proc => nil,
29
- :timestamp_format => '%b %d %Y, %I:%M %p',
30
- :admin_can_edit_comments => false,
31
- :auto_subscribe_on_comment => false,
32
- :can_edit_old_comments => false,
33
- :can_edit_own_comments => true,
34
- :can_delete_old_comments => false,
35
- :can_delete_own_comments => false,
36
- :can_subscribe_to_thread => true,
37
- :comments_can_be_voted_on => false,
38
- :closed_threads_are_readable => true,
39
- :deleted_comments_are_visible => true,
40
- :commontable_id_method => 'id',
41
- :can_edit_thread_method => '',
42
- :can_read_thread_method => '',
43
- :comment_created_callback => '',
44
- :comment_edited_callback => '',
45
- :comment_deleted_callback => '',
46
- :thread_closed_callback => '',
47
- :subscribe_callback => '',
48
- :unsubscribe_callback => ''
49
- }
19
+ # Can be set in initializer or passed as an option to acts_as_commontable
20
+ COMMONTABLE_ATTRIBUTES = [
21
+ :comment_name,
22
+ :comment_create_verb_present,
23
+ :comment_create_verb_past,
24
+ :commontable_name,
25
+ :subscription_email_subject_proc,
26
+ :timestamp_format,
27
+ :admin_can_edit_comments,
28
+ :auto_subscribe_on_comment,
29
+ :can_edit_own_comments,
30
+ :can_edit_old_comments,
31
+ :can_delete_own_comments,
32
+ :can_delete_old_comments,
33
+ :can_subscribe_to_thread,
34
+ :comments_can_be_voted_on,
35
+ :comments_ordered_by_votes,
36
+ :closed_threads_are_readable,
37
+ :deleted_comments_are_visible,
38
+ :commontable_id_method,
39
+ :can_edit_thread_method,
40
+ :can_read_thread_method,
41
+ :comment_created_callback,
42
+ :comment_edited_callback,
43
+ :comment_deleted_callback,
44
+ :thread_closed_callback,
45
+ :subscribe_callback,
46
+ :unsubscribe_callback
47
+ ]
50
48
 
51
- ENGINE_CONFIG.merge(COMMONTATOR_CONFIG.merge(\
52
- COMMONTABLE_CONFIG)).each do |key, value|
53
- mattr_accessor key
54
- self.send key.to_s + '=', value
49
+ (ENGINE_ATTRIBUTES + COMMONTATOR_ATTRIBUTES + \
50
+ COMMONTABLE_ATTRIBUTES).each do |attribute|
51
+ mattr_accessor attribute
55
52
  end
56
53
 
57
54
  def self.configure
data/lib/commontator.rb~ CHANGED
@@ -1,57 +1,54 @@
1
1
  module Commontator
2
- # Attributes and default values
2
+ # Attributes
3
3
 
4
- # Can be overriden in initializer only
5
- ENGINE_CONFIG = {
6
- :current_user_method => 'current_user',
7
- :heading_proc => nil,
8
- :javascript_proc => nil,
9
- }
4
+ # Can be set in initializer only
5
+ ENGINE_ATTRIBUTES = [
6
+ :current_user_method,
7
+ :heading_proc,
8
+ :javascript_proc
9
+ ]
10
10
 
11
- # Can be overriden in initializer and acts_as_commontator
12
- COMMONTATOR_CONFIG = {
13
- :commontator_name_clickable => false,
14
- :commontator_email_method => 'email',
15
- :commontator_name_method => '',
16
- :is_admin_method => ''
17
- }
11
+ # Can be set in initializer or passed as an option to acts_as_commontator
12
+ COMMONTATOR_ATTRIBUTES = [
13
+ :commontator_name_clickable,
14
+ :commontator_email_method,
15
+ :commontator_name_method,
16
+ :is_admin_method
17
+ ]
18
18
 
19
- # Can be overriden in initializer and acts_as_commontable
20
- COMMONTABLE_CONFIG = {
21
- :comment_name => 'comment',
22
- :comment_create_verb_present => 'post',
23
- :comment_create_verb_past => 'posted',
24
- :commontable_name => 'commontable',
25
- :subscription_email_subject_proc => Proc.new {|params| "#{params[:commontator_name]} " + \
26
- "#{params[:config].comment_create_verb_past} a #{params[:config].comment_name} on " + \
27
- "#{params[:commontable_name]} ##{params[:commontable_id]}"},
28
- :subscription_email_body_proc => nil,
29
- :timestamp_format => '%b %d %Y, %I:%M %p',
30
- :admin_can_edit_comments => false,
31
- :auto_subscribe_on_comment => false,
32
- :can_edit_old_comments => false,
33
- :can_edit_own_comments => true,
34
- :can_delete_old_comments => false,
35
- :can_delete_own_comments => false,
36
- :can_subscribe_to_thread => true,
37
- :comments_can_be_voted_on => false,
38
- :closed_threads_are_readable => true,
39
- :deleted_comments_are_visible => true,
40
- :commontable_id_method => 'id',
41
- :can_edit_thread_method => '',
42
- :can_read_thread_method => '',
43
- :comment_created_callback => '',
44
- :comment_edited_callback => '',
45
- :comment_deleted_callback => '',
46
- :thread_closed_callback => '',
47
- :subscribe_callback => '',
48
- :unsubscribe_callback => ''
49
- }
19
+ # Can be set in initializer or passed as an option to acts_as_commontable
20
+ COMMONTABLE_ATTRIBUTES = [
21
+ :comment_name,
22
+ :comment_create_verb_present,
23
+ :comment_create_verb_past,
24
+ :commontable_name,
25
+ :subscription_email_subject_proc,
26
+ :timestamp_format,
27
+ :admin_can_edit_comments,
28
+ :auto_subscribe_on_comment,
29
+ :can_edit_own_comments,
30
+ :can_edit_old_comments,
31
+ :can_delete_own_comments,
32
+ :can_delete_old_comments,
33
+ :can_subscribe_to_thread,
34
+ :comments_can_be_voted_on,
35
+ :comments_order_by_votes,
36
+ :closed_threads_are_readable,
37
+ :deleted_comments_are_visible,
38
+ :commontable_id_method,
39
+ :can_edit_thread_method,
40
+ :can_read_thread_method,
41
+ :comment_created_callback,
42
+ :comment_edited_callback,
43
+ :comment_deleted_callback,
44
+ :thread_closed_callback,
45
+ :subscribe_callback,
46
+ :unsubscribe_callback
47
+ ]
50
48
 
51
- ENGINE_CONFIG.merge(COMMONTATOR_CONFIG.merge(\
52
- COMMONTABLE_CONFIG)).each do |key, value|
53
- mattr_accessor key
54
- self.send key.to_s + '=', value
49
+ (ENGINE_ATTRIBUTES + COMMONTATOR_ATTRIBUTES + \
50
+ COMMONTABLE_ATTRIBUTES).each do |attribute|
51
+ mattr_accessor attribute
55
52
  end
56
53
 
57
54
  def self.configure
@@ -1,11 +1,11 @@
1
1
  module Commontator
2
2
  class CommontableConfig
3
- Commontator::COMMONTABLE_CONFIG.keys.each do |attribute|
3
+ Commontator::COMMONTABLE_ATTRIBUTES.each do |attribute|
4
4
  cattr_accessor attribute
5
5
  end
6
6
 
7
7
  def initialize(options = {})
8
- Commontator::COMMONTABLE_CONFIG.keys.each do |attribute|
8
+ Commontator::COMMONTABLE_ATTRIBUTES.each do |attribute|
9
9
  self.send attribute.to_s + '=', options[attribute] || Commontator.send(attribute)
10
10
  end
11
11
  end
@@ -0,0 +1,13 @@
1
+ module Commontator
2
+ class CommontableConfig
3
+ Commontator::COMMONTABLE_ATTRIBUTES.each do |attribute|
4
+ cattr_accessor attribute
5
+ end
6
+
7
+ def initialize(options = {})
8
+ Commontator::COMMONTABLE_CONFIG.keys.each do |attribute|
9
+ self.send attribute.to_s + '=', options[attribute] || Commontator.send(attribute)
10
+ end
11
+ end
12
+ end
13
+ end