commontator 0.2.4 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/app/assets/stylesheets/commontator/threads.css +4 -0
  2. data/app/assets/stylesheets/commontator/threads.css~ +1 -1
  3. data/app/controllers/commontator/application_controller.rb +5 -0
  4. data/app/controllers/commontator/application_controller.rb~ +8 -1
  5. data/app/controllers/commontator/comments_controller.rb +24 -31
  6. data/app/controllers/commontator/comments_controller.rb~ +25 -32
  7. data/app/controllers/commontator/subscriptions_controller.rb +8 -18
  8. data/app/controllers/commontator/subscriptions_controller.rb~ +10 -16
  9. data/app/controllers/commontator/threads_controller.rb +3 -5
  10. data/app/controllers/commontator/threads_controller.rb~ +3 -6
  11. data/app/helpers/commontator/application_helper.rb +2 -6
  12. data/app/helpers/commontator/application_helper.rb~ +4 -4
  13. data/app/helpers/commontator/commontator_helper.rb +2 -2
  14. data/app/helpers/commontator/commontator_helper.rb~ +2 -2
  15. data/app/helpers/commontator/threads_helper.rb +1 -1
  16. data/app/helpers/commontator/threads_helper.rb~ +5 -12
  17. data/app/mailers/commontator/subscriptions_mailer.rb +15 -11
  18. data/app/mailers/commontator/subscriptions_mailer.rb~ +15 -12
  19. data/app/models/commontator/comment.rb +2 -2
  20. data/app/models/commontator/thread.rb +11 -11
  21. data/app/models/commontator/thread.rb~ +7 -9
  22. data/app/views/commontator/comments/_actions.html.erb +13 -16
  23. data/app/views/commontator/comments/_actions.html.erb~ +13 -17
  24. data/app/views/commontator/comments/create.js.erb +1 -1
  25. data/app/views/commontator/comments/create.js.erb~ +2 -2
  26. data/app/views/commontator/comments/delete.js.erb +1 -1
  27. data/app/views/commontator/comments/delete.js.erb~ +2 -2
  28. data/app/views/commontator/comments/edit.js.erb +1 -1
  29. data/app/views/commontator/comments/edit.js.erb~ +2 -2
  30. data/app/views/commontator/comments/new.js.erb +1 -1
  31. data/app/views/commontator/comments/new.js.erb~ +2 -2
  32. data/app/views/commontator/comments/update.js.erb +1 -1
  33. data/app/views/commontator/comments/update.js.erb~ +2 -2
  34. data/app/views/commontator/comments/vote.js.erb +1 -1
  35. data/app/views/commontator/comments/vote.js.erb~ +2 -2
  36. data/app/views/commontator/{commontator/_thread.html.erb~ → shared/_thread_link.html.erb} +1 -3
  37. data/app/views/commontator/subscriptions/{index.html.erb → _index.html.erb~} +0 -0
  38. data/app/views/commontator/subscriptions/_link.html.erb +15 -0
  39. data/app/views/commontator/subscriptions/_link.html.erb~ +15 -0
  40. data/app/views/commontator/subscriptions/_subscription_link.html.erb~ +8 -7
  41. data/app/views/commontator/subscriptions/create.js.erb~ +4 -2
  42. data/app/views/commontator/subscriptions/subscribe.js.erb +5 -0
  43. data/app/views/commontator/subscriptions/subscribe.js.erb~ +5 -0
  44. data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb +4 -12
  45. data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb~ +4 -12
  46. data/app/views/commontator/threads/_actions.html.erb~ +28 -0
  47. data/app/views/commontator/{commontator/_thread.html.erb → threads/_link.html.erb~} +1 -1
  48. data/app/views/commontator/threads/_show.html.erb +30 -2
  49. data/app/views/commontator/threads/_show.html.erb~ +31 -3
  50. data/app/views/commontator/threads/close.js.erb~ +5 -0
  51. data/app/views/commontator/threads/{show.html.erb → show.html.erb~} +0 -0
  52. data/app/views/commontator/threads/show.js.erb +1 -1
  53. data/app/views/commontator/threads/show.js.erb~ +6 -0
  54. data/config/initializers/commontator.rb +17 -11
  55. data/config/initializers/commontator.rb~ +16 -11
  56. data/config/routes.rb +2 -4
  57. data/config/routes.rb~ +4 -2
  58. data/lib/commontator.rb +1 -1
  59. data/lib/commontator.rb~ +2 -2
  60. data/lib/commontator/version.rb +1 -1
  61. data/lib/commontator/version.rb~ +1 -1
  62. data/test/dummy/config/initializers/commontator.rb +23 -12
  63. data/test/dummy/config/initializers/commontator.rb~ +174 -0
  64. data/test/dummy/log/development.log +6 -0
  65. metadata +15 -11
  66. data/app/views/commontator/comments/edit.html.erb +0 -6
  67. data/app/views/commontator/comments/new.html.erb +0 -8
  68. data/app/views/commontator/subscriptions/_subscription_link.html.erb +0 -12
  69. data/app/views/commontator/subscriptions/create.js.erb +0 -5
  70. data/app/views/commontator/subscriptions/destroy.js.erb +0 -5
@@ -1,3 +1,7 @@
1
+ .thread_actions {
2
+ float: right;
3
+ }
4
+
1
5
  .thread_header {
2
6
  font-size: 16px;
3
7
  font-weight: bold;
@@ -1,6 +1,6 @@
1
1
  .thread_header {
2
2
  font-size: 16px;
3
- font-weight: normal;
3
+ font-weight: bold;
4
4
  font-style: normal;
5
5
  }
6
6
 
@@ -13,6 +13,11 @@ module Commontator
13
13
  @thread = params[:thread_id].blank? ? \
14
14
  Commontator::Thread.find(params[:id]) : \
15
15
  Commontator::Thread.find(params[:thread_id])
16
+ get_commontable_url
17
+ end
18
+
19
+ def get_commontable_url
20
+ @commontable_url = @thread.config.commontable_url_proc.call(main_app, @thread.commontable)
16
21
  end
17
22
  end
18
23
  end
@@ -10,7 +10,14 @@ module Commontator
10
10
  end
11
11
 
12
12
  def get_thread
13
- @thread = params[:thread_id].blank? ? Commontator::Thread.find(params[:thread_id]) : Commontator::Thread.find(params[:id])
13
+ @thread = params[:thread_id].blank? ? \
14
+ Commontator::Thread.find(params[:id]) : \
15
+ Commontator::Thread.find(params[:thread_id])
16
+ get_commontable_url
17
+ end
18
+
19
+ def get_commontable_url
20
+ @thread.config.commontable_url_proc.call(main_app, @thread.commontable)
14
21
  end
15
22
  end
16
23
  end
@@ -1,7 +1,5 @@
1
1
  module Commontator
2
2
  class CommentsController < ApplicationController
3
- include ThreadsHelper
4
-
5
3
  before_filter :get_thread, :only => [:new, :create]
6
4
  before_filter :get_comment_and_thread, :except => [:new, :create]
7
5
 
@@ -14,7 +12,7 @@ module Commontator
14
12
  raise SecurityTransgression unless @comment.can_be_created_by?(@commontator)
15
13
 
16
14
  respond_to do |format|
17
- format.html
15
+ format.html { redirect_to @commontable_url }
18
16
  format.js
19
17
  end
20
18
 
@@ -27,21 +25,19 @@ module Commontator
27
25
  @comment.commontator = @commontator
28
26
 
29
27
  raise SecurityTransgression unless @comment.can_be_created_by?(@commontator)
28
+
29
+ if @comment.save
30
+ @thread.subscribe(@commontator) if @thread.config.auto_subscribe_on_comment
31
+ @thread.mark_as_unread_except_for(@commontator)
32
+ SubscriptionsMailer.comment_created_email(@comment, @commontable_url)
33
+ @thread.comment_created_callback(@commontator, @comment)
34
+ else
35
+ @errors = @comment.errors
36
+ end
30
37
 
31
38
  respond_to do |format|
32
- if @comment.save
33
- @thread.subscribe(@commontator) if @thread.config.auto_subscribe_on_comment
34
- @thread.mark_as_unread_except_for(@commontator)
35
- SubscriptionsMailer.comment_created_email(@comment)
36
- @thread.comment_created_callback(@commontator, @comment)
37
- flash[:notice] = @thread.config.comment_name + ' ' + @thread.config.comment_create_verb_past
38
- format.html { redirect_to @thread }
39
- format.js
40
- else
41
- @errors = @comment.errors
42
- format.html { render :action => 'new' }
43
- format.js
44
- end
39
+ format.html { redirect_to @commontable_url }
40
+ format.js
45
41
  end
46
42
  end
47
43
 
@@ -50,7 +46,7 @@ module Commontator
50
46
  raise SecurityTransgression unless @comment.can_be_edited_by?(@commontator)
51
47
 
52
48
  respond_to do |format|
53
- format.html
49
+ format.html { redirect_to @commontable_url }
54
50
  format.js
55
51
  end
56
52
  end
@@ -58,17 +54,13 @@ module Commontator
58
54
  # PUT /comments/1
59
55
  def update
60
56
  raise SecurityTransgression unless @comment.can_be_edited_by?(@commontator)
57
+
58
+ @thread.comment_edited_callback(@commontator, @comment) \
59
+ if @comment.update_attributes(params[:comment])
61
60
 
62
61
  respond_to do |format|
63
- if @comment.update_attributes(params[:comment])
64
- flash[:notice] = @thread.config.comment_name + ' updated'
65
- @thread.comment_edited_callback(@commontator, @comment)
66
- format.html { redirect_to @thread }
67
- format.js
68
- else
69
- format.html { render :action => "edit" }
70
- format.js
71
- end
62
+ format.html { redirect_to @commontable_url }
63
+ format.js
72
64
  end
73
65
  end
74
66
 
@@ -80,7 +72,7 @@ module Commontator
80
72
  @thread.comment_deleted_callback(@commontator, @comment)
81
73
 
82
74
  respond_to do |format|
83
- format.html { redirect_to @thread }
75
+ format.html { redirect_to @commontable_url }
84
76
  format.js { render :delete }
85
77
  end
86
78
  end
@@ -92,7 +84,7 @@ module Commontator
92
84
  @comment.undelete
93
85
 
94
86
  respond_to do |format|
95
- format.html { redirect_to @thread }
87
+ format.html { redirect_to @commontable_url }
96
88
  format.js { render :delete }
97
89
  end
98
90
  end
@@ -104,7 +96,7 @@ module Commontator
104
96
  @comment.upvote_from @commontator
105
97
 
106
98
  respond_to do |format|
107
- format.html { redirect_to @thread }
99
+ format.html { redirect_to @commontable_url }
108
100
  format.js { render :vote }
109
101
  end
110
102
  end
@@ -116,7 +108,7 @@ module Commontator
116
108
  @comment.downvote_from @commontator
117
109
 
118
110
  respond_to do |format|
119
- format.html { redirect_to @thread }
111
+ format.html { redirect_to @commontable_url }
120
112
  format.js { render :vote }
121
113
  end
122
114
  end
@@ -128,7 +120,7 @@ module Commontator
128
120
  @comment.unvote :voter => @commontator
129
121
 
130
122
  respond_to do |format|
131
- format.html { redirect_to @thread }
123
+ format.html { redirect_to @commontable_url }
132
124
  format.js { render :vote }
133
125
  end
134
126
  end
@@ -138,6 +130,7 @@ module Commontator
138
130
  def get_comment_and_thread
139
131
  @comment = Comment.find(params[:id])
140
132
  @thread = @comment.thread
133
+ get_commontable_url
141
134
  end
142
135
  end
143
136
  end
@@ -1,7 +1,5 @@
1
1
  module Commontator
2
2
  class CommentsController < ApplicationController
3
- include ThreadsHelper
4
-
5
3
  before_filter :get_thread, :only => [:new, :create]
6
4
  before_filter :get_comment_and_thread, :except => [:new, :create]
7
5
 
@@ -14,7 +12,7 @@ module Commontator
14
12
  raise SecurityTransgression unless @comment.can_be_created_by?(@commontator)
15
13
 
16
14
  respond_to do |format|
17
- format.html
15
+ format.html { redirect_to @commontable_url }
18
16
  format.js
19
17
  end
20
18
 
@@ -27,21 +25,19 @@ module Commontator
27
25
  @comment.commontator = @commontator
28
26
 
29
27
  raise SecurityTransgression unless @comment.can_be_created_by?(@commontator)
28
+
29
+ if @comment.save
30
+ @thread.subscribe(@commontator) if @thread.config.auto_subscribe_on_comment
31
+ @thread.mark_as_unread_except_for(@commontator)
32
+ SubscriptionsMailer.comment_created_email(@comment)
33
+ @thread.comment_created_callback(@commontator, @comment)
34
+ else
35
+ @errors = @comment.errors
36
+ end
30
37
 
31
38
  respond_to do |format|
32
- if @comment.save
33
- @thread.subscribe(@commontator) if @thread.config.auto_subscribe_on_comment
34
- @thread.mark_as_unread_except_for(@commontator)
35
- SubscriptionsMailer.comment_created_email(@comment)
36
- @thread.comment_created_callback(@commontator, @comment)
37
- flash[:notice] = @thread.config.comment_name + ' ' + @thread.config.comment_create_verb_past
38
- format.html { redirect_to @thread }
39
- format.js
40
- else
41
- @errors = @comment.errors
42
- format.html { render :action => 'new' }
43
- format.js
44
- end
39
+ format.html { redirect_to @commontable_url }
40
+ format.js
45
41
  end
46
42
  end
47
43
 
@@ -50,7 +46,7 @@ module Commontator
50
46
  raise SecurityTransgression unless @comment.can_be_edited_by?(@commontator)
51
47
 
52
48
  respond_to do |format|
53
- format.html
49
+ format.html { redirect_to @commontable_url }
54
50
  format.js
55
51
  end
56
52
  end
@@ -58,17 +54,13 @@ module Commontator
58
54
  # PUT /comments/1
59
55
  def update
60
56
  raise SecurityTransgression unless @comment.can_be_edited_by?(@commontator)
57
+
58
+ @thread.comment_edited_callback(@commontator, @comment) \
59
+ if @comment.update_attributes(params[:comment])
61
60
 
62
61
  respond_to do |format|
63
- if @comment.update_attributes(params[:comment])
64
- flash[:notice] = @thread.config.comment_name + ' updated'
65
- @thread.comment_edited_callback(@commontator, @comment)
66
- format.html { redirect_to @thread }
67
- format.js
68
- else
69
- format.html { render :action => "edit" }
70
- format.js
71
- end
62
+ format.html { redirect_to @commontable_url }
63
+ format.js
72
64
  end
73
65
  end
74
66
 
@@ -80,7 +72,7 @@ module Commontator
80
72
  @thread.comment_deleted_callback(@commontator, @comment)
81
73
 
82
74
  respond_to do |format|
83
- format.html { redirect_to @thread }
75
+ format.html { redirect_to @commontable_url }
84
76
  format.js { render :delete }
85
77
  end
86
78
  end
@@ -92,8 +84,8 @@ module Commontator
92
84
  @comment.undelete
93
85
 
94
86
  respond_to do |format|
95
- format.html { redirect_to @thread }
96
- format.js { render :update }
87
+ format.html { redirect_to @commontable_url }
88
+ format.js { render :delete }
97
89
  end
98
90
  end
99
91
 
@@ -104,7 +96,7 @@ module Commontator
104
96
  @comment.upvote_from @commontator
105
97
 
106
98
  respond_to do |format|
107
- format.html { redirect_to @thread }
99
+ format.html { redirect_to @commontable_url }
108
100
  format.js { render :vote }
109
101
  end
110
102
  end
@@ -116,7 +108,7 @@ module Commontator
116
108
  @comment.downvote_from @commontator
117
109
 
118
110
  respond_to do |format|
119
- format.html { redirect_to @thread }
111
+ format.html { redirect_to @commontable_url }
120
112
  format.js { render :vote }
121
113
  end
122
114
  end
@@ -128,7 +120,7 @@ module Commontator
128
120
  @comment.unvote :voter => @commontator
129
121
 
130
122
  respond_to do |format|
131
- format.html { redirect_to @thread }
123
+ format.html { redirect_to @commontable_url }
132
124
  format.js { render :vote }
133
125
  end
134
126
  end
@@ -138,6 +130,7 @@ module Commontator
138
130
  def get_comment_and_thread
139
131
  @comment = Comment.find(params[:id])
140
132
  @thread = @comment.thread
133
+ get_commontable_url
141
134
  end
142
135
  end
143
136
  end
@@ -1,26 +1,17 @@
1
1
  module Commontator
2
2
  class SubscriptionsController < ApplicationController
3
- include ThreadsHelper
4
-
5
3
  before_filter :get_thread, :except => :index
6
4
 
7
- # GET /subscriptions
8
- def index
9
- @threads = Subscription.find_all_by_subscriber_id(@commontator.id)\
10
- .collect { |cts| cts.thread }
11
- end
12
-
13
5
  # POST /1/subscribe
14
6
  def create
15
7
  raise SecurityTransgression unless @thread.can_subscribe?(@commontator)
16
8
 
17
- if !@thread.subscribe(@commontator)
18
- flash[:alert] = "You are already subscribed to this " + commontable_name(@thread)
19
- end
9
+ @thread.errors.add(:base, "You are already subscribed to this thread") \
10
+ unless @thread.subscribe(@commontator)
20
11
 
21
12
  respond_to do |format|
22
- format.html { redirect_to @thread }
23
- format.js
13
+ format.html { redirect_to @commontable_url }
14
+ format.js { render :subscribe }
24
15
  end
25
16
 
26
17
  end
@@ -29,13 +20,12 @@ module Commontator
29
20
  def destroy
30
21
  raise SecurityTransgression unless @thread.can_subscribe?(@commontator)
31
22
 
32
- if !@thread.unsubscribe(@commontator)
33
- flash[:alert] = "You are not subscribed to this " + commontable_name(@thread)
34
- end
23
+ @thread.errors.add(:base, "You are not subscribed to this thread") \
24
+ unless @thread.unsubscribe(@commontator)
35
25
 
36
26
  respond_to do |format|
37
- format.html { redirect_to @thread }
38
- format.js
27
+ format.html { redirect_to @commontable_url }
28
+ format.js { render :subscribe }
39
29
  end
40
30
  end
41
31
  end
@@ -1,24 +1,19 @@
1
1
  module Commontator
2
2
  class SubscriptionsController < ApplicationController
3
+ helper ThreadsHelper
4
+
3
5
  before_filter :get_thread, :except => :index
4
6
 
5
- # GET /subscriptions
6
- def index
7
- @threads = Subscription.find_all_by_subscriber_id(@commontator.id)\
8
- .collect { |cts| cts.thread }
9
- end
10
-
11
7
  # POST /1/subscribe
12
8
  def create
13
9
  raise SecurityTransgression unless @thread.can_subscribe?(@commontator)
14
10
 
15
- if !@thread.subscribe(@commontator)
16
- flash[:alert] = "You are already subscribed to this " + commontable_name(@thread)
17
- end
11
+ @thread.errors.add(:base, "You are already subscribed to this thread") \
12
+ unless @thread.subscribe(@commontator)
18
13
 
19
14
  respond_to do |format|
20
- format.html { redirect_to @thread }
21
- format.js
15
+ format.html { redirect_to @commontable_url }
16
+ format.js { render :subscribe }
22
17
  end
23
18
 
24
19
  end
@@ -27,13 +22,12 @@ module Commontator
27
22
  def destroy
28
23
  raise SecurityTransgression unless @thread.can_subscribe?(@commontator)
29
24
 
30
- if !@thread.unsubscribe(@commontator)
31
- flash[:alert] = "You are not subscribed to this " + commontable_name(@thread)
32
- end
25
+ @thread.errors.add(:base, "You are not subscribed to this thread") \
26
+ unless @thread.unsubscribe(@commontator)
33
27
 
34
28
  respond_to do |format|
35
- format.html { redirect_to @thread }
36
- format.js
29
+ format.html { redirect_to @commontable_url }
30
+ format.js { render :subscribe }
37
31
  end
38
32
  end
39
33
  end
@@ -9,7 +9,7 @@ module Commontator
9
9
  @thread.mark_as_read_for(@commontator)
10
10
 
11
11
  respond_to do |format|
12
- format.html
12
+ format.html { redirect_to @commontable_url }
13
13
  format.js
14
14
  end
15
15
  end
@@ -22,8 +22,7 @@ module Commontator
22
22
  @thread.thread_closed_callback(@commontator)
23
23
 
24
24
  respond_to do |format|
25
- format.html { redirect_to @thread }
26
- format.js
25
+ format.html { redirect_to @commontable_url }
27
26
  end
28
27
  end
29
28
 
@@ -34,8 +33,7 @@ module Commontator
34
33
  @thread.reopen
35
34
 
36
35
  respond_to do |format|
37
- format.html { redirect_to @thread }
38
- format.js
36
+ format.html { redirect_to @commontable_url }
39
37
  end
40
38
  end
41
39
  end
@@ -1,6 +1,5 @@
1
1
  module Commontator
2
2
  class ThreadsController < ApplicationController
3
-
4
3
  before_filter :get_thread
5
4
 
6
5
  # GET /threads/1
@@ -10,7 +9,7 @@ module Commontator
10
9
  @thread.mark_as_read_for(@commontator)
11
10
 
12
11
  respond_to do |format|
13
- format.html
12
+ format.html { redirect_to commontable_url(@thread) }
14
13
  format.js
15
14
  end
16
15
  end
@@ -23,8 +22,7 @@ module Commontator
23
22
  @thread.thread_closed_callback(@commontator)
24
23
 
25
24
  respond_to do |format|
26
- format.html { redirect_to @thread }
27
- format.js
25
+ format.html { redirect_to commontable_url(@thread) }
28
26
  end
29
27
  end
30
28
 
@@ -35,8 +33,7 @@ module Commontator
35
33
  @thread.reopen
36
34
 
37
35
  respond_to do |format|
38
- format.html { redirect_to @thread }
39
- format.js
36
+ format.html { redirect_to commontable_url(@thread) }
40
37
  end
41
38
  end
42
39
  end