commontator 4.5.4 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +5 -13
  2. data/MIT-LICENSE +2 -1
  3. data/README.md +31 -34
  4. data/Rakefile +3 -2
  5. data/app/assets/stylesheets/commontator/application.css +1 -0
  6. data/app/assets/stylesheets/commontator/comments.css +1 -0
  7. data/app/assets/stylesheets/commontator/threads.css +13 -7
  8. data/{spec/dummy/tmp/cache/assets/test/sprockets/a473b3873e554893372a53d71f5e9879 → app/assets/stylesheets/commontator/threads.css~} +0 -0
  9. data/app/controllers/commontator/application_controller.rb +14 -14
  10. data/app/controllers/commontator/application_controller.rb~ +35 -0
  11. data/app/controllers/commontator/comments_controller.rb +8 -7
  12. data/app/controllers/commontator/comments_controller.rb~ +153 -0
  13. data/app/controllers/commontator/subscriptions_controller.rb +1 -0
  14. data/app/controllers/commontator/threads_controller.rb +7 -2
  15. data/app/helpers/commontator/application_helper.rb +1 -0
  16. data/app/mailers/commontator/subscriptions_mailer.rb +8 -10
  17. data/app/mailers/commontator/subscriptions_mailer.rb~ +44 -0
  18. data/app/models/commontator/comment.rb +14 -13
  19. data/app/models/commontator/comment.rb~ +119 -0
  20. data/app/models/commontator/subscription.rb +8 -4
  21. data/app/models/commontator/thread.rb +64 -43
  22. data/app/models/commontator/thread.rb~ +159 -0
  23. data/app/views/commontator/comments/_actions.html.erb +1 -0
  24. data/app/views/commontator/comments/_body.html.erb +2 -1
  25. data/app/views/commontator/comments/_form.html.erb +5 -1
  26. data/app/views/commontator/comments/_form.html.erb~ +39 -0
  27. data/app/views/commontator/comments/_list.html.erb +1 -1
  28. data/app/views/commontator/comments/_show.html.erb +5 -3
  29. data/app/views/commontator/comments/_show.html.erb~ +49 -0
  30. data/app/views/commontator/comments/_votes.html.erb +2 -1
  31. data/app/views/commontator/comments/_votes.html.erb~ +69 -0
  32. data/app/views/commontator/comments/cancel.js.erb +1 -0
  33. data/app/views/commontator/comments/create.js.erb +6 -4
  34. data/app/views/commontator/comments/create.js.erb~ +14 -0
  35. data/app/views/commontator/comments/delete.js.erb +1 -0
  36. data/app/views/commontator/comments/edit.js.erb +1 -0
  37. data/app/views/commontator/comments/new.js.erb +3 -1
  38. data/app/views/commontator/comments/new.js.erb~ +13 -0
  39. data/app/views/commontator/comments/update.js.erb +1 -0
  40. data/app/views/commontator/comments/vote.js.erb +1 -0
  41. data/app/views/commontator/shared/_thread.html.erb +4 -5
  42. data/app/views/commontator/subscriptions/_link.html.erb +2 -1
  43. data/app/views/commontator/subscriptions/_link.html.erb~ +16 -0
  44. data/app/views/commontator/subscriptions/subscribe.js.erb +1 -0
  45. data/app/views/commontator/subscriptions_mailer/comment_created.html.erb +1 -0
  46. data/app/views/commontator/threads/_reply.html.erb +4 -2
  47. data/app/views/commontator/threads/_reply.html.erb~ +19 -0
  48. data/app/views/commontator/threads/_show.html.erb +44 -9
  49. data/app/views/commontator/threads/_show.html.erb~ +95 -0
  50. data/app/views/commontator/threads/_show.js.erb +19 -0
  51. data/app/views/commontator/threads/show.js.erb +4 -4
  52. data/config/initializers/commontator.rb +169 -132
  53. data/config/initializers/commontator.rb~ +238 -0
  54. data/config/locales/commontator/en.yml +12 -3
  55. data/config/locales/commontator/en.yml~ +104 -0
  56. data/config/routes.rb +1 -0
  57. data/db/migrate/0_install_commontator.rb +9 -11
  58. data/db/migrate/0_install_commontator.rb~ +54 -0
  59. data/lib/commontator.rb +57 -16
  60. data/lib/commontator.rb~ +142 -0
  61. data/lib/commontator/acts_as_commontable.rb +12 -14
  62. data/lib/commontator/acts_as_commontator.rb +1 -16
  63. data/lib/commontator/commontable_config.rb +1 -0
  64. data/lib/commontator/commontator_config.rb +1 -0
  65. data/lib/commontator/controller_includes.rb +3 -3
  66. data/lib/commontator/engine.rb +1 -0
  67. data/lib/commontator/link_renderer.rb +29 -0
  68. data/lib/commontator/security_transgression.rb +1 -0
  69. data/lib/commontator/shared_helper.rb +7 -5
  70. data/lib/commontator/version.rb +2 -1
  71. data/lib/tasks/commontator_tasks.rake +1 -0
  72. data/spec/app/controllers/commontator/comments_controller_spec.rb +12 -11
  73. data/spec/app/controllers/commontator/subscriptions_controller_spec.rb +2 -1
  74. data/spec/app/controllers/commontator/threads_controller_spec.rb +2 -1
  75. data/spec/app/helpers/commontator/application_helper_spec.rb +2 -1
  76. data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb +2 -1
  77. data/spec/app/models/commontator/comment_spec.rb +18 -11
  78. data/spec/app/models/commontator/comment_spec.rb~ +74 -0
  79. data/spec/app/models/commontator/subscription_spec.rb +18 -8
  80. data/spec/app/models/commontator/thread_spec.rb +28 -42
  81. data/spec/dummy/README.md +1 -0
  82. data/spec/dummy/Rakefile +1 -0
  83. data/spec/dummy/app/assets/javascripts/application.js +1 -0
  84. data/spec/dummy/app/assets/stylesheets/application.css +1 -0
  85. data/spec/dummy/app/controllers/application_controller.rb +1 -0
  86. data/spec/dummy/app/controllers/dummy_models_controller.rb +1 -0
  87. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  88. data/spec/dummy/app/models/dummy_model.rb +1 -0
  89. data/spec/dummy/app/models/dummy_user.rb +7 -2
  90. data/spec/dummy/app/models/dummy_user.rb~ +16 -0
  91. data/spec/dummy/app/views/dummy_model/show.html.erb +1 -0
  92. data/spec/dummy/app/views/layouts/application.html.erb +1 -0
  93. data/spec/dummy/config.ru +1 -0
  94. data/spec/dummy/config/boot.rb +1 -0
  95. data/spec/dummy/config/database.yml +1 -0
  96. data/spec/dummy/config/environment.rb +1 -0
  97. data/spec/dummy/config/environments/development.rb +1 -0
  98. data/spec/dummy/config/environments/production.rb +1 -0
  99. data/spec/dummy/config/environments/test.rb +1 -0
  100. data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
  101. data/spec/dummy/config/initializers/commontator.rb +6 -1
  102. data/spec/dummy/config/initializers/commontator.rb~ +15 -0
  103. data/spec/dummy/config/initializers/filter_parameter_logging.rb +1 -0
  104. data/spec/dummy/config/initializers/inflections.rb +1 -0
  105. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  106. data/spec/dummy/config/initializers/secret_token.rb +1 -0
  107. data/spec/dummy/config/initializers/session_store.rb +1 -0
  108. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -0
  109. data/spec/dummy/config/routes.rb +1 -0
  110. data/spec/dummy/db/development.sqlite3 +0 -0
  111. data/spec/dummy/db/migrate/1_create_dummy_models.rb +1 -0
  112. data/spec/dummy/db/migrate/2_create_dummy_users.rb +1 -0
  113. data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb +1 -0
  114. data/spec/dummy/db/schema.rb +10 -13
  115. data/spec/dummy/db/test.sqlite3 +0 -0
  116. data/spec/dummy/public/404.html +1 -0
  117. data/spec/dummy/public/422.html +1 -0
  118. data/spec/dummy/public/500.html +1 -0
  119. data/spec/dummy/script/rails +1 -0
  120. data/spec/dummy/tmp/cache/assets/test/sprockets/{72b63dddbc5c995f79af8e3c94904fd9 → 02d4b791eb831cf2057bf4703a1218d1} +0 -0
  121. data/spec/dummy/tmp/cache/assets/test/sprockets/{a77b1a9223d168112e1705c29220116f → 0f196a1a50363b0a076ec6e1ee5417f6} +0 -0
  122. data/spec/dummy/tmp/cache/assets/test/sprockets/a3fb9025f90ff05a6fd4afc7ded2692c +0 -0
  123. data/spec/dummy/tmp/cache/assets/test/sprockets/a41c8be5379abec3c0d0d98e2f0d5609 +0 -0
  124. data/spec/dummy/tmp/cache/assets/test/sprockets/c69ee3cc5796188d873574179290a6ef +0 -0
  125. data/spec/dummy/tmp/cache/assets/test/sprockets/{f721383d531f067d82b071e14aed7a92 → e1f674c11941d62aac1764ef3a7134e4} +0 -0
  126. data/spec/dummy/tmp/cache/assets/test/sprockets/{d2244ccef8e05bb993f75715af0344cc → e85565206c3e5fdf9dfeb367c85557b1} +0 -0
  127. data/spec/lib/commontator/acts_as_commontable_spec.rb +3 -2
  128. data/spec/lib/commontator/acts_as_commontator_spec.rb +2 -5
  129. data/spec/lib/commontator/commontable_config_spec.rb +8 -5
  130. data/spec/lib/commontator/commontator_config_spec.rb +2 -1
  131. data/spec/lib/commontator/controller_includes_spec.rb +2 -1
  132. data/spec/lib/commontator/shared_helper_spec.rb +2 -1
  133. data/spec/lib/commontator_spec.rb +2 -1
  134. data/spec/{test_helper.rb → spec_helper.rb} +0 -0
  135. metadata +154 -135
  136. data/lib/commontator/remote_link_renderer.rb +0 -10
  137. data/spec/dummy/config/locales/en.yml +0 -23
  138. data/spec/dummy/log/development.log +0 -36
  139. data/spec/dummy/log/test.log +0 -22683
  140. data/spec/dummy/tmp/cache/assets/test/sprockets/afa63eb365bdf4f42584b17ac9176b9d +0 -0
  141. data/spec/dummy/tmp/cache/assets/test/sprockets/decb63cac838a5314aa0c22a979f5ac9 +0 -0
@@ -3,3 +3,4 @@ $("#comment_<%= @comment.id.to_s %>_body_div").html("<%= escape_javascript(
3
3
  :locals => {:comment => @comment}) %>");
4
4
 
5
5
  <%= javascript_proc %>
6
+
@@ -2,7 +2,8 @@ $("#thread_<%= @thread.id %>_new_comment_div").html("<%= escape_javascript(
2
2
  render :partial => 'form',
3
3
  :locals => {
4
4
  :comment => @comment,
5
- :thread => @thread
5
+ :thread => @thread,
6
+ :per_page => @per_page
6
7
  }) %>");
7
8
 
8
9
  $("#thread_<%= @thread.id %>_new_comment_div").fadeIn()[0].scrollIntoView();
@@ -10,3 +11,4 @@ $("#thread_<%= @thread.id %>_new_comment_div").fadeIn()[0].scrollIntoView();
10
11
  $("#thread_<%= @thread.id %>_new_comment_link_span").hide();
11
12
 
12
13
  <%= javascript_proc %>
14
+
@@ -0,0 +1,13 @@
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
+ <%= javascript_proc %>
13
+
@@ -5,3 +5,4 @@ $("#comment_<%= @comment.id.to_s %>_updated_timestamp_span").html("<%= escape_ja
5
5
  @comment.updated_timestamp) %>");
6
6
 
7
7
  <%= javascript_proc %>
8
+
@@ -4,3 +4,4 @@ $("#comment_<%= @comment.id %>_votes_span").html("<%= escape_javascript(
4
4
  :user => @user}) %>");
5
5
 
6
6
  <%= javascript_proc %>
7
+
@@ -3,8 +3,6 @@
3
3
  # user
4
4
  %>
5
5
 
6
- <% subscription = thread.subscription_for(user) %>
7
-
8
6
  <% if thread.can_be_read_by?(user) %>
9
7
  <%= stylesheet_link_tag "commontator/application.css", :media => "all" %>
10
8
 
@@ -16,10 +14,11 @@
16
14
  :page => @commontator_page,
17
15
  :per_page => @commontator_per_page} %>
18
16
  <% else %>
19
- <%= link_to "#{t 'commontator.thread.actions.show'} (#{subscription ?
20
- (subscription.unread.to_s + '/' + thread.comments.count.to_s) :
21
- thread.comments.count.to_s})", commontator.thread_path(thread),
17
+ <% subscription = thread.subscription_for(user) %>
18
+ <%= link_to "#{t 'commontator.thread.actions.show'} (#{(subscription.unread_comments.count.to_s + '/') \
19
+ if subscription}#{thread.filtered_comments.count.to_s})", commontator.thread_path(thread),
22
20
  :remote => true %>
23
21
  <% end %>
24
22
  </div>
25
23
  <% end %>
24
+
@@ -3,7 +3,7 @@
3
3
  # user
4
4
  %>
5
5
 
6
- <% is_subscribed = thread.is_subscribed?(user) %>
6
+ <% is_subscribed = !!thread.subscription_for(user) %>
7
7
  <% sub_string = is_subscribed ? "unsubscribe" : "subscribe" %>
8
8
  <%= link_to t("commontator.subscription.actions.#{sub_string}"),
9
9
  commontator.polymorphic_path([sub_string, thread]),
@@ -13,3 +13,4 @@
13
13
  :id => "thread_#{thread.id.to_s}_#{sub_string}_link",
14
14
  :class => "thread_#{sub_string}_link",
15
15
  :remote => true %>
16
+
@@ -0,0 +1,16 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # thread
3
+ # user
4
+ %>
5
+
6
+ <% is_subscribed = thread.subscription_for(user) %>
7
+ <% sub_string = is_subscribed ? "unsubscribe" : "subscribe" %>
8
+ <%= link_to t("commontator.subscription.actions.#{sub_string}"),
9
+ commontator.polymorphic_path([sub_string, thread]),
10
+ :confirm => (is_subscribed ? t('commontator.subscription.actions.confirm_unsubscribe') : \
11
+ nil),
12
+ :method => :put,
13
+ :id => "thread_#{thread.id.to_s}_#{sub_string}_link",
14
+ :class => "thread_#{sub_string}_link",
15
+ :remote => true %>
16
+
@@ -4,3 +4,4 @@ $("#thread_<%= @thread.id.to_s %>_subscription_span").html("<%= escape_javascrip
4
4
  :user => @user}) %>");
5
5
 
6
6
  <%= javascript_proc %>
7
+
@@ -8,3 +8,4 @@
8
8
  <p><%= t 'commontator.email.thread_link_html',
9
9
  :commontable_url => @commontable_url,
10
10
  :commontable_name => @commontable_name %></p>
11
+
@@ -1,10 +1,11 @@
1
1
  <% # Clients of this partial must supply the following variables:
2
2
  # thread
3
3
  # user
4
+ # per_page
4
5
  %>
5
6
 
6
7
  <% if thread.is_closed? %>
7
- <p><%= t 'commontator.thread.status.closed_by' %></p>
8
+ <p><%= t 'commontator.thread.status.cannot_post' %></p>
8
9
  <% elsif !user %>
9
10
  <p><%= t 'commontator.require_login' %>.</p>
10
11
  <% else %>
@@ -12,6 +13,7 @@
12
13
 
13
14
  <span id="thread_<%= thread.id %>_new_comment_link_span" class="thread_new_comment_link">
14
15
  <%= link_to t('commontator.comment.actions.new'),
15
- commontator.new_thread_comment_path(thread), :remote => true %>
16
+ commontator.new_thread_comment_path(thread, :per_page => per_page), :remote => true %>
16
17
  </span>
17
18
  <% end %>
19
+
@@ -0,0 +1,19 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # thread
3
+ # user
4
+ # per_page
5
+ %>
6
+
7
+ <% if thread.is_closed? %>
8
+ <p><%= t 'commontator.thread.status.cannot_post' %></p>
9
+ <% elsif !user %>
10
+ <p><%= t 'commontator.require_login' %>.</p>
11
+ <% else %>
12
+ <div id="thread_<%= thread.id %>_new_comment_div" class="thread_new_comment"></div>
13
+
14
+ <span id="thread_<%= thread.id %>_new_comment_link_span" class="thread_new_comment_link">
15
+ <%= link_to t('commontator.comment.actions.new'),
16
+ commontator.new_thread_comment_path(thread, :per_page => @commontator_per_page), :remote => true %>
17
+ </span>
18
+ <% end %>
19
+
@@ -3,6 +3,8 @@
3
3
  # user
4
4
  # page
5
5
  # per_page
6
+ # Optionally, they can also supply the following variable:
7
+ show_all ||= false
6
8
  %>
7
9
 
8
10
  <% can_subscribe = thread.can_subscribe?(user) %>
@@ -20,8 +22,20 @@
20
22
  &nbsp;
21
23
 
22
24
  <% if can_edit %>
23
- <% is_closed = thread.is_closed? %>
24
- <% close_string = is_closed ? 'reopen' : 'close' %>
25
+ <% filter_string = show_all ? 'filter' : 'show_all'
26
+ is_closed = thread.is_closed?
27
+ close_string = is_closed ? 'reopen' : 'close' %>
28
+
29
+ <% if thread.is_filtered? %>
30
+ <%= link_to t("commontator.thread.actions.#{filter_string}"),
31
+ commontator.thread_path(thread, :show_all => (show_all ? nil : true)),
32
+ :id => "thread_#{thread.id.to_s}_#{filter_string}_link",
33
+ :class => "thread_#{filter_string}_link",
34
+ :remote => true %>
35
+
36
+ &nbsp;
37
+ <% end %>
38
+
25
39
  <%= link_to t("commontator.thread.actions.#{close_string}"),
26
40
  commontator.polymorphic_path([close_string, thread]),
27
41
  :confirm => (!is_closed ? t('commontator.thread.actions.confirm_close') : nil),
@@ -34,27 +48,48 @@
34
48
 
35
49
  <span id="thread_<%= thread.id.to_s %>_header_span" class="thread_header">
36
50
  <%= t "commontator.thread.status.#{thread.is_closed? ? 'closed' : 'open'}",
37
- :closer_name => thread.closer.try(:commontator_name) %>
51
+ :closer_name => Commontator.commontator_name(thread.closer) %>
38
52
  </span>
39
53
 
40
54
  <% if thread.config.comment_order == :l %>
41
- <%= render :partial => 'commontator/threads/reply', :locals => {:thread => thread, :user => user} %>
55
+ <%= render :partial => 'commontator/threads/reply',
56
+ :locals => {:thread => thread, :user => user, :per_page => per_page} %>
42
57
  <% end %>
43
58
 
44
59
  <div id="thread_<%= thread.id.to_s %>_comment_list_div" class="thread_comment_list">
45
- <% comments = thread.paginated_comments(page, per_page) %>
60
+ <% comments = show_all ? thread.ordered_comments(true) : thread.paginated_comments(page, per_page) %>
46
61
  <%= render :partial => 'commontator/comments/list',
47
62
  :locals => {:comments => comments,
48
63
  :user => user} %>
49
64
  </div>
50
65
 
51
- <% if thread.will_paginate? %>
66
+ <% if thread.will_paginate? && !show_all %>
52
67
  <div id="thread_<%= thread.id.to_s %>_pagination_div" class="thread_pagination">
53
- <%= will_paginate comments,
54
- :renderer => thread.config.wp_link_renderer_proc.call(thread) %>
68
+ <div id="thread_<%= thread.id.to_s %>_page_entries_info_div" class="thread_page_entries_info">
69
+ <%= page_entries_info comments,
70
+ :params => {:controller => 'commontator/threads',
71
+ :action => 'show',
72
+ :id => thread.id,
73
+ :page => page,
74
+ :per_page => per_page} %>.
75
+ </div>
76
+
77
+ <div id="thread_<%= thread.id.to_s %>_will_paginate_div" class="thread_will_paginate">
78
+ <%= will_paginate comments,
79
+ :renderer => Commontator::LinkRenderer,
80
+ :routes_proxy => commontator,
81
+ :remote => true,
82
+ :params => {:controller => 'commontator/threads',
83
+ :action => 'show',
84
+ :id => thread.id,
85
+ :page => page,
86
+ :per_page => per_page} %>
87
+ </div>
55
88
  </div>
56
89
  <% end %>
57
90
 
58
91
  <% if thread.config.comment_order != :l %>
59
- <%= render :partial => 'commontator/threads/reply', :locals => {:thread => thread, :user => user} %>
92
+ <%= render :partial => 'commontator/threads/reply',
93
+ :locals => {:thread => thread, :user => user, :per_page => per_page} %>
60
94
  <% end %>
95
+
@@ -0,0 +1,95 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # thread
3
+ # user
4
+ # page
5
+ # per_page
6
+ # Optionally, they can also supply the following variable:
7
+ show_all ||= false
8
+ %>
9
+
10
+ <% can_subscribe = thread.can_subscribe?(user) %>
11
+ <% can_edit = thread.can_be_edited_by?(user) %>
12
+
13
+ <span id="thread_<%= thread.id.to_s %>_actions_span" class="thread_actions">
14
+ <% if can_subscribe %>
15
+ <span id="thread_<%= thread.id.to_s %>_subscription_span" class="thread_subscription">
16
+ <%= render :partial => 'commontator/subscriptions/link',
17
+ :locals => {:thread => thread,
18
+ :user => user} %>
19
+ </span>
20
+ <% end %>
21
+
22
+ &nbsp;
23
+
24
+ <% if can_edit %>
25
+ <% filter_string = show_all ? 'filter' : 'show_all'
26
+ is_closed = thread.is_closed?
27
+ close_string = is_closed ? 'reopen' : 'close' %>
28
+
29
+ <% if thread.is_filtered? %>
30
+ <%= link_to t("commontator.thread.actions.#{filter_string}"),
31
+ commontator.thread_path(thread, :show_all => (show_all ? nil : true)),
32
+ :id => "thread_#{thread.id.to_s}_#{filter_string}_link",
33
+ :class => "thread_#{filter_string}_link",
34
+ :remote => true %>
35
+
36
+ &nbsp;
37
+ <% end %>
38
+
39
+ <%= link_to t("commontator.thread.actions.#{close_string}"),
40
+ commontator.polymorphic_path([close_string, thread]),
41
+ :confirm => (!is_closed ? t('commontator.thread.actions.confirm_close') : nil),
42
+ :method => :put,
43
+ :id => "thread_#{thread.id.to_s}_#{close_string}_link",
44
+ :class => "thread_#{close_string}_link",
45
+ :remote => true %>
46
+ <% end %>
47
+ </span>
48
+
49
+ <span id="thread_<%= thread.id.to_s %>_header_span" class="thread_header">
50
+ <%= t "commontator.thread.status.#{thread.is_closed? ? 'closed' : 'open'}",
51
+ :closer_name => Commontator.commontator_name(thread.closer) %>
52
+ </span>
53
+
54
+ <% if thread.config.comment_order == :l %>
55
+ <%= render :partial => 'commontator/threads/reply',
56
+ :locals => {:thread => thread, :user => user, :per_page => per_page} %>
57
+ <% end %>
58
+
59
+ <div id="thread_<%= thread.id.to_s %>_comment_list_div" class="thread_comment_list">
60
+ <% comments = show_all ? thread.ordered_comments(true) : thread.paginated_comments(page, per_page) %>
61
+ <%= render :partial => 'commontator/comments/list',
62
+ :locals => {:comments => comments,
63
+ :user => user} %>
64
+ </div>
65
+
66
+ <% if thread.will_paginate? && !show_all %>
67
+ <div id="thread_<%= thread.id.to_s %>_pagination_div" class="thread_pagination">
68
+ <div id="thread_<%= thread.id.to_s %>_page_entries_info_div" class="thread_page_entries_info">
69
+ <%= page_entries_info comments,
70
+ :params => {:controller => 'commontator/threads',
71
+ :action => 'show',
72
+ :id => thread.id,
73
+ :page => page,
74
+ :per_page => per_page} %>
75
+ </div>
76
+
77
+ <div id="thread_<%= thread.id.to_s %>_will_paginate_div" class="thread_will_paginate">
78
+ <%= will_paginate comments,
79
+ :renderer => Commontator::LinkRenderer,
80
+ :routes_proxy => commontator,
81
+ :remote => true,
82
+ :params => {:controller => 'commontator/threads',
83
+ :action => 'show',
84
+ :id => thread.id,
85
+ :page => page,
86
+ :per_page => per_page} %>
87
+ </div>
88
+ </div>
89
+ <% end %>
90
+
91
+ <% if thread.config.comment_order != :l %>
92
+ <%= render :partial => 'commontator/threads/reply',
93
+ :locals => {:thread => thread, :user => user, :per_page => per_page} %>
94
+ <% end %>
95
+
@@ -0,0 +1,19 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # thread
3
+ # user
4
+ # page
5
+ # per_page
6
+ # Optionally, they can also supply the following variable:
7
+ show_all ||= false
8
+ %>
9
+
10
+ $("#thread_<%= thread.id %>_div").html(
11
+ "<%= escape_javascript(
12
+ render :partial => 'commontator/threads/show',
13
+ :formats => [:html],
14
+ :locals => {:thread => thread,
15
+ :user => user,
16
+ :page => page,
17
+ :per_page => per_page,
18
+ :show_all => show_all}) %>");
19
+
@@ -1,9 +1,9 @@
1
- $("#thread_<%= @thread.id %>_div").html(
2
- "<%= escape_javascript(
3
- render :partial => 'show',
1
+ <%= render :partial => 'show',
4
2
  :locals => {:thread => @thread,
5
3
  :user => @user,
6
4
  :page => @commontator_page,
7
- :per_page => @commontator_per_page}) %>");
5
+ :per_page => @commontator_per_page,
6
+ :show_all => @show_all} %>
8
7
 
9
8
  <%= javascript_proc %>
9
+
@@ -1,123 +1,175 @@
1
1
  # Change the settings below to suit your needs
2
2
  # All settings are initially set to their default values
3
3
 
4
- # Note: Do not "return" from procs
5
- # Use "next" instead
4
+ # Note: Do not "return" from a Proc, use "next" instead if necessary
5
+ # "return" in a lambda is OK
6
6
  Commontator.configure do |config|
7
7
  # Engine Configuration
8
8
 
9
- # Proc that is passed the current controller as argument
10
- # Returns the current user
9
+ # current_user_proc
10
+ # Type: Proc
11
+ # Arguments: the current controller (ActionController::Base)
12
+ # Returns: the current user (acts_as_commontator)
13
+ # The default works for Devise and similar authentication plugins
11
14
  # Default: lambda { |controller| controller.current_user }
12
15
  config.current_user_proc = lambda { |controller| controller.current_user }
13
16
 
14
- # Proc called with the current view_context as argument
15
- # Returns a string to be appended to all JavaScript responses from Commontator
17
+ # javascript_proc
18
+ # Type: Proc
19
+ # Arguments: a view (ActionView::Base)
20
+ # Returns: a String that is appended to Commontator JS views
16
21
  # Can be used, for example, to display/clear Rails error messages
17
- # Objects visible in view templates can be accessed through
18
- # the view_context object (for example, view_context.flash)
19
- # However, the view_context does not include the main application's helpers
20
- # Default: lambda { |view_context| '$("#error_explanation").remove();' }
21
- config.javascript_proc = lambda { |view_context|
22
+ # Objects visible in view templates can be accessed
23
+ # through the view object (for example, view.flash)
24
+ # However, the view does not include the main application's helpers
25
+ # Default: lambda { |view| '$("#error_explanation").remove();' }
26
+ config.javascript_proc = lambda { |view|
22
27
  '$("#error_explanation").remove();' }
23
28
 
24
29
 
25
30
 
26
31
  # User (acts_as_commontator) Configuration
27
32
 
28
- # Proc called with a user as argument
29
- # Returns the user's display name
30
- # Important: change this to return actual names or usernames
31
- # Default: lambda { |user| t('commontator.anonymous') } (all users are Anonymous)
33
+ # user_name_proc
34
+ # Type: Proc
35
+ # Arguments: a user (acts_as_commontator)
36
+ # Returns: the user's name (String)
37
+ # Default: lambda { |user| I18n.t('commontator.anonymous') } (all users are anonymous)
32
38
  config.user_name_proc = lambda { |user| I18n.t('commontator.anonymous') }
33
39
 
34
- # Proc called with a user and the current view_context as arguments
35
- # Returns an HTML image tag containing the user's avatar image
40
+ # user_link_proc
41
+ # Type: Proc
42
+ # Arguments: a user (acts_as_commontator),
43
+ # the app_routes (ActionDispatch::Routing::RoutesProxy)
44
+ # Returns: a path to the user's `show` page (String)
45
+ # If anything non-blank is returned, the user's name in comments
46
+ # comments will become a hyperlink pointing to this path
47
+ # The main application's routes can be accessed through the app_routes object
48
+ # Default: lambda { |user, app_routes| '' } (no link)
49
+ config.user_link_proc = lambda { |user, app_routes| '' }
50
+
51
+ # user_avatar_proc
52
+ # Type: Proc
53
+ # Arguments: a user (acts_as_commontator), a view (ActionView::Base)
54
+ # Returns: a String containing a HTML <img> tag pointing to the user's avatar image
36
55
  # The commontator_gravatar_image_tag helper takes a user object,
37
- # a border size, and an options hash for gravatar
56
+ # a border size and an options hash for Gravatar, and produces a Gravatar image tag
38
57
  # See available options at http://en.gravatar.com/site/implement/images/)
39
- # Default: lambda { |user, view_context|
40
- # view_context.commontator_gravatar_image_tag(
58
+ # Note: Gravatar has several security implications for your users
59
+ # It makes your users trackable across different sites and
60
+ # allows de-anonymization attacks against their email addresses
61
+ # If you absolutely want to keep users' email addresses or identities secret,
62
+ # do not use Gravatar or similar services
63
+ # Default: lambda { |user, view|
64
+ # view.commontator_gravatar_image_tag(
41
65
  # user, 1, :s => 60, :d => 'mm') }
42
- config.user_avatar_proc = lambda { |user, view_context|
43
- view_context.commontator_gravatar_image_tag(
66
+ config.user_avatar_proc = lambda { |user, view|
67
+ view.commontator_gravatar_image_tag(
44
68
  user, 1, :s => 60, :d => 'mm') }
45
69
 
46
- # Proc called with a user and a mailer object as arguments
47
- # If the mailer argument is nil, the email is for internal use only and
48
- # this method should always return the user's email, no matter what
49
- # If the mailer argument is not nil, then an actual email will be sent to the
50
- # address returned; you can prevent it from being sent by checking the
51
- # arguments and returning a blank string, if appropriate
52
- # Default: lambda { |user, mailer| user.email }
53
- config.user_email_proc = lambda { |user, mailer| user.email }
54
-
55
- # Proc called with a user and the current view_context as arguments
56
- # Returns a link to the user's page
57
- # If anything non-blank is returned, the user's name in comments
58
- # will become a hyperlink pointing to this
59
- # The main application's routes can be accessed through the main_app object
60
- # Default: lambda { |user, main_app| '' } (no link)
61
- config.user_link_proc = lambda { |user, main_app| '' }
70
+ # user_email_proc
71
+ # Type: Proc
72
+ # Arguments: a user (acts_as_commontator), a mailer (ActionMailer::Base)
73
+ # Returns: the user's email address (String)
74
+ # The default works for Devise's defaults
75
+ # If the mailer argument is nil, Commontator intends to hash the email and send the hash
76
+ # to Gravatar, so you should always return the user's email address (if using Gravatar)
77
+ # If the mailer argument is not nil, then Commontator intends to send an email to
78
+ # the address returned; you can prevent it from being sent by returning a blank String
79
+ # Default: lambda { |user, mailer| user.try(:email) || '' }
80
+ config.user_email_proc = lambda { |user, mailer| user.try(:email) || '' }
62
81
 
63
82
 
64
83
 
65
84
  # Thread/Commontable (acts_as_commontable) Configuration
66
85
 
67
- # Proc called with a mailer object as argument
68
- # Returns the address emails are sent "from"
69
- # Important: Change this to at least match your domain name
70
- # Default: lambda { |mailer| 'no-reply@example.com' }
71
- config.email_from_proc = lambda { |mailer| 'no-reply@example.com' }
72
-
73
- # Proc called with a thread and a user as arguments
74
- # Returns true iif the user should be allowed to read that thread
75
- # Note: can be called with a user object that is false or nil if not logged in
86
+ # comment_filter
87
+ # Type: Arel node (Arel::Nodes::Node) or nil
88
+ # Arel that filters visible comments
89
+ # If specified, visible comments will be filtered according to this Arel node
90
+ # A value of nil will cause no filtering to be done
91
+ # Moderators can manually override this filter for themselves
92
+ # Example: Commontator::Comment.arel_table[:deleted_at].eq(nil) (hides deleted comments)
93
+ # This is not recommended, as it can cause confusion over deleted comments
94
+ # If using pagination, it can also cause comments to change pages
95
+ # Default: nil (no filtering - all comments are visible)
96
+ config.comment_filter = nil
97
+
98
+ # thread_read_proc
99
+ # Type: Proc
100
+ # Arguments: a thread (Commontator::Thread), a user (acts_as_commontator)
101
+ # Returns: a Boolean, true iif the user should be allowed to read that thread
102
+ # Note: can be called with a user object that is nil (if they are not logged in)
76
103
  # Default: lambda { |thread, user| true } (anyone can read any thread)
77
104
  config.thread_read_proc = lambda { |thread, user| true }
78
105
 
79
- # Proc called with a thread and a user as arguments
80
- # Returns true iif the user is a moderator for that thread
81
- # Moderators can delete other users' comments and close threads
82
- # If you want global moderators, make this proc true for them
83
- # Note: moderators must "acts_as_commontator" too (like other users)
106
+ # thread_moderator_proc
107
+ # Type: Proc
108
+ # Arguments: a thread (Commontator::Thread), a user (acts_as_commontator)
109
+ # Returns: a Boolean, true iif the user is a moderator for that thread
110
+ # If you want global moderators, make this proc true for them regardless of thread
84
111
  # Default: lambda { |thread, user| false } (no moderators)
85
112
  config.thread_moderator_proc = lambda { |thread, user| false }
86
113
 
87
- # Whether users can subscribe to threads to receive activity email notifications
114
+ # comment_editing
115
+ # Type: Symbol
116
+ # Whether users can edit their own comments
88
117
  # Valid options:
89
- # :n (no subscriptions)
90
- # :a (automatically subscribe when you comment; cannot do it manually)
91
- # :m (manual subscriptions only)
92
- # :b (both automatic, when commenting, and manual)
93
- # Default: :m
94
- config.thread_subscription = :m
118
+ # :a (always)
119
+ # :l (only if it's the latest comment)
120
+ # :n (never)
121
+ # Default: :l
122
+ config.comment_editing = :l
95
123
 
124
+ # comment_deletion
125
+ # Type: Symbol
126
+ # Whether users can delete their own comments
127
+ # Valid options:
128
+ # :a (always)
129
+ # :l (only if it's the latest comment)
130
+ # :n (never)
131
+ # Note: For moderators, see the next option
132
+ # Default: :l
133
+ config.comment_deletion = :l
134
+
135
+ # moderator_permissions
136
+ # Type: Symbol
137
+ # What permissions moderators have
138
+ # Valid options:
139
+ # :e (delete and edit comments and close threads)
140
+ # :d (delete comments and close threads)
141
+ # :c (close threads only)
142
+ # Default: :d
143
+ config.moderator_permissions = :d
144
+
145
+ # comment_voting
146
+ # Type: Symbol
96
147
  # Whether users can vote on other users' comments
97
148
  # Valid options:
98
- # :n (no voting)
99
- # :l (likes - requires acts_as_votable gem)
149
+ # :n (no voting)
150
+ # :l (likes - requires acts_as_votable gem)
100
151
  # :ld (likes/dislikes - requires acts_as_votable gem)
101
152
  # Not yet implemented:
102
- # :s (star ratings)
103
- # :r (reputation system)
104
- # Note: you can format how the votes are displayed by modifying the locale file
153
+ # :s (star ratings)
154
+ # :r (reputation system)
105
155
  # Default: :n
106
156
  config.comment_voting = :n
107
157
 
108
- # This proc is called with the value of config.comment_voting as an argument,
109
- # as well as pos and neg
110
- # pos is the number of likes or the rating or the reputation
158
+ # vote_count_proc
159
+ # Type: Proc
160
+ # Arguments: a thread (Commontator::Thread), pos (Fixnum), neg (Fixnum)
161
+ # Returns: vote count to be displayed (String)
162
+ # pos is the number of likes, or the rating, or the reputation
111
163
  # neg is the number of dislikes, if applicable, or 0 otherwise
112
- # Returns the text to be displayed in between the voting buttons
113
- # Default: lambda { |comment_voting, pos, neg| "%+d" % (pos - neg) }
114
- config.voting_text_proc = lambda { |comment_voting, pos, neg|
115
- "%+d" % (pos - neg) }
164
+ # Default: lambda { |thread, pos, neg| "%+d" % (pos - neg) }
165
+ config.vote_count_proc = lambda { |thread, pos, neg| "%+d" % (pos - neg) }
116
166
 
167
+ # comment_order
168
+ # Type: Symbol
117
169
  # What order to use for comments
118
170
  # Valid options:
119
- # :e (earliest comment first)
120
- # :l (latest comment first)
171
+ # :e (earliest comment first)
172
+ # :l (latest comment first)
121
173
  # :ve (highest voted first; earliest first if tied)
122
174
  # :vl (highest voted first; latest first if tied)
123
175
  # Notes:
@@ -130,72 +182,57 @@ Commontator.configure do |config|
130
182
  # Default: :e
131
183
  config.comment_order = :e
132
184
 
185
+ # comments_per_page
186
+ # Type: Fixnum or nil
133
187
  # Number of comments to display in each page
134
188
  # Set to nil to disable pagination
135
189
  # Any other value requires the will_paginate gem
136
190
  # Default: nil (no pagination)
137
191
  config.comments_per_page = nil
138
192
 
139
- # Proc called with a thread as argument
140
- # Returns a LinkRenderer to be used with will_paginate for that thread,
141
- # assuming pagination is enabled
142
- # Commontator supplies its own RemoteLinkRenderer,
143
- # which is exactly like will_paginate's default, except it returns remote links
144
- # For more information, see:
145
- # https://github.com/mislav/will_paginate/wiki/Link-renderer
146
- # Default: lambda { |thread| Commontator::RemoteLinkRenderer }
147
- config.wp_link_renderer_proc = lambda { |thread|
148
- Commontator::RemoteLinkRenderer }
149
-
150
- # Whether users can edit their own comments
151
- # Valid options:
152
- # :a (always)
153
- # :l (only if it's the latest comment)
154
- # :n (never)
155
- # Default: :l
156
- config.comment_editing = :l
157
-
158
- # Whether users can delete their own comments
193
+ # thread_subscription
194
+ # Type: Symbol
195
+ # Whether users can subscribe to threads to receive activity email notifications
159
196
  # Valid options:
160
- # :a (always)
161
- # :l (only if it's the latest comment)
162
- # :n (never)
163
- # Note: moderators can always delete any comment
164
- # Default: :l
165
- config.comment_deletion = :l
166
-
167
- # Whether moderators can edit other users' comments
168
- # Default: false
169
- config.moderators_can_edit_comments = false
170
-
171
- # Whether to hide deleted comments completely or show a placeholder message
172
- # that indicates when a comment was deleted in a thread
173
- # (moderators will always see the placeholder;
174
- # the content of the comment will be hidden from all users with either option)
175
- # Default: false (show placeholder message)
176
- config.hide_deleted_comments = false
177
-
178
- # If set to true, threads closed by moderators will be invisible to normal users
179
- # (moderators can still see them)
180
- # Default: false (normal users can still read closed threads)
181
- config.hide_closed_threads = false
182
-
183
- # Proc called with the commontable object as argument
184
- # Returns the name by which the commontable object will be called in email messages
185
- # If you have multiple commontable models, you may want to pass this
186
- # configuration value as an argument to acts_as_commontable in each one
187
- # Default: lambda { |commontable|
188
- # "#{commontable.class.name} ##{commontable.id}" }
189
- config.commontable_name_proc = lambda { |commontable|
190
- "#{commontable.class.name} ##{commontable.id}" }
191
-
192
- # Proc called with main_app and a commontable object as arguments
193
- # Return the url that contains the commontable's thread
197
+ # :n (no subscriptions)
198
+ # :a (automatically subscribe when you comment; cannot do it manually)
199
+ # :m (manual subscriptions only)
200
+ # :b (both automatic, when commenting, and manual)
201
+ # Default: :n
202
+ config.thread_subscription = :n
203
+
204
+ # email_from_proc
205
+ # Type: Proc
206
+ # Arguments: a thread (Commontator::Thread)
207
+ # Returns: the address emails are sent "from" (String)
208
+ # Important: If using subscriptions, change this to at least match your domain name
209
+ # Default: lambda { |thread|
210
+ # "no-reply@#{Rails.application.class.parent.to_s.downcase}.com" }
211
+ config.email_from_proc = lambda { |thread|
212
+ "no-reply@#{Rails.application.class.parent.to_s.downcase}.com" }
213
+
214
+ # commontable_name_proc
215
+ # Type: Proc
216
+ # Arguments: a thread (Commontator::Thread)
217
+ # Returns: a name that refers to the commontable object (String)
218
+ # If you have multiple commontable models, you can also pass this
219
+ # configuration value as an argument to acts_as_commontable for each one
220
+ # Default: lambda { |thread|
221
+ # "#{thread.commontable.class.name} ##{thread.commontable.id}" }
222
+ config.commontable_name_proc = lambda { |thread|
223
+ "#{thread.commontable.class.name} ##{thread.commontable.id}" }
224
+
225
+ # commontable_url_proc
226
+ # Type: Proc
227
+ # Arguments: a thread (Commontator::Thread),
228
+ # the app_routes (ActionDispatch::Routing::RoutesProxy)
229
+ # Returns: a String containing the url of the view that displays the given thread
194
230
  # This usually is the commontable's "show" page
195
- # The main application's routes can be accessed through the main_app object
196
- # Default: lambda { |commontable, main_app|
197
- # main_app.polymorphic_url(commontable) }
231
+ # The main application's routes can be accessed through the app_routes object
232
+ # Default: lambda { |commontable, app_routes|
233
+ # app_routes.polymorphic_url(commontable) }
198
234
  # (defaults to the commontable's show url)
199
- config.commontable_url_proc = lambda { |commontable, main_app|
200
- main_app.polymorphic_url(commontable) }
235
+ config.commontable_url_proc = lambda { |thread, app_routes|
236
+ app_routes.polymorphic_url(thread.commontable) }
201
237
  end
238
+