commontator 0.1.46
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.
- data/MIT-LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +40 -0
- data/app/assets/images/commontator/downvote.png +0 -0
- data/app/assets/images/commontator/downvote_hover.png +0 -0
- data/app/assets/images/commontator/upvote.png +0 -0
- data/app/assets/images/commontator/upvote_hover.png +0 -0
- data/app/assets/stylesheets/commontator/application.css +13 -0
- data/app/assets/stylesheets/commontator/application.css~ +88 -0
- data/app/assets/stylesheets/commontator/comments.css +86 -0
- data/app/assets/stylesheets/commontator/comments.css~ +90 -0
- data/app/assets/stylesheets/commontator/threads.css +13 -0
- data/app/assets/stylesheets/commontator/threads.css~ +13 -0
- data/app/controllers/commontator/application_controller.rb +18 -0
- data/app/controllers/commontator/application_controller.rb~ +16 -0
- data/app/controllers/commontator/comments_controller.rb +143 -0
- data/app/controllers/commontator/comments_controller.rb~ +143 -0
- data/app/controllers/commontator/subscriptions_controller.rb +42 -0
- data/app/controllers/commontator/subscriptions_controller.rb~ +40 -0
- data/app/controllers/commontator/threads_controller.rb +42 -0
- data/app/controllers/commontator/threads_controller.rb~ +43 -0
- data/app/helpers/commontator/application_helper.rb +11 -0
- data/app/helpers/commontator/application_helper.rb~ +11 -0
- data/app/helpers/commontator/comments_helper.rb +47 -0
- data/app/helpers/commontator/comments_helper.rb~ +58 -0
- data/app/helpers/commontator/commontable_helper.rb~ +9 -0
- data/app/helpers/commontator/commontator_helper.rb +8 -0
- data/app/helpers/commontator/commontator_helper.rb~ +8 -0
- data/app/helpers/commontator/subscriptions_helper.rb +8 -0
- data/app/helpers/commontator/subscriptions_helper.rb~ +8 -0
- data/app/helpers/commontator/threads_helper.rb +21 -0
- data/app/helpers/commontator/threads_helper.rb~ +32 -0
- data/app/mailers/commontator/subscription_mailer.rb~ +38 -0
- data/app/mailers/commontator/subscriptions_mailer.rb +51 -0
- data/app/mailers/commontator/subscriptions_mailer.rb~ +51 -0
- data/app/models/commontator/comment.rb +84 -0
- data/app/models/commontator/comment.rb~ +84 -0
- data/app/models/commontator/subscription.rb +21 -0
- data/app/models/commontator/subscription.rb~ +21 -0
- data/app/models/commontator/thread.rb +138 -0
- data/app/models/commontator/thread.rb~ +141 -0
- data/app/views/commontator/comments/_actions.html.erb +32 -0
- data/app/views/commontator/comments/_actions.html.erb~ +33 -0
- data/app/views/commontator/comments/_body.html.erb +7 -0
- data/app/views/commontator/comments/_body.html.erb~ +8 -0
- data/app/views/commontator/comments/_form.html.erb +20 -0
- data/app/views/commontator/comments/_form.html.erb~ +21 -0
- data/app/views/commontator/comments/_show.html.erb +41 -0
- data/app/views/commontator/comments/_show.html.erb~ +45 -0
- data/app/views/commontator/comments/_votes.html.erb +60 -0
- data/app/views/commontator/comments/_votes.html.erb~ +62 -0
- data/app/views/commontator/comments/create.js.erb +15 -0
- data/app/views/commontator/comments/create.js.erb~ +15 -0
- data/app/views/commontator/comments/delete.js.erb +15 -0
- data/app/views/commontator/comments/delete.js.erb~ +15 -0
- data/app/views/commontator/comments/destroy.js.erb~ +1 -0
- data/app/views/commontator/comments/edit.html.erb +6 -0
- data/app/views/commontator/comments/edit.html.erb~ +6 -0
- data/app/views/commontator/comments/edit.js.erb +5 -0
- data/app/views/commontator/comments/edit.js.erb~ +5 -0
- data/app/views/commontator/comments/new.html.erb +8 -0
- data/app/views/commontator/comments/new.html.erb~ +8 -0
- data/app/views/commontator/comments/new.js.erb +12 -0
- data/app/views/commontator/comments/new.js.erb~ +12 -0
- data/app/views/commontator/comments/update.js.erb +7 -0
- data/app/views/commontator/comments/update.js.erb~ +7 -0
- data/app/views/commontator/comments/vote.js.erb +5 -0
- data/app/views/commontator/comments/vote.js.erb~ +5 -0
- data/app/views/commontator/commontator/_thread.html.erb +14 -0
- data/app/views/commontator/commontator/_thread.html.erb~ +15 -0
- data/app/views/commontator/subscriptions/_subscription_link.html.erb +12 -0
- data/app/views/commontator/subscriptions/_subscription_link.html.erb~ +12 -0
- data/app/views/commontator/subscriptions/create.js.erb +5 -0
- data/app/views/commontator/subscriptions/create.js.erb~ +3 -0
- data/app/views/commontator/subscriptions/destroy.js.erb +5 -0
- data/app/views/commontator/subscriptions/destroy.js.erb~ +3 -0
- data/app/views/commontator/subscriptions/index.html.erb +16 -0
- data/app/views/commontator/subscriptions/index.html.erb~ +16 -0
- data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb +14 -0
- data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb~ +14 -0
- data/app/views/commontator/threads/_show.html.erb +26 -0
- data/app/views/commontator/threads/_show.html.erb~ +26 -0
- data/app/views/commontator/threads/show.html.erb +3 -0
- data/app/views/commontator/threads/show.js.erb +6 -0
- data/app/views/layouts/commontator/application.html.erb +14 -0
- data/config/initializers/commontator.rb +7 -0
- data/config/routes.rb +24 -0
- data/config/routes.rb~ +22 -0
- data/db/migrate/0_install_commontator.rb +40 -0
- data/db/migrate/0_install_commontator.rb~ +40 -0
- data/lib/commontator.rb +66 -0
- data/lib/commontator.rb~ +66 -0
- data/lib/commontator/acts_as_commontable.rb +39 -0
- data/lib/commontator/acts_as_commontable.rb~ +42 -0
- data/lib/commontator/acts_as_commontator.rb +28 -0
- data/lib/commontator/acts_as_commontator.rb~ +37 -0
- data/lib/commontator/commontable_config.rb +13 -0
- data/lib/commontator/commontator_config.rb +13 -0
- data/lib/commontator/engine.rb +5 -0
- data/lib/commontator/routes.rb~ +37 -0
- data/lib/commontator/version.rb +3 -0
- data/lib/commontator/version.rb~ +3 -0
- data/test/commontator_test.rb +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +16 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +204 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/comment_thread_subscriptions_controller_test.rb~ +125 -0
- data/test/functional/comments_controller_test.rb +181 -0
- data/test/functional/comments_controller_test.rb~ +184 -0
- data/test/functional/subscriptions_controller_test.rb +122 -0
- data/test/functional/subscriptions_controller_test.rb~ +122 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/comment_test.rb +35 -0
- data/test/unit/comment_test.rb~ +38 -0
- data/test/unit/comment_thread_subscription_test.rb~ +18 -0
- data/test/unit/comment_thread_test.rb~ +60 -0
- data/test/unit/helpers/comment_thread_subscriptions_helper_test.rb~ +7 -0
- data/test/unit/helpers/comments_helper_test.rb +4 -0
- data/test/unit/helpers/comments_helper_test.rb~ +7 -0
- data/test/unit/helpers/subscriptions_helper_test.rb +4 -0
- data/test/unit/helpers/subscriptions_helper_test.rb~ +4 -0
- data/test/unit/subscription_test.rb +15 -0
- data/test/unit/subscription_test.rb~ +15 -0
- data/test/unit/thread_test.rb +57 -0
- data/test/unit/thread_test.rb~ +57 -0
- metadata +301 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Commontator
|
|
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?
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
module ApplicationHelper
|
|
3
|
+
def heading(string)
|
|
4
|
+
Commontator.heading_proc.call unless Commontator.heading_proc.blank?
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def javascript_callback
|
|
8
|
+
Commontator.javascript_proc.call unless Commontator.javascript_proc.blank?
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
module CommentsHelper
|
|
3
|
+
def commontator_name(comment)
|
|
4
|
+
commontator = comment.commontator
|
|
5
|
+
config = commontator.commontator_config
|
|
6
|
+
config.commontator_name_method.blank? ? config.anonymous_name : \
|
|
7
|
+
commontator.send(config.commontator_name_method)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def deleter_name(comment)
|
|
11
|
+
deleter = comment.deleter
|
|
12
|
+
config = deleter.commontator_config
|
|
13
|
+
config.commontator_name_method.blank? ? config.anonymous_name : \
|
|
14
|
+
deleter.send(config.commontator_name_method)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def comment_timestamp(comment)
|
|
18
|
+
config = comment.thread.config
|
|
19
|
+
(comment.is_modified? ? 'Last modified on ' : \
|
|
20
|
+
config.comment_create_verb_past.capitalize + \
|
|
21
|
+
' on ') + comment.updated_at.strftime(config.timestamp_format)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def gravatar_url(comment, options = {})
|
|
25
|
+
commontator = comment.commontator
|
|
26
|
+
config = commontator.commontator_config
|
|
27
|
+
|
|
28
|
+
options[:secure] ||= request.ssl?
|
|
29
|
+
options[:size] ||= 50
|
|
30
|
+
|
|
31
|
+
hash = Digest::MD5.hexdigest(commontator.send(config.commontator_email_method))
|
|
32
|
+
base = options[:secure] ? "s://secure" : "://www"
|
|
33
|
+
|
|
34
|
+
"http#{base}.gravatar.com/avatar/#{hash}?s=#{options[:size]}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def gravatar_image(comment, options = {})
|
|
38
|
+
commontator = comment.commontator
|
|
39
|
+
config = commontator.commontator_config
|
|
40
|
+
name = commontator.send(config.commontator_name_method)
|
|
41
|
+
image_tag(gravatar_url(comment, options),
|
|
42
|
+
{ :alt => name,
|
|
43
|
+
:title => name,
|
|
44
|
+
:border => 1 })
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
module CommentsHelper
|
|
3
|
+
def commontator_name(comment)
|
|
4
|
+
commontator = comment.commontator
|
|
5
|
+
config = commontator.commontator_config
|
|
6
|
+
config.commontator_name_method.blank? ? config.anonymous_name : \
|
|
7
|
+
commontator.send(config.commontator_name_method)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def deleter_name(comment)
|
|
11
|
+
deleter = comment.deleter
|
|
12
|
+
config = deleter.commontator_config
|
|
13
|
+
config.commontator_name_method.blank? ? config.anonymous_name : \
|
|
14
|
+
deleter.send(config.commontator_name_method)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def comment_timestamp(comment)
|
|
18
|
+
config = comment.thread.config
|
|
19
|
+
(comment.is_modified? ? 'Last modified on ' : \
|
|
20
|
+
config.comment_create_verb_past.capitalize + \
|
|
21
|
+
' on ') + comment.updated_at.strftime(config.timestamp_format)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def gravatar_url(comment, options = {})
|
|
25
|
+
commontator = comment.commontator
|
|
26
|
+
config = commontator.commontator_config
|
|
27
|
+
|
|
28
|
+
options[:secure] ||= request.ssl?
|
|
29
|
+
options[:size] ||= 50
|
|
30
|
+
|
|
31
|
+
hash = Digest::MD5.hexdigest(commontator.send(config.commontator_email_method))
|
|
32
|
+
base = options[:secure] ? "s://secure" : "://www"
|
|
33
|
+
|
|
34
|
+
"http#{base}.gravatar.com/avatar/#{hash}?s=#{options[:size]}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def gravatar_image(comment, options = {})
|
|
38
|
+
commontator = comment.commontator
|
|
39
|
+
config = commontator.commontator_config
|
|
40
|
+
name = commontator.send(config.commontator_name_method)
|
|
41
|
+
image_tag(gravatar_url(comment, options),
|
|
42
|
+
{ :alt => name,
|
|
43
|
+
:title => name,
|
|
44
|
+
:border => 1 })
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def refresh_comment_actions(thread)
|
|
48
|
+
output = ""
|
|
49
|
+
thread.comments.each do |comment|
|
|
50
|
+
output << "$('#comment_#{comment.id.to_s}_actions_span').html('" + \
|
|
51
|
+
escape_javascript(
|
|
52
|
+
render :partial => :actions,
|
|
53
|
+
:locals => { :comment => comment }) + "');\n\n"
|
|
54
|
+
end
|
|
55
|
+
output.slice(0..-3).html_safe
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
module ThreadsHelper
|
|
3
|
+
def commontable_name(thread)
|
|
4
|
+
config = thread.config
|
|
5
|
+
config.commontable_name.blank? ? \
|
|
6
|
+
thread.commontable.class.name : \
|
|
7
|
+
config.commontable_name
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def commontable_id(thread)
|
|
11
|
+
thread.commontable.send(thread.config.commontable_id_method)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def closer_name(thread)
|
|
15
|
+
closer = thread.closer
|
|
16
|
+
config = closer.commontator_config
|
|
17
|
+
config.commontator_name_method.blank? ? config.anonymous_name : \
|
|
18
|
+
closer.send(config.commontator_name_method)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
module ThreadsHelper
|
|
3
|
+
def commontable_name(thread)
|
|
4
|
+
config = thread.config
|
|
5
|
+
config.commontable_name.blank? ? \
|
|
6
|
+
thread.commontable.class.name : \
|
|
7
|
+
config.commontable_name
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def commontable_id(thread)
|
|
11
|
+
thread.commontable.send(thread.config.commontable_id_method)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def closer_name(thread)
|
|
15
|
+
closer = thread.closer
|
|
16
|
+
config = closer.commontator_config
|
|
17
|
+
config.commontator_name_method.blank? ? config.anonymous_name : \
|
|
18
|
+
closer.send(config.commontator_name_method)
|
|
19
|
+
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
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
class SubscriptionMailer < ActionMailer::Base
|
|
3
|
+
|
|
4
|
+
include CommentsHelper
|
|
5
|
+
include ThreadsHelper
|
|
6
|
+
|
|
7
|
+
def comment_created_email(comment)
|
|
8
|
+
setup_variables(comment)
|
|
9
|
+
|
|
10
|
+
mail(:bcc => @bcc,
|
|
11
|
+
:subject => @subject,
|
|
12
|
+
:body => @body)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
def setup_variables(comment)
|
|
18
|
+
@comment = comment
|
|
19
|
+
@thread = @comment.thread
|
|
20
|
+
@commontator = @comment.commontator
|
|
21
|
+
@commontable = @thread.commontable
|
|
22
|
+
@config = @thread.config
|
|
23
|
+
@bcc = @thread.subscribers.reject{|s| s == @commontator}\
|
|
24
|
+
.collect{|s| email(s)}
|
|
25
|
+
|
|
26
|
+
@commontator_name = commontator_name(@commontator)
|
|
27
|
+
@comment_timestamp = comment_timestamp(@comment)
|
|
28
|
+
|
|
29
|
+
@commontable_name = commontable_name(@thread)
|
|
30
|
+
@commontable_id = commontable_id(@thread).to_s
|
|
31
|
+
|
|
32
|
+
@subject = eval(@config.subscription_email_subject)
|
|
33
|
+
@body = @config.subscription_email_body.blank? ? nil : \
|
|
34
|
+
eval(@config.subscription_email_body)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
class SubscriptionsMailer < ActionMailer::Base
|
|
3
|
+
|
|
4
|
+
include CommentsHelper
|
|
5
|
+
include ThreadsHelper
|
|
6
|
+
|
|
7
|
+
def comment_created_email(comment)
|
|
8
|
+
setup_variables(comment)
|
|
9
|
+
|
|
10
|
+
mail(:bcc => @bcc,
|
|
11
|
+
:subject => @subject,
|
|
12
|
+
:body => @body)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
def setup_variables(comment)
|
|
18
|
+
|
|
19
|
+
@comment = comment
|
|
20
|
+
@thread = @comment.thread
|
|
21
|
+
|
|
22
|
+
@commontator = @comment.commontator
|
|
23
|
+
@commontable = @thread.commontable
|
|
24
|
+
@config = @thread.config
|
|
25
|
+
@bcc = @thread.subscribers.reject{|s| s == @commontator}\
|
|
26
|
+
.collect{|s| email(s)}
|
|
27
|
+
|
|
28
|
+
@commontator_name = commontator_name(@comment)
|
|
29
|
+
@comment_timestamp = comment_timestamp(@comment)
|
|
30
|
+
|
|
31
|
+
@commontable_name = commontable_name(@thread)
|
|
32
|
+
@commontable_id = commontable_id(@thread).to_s
|
|
33
|
+
|
|
34
|
+
params = Hash.new
|
|
35
|
+
params[:comment] = @comment
|
|
36
|
+
params[:thread] = @thread
|
|
37
|
+
params[:commontator] = @commontator
|
|
38
|
+
params[:commontable] = @commontable
|
|
39
|
+
params[:config] = @config
|
|
40
|
+
params[:commontator_name] = @commontator_name
|
|
41
|
+
params[:comment_timestamp] = @comment_timestamp
|
|
42
|
+
params[:commontable_name] = @commontable_name
|
|
43
|
+
params[:commontable_id] = @commontable_id
|
|
44
|
+
|
|
45
|
+
@subject = @config.subscription_email_subject_proc.call(params)
|
|
46
|
+
@body = @config.subscription_email_body_proc.blank? ? nil : \
|
|
47
|
+
@config.subscription_email_body_proc.call?(params)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
class SubscriptionsMailer < ActionMailer::Base
|
|
3
|
+
|
|
4
|
+
include CommentsHelper
|
|
5
|
+
include ThreadsHelper
|
|
6
|
+
|
|
7
|
+
def comment_created_email(comment)
|
|
8
|
+
setup_variables(comment)
|
|
9
|
+
|
|
10
|
+
mail(:bcc => @bcc,
|
|
11
|
+
:subject => @subject,
|
|
12
|
+
:body => @body)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
def setup_variables(comment)
|
|
18
|
+
|
|
19
|
+
@comment = comment
|
|
20
|
+
@thread = @comment.thread
|
|
21
|
+
|
|
22
|
+
@commontator = @comment.commontator
|
|
23
|
+
@commontable = @thread.commontable
|
|
24
|
+
@config = @thread.config
|
|
25
|
+
@bcc = @thread.subscribers.reject{|s| s == @commontator}\
|
|
26
|
+
.collect{|s| email(s)}
|
|
27
|
+
|
|
28
|
+
@commontator_name = commontator_name(@comment)
|
|
29
|
+
@comment_timestamp = comment_timestamp(@comment)
|
|
30
|
+
|
|
31
|
+
@commontable_name = commontable_name(@thread)
|
|
32
|
+
@commontable_id = commontable_id(@thread).to_s
|
|
33
|
+
|
|
34
|
+
params = Hash.new
|
|
35
|
+
params[:comment] = @comment
|
|
36
|
+
params[:thread] = @thread
|
|
37
|
+
params[:commontator] = @commontator
|
|
38
|
+
params[:commontable] = @commontable
|
|
39
|
+
params[:config] = @config
|
|
40
|
+
params[:commontator_name] = @commontator_name
|
|
41
|
+
params[:comment_timestamp] = @comment_timestamp
|
|
42
|
+
params[:commontable_name] = @commontable_name
|
|
43
|
+
params[:commontable_id] = @commontable_id
|
|
44
|
+
|
|
45
|
+
@subject = params[:config].subscription_email_subject_proc.call(params)
|
|
46
|
+
@body = params[:config].subscription_email_body_proc.blank? ? nil : \
|
|
47
|
+
params[:config].subscription_email_body_proc.call?(params)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
module Commontator
|
|
2
|
+
class Comment < ActiveRecord::Base
|
|
3
|
+
|
|
4
|
+
belongs_to :commontator, :polymorphic => true
|
|
5
|
+
belongs_to :deleter, :polymorphic => true
|
|
6
|
+
belongs_to :thread
|
|
7
|
+
|
|
8
|
+
has_one :commontable, :through => :thread
|
|
9
|
+
#has_one :subthread, :class_name => "Commontator::Thread",
|
|
10
|
+
# :as => :commontable,
|
|
11
|
+
# :dependent => :destroy
|
|
12
|
+
|
|
13
|
+
#before_validation :build_subthread, :on => :create
|
|
14
|
+
validates_presence_of :commontator, :thread#, :subthread
|
|
15
|
+
#validates_uniqueness_of :subthread
|
|
16
|
+
|
|
17
|
+
attr_accessible :body
|
|
18
|
+
|
|
19
|
+
cattr_accessor :is_votable
|
|
20
|
+
if respond_to?(:acts_as_votable)
|
|
21
|
+
acts_as_votable if respond_to?(:acts_as_votable)
|
|
22
|
+
self.is_votable = true
|
|
23
|
+
else
|
|
24
|
+
self.is_votable = false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def is_modified?
|
|
28
|
+
updated_at != created_at
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def is_deleted?
|
|
32
|
+
!deleted_at.blank?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def delete(user = nil)
|
|
36
|
+
self.deleted_at = Time.now
|
|
37
|
+
self.deleter = user
|
|
38
|
+
self.save!
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def undelete
|
|
42
|
+
self.deleted_at = nil
|
|
43
|
+
self.save!
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
##########################
|
|
47
|
+
# Access control methods #
|
|
48
|
+
##########################
|
|
49
|
+
|
|
50
|
+
def can_be_read_by?(user)
|
|
51
|
+
(thread.can_be_read_by?(user) && (!is_deleted? ||\
|
|
52
|
+
thread.config.deleted_comments_are_visible)) ||\
|
|
53
|
+
thread.can_be_edited_by?(user)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def can_be_created_by?(user)
|
|
57
|
+
!thread.is_closed? && thread.can_be_read_by?(user) && user == commontator
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def can_be_edited_by?(user)
|
|
61
|
+
!thread.is_closed? && !is_deleted? &&\
|
|
62
|
+
((user == commontator && thread.config.can_edit_own_comments) ||\
|
|
63
|
+
(thread.can_be_edited_by?(user) && thread.config.admin_can_edit_comments)) &&\
|
|
64
|
+
(thread.comments.last == self || thread.config.can_edit_old_comments)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def can_be_deleted_by?(user)
|
|
68
|
+
!thread.is_closed? &&\
|
|
69
|
+
((user == commontator && thread.config.can_delete_own_comments) &&\
|
|
70
|
+
(thread.comments.last == self || thread.config.can_delete_old_comments)) ||\
|
|
71
|
+
thread.can_be_edited_by?(user)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def can_be_voted_on?
|
|
75
|
+
is_votable && !is_deleted? && thread.config.comments_can_be_voted_on
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def can_be_voted_on_by?(user)
|
|
79
|
+
can_be_voted_on? && !thread.is_closed? &&\
|
|
80
|
+
thread.can_be_read_by?(user) && user != commontator
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
end
|