the_comments_ruby 2.3.3
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.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/.ruby-gemset.example +1 -0
- data/.ruby-version.example +1 -0
- data/.rvmrc.example +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +338 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/the_comments.js.coffee +108 -0
- data/app/assets/javascripts/the_comments_manage.js.coffee +27 -0
- data/app/assets/stylesheets/the_comments.css.scss +248 -0
- data/app/controllers/_templates_/comments_controller.rb +44 -0
- data/app/controllers/concerns/the_comments/controller.rb +197 -0
- data/app/controllers/concerns/the_comments/view_token.rb +20 -0
- data/app/helpers/render_comments_tree_helper.rb +111 -0
- data/app/models/_templates_/comment.rb +38 -0
- data/app/models/concerns/the_comments/comment.rb +116 -0
- data/app/models/concerns/the_comments/comment_states.rb +80 -0
- data/app/models/concerns/the_comments/commentable.rb +69 -0
- data/app/models/concerns/the_comments/user.rb +56 -0
- data/app/views/the_comments/_tree.html.erb +3 -0
- data/app/views/the_comments/haml/_additional_info.html.haml +13 -0
- data/app/views/the_comments/haml/_comment.html.haml +1 -0
- data/app/views/the_comments/haml/_comment_body.html.haml +25 -0
- data/app/views/the_comments/haml/_comment_edit.html.haml +26 -0
- data/app/views/the_comments/haml/_form.html.haml +8 -0
- data/app/views/the_comments/haml/_guest_form.html.haml +22 -0
- data/app/views/the_comments/haml/_logined_form.html.haml +18 -0
- data/app/views/the_comments/haml/_manage_controls.html.haml +30 -0
- data/app/views/the_comments/haml/_sidebar.html.haml +9 -0
- data/app/views/the_comments/haml/_sidebar_admin.html.haml +12 -0
- data/app/views/the_comments/haml/_sidebar_backlink.html.haml +3 -0
- data/app/views/the_comments/haml/_sidebar_user.html.haml +29 -0
- data/app/views/the_comments/haml/_tree.html.haml +16 -0
- data/app/views/the_comments/haml/manage.html.haml +26 -0
- data/app/views/the_comments/slim/_additional_info.html.slim +13 -0
- data/app/views/the_comments/slim/_comment.html.slim +1 -0
- data/app/views/the_comments/slim/_comment_body.html.slim +24 -0
- data/app/views/the_comments/slim/_comment_edit.html.slim +26 -0
- data/app/views/the_comments/slim/_form.html.slim +8 -0
- data/app/views/the_comments/slim/_guest_form.html.slim +22 -0
- data/app/views/the_comments/slim/_logined_form.html.slim +18 -0
- data/app/views/the_comments/slim/_manage_controls.html.slim +30 -0
- data/app/views/the_comments/slim/_sidebar.html.slim +9 -0
- data/app/views/the_comments/slim/_sidebar_admin.html.slim +12 -0
- data/app/views/the_comments/slim/_sidebar_backlink.html.slim +3 -0
- data/app/views/the_comments/slim/_sidebar_user.html.slim +29 -0
- data/app/views/the_comments/slim/_tree.html.slim +16 -0
- data/app/views/the_comments/slim/index.html.slim +18 -0
- data/app/views/the_comments/slim/manage.html.slim +26 -0
- data/app/views/the_comments/slim/my_comments.html.slim +28 -0
- data/config/initializers/the_comments.rb +14 -0
- data/config/locales/en.yml +68 -0
- data/config/locales/ru.yml +71 -0
- data/config/routes.rb +38 -0
- data/db/migrate/20130101010101_the_comments_change_user.rb +18 -0
- data/db/migrate/20130101010102_the_comments_create_comments.rb +50 -0
- data/db/migrate/20130101010103_the_comments_change_commentable.rb +13 -0
- data/docs/admin_ui_installation.md +145 -0
- data/docs/advanced_installation.md +185 -0
- data/docs/comment_api.md +58 -0
- data/docs/commentable_api.md +59 -0
- data/docs/config_file.md +27 -0
- data/docs/content_preprocessors.md +73 -0
- data/docs/customazation_of_views.md +30 -0
- data/docs/denormalization_and_recent_comments.md +40 -0
- data/docs/documentation.md +29 -0
- data/docs/generators.md +74 -0
- data/docs/pagination.md +123 -0
- data/docs/routes.md +77 -0
- data/docs/screencast.jpg +0 -0
- data/docs/the_comments.jpg +0 -0
- data/docs/the_comments_view_1.gif +0 -0
- data/docs/the_comments_view_2.gif +0 -0
- data/docs/the_comments_view_3.gif +0 -0
- data/docs/the_comments_view_4.gif +0 -0
- data/docs/the_comments_view_5.gif +0 -0
- data/docs/user_api.md +75 -0
- data/docs/what_is_comcoms.md +63 -0
- data/docs/whats_wrong_with_other_gems.md +28 -0
- data/docs/where_is_example_application.md +37 -0
- data/gem_version.rb +3 -0
- data/lib/generators/the_comments/USAGE +44 -0
- data/lib/generators/the_comments/the_comments_generator.rb +56 -0
- data/lib/generators/the_comments/views_generator.rb +79 -0
- data/lib/the_comments/config.rb +37 -0
- data/lib/the_comments/version.rb +1 -0
- data/lib/the_comments.rb +28 -0
- data/spec/dummy_app/.gitignore +18 -0
- data/spec/dummy_app/.rspec +1 -0
- data/spec/dummy_app/Gemfile +43 -0
- data/spec/dummy_app/README.md +33 -0
- data/spec/dummy_app/Rakefile +6 -0
- data/spec/dummy_app/app/assets/images/.keep +0 -0
- data/spec/dummy_app/app/assets/javascripts/admin_panel.js +5 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +16 -0
- data/spec/dummy_app/app/assets/stylesheets/admin_panel.css +3 -0
- data/spec/dummy_app/app/assets/stylesheets/app.css.scss +4 -0
- data/spec/dummy_app/app/assets/stylesheets/application.css +16 -0
- data/spec/dummy_app/app/controllers/application_controller.rb +7 -0
- data/spec/dummy_app/app/controllers/comments_controller.rb +28 -0
- data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
- data/spec/dummy_app/app/controllers/posts_controller.rb +13 -0
- data/spec/dummy_app/app/controllers/users_controller.rb +7 -0
- data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/app/mailers/.keep +0 -0
- data/spec/dummy_app/app/models/.keep +0 -0
- data/spec/dummy_app/app/models/comment.rb +32 -0
- data/spec/dummy_app/app/models/concerns/.keep +0 -0
- data/spec/dummy_app/app/models/post.rb +17 -0
- data/spec/dummy_app/app/models/user.rb +21 -0
- data/spec/dummy_app/app/views/layouts/admin.html.haml +25 -0
- data/spec/dummy_app/app/views/layouts/application.html.haml +20 -0
- data/spec/dummy_app/app/views/posts/index.html.haml +22 -0
- data/spec/dummy_app/app/views/posts/show.html.haml +7 -0
- data/spec/dummy_app/bin/bundle +3 -0
- data/spec/dummy_app/bin/rails +4 -0
- data/spec/dummy_app/bin/rake +4 -0
- data/spec/dummy_app/config/application.rb +23 -0
- data/spec/dummy_app/config/boot.rb +4 -0
- data/spec/dummy_app/config/database.yml +11 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +29 -0
- data/spec/dummy_app/config/environments/production.rb +80 -0
- data/spec/dummy_app/config/environments/test.rb +36 -0
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy_app/config/initializers/inflections.rb +16 -0
- data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +12 -0
- data/spec/dummy_app/config/initializers/session_store.rb +3 -0
- data/spec/dummy_app/config/initializers/sorcery.rb +437 -0
- data/spec/dummy_app/config/initializers/the_comments.rb +14 -0
- data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_app/config/locales/en.yml +23 -0
- data/spec/dummy_app/config/routes.rb +19 -0
- data/spec/dummy_app/config.ru +4 -0
- data/spec/dummy_app/db/migrate/20130712061503_sorcery_core.rb +16 -0
- data/spec/dummy_app/db/migrate/20130712065951_create_posts.rb +11 -0
- data/spec/dummy_app/db/migrate/20131027185332_change_user.the_comments_engine.rb +19 -0
- data/spec/dummy_app/db/migrate/20131027185333_create_comments.the_comments_engine.rb +51 -0
- data/spec/dummy_app/db/migrate/20131027185334_change_commentable.the_comments_engine.rb +14 -0
- data/spec/dummy_app/db/schema.rb +74 -0
- data/spec/dummy_app/db/seeds.rb +42 -0
- data/spec/dummy_app/lib/assets/.keep +0 -0
- data/spec/dummy_app/lib/tasks/.keep +0 -0
- data/spec/dummy_app/lib/tasks/app_bootstrap.rake +15 -0
- data/spec/dummy_app/log/.keep +0 -0
- data/spec/dummy_app/public/404.html +58 -0
- data/spec/dummy_app/public/422.html +58 -0
- data/spec/dummy_app/public/500.html +57 -0
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/robots.txt +5 -0
- data/spec/dummy_app/spec/factories/post.rb +6 -0
- data/spec/dummy_app/spec/factories/user.rb +6 -0
- data/spec/dummy_app/spec/models/user_counters_spec.rb +339 -0
- data/spec/dummy_app/spec/spec_helper.rb +29 -0
- data/spec/dummy_app/test/controllers/.keep +0 -0
- data/spec/dummy_app/test/fixtures/.keep +0 -0
- data/spec/dummy_app/test/helpers/.keep +0 -0
- data/spec/dummy_app/test/integration/.keep +0 -0
- data/spec/dummy_app/test/mailers/.keep +0 -0
- data/spec/dummy_app/test/models/.keep +0 -0
- data/spec/dummy_app/test/test_helper.rb +15 -0
- data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
- data/the_comments.gemspec +25 -0
- data/the_comments.yml.teamocil.example +11 -0
- data/views_converter.rb +16 -0
- metadata +333 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 416d9f10942340f874cbe6ed2492774421cc2289
|
|
4
|
+
data.tar.gz: cc690194ff545305a7ebc455acccd3f5bac96168
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 624ea547016b3b7a23e7aa9934ac6194f348134caabb28c694521ae652c19b16956972d69fa95a3e91b20b9de1851acb9ced1ad280d89b73e7630dbc150dc327
|
|
7
|
+
data.tar.gz: 752e3865a7e80f19f535d9ef4a094591536e6e77ffe8623dd2a6a1a63dd6b6bd61a7ce0e8e1d94e6320eb1f683691b6e4f2b10957f75a4eaf9f6d5b1df09c694
|
data/.gitignore
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
|
|
4
|
+
.bundle
|
|
5
|
+
.config
|
|
6
|
+
.yardoc
|
|
7
|
+
.idea
|
|
8
|
+
.rvmrc
|
|
9
|
+
.ruby-gemset
|
|
10
|
+
.ruby-version
|
|
11
|
+
|
|
12
|
+
_yardoc
|
|
13
|
+
coverage
|
|
14
|
+
Gemfile.lock
|
|
15
|
+
InstalledFiles
|
|
16
|
+
lib/bundler/man
|
|
17
|
+
spec/dummy_app/public/assets
|
|
18
|
+
|
|
19
|
+
tmp
|
|
20
|
+
doc
|
|
21
|
+
pkg
|
|
22
|
+
rdoc
|
|
23
|
+
|
|
24
|
+
test/tmp
|
|
25
|
+
spec/reports
|
|
26
|
+
test/version_tmp
|
|
27
|
+
|
|
28
|
+
.DS_Store
|
|
29
|
+
.LSOverride
|
|
30
|
+
.AppleDouble
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
the_comments
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-2.0.0-p353
|
data/.rvmrc.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rvm use ruby-2.0.0-p353@the_comments --create
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Ilya N. Zykin
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# TheComments
|
|
2
|
+
|
|
3
|
+
[](http://badge.fury.io/rb/the_comments) | [](https://travis-ci.org/the-teacher/the_comments) | [](https://codeclimate.com/github/the-teacher/the_comments) | [(rubygems)](http://rubygems.org/gems/the_comments)
|
|
4
|
+
|
|
5
|
+
TheComments - The best Rails gem for blog-style comments
|
|
6
|
+
|
|
7
|
+
:question: [Why is TheComments better than other gems?](docs/whats_wrong_with_other_gems.md#why-thecomments-is-better-than-others-gems)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Threaded comments
|
|
12
|
+
* Useful cache counters
|
|
13
|
+
* Admin UI for moderation
|
|
14
|
+
* Mountable Engine.routes
|
|
15
|
+
* Online Support via skype: **ilya.killich**
|
|
16
|
+
* [Denormalization](docs/denormalization_and_recent_comments.md) for recent comments
|
|
17
|
+
* Production-ready commenting system for Rails 4+
|
|
18
|
+
* Designed for preprocessors such as Sanitize, Textile, Markdown etc.
|
|
19
|
+
|
|
20
|
+
### :books: [Documentation](docs/documentation.md)
|
|
21
|
+
|
|
22
|
+
## If you have any questions
|
|
23
|
+
|
|
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
|
+
|
|
26
|
+
## How to start the dummy app (screencast)
|
|
27
|
+
|
|
28
|
+
[](http://vk.com/video_ext.php?oid=49225742&id=166578209&hash=10be1dba625149bb&hd=3)
|
|
29
|
+
|
|
30
|
+
## Quick Start Installation
|
|
31
|
+
|
|
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
|
|
35
|
+
|
|
36
|
+
**Gemfile**
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
gem "the_comments", "~> 2.2.1"
|
|
40
|
+
|
|
41
|
+
gem 'haml' # or gem 'slim'
|
|
42
|
+
gem 'awesome_nested_set' # or same gem
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Bundle**
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
bundle
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Don't forget to restart your server!
|
|
52
|
+
|
|
53
|
+
### 2. Add migrations
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
rake the_comments_engine:install:migrations
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Will create:
|
|
60
|
+
|
|
61
|
+
* xxxxx_change_user.rb
|
|
62
|
+
* xxxxx_create_comments.rb
|
|
63
|
+
* xxxxx_change_commentable.rb
|
|
64
|
+
|
|
65
|
+
:warning: **Open and change xxxxx_change_commentable.rb migration**
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
class ChangeCommentable < ActiveRecord::Migration
|
|
69
|
+
def change
|
|
70
|
+
# Additional fields to Commentable Models
|
|
71
|
+
# [:posts, :articles, ... ]
|
|
72
|
+
|
|
73
|
+
# There is only Post model is commentable
|
|
74
|
+
[:posts].each do |table_name|
|
|
75
|
+
change_table table_name do |t|
|
|
76
|
+
t.integer :draft_comments_count, default: 0
|
|
77
|
+
t.integer :published_comments_count, default: 0
|
|
78
|
+
t.integer :deleted_comments_count, default: 0
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
:warning: **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
|
+
|
|
108
|
+
**Invoke migrations**
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
rake db:migrate
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 3. Code installation
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
rails g the_comments install
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Will create:
|
|
121
|
+
|
|
122
|
+
* config/initializers/the_comments.rb
|
|
123
|
+
* app/controllers/comments_controller.rb
|
|
124
|
+
* app/models/comment.rb
|
|
125
|
+
|
|
126
|
+
:warning: **Open each file and follow the instructions**
|
|
127
|
+
|
|
128
|
+
### 4. Models modifictions
|
|
129
|
+
|
|
130
|
+
**app/models/user.rb**
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
class User < ActiveRecord::Base
|
|
134
|
+
include TheComments::User
|
|
135
|
+
|
|
136
|
+
has_many :posts
|
|
137
|
+
|
|
138
|
+
# IT'S JUST AN EXAMPLE OF ANY ROLE SYSTEM
|
|
139
|
+
def admin?
|
|
140
|
+
self == User.first
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# YOU HAVE TO IMPLEMENT YOUR ROLE POLICY FOR COMMENTS HERE
|
|
144
|
+
def comments_admin?
|
|
145
|
+
admin?
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def comments_moderator? comment
|
|
149
|
+
id == comment.holder_id
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**app/models/post.rb**
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
class Post < ActiveRecord::Base
|
|
158
|
+
include TheComments::Commentable
|
|
159
|
+
|
|
160
|
+
belongs_to :user
|
|
161
|
+
|
|
162
|
+
# Denormalization methods
|
|
163
|
+
# Check the documentation for information on advanced usage
|
|
164
|
+
def commentable_title
|
|
165
|
+
"Undefined Post Title"
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def commentable_url
|
|
169
|
+
"#"
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def commentable_state
|
|
173
|
+
"published"
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 5. Add routes
|
|
179
|
+
|
|
180
|
+
**config/routes.rb**
|
|
181
|
+
|
|
182
|
+
```ruby
|
|
183
|
+
MyApp::Application.routes.draw do
|
|
184
|
+
root 'posts#index'
|
|
185
|
+
resources :posts
|
|
186
|
+
|
|
187
|
+
# ...
|
|
188
|
+
|
|
189
|
+
# TheComments routes
|
|
190
|
+
concern :user_comments, TheComments::UserRoutes.new
|
|
191
|
+
concern :admin_comments, TheComments::AdminRoutes.new
|
|
192
|
+
resources :comments, concerns: [:user_comments, :admin_comments]
|
|
193
|
+
end
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Refer to the [documentation](docs/documentation.md) for more information
|
|
197
|
+
|
|
198
|
+
### 6. Add to Application Controller
|
|
199
|
+
|
|
200
|
+
**app/controllers/application_controller.rb**
|
|
201
|
+
|
|
202
|
+
```ruby
|
|
203
|
+
class ApplicationController < ActionController::Base
|
|
204
|
+
include TheComments::ViewToken
|
|
205
|
+
|
|
206
|
+
# Prevent CSRF attacks by raising an exception.
|
|
207
|
+
# For APIs, you may want to use :null_session instead.
|
|
208
|
+
protect_from_forgery with: :exception
|
|
209
|
+
end
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### 7. Install assets
|
|
213
|
+
|
|
214
|
+
**app/assets/stylesheets/application.css**
|
|
215
|
+
|
|
216
|
+
```css
|
|
217
|
+
/*
|
|
218
|
+
*= require the_comments
|
|
219
|
+
*/
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**app/assets/javascripts/application.js**
|
|
223
|
+
|
|
224
|
+
```js
|
|
225
|
+
//= require the_comments
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 8. Example controller code
|
|
229
|
+
|
|
230
|
+
**app/controllers/posts_controller.rb**
|
|
231
|
+
|
|
232
|
+
```ruby
|
|
233
|
+
def show
|
|
234
|
+
@post = Post.find params[:id]
|
|
235
|
+
@comments = @post.comments.with_state([:draft, :published])
|
|
236
|
+
end
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### 9. Example view code
|
|
240
|
+
|
|
241
|
+
**app/views/posts/show.html.haml**
|
|
242
|
+
|
|
243
|
+
```haml
|
|
244
|
+
= render partial: 'the_comments/tree', locals: { commentable: @post, comments_tree: @comments }
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
<hr>
|
|
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
|
+
|
|
304
|
+
### Feedback
|
|
305
|
+
|
|
306
|
+
:speech_balloon: My twitter: [@iam_teacher](https://twitter.com/iam_teacher) hashtag: **#the_comments**
|
|
307
|
+
|
|
308
|
+
### Acknowledgments
|
|
309
|
+
|
|
310
|
+
* Anna Nechaeva (my wife) - for love and my happy life
|
|
311
|
+
* @tanraya (Andrew Kozlov) - for code review
|
|
312
|
+
* @solenko (Anton Petrunich) - for mountable routes
|
|
313
|
+
* @pyromaniac (Arkadiy Zabazhanov) - for consulting
|
|
314
|
+
|
|
315
|
+
<hr>
|
|
316
|
+
|
|
317
|
+
### MIT License
|
|
318
|
+
|
|
319
|
+
Copyright (c) 2013 Ilya N. Zykin
|
|
320
|
+
|
|
321
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
322
|
+
a copy of this software and associated documentation files (the
|
|
323
|
+
"Software"), to deal in the Software without restriction, including
|
|
324
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
325
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
326
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
327
|
+
the following conditions:
|
|
328
|
+
|
|
329
|
+
The above copyright notice and this permission notice shall be
|
|
330
|
+
included in all copies or substantial portions of the Software.
|
|
331
|
+
|
|
332
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
333
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
334
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
335
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
336
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
337
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
338
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# ERROR MSG BUILDER
|
|
2
|
+
@comments_errors_builder = (errors) ->
|
|
3
|
+
error_msgs = ''
|
|
4
|
+
for field, errs of errors
|
|
5
|
+
for err in errs
|
|
6
|
+
error_msgs += "<p><b>#{ field }:</b> #{ err }</p>"
|
|
7
|
+
error_msgs
|
|
8
|
+
|
|
9
|
+
# FORM CLEANER
|
|
10
|
+
@clear_comment_form = ->
|
|
11
|
+
$('.error_notifier', '#new_comment, .comments_tree').hide()
|
|
12
|
+
$("input[name='comment[title]']").val('')
|
|
13
|
+
$("textarea[name='comment[raw_content]']").val('')
|
|
14
|
+
|
|
15
|
+
# NOTIFIER
|
|
16
|
+
@comments_error_notifier = (form, text) ->
|
|
17
|
+
form.children('.error_notifier').empty().hide().append(text).show()
|
|
18
|
+
|
|
19
|
+
# TIME HELPER
|
|
20
|
+
@unixsec = (t) -> Math.round(t.getTime() / 1000)
|
|
21
|
+
|
|
22
|
+
# HIGHTLIGHT ANCHOR
|
|
23
|
+
@highlight_anchor = ->
|
|
24
|
+
hash = document.location.hash
|
|
25
|
+
if hash.match('#comment_')
|
|
26
|
+
$(hash).addClass 'highlighted'
|
|
27
|
+
|
|
28
|
+
$ ->
|
|
29
|
+
window.tolerance_time_start = unixsec(new Date)
|
|
30
|
+
tolerance_time = $('[data-comments-tolarance-time]').first().data('comments-tolarance-time')
|
|
31
|
+
|
|
32
|
+
# Button Click => AJAX Before Send
|
|
33
|
+
submits = '#new_comment input[type=submit], .reply_comments_form input[type=submit]'
|
|
34
|
+
|
|
35
|
+
$(document).on 'click', submits, (e) ->
|
|
36
|
+
button = $ e.target
|
|
37
|
+
form = button.parents('form').first()
|
|
38
|
+
time_diff = unixsec(new Date) - window.tolerance_time_start
|
|
39
|
+
|
|
40
|
+
if tolerance_time && (time_diff < tolerance_time)
|
|
41
|
+
delta = tolerance_time - time_diff
|
|
42
|
+
error_msgs = comments_errors_builder({ delay: ["Please wait #{delta} secs"] })
|
|
43
|
+
comments_error_notifier(form, error_msgs)
|
|
44
|
+
return false
|
|
45
|
+
|
|
46
|
+
$('.tolerance_time').val time_diff
|
|
47
|
+
button.hide()
|
|
48
|
+
true
|
|
49
|
+
|
|
50
|
+
################ COMMENTS FORMS ################
|
|
51
|
+
comment_forms = "#new_comment, .reply_comments_form"
|
|
52
|
+
|
|
53
|
+
# ERROR
|
|
54
|
+
$(document).on 'ajax:error', comment_forms, (request, response, status) ->
|
|
55
|
+
form = $ @
|
|
56
|
+
$('input[type=submit]', form).show()
|
|
57
|
+
error_msgs = comments_errors_builder({ "Server Error: ": [response.status] })
|
|
58
|
+
comments_error_notifier(form, error_msgs)
|
|
59
|
+
|
|
60
|
+
# SUCCESS
|
|
61
|
+
$(document).on 'ajax:success', comment_forms, (request, response, status) ->
|
|
62
|
+
form = $ @
|
|
63
|
+
$('input[type=submit]', form).show()
|
|
64
|
+
|
|
65
|
+
if typeof(response) is 'string'
|
|
66
|
+
anchor = $(response).find('.comment').attr('id')
|
|
67
|
+
clear_comment_form()
|
|
68
|
+
form.hide()
|
|
69
|
+
$('.parent_id').val('')
|
|
70
|
+
$('#new_comment').fadeIn()
|
|
71
|
+
tree = form.parent().siblings('.nested_set')
|
|
72
|
+
tree = $('ol.comments_tree') if tree.length is 0
|
|
73
|
+
tree.append(response)
|
|
74
|
+
document.location.hash = anchor
|
|
75
|
+
else
|
|
76
|
+
error_msgs = comments_errors_builder(response.errors)
|
|
77
|
+
comments_error_notifier(form, error_msgs)
|
|
78
|
+
|
|
79
|
+
# NEW ROOT BUTTON
|
|
80
|
+
$(document).on 'click', '#new_root_comment', ->
|
|
81
|
+
$('.reply_comments_form').hide()
|
|
82
|
+
$('.parent_id').val('')
|
|
83
|
+
$('#new_comment').fadeIn()
|
|
84
|
+
false
|
|
85
|
+
|
|
86
|
+
# REPLY BUTTON
|
|
87
|
+
$(document).on 'click', '.reply_link', ->
|
|
88
|
+
link = $ @
|
|
89
|
+
comment = link.parent().parent().parent()
|
|
90
|
+
|
|
91
|
+
$(comment_forms).hide()
|
|
92
|
+
form = $('#new_comment').clone().removeAttr('id').addClass('reply_comments_form')
|
|
93
|
+
|
|
94
|
+
comment_id = comment.data('comment-id')
|
|
95
|
+
$('.parent_id', form).val comment_id
|
|
96
|
+
|
|
97
|
+
comment.siblings('.form_holder').html(form)
|
|
98
|
+
$('.error_notifier', form).empty().hide()
|
|
99
|
+
form.fadeIn()
|
|
100
|
+
false
|
|
101
|
+
|
|
102
|
+
$ ->
|
|
103
|
+
# ANCHOR HIGHLIGHT
|
|
104
|
+
highlight_anchor()
|
|
105
|
+
|
|
106
|
+
$(window).on 'hashchange', ->
|
|
107
|
+
$('.comment.highlighted').removeClass 'highlighted'
|
|
108
|
+
highlight_anchor()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
$ ->
|
|
2
|
+
hide_comment_panel = (btn) -> $(btn).parents('.panel').slideUp()
|
|
3
|
+
|
|
4
|
+
comments = $ '.comments'
|
|
5
|
+
|
|
6
|
+
# CONTROLS
|
|
7
|
+
comments.on 'click', 'a.additional_info', ->
|
|
8
|
+
btn = $ @
|
|
9
|
+
holder = btn.parents('.panel-body')
|
|
10
|
+
holder.find('div.additional_info').slideToggle()
|
|
11
|
+
false
|
|
12
|
+
|
|
13
|
+
comments.on 'click', 'a.edit', ->
|
|
14
|
+
btn = $ @
|
|
15
|
+
holder = btn.parents('.panel-body')
|
|
16
|
+
holder.find('.edit_form, .comment_body, a.edit').toggle()
|
|
17
|
+
false
|
|
18
|
+
|
|
19
|
+
comments.on 'ajax:success', '.to_published, .to_draft, .to_spam, .to_deleted', ->
|
|
20
|
+
hide_comment_panel @
|
|
21
|
+
|
|
22
|
+
# Edit form
|
|
23
|
+
comments.on 'ajax:success', '.edit_comment', (request, response, status) ->
|
|
24
|
+
form = $ @
|
|
25
|
+
holder = form.parents('.panel-body')
|
|
26
|
+
holder.find('.edit_form, .comment_body, a.edit').toggle()
|
|
27
|
+
holder.find('.comment_body').replaceWith response
|