the_comments 2.2.2 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +104 -20
  3. data/app/assets/javascripts/the_comments.js.coffee +7 -6
  4. data/app/assets/stylesheets/the_comments.css.scss +11 -8
  5. data/app/controllers/concerns/{controller.rb → the_comments/controller.rb} +29 -48
  6. data/app/controllers/concerns/the_comments/view_token.rb +20 -0
  7. data/app/models/concerns/{comment.rb → the_comments/comment.rb} +22 -9
  8. data/app/models/concerns/{comment_states.rb → the_comments/comment_states.rb} +2 -8
  9. data/app/models/concerns/{commentable.rb → the_comments/commentable.rb} +0 -0
  10. data/app/models/concerns/{user.rb → the_comments/user.rb} +6 -2
  11. data/app/views/the_comments/haml/_additional_info.html.haml +1 -1
  12. data/app/views/the_comments/haml/_comment_body.html.haml +7 -2
  13. data/app/views/the_comments/haml/_comment_edit.html.haml +1 -1
  14. data/app/views/the_comments/haml/_form.html.haml +4 -23
  15. data/app/views/the_comments/haml/_guest_form.html.haml +22 -0
  16. data/app/views/the_comments/haml/_logined_form.html.haml +18 -0
  17. data/app/views/the_comments/haml/_manage_controls.html.haml +20 -17
  18. data/app/views/the_comments/haml/_sidebar.html.haml +6 -25
  19. data/app/views/the_comments/haml/_sidebar_admin.html.haml +12 -0
  20. data/app/views/the_comments/haml/_sidebar_backlink.html.haml +3 -0
  21. data/app/views/the_comments/haml/_sidebar_user.html.haml +29 -0
  22. data/app/views/the_comments/haml/_tree.html.haml +13 -1
  23. data/app/views/the_comments/haml/manage.html.haml +8 -7
  24. data/app/views/the_comments/slim/_comment_body.html.slim +5 -1
  25. data/app/views/the_comments/slim/_form.html.slim +4 -23
  26. data/app/views/the_comments/slim/_guest_form.html.slim +22 -0
  27. data/app/views/the_comments/slim/_logined_form.html.slim +18 -0
  28. data/app/views/the_comments/slim/_manage_controls.html.slim +19 -16
  29. data/app/views/the_comments/slim/_sidebar.html.slim +6 -25
  30. data/app/views/the_comments/slim/_sidebar_admin.html.slim +12 -0
  31. data/app/views/the_comments/slim/_sidebar_backlink.html.slim +3 -0
  32. data/app/views/the_comments/slim/_sidebar_user.html.slim +29 -0
  33. data/app/views/the_comments/slim/_tree.html.slim +13 -1
  34. data/app/views/the_comments/slim/index.html.slim +2 -2
  35. data/app/views/the_comments/slim/manage.html.slim +7 -6
  36. data/config/initializers/the_comments.rb +0 -1
  37. data/config/locales/ru.yml +14 -10
  38. data/config/routes.rb +4 -2
  39. data/docs/whats_wrong_with_other_gems.md +13 -13
  40. data/docs/where_is_example_application.md +3 -3
  41. data/gem_version.rb +2 -2
  42. data/lib/the_comments.rb +26 -7
  43. data/lib/the_comments/config.rb +1 -4
  44. data/spec/dummy_app/Gemfile +2 -2
  45. data/spec/dummy_app/config/routes.rb +1 -0
  46. data/spec/dummy_app/spec/models/user_counters_spec.rb +5 -5
  47. data/the_comments.gemspec +3 -2
  48. data/views_converter.rb +2 -2
  49. metadata +49 -26
  50. data/app/views/the_comments/haml/index.html.haml +0 -18
  51. data/app/views/the_comments/haml/my_comments.html.haml +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49fd19e10fb5ca5adbbb061aced7c0c844b85bac
4
- data.tar.gz: 36c6ab87c989e3bb71f108f382537084bf6aa78e
3
+ metadata.gz: d33700b0151040d95f8a455e475ad5d66eb8b928
4
+ data.tar.gz: 5d104aa0145c131bf1cc3a98002a0f1dff5e1365
5
5
  SHA512:
6
- metadata.gz: 1ea2f9f5bf511f4350efc70c0a53a65c4db5cdeb0fcbe98e09d33afc6c9c57d5ab88a766b7e0e6db4ec1c21f9db209af10b9546285b0c414fe85f4920e56fea1
7
- data.tar.gz: 096802337316119520c1811ecc7e463adb9f684deab5f97a7a4ba64d3c0137a53def4d110f292d65be7c237d5bd7eed4edc079bf03f86093244f8f865a12a6b4
6
+ metadata.gz: c37bcfd7ef8a5badd433e6eb711d3bc74d5e7a8b7349b13aa2bb7b3bb8e13e7d744e3ab5570c323a905a338f6efd75dc4b57dd38caf190d13c80ad97f81874d6
7
+ data.tar.gz: bf99d747ea1f2aa1e4df5fda067527e03571e596c34ea4226f5182ba6a0bd0657a008ed16323f611a9c7a1e2e54747d749d026c5f4e30ee2cc12f9206dd2315a
data/README.md CHANGED
@@ -2,34 +2,36 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/the_comments.png)](http://badge.fury.io/rb/the_comments) | [![Build Status](https://travis-ci.org/the-teacher/the_comments.png?branch=master)](https://travis-ci.org/the-teacher/the_comments) | [![Code Climate](https://codeclimate.com/github/the-teacher/the_comments.png)](https://codeclimate.com/github/the-teacher/the_comments) | [(rubygems)](http://rubygems.org/gems/the_comments)
4
4
 
5
- TheComments - probably, best commenting system for Rails
5
+ TheComments - The best Rails gem for blog-style comments
6
6
 
7
- :question:   [Why TheComments is better than others gems?](docs/whats_wrong_with_other_gems.md#why-thecomments-is-better-than-others-gems)
7
+ :question:   [Why is TheComments better than other gems?](docs/whats_wrong_with_other_gems.md#why-thecomments-is-better-than-others-gems)
8
8
 
9
- ### Main features
9
+ ### Features
10
10
 
11
11
  * Threaded comments
12
12
  * Useful cache counters
13
13
  * Admin UI for moderation
14
14
  * Mountable Engine.routes
15
15
  * Online Support via skype: **ilya.killich**
16
- * [Denormalization](docs/denormalization_and_recent_comments.md) for Recent comments
16
+ * [Denormalization](docs/denormalization_and_recent_comments.md) for recent comments
17
17
  * Production-ready commenting system for Rails 4+
18
- * Designed for preprocessors Sanitize, Textile, Markdawn etc.
18
+ * Designed for preprocessors such as Sanitize, Textile, Markdown etc.
19
19
 
20
20
  ### :books:   [Documentation](docs/documentation.md)
21
21
 
22
22
  ## If you have any questions
23
23
 
24
- Please before ask anything try to launch and play with **[Dummy App](spec/dummy_app)** in spec folder. Maybe example of integration will be better than any documentation. Thank you!
24
+ Please try playing around with the **[Dummy App](spec/dummy_app)** in the `spec` folder first. An example integration is often better than any documentation! Thanks.
25
25
 
26
- ## How to start dummy app (screencast)
26
+ ## How to start the dummy app (screencast)
27
27
 
28
28
  [![Foo](https://raw.github.com/the-teacher/the_comments/master/docs/screencast.jpg)](http://vk.com/video_ext.php?oid=49225742&id=166578209&hash=10be1dba625149bb&hd=3)
29
29
 
30
30
  ## Quick Start Installation
31
31
 
32
- ### 1. Gems install
32
+ **NB: In the following examples, `Posts` is the model to which comments are being added. For your app, the model might be `Articles` or similar instead.**
33
+
34
+ ### 1. Install Gems
33
35
 
34
36
  **Gemfile**
35
37
 
@@ -46,9 +48,9 @@ gem 'awesome_nested_set' # or same gem
46
48
  bundle
47
49
  ```
48
50
 
49
- ### 2. Migrations install
51
+ Don't forget to restart your server!
50
52
 
51
- **Copy migrations**
53
+ ### 2. Add migrations
52
54
 
53
55
  ```
54
56
  rake the_comments_engine:install:migrations
@@ -80,13 +82,36 @@ class ChangeCommentable < ActiveRecord::Migration
80
82
  end
81
83
  ```
82
84
 
85
+ :warning: &nbsp; **Open and change xxxxx_change_user.rb migration**
86
+
87
+ ```ruby
88
+ class TheCommentsChangeUser < ActiveRecord::Migration
89
+ def change
90
+ #if you User class is not called User, you may want to change it.
91
+ change_table :users do |t|
92
+ # "Written by me" (cache counters)
93
+ t.integer :my_draft_comments_count, default: 0
94
+ t.integer :my_published_comments_count, default: 0
95
+ t.integer :my_comments_count, default: 0 # my_draft_comments_count + my_published_comments_count
96
+
97
+ # commentable's comments => comcoms (cache counters)
98
+ # Relation through Comment#holder_id field
99
+ t.integer :draft_comcoms_count, default: 0
100
+ t.integer :published_comcoms_count, default: 0
101
+ t.integer :deleted_comcoms_count, default: 0
102
+ t.integer :spam_comcoms_count, default: 0
103
+ end
104
+ end
105
+ end
106
+ ```
107
+
83
108
  **Invoke migrations**
84
109
 
85
110
  ```
86
111
  rake db:migrate
87
112
  ```
88
113
 
89
- ### 3. Code install
114
+ ### 3. Code installation
90
115
 
91
116
  ```ruby
92
117
  rails g the_comments install
@@ -98,7 +123,7 @@ Will create:
98
123
  * app/controllers/comments_controller.rb
99
124
  * app/models/comment.rb
100
125
 
101
- :warning: &nbsp; **Open each file and follow an instructions**
126
+ :warning: &nbsp; **Open each file and follow the instructions**
102
127
 
103
128
  ### 4. Models modifictions
104
129
 
@@ -110,10 +135,12 @@ class User < ActiveRecord::Base
110
135
 
111
136
  has_many :posts
112
137
 
138
+ # IT'S JUST AN EXAMPLE OF ANY ROLE SYSTEM
113
139
  def admin?
114
140
  self == User.first
115
141
  end
116
142
 
143
+ # YOU HAVE TO IMPLEMENT YOUR ROLE POLICY FOR COMMENTS HERE
117
144
  def comments_admin?
118
145
  admin?
119
146
  end
@@ -133,7 +160,7 @@ class Post < ActiveRecord::Base
133
160
  belongs_to :user
134
161
 
135
162
  # Denormalization methods
136
- # Please, read about advanced using
163
+ # Check the documentation for information on advanced usage
137
164
  def commentable_title
138
165
  "Undefined Post Title"
139
166
  end
@@ -166,9 +193,11 @@ MyApp::Application.routes.draw do
166
193
  end
167
194
  ```
168
195
 
169
- Please, read [documentation](docs/documentation.md) to learn more
196
+ Refer to the [documentation](docs/documentation.md) for more information
170
197
 
171
- ### 6. Controller's addon
198
+ ### 6. Add to Application Controller
199
+
200
+ **app/controllers/application_controller.rb**
172
201
 
173
202
  ```ruby
174
203
  class ApplicationController < ActionController::Base
@@ -180,7 +209,7 @@ class ApplicationController < ActionController::Base
180
209
  end
181
210
  ```
182
211
 
183
- ### 7. Assets install
212
+ ### 7. Install assets
184
213
 
185
214
  **app/assets/stylesheets/application.css**
186
215
 
@@ -196,9 +225,9 @@ end
196
225
  //= require the_comments
197
226
  ```
198
227
 
199
- ### 8. Controller code example
228
+ ### 8. Example controller code
200
229
 
201
- **app/controllers/posts_controllers.rb**
230
+ **app/controllers/posts_controller.rb**
202
231
 
203
232
  ```ruby
204
233
  def show
@@ -207,7 +236,7 @@ def show
207
236
  end
208
237
  ```
209
238
 
210
- ### 9. View code example
239
+ ### 9. Example view code
211
240
 
212
241
  **app/views/posts/show.html.haml**
213
242
 
@@ -217,11 +246,66 @@ end
217
246
 
218
247
  <hr>
219
248
 
249
+ ### Common problems
250
+
251
+ For error with `unpermitted parameters` in webserver output.
252
+
253
+ Example:
254
+
255
+ Unpermitted parameters: commentable_type, commentable_id
256
+
257
+ User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
258
+
259
+ Completed 500 Internal Server Error in 8ms
260
+
261
+ Add the following to your Comments Controller.
262
+
263
+ def comment_params
264
+ params
265
+ .require(:comment)
266
+ .permit(:title, :contacts, :raw_content, :parent_id, :commentable_type, :commentable_id)
267
+ .merge(denormalized_fields)
268
+ .merge(request_data_for_comment)
269
+ .merge(tolerance_time: params[:tolerance_time].to_i)
270
+ .merge(user: current_user, view_token: comments_view_token)
271
+ end
272
+
273
+ See [here](https://github.com/the-teacher/the_comments/issues/34).
274
+
275
+ <hr>
276
+
277
+ For errors with `around_validation`.
278
+
279
+ Example:
280
+
281
+ NoMethodError - protected method `around_validation' called for #<StateMachine::Machine:0x007f84148c3c60>:
282
+
283
+ Create a new file `config/state_machine.rb`.
284
+
285
+ # Rails 4.1.0.rc1 and StateMachine don't play nice
286
+ # https://github.com/pluginaweek/state_machine/issues/295
287
+
288
+ require 'state_machine/version'
289
+
290
+ unless StateMachine::VERSION == '1.2.0'
291
+ # If you see this message, please test removing this file
292
+ # If it's still required, please bump up the version above
293
+ Rails.logger.warn "Please remove me, StateMachine version has changed"
294
+ end
295
+
296
+ module StateMachine::Integrations::ActiveModel
297
+ public :around_validation
298
+ end
299
+
300
+ See [here](https://github.com/pluginaweek/state_machine/issues/295).
301
+
302
+ <hr>
303
+
220
304
  ### Feedback
221
305
 
222
306
  :speech_balloon: &nbsp; My twitter: [@iam_teacher](https://twitter.com/iam_teacher) &nbsp; &nbsp; &nbsp; hashtag: **#the_comments**
223
307
 
224
- ### Acknowledgment
308
+ ### Acknowledgments
225
309
 
226
310
  * Anna Nechaeva (my wife) - for love and my happy life
227
311
  * @tanraya (Andrew Kozlov) - for code review
@@ -1,8 +1,9 @@
1
1
  # ERROR MSG BUILDER
2
2
  @comments_errors_builder = (errors) ->
3
3
  error_msgs = ''
4
- for error in errors
5
- error_msgs += "<p><b>#{ error }</b></p>"
4
+ for field, errs of errors
5
+ for err in errs
6
+ error_msgs += "<p><b>#{ field }:</b> #{ err }</p>"
6
7
  error_msgs
7
8
 
8
9
  # FORM CLEANER
@@ -38,7 +39,7 @@ $ ->
38
39
 
39
40
  if tolerance_time && (time_diff < tolerance_time)
40
41
  delta = tolerance_time - time_diff
41
- error_msgs = comments_errors_builder(["Please wait #{delta} secs"])
42
+ error_msgs = comments_errors_builder({ delay: ["Please wait #{delta} secs"] })
42
43
  comments_error_notifier(form, error_msgs)
43
44
  return false
44
45
 
@@ -53,7 +54,7 @@ $ ->
53
54
  $(document).on 'ajax:error', comment_forms, (request, response, status) ->
54
55
  form = $ @
55
56
  $('input[type=submit]', form).show()
56
- error_msgs = comments_errors_builder(["Server Error: #{response.status}"])
57
+ error_msgs = comments_errors_builder({ "Server Error: ": [response.status] })
57
58
  comments_error_notifier(form, error_msgs)
58
59
 
59
60
  # SUCCESS
@@ -86,7 +87,7 @@ $ ->
86
87
  $(document).on 'click', '.reply_link', ->
87
88
  link = $ @
88
89
  comment = link.parent().parent().parent()
89
-
90
+
90
91
  $(comment_forms).hide()
91
92
  form = $('#new_comment').clone().removeAttr('id').addClass('reply_comments_form')
92
93
 
@@ -104,4 +105,4 @@ $ ->
104
105
 
105
106
  $(window).on 'hashchange', ->
106
107
  $('.comment.highlighted').removeClass 'highlighted'
107
- highlight_anchor()
108
+ highlight_anchor()
@@ -22,17 +22,19 @@
22
22
  }
23
23
  }
24
24
 
25
+ .action_btns a{ margin-right: 15px; }
26
+
25
27
  .comments, .comments_tree{
26
28
  font-family: Arial;
27
29
  font-size: 13px;
28
30
 
29
31
  h3{ font-size: 1.6em; }
30
32
 
31
- .error_notifier{
33
+ .error_notifier{
32
34
  background-color: #F2DEDE;
33
35
  border: 1px solid #B94A48;
34
36
  color: #B94A48;
35
-
37
+
36
38
  border-radius: 4px;
37
39
  margin: 0 0 15px 0;
38
40
  padding: 10px 10px 0 10px;
@@ -41,13 +43,13 @@
41
43
  p{ margin: 0 0 10px 0; }
42
44
  }
43
45
  form{
44
-
46
+
45
47
  background: #e0e4f5;
46
48
 
47
49
  border: 1px solid #c6cff5;
48
50
  border-radius: 5px;
49
51
  padding: 10px;
50
-
52
+
51
53
  p{ margin: 0 0 10px 0; }
52
54
 
53
55
  input[type=text]{
@@ -88,7 +90,7 @@
88
90
  }
89
91
 
90
92
  .form_holder{ margin-left: 40px; }
91
-
93
+
92
94
  .edit, .delete{
93
95
  margin-bottom: 3px;
94
96
  text-align:center;
@@ -142,6 +144,7 @@
142
144
  .controls{
143
145
  position: absolute;
144
146
  top: 53px; left: 5px;
147
+
145
148
  a{
146
149
  font-size:11px;
147
150
  display:block;
@@ -161,7 +164,7 @@
161
164
  }
162
165
 
163
166
  .form_holder{
164
- form{ margin: 10px 0; }
167
+ form{ margin: 10px 0; }
165
168
  }
166
169
  }
167
170
 
@@ -187,7 +190,7 @@
187
190
  border-left: 5px solid orange;
188
191
 
189
192
  .controls{
190
- a.to_draft{ display: none }
193
+ a.to_draft{ display: none }
191
194
  }
192
195
  }
193
196
  .published{
@@ -242,4 +245,4 @@
242
245
  }
243
246
  }
244
247
  }
245
- }
248
+ }
@@ -1,25 +1,4 @@
1
1
  module TheComments
2
- COMMENTS_COOKIES_TOKEN = 'JustTheCommentsCookies'
3
-
4
- # Cookies and View token for spam protection
5
- # include TheComments::ViewToken
6
- module ViewToken
7
- extend ActiveSupport::Concern
8
-
9
- included { before_action :set_the_comments_cookies }
10
-
11
- def comments_view_token
12
- cookies[:comments_view_token]
13
- end
14
-
15
- private
16
-
17
- def set_the_comments_cookies
18
- cookies[:the_comment_cookies] = { value: TheComments::COMMENTS_COOKIES_TOKEN, expires: 1.year.from_now }
19
- cookies[:comments_view_token] = { value: SecureRandom.hex, expires: 7.days.from_now } unless cookies[:comments_view_token]
20
- end
21
- end
22
-
23
2
  # Base functionality of Comments Controller
24
3
  # class CommentsController < ApplicationController
25
4
  # include TheComments::Controller
@@ -50,23 +29,14 @@ module TheComments
50
29
  end
51
30
 
52
31
  # App side methods (you can overwrite them)
53
- def index
54
- @comments = ::Comment.with_state(:published).recent.page(params[:page])
55
- render comment_template(:index)
56
- end
57
32
 
58
33
  def manage
59
- @comments = current_user.comcoms.active.recent.page(params[:page])
34
+ @comments = current_user.comcoms.with_users.active.recent.page(params[:page])
60
35
  render comment_template(:manage)
61
36
  end
62
37
 
63
38
  def my_comments
64
- @comments = current_user.my_comments.active.recent.page(params[:page])
65
- render comment_template(:my_comments)
66
- end
67
-
68
- def edit
69
- @comments = current_user.comcoms.where(id: params[:id]).page(params[:page])
39
+ @comments = current_user.my_comments.with_users.active.recent.page(params[:page])
70
40
  render comment_template(:manage)
71
41
  end
72
42
 
@@ -74,40 +44,39 @@ module TheComments
74
44
  # Methods for admin
75
45
  %w[draft published deleted].each do |state|
76
46
  define_method "#{state}" do
77
- @comments = current_user.comcoms.with_state(state).recent.page(params[:page])
47
+ @comments = current_user.comcoms.with_users.with_state(state).recent.page(params[:page])
78
48
  render comment_template(:manage)
79
49
  end
80
50
 
81
51
  define_method "total_#{state}" do
82
- @comments = ::Comment.with_state(state).recent.page(params[:page])
52
+ @comments = ::Comment.with_state(state).with_users.recent.page(params[:page])
83
53
  render comment_template(:manage)
84
54
  end
85
55
 
86
- unless state == 'deleted'
87
- define_method "my_#{state}" do
88
- @comments = current_user.my_comments.with_state(state).recent.page(params[:page])
89
- render comment_template(:my_comments)
90
- end
56
+ define_method "my_#{state}" do
57
+ @comments = current_user.my_comments.with_users.with_state(state).recent.page(params[:page])
58
+ render comment_template(:manage)
91
59
  end
92
60
  end
93
61
 
94
62
  def spam
95
- @comments = current_user.comcoms.where(spam: true).recent.page(params[:page])
63
+ @comments = current_user.comcoms.with_users.where(spam: true).recent.page(params[:page])
64
+ render comment_template(:manage)
65
+ end
66
+
67
+ def my_spam
68
+ @comments = current_user.my_comments.with_users.where(spam: true).recent.page(params[:page])
96
69
  render comment_template(:manage)
97
70
  end
98
71
 
99
72
  def total_spam
100
- @comments = ::Comment.where(spam: true).recent.page(params[:page])
73
+ @comments = ::Comment.where(spam: true).with_users.recent.page(params[:page])
101
74
  render comment_template(:manage)
102
75
  end
103
76
 
104
77
  # BASE METHODS
78
+
105
79
  # Public methods
106
- def update
107
- comment = ::Comment.find(params[:id])
108
- comment.update_attributes!(patch_comment_params)
109
- render(layout: false, partial: comment_partial(:comment_body), locals: { comment: comment })
110
- end
111
80
 
112
81
  def create
113
82
  @comment = @commentable.comments.new comment_params
@@ -115,10 +84,22 @@ module TheComments
115
84
  @comment.save
116
85
  return render layout: false, partial: comment_partial(:comment), locals: { tree: @comment }
117
86
  end
118
- render json: { errors: @comment.errors.full_messages }
87
+ render json: { errors: @comment.errors }
119
88
  end
120
89
 
121
90
  # Restricted area
91
+
92
+ def edit
93
+ @comments = current_user.comcoms.where(id: params[:id]).page(params[:page])
94
+ render comment_template(:manage)
95
+ end
96
+
97
+ def update
98
+ comment = ::Comment.find(params[:id])
99
+ comment.update_attributes!(patch_comment_params)
100
+ render(layout: false, partial: comment_partial(:comment_body), locals: { comment: comment })
101
+ end
102
+
122
103
  %w[draft published deleted].each do |state|
123
104
  define_method "to_#{state}" do
124
105
  ::Comment.find(params[:id]).try "to_#{state}"
@@ -213,4 +194,4 @@ module TheComments
213
194
  end
214
195
  end
215
196
  end
216
- end
197
+ end