the_comments 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc.example +1 -0
- data/.travis.yml +5 -0
- data/README.md +105 -425
- data/app/assets/javascripts/the_comments.js.coffee +12 -9
- data/app/assets/javascripts/the_comments_manage.js.coffee +19 -49
- data/app/assets/stylesheets/the_comments.css.scss +20 -29
- data/app/controllers/_templates_/comments_controller.rb +44 -0
- data/app/controllers/concerns/controller.rb +216 -0
- data/app/helpers/render_comments_tree_helper.rb +4 -7
- data/app/models/_templates_/comment.rb +38 -0
- data/app/models/concerns/comment.rb +103 -0
- data/app/models/concerns/comment_states.rb +80 -0
- data/app/models/concerns/commentable.rb +69 -0
- data/app/models/concerns/user.rb +52 -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/{_comment.html.haml → haml/_comment.html.haml} +0 -0
- data/app/views/the_comments/haml/_comment_body.html.haml +20 -0
- data/app/views/the_comments/haml/_comment_edit.html.haml +26 -0
- data/app/views/the_comments/{_form.html.haml → haml/_form.html.haml} +8 -6
- data/app/views/the_comments/haml/_manage_controls.html.haml +27 -0
- data/app/views/the_comments/haml/_sidebar.html.haml +28 -0
- data/app/views/the_comments/haml/_tree.html.haml +4 -0
- data/app/views/the_comments/haml/index.html.haml +18 -0
- data/app/views/the_comments/haml/manage.html.haml +25 -0
- data/app/views/the_comments/haml/my_comments.html.haml +28 -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 +20 -0
- data/app/views/the_comments/slim/_comment_edit.html.slim +26 -0
- data/app/views/the_comments/slim/_form.html.slim +27 -0
- data/app/views/the_comments/slim/_manage_controls.html.slim +27 -0
- data/app/views/the_comments/slim/_sidebar.html.slim +28 -0
- data/app/views/the_comments/slim/_tree.html.slim +4 -0
- data/app/views/the_comments/slim/index.html.slim +18 -0
- data/app/views/the_comments/slim/manage.html.slim +25 -0
- data/app/views/the_comments/slim/my_comments.html.slim +28 -0
- data/{lib/generators/the_comments/templates → config/initializers}/the_comments.rb +3 -0
- data/config/locales/en.yml +39 -14
- data/config/locales/ru.yml +67 -0
- data/config/routes.rb +17 -13
- data/db/migrate/20130101010101_change_user.rb +18 -0
- data/db/migrate/20130101010102_create_comments.rb +50 -0
- data/db/migrate/20130101010103_change_commentable.rb +13 -0
- data/docs/admin_ui_installation.md +145 -0
- data/docs/advanced_installation.md +182 -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 +28 -0
- data/docs/mountable_routes.md +80 -0
- data/docs/pagination.md +123 -0
- data/docs/screencast.jpg +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 +18 -0
- data/docs/where_is_example_application.md +37 -0
- data/gem_version.rb +3 -0
- data/lib/generators/the_comments/USAGE +31 -20
- data/lib/generators/the_comments/the_comments_generator.rb +35 -18
- data/lib/generators/the_comments/views_generator.rb +52 -16
- data/lib/the_comments/config.rb +14 -1
- data/lib/the_comments/version.rb +1 -3
- data/lib/the_comments.rb +10 -0
- data/spec/dummy_app/.gitignore +17 -0
- data/spec/dummy_app/.rspec +1 -0
- data/spec/dummy_app/.ruby-gemset +1 -0
- data/spec/dummy_app/.ruby-version +1 -0
- data/spec/dummy_app/Gemfile +43 -0
- data/spec/dummy_app/README.md +50 -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/{lib/generators/the_comments/templates → spec/dummy_app/app/controllers}/comments_controller.rb +3 -1
- 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 +13 -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 +15 -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/views_converter.rb +16 -0
- metadata +223 -45
- data/app/controllers/concerns/the_comments_controller.rb +0 -229
- data/app/controllers/concerns/the_comments_ip_controller.rb +0 -17
- data/app/controllers/concerns/the_comments_user_agent_controller.rb +0 -15
- data/app/models/concerns/the_comments_base.rb +0 -69
- data/app/models/concerns/the_comments_black_ip.rb +0 -9
- data/app/models/concerns/the_comments_black_user_agent.rb +0 -9
- data/app/models/concerns/the_comments_commentable.rb +0 -66
- data/app/models/concerns/the_comments_states.rb +0 -65
- data/app/models/concerns/the_comments_user.rb +0 -32
- data/app/views/ip_black_lists/index.html.haml +0 -17
- data/app/views/the_comments/_comment_body.html.haml +0 -30
- data/app/views/the_comments/_manage_controls.html.haml +0 -4
- data/app/views/the_comments/_tree.html.haml +0 -4
- data/app/views/the_comments/index.html.haml +0 -19
- data/app/views/the_comments/manage.html.haml +0 -29
- data/app/views/user_agent_black_lists/index.html.haml +0 -17
- data/db/migrate/20130101010101_create_comments.rb +0 -90
- data/lib/generators/the_comments/templates/ip_black_list.rb +0 -3
- data/lib/generators/the_comments/templates/ip_black_lists_controller.rb +0 -10
- data/lib/generators/the_comments/templates/the_comments_black_ip.rb +0 -9
- data/lib/generators/the_comments/templates/the_comments_black_user_agent.rb +0 -9
- data/lib/generators/the_comments/templates/user_agent_black_list.rb +0 -3
- data/lib/generators/the_comments/templates/user_agent_black_lists_controller.rb +0 -10
@@ -0,0 +1,28 @@
|
|
1
|
+
- cuser = current_user
|
2
|
+
|
3
|
+
- content_for :title do
|
4
|
+
= t "the_comments.management"
|
5
|
+
|
6
|
+
- content_for :comments_sidebar do
|
7
|
+
= render partial: 'the_comments/slim/sidebar'
|
8
|
+
|
9
|
+
- content_for :comments_main do
|
10
|
+
= paginate @comments
|
11
|
+
|
12
|
+
- if @comments.blank?
|
13
|
+
.alert.alert-info= t 'the_comments.no_comments_here'
|
14
|
+
|
15
|
+
.comments
|
16
|
+
- @comments.each do |comment|
|
17
|
+
- klass = { published: :primary, draft: :warning, deleted: :danger }[comment.state.to_sym]
|
18
|
+
.panel class: "panel-#{klass}"
|
19
|
+
.panel-heading= comment.title
|
20
|
+
.panel-body
|
21
|
+
= render partial: 'the_comments/slim/comment_body', locals: { comment: comment }
|
22
|
+
|
23
|
+
- if cuser.comments_admin?
|
24
|
+
= render partial: 'the_comments/slim/comment_edit', locals: { comment: comment }
|
25
|
+
= render partial: 'the_comments/slim/manage_controls', locals: { comment: comment }
|
26
|
+
= render partial: 'the_comments/slim/additional_info', locals: { comment: comment }
|
27
|
+
|
28
|
+
= paginate @comments
|
@@ -7,4 +7,7 @@ TheComments.configure do |config|
|
|
7
7
|
config.default_owner_state = :published # default state for comment for Moderator
|
8
8
|
config.empty_inputs = [:commentBody] # array of spam trap fields
|
9
9
|
config.default_title = 'Undefined title' # default commentable_title for denormalization
|
10
|
+
|
11
|
+
config.empty_trap_protection = true
|
12
|
+
config.tolerance_time_protection = true
|
10
13
|
end
|
data/config/locales/en.yml
CHANGED
@@ -12,22 +12,26 @@ en:
|
|
12
12
|
# blank: '%{attribute} should not be empty'
|
13
13
|
|
14
14
|
the_comments:
|
15
|
-
|
16
|
-
|
15
|
+
incoming: "Incoming:"
|
16
|
+
in_system: "In system:"
|
17
|
+
written_by_me: "Written by me:"
|
18
|
+
back_to_root: "← To root"
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
my_comments: "My comments (%{num})"
|
21
|
+
draft_comments: "New (%{num})"
|
22
|
+
published_comments: "Published (%{num})"
|
23
|
+
deleted_comments: "Deleted (%{num})"
|
24
|
+
spam_comments: "Spam (%{num})"
|
20
25
|
|
21
|
-
|
22
|
-
|
26
|
+
management: Comments management
|
27
|
+
new: "New comment"
|
28
|
+
update: "Update comment"
|
29
|
+
additional_info: "Additional info"
|
30
|
+
cancel: "Cancel"
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
black_ip_message: Sorry! Your IP banned
|
28
|
-
|
29
|
-
black_user_agent: Black User Agent
|
30
|
-
black_user_agent_message: Sorry! Your User Agent banned
|
32
|
+
title: "Title on name:"
|
33
|
+
contacts: "Contacts:"
|
34
|
+
content: "Message:"
|
31
35
|
|
32
36
|
guest_name: Guest
|
33
37
|
reply: Reply to this comment
|
@@ -37,7 +41,28 @@ en:
|
|
37
41
|
to_published: Publicate
|
38
42
|
to_deleted: Delete
|
39
43
|
|
44
|
+
no_comments_here: No comments here
|
45
|
+
|
46
|
+
nav:
|
47
|
+
header: "Navigation"
|
48
|
+
|
49
|
+
form:
|
50
|
+
title: "Your name:"
|
51
|
+
contacts: "Contacts (only admin can see this):"
|
52
|
+
content: "Comment* :"
|
53
|
+
create: "Submit comment"
|
54
|
+
thank_you: "Thank you!"
|
55
|
+
|
56
|
+
trap: Trap
|
57
|
+
trap_message: should be empty
|
58
|
+
|
59
|
+
tolerance_time: Page view time
|
60
|
+
tolerance_time_message: "Please wait %{time} seconds before send a comment and try again"
|
61
|
+
|
40
62
|
delete_confirm: Are you sure?
|
41
63
|
|
64
|
+
cookies: Cookies
|
65
|
+
cookies_required: 'Please enable cookies and try to reload page'
|
66
|
+
ajax_requests_required: 'Sorry, JavaScript/Ajax Requests required'
|
42
67
|
waiting_for_moderation: Waiting for moderation
|
43
|
-
|
68
|
+
undefined_commentable: Commentable object is undefined
|
@@ -0,0 +1,67 @@
|
|
1
|
+
ru:
|
2
|
+
activerecord:
|
3
|
+
attributes:
|
4
|
+
comment:
|
5
|
+
raw_content: Содержимое
|
6
|
+
errors:
|
7
|
+
models:
|
8
|
+
comment:
|
9
|
+
attributes:
|
10
|
+
raw_content:
|
11
|
+
blank: 'Не может быть пустым'
|
12
|
+
|
13
|
+
the_comments:
|
14
|
+
incoming: "Входящие:"
|
15
|
+
in_system: "Все в системе:"
|
16
|
+
written_by_me: "Написанные мной:"
|
17
|
+
back_to_root: "← На главную"
|
18
|
+
|
19
|
+
my_comments: "Мои комментарии (%{num})"
|
20
|
+
draft_comments: "Новые (%{num})"
|
21
|
+
published_comments: "Опубликованные (%{num})"
|
22
|
+
deleted_comments: "Удаленные (%{num})"
|
23
|
+
spam_comments: "Спам (%{num})"
|
24
|
+
|
25
|
+
management: Управление комментариями
|
26
|
+
new: "Написать новый комментарий"
|
27
|
+
update: "Обновить"
|
28
|
+
additional_info: "Подробнее"
|
29
|
+
cancel: "Отмена"
|
30
|
+
|
31
|
+
title: "Имя или тема:"
|
32
|
+
contacts: "Контакты:"
|
33
|
+
content: "Сообщение:"
|
34
|
+
|
35
|
+
guest_name: Гость
|
36
|
+
reply: Ответить на этот комментарий
|
37
|
+
edit: Править
|
38
|
+
to_spam: Спам!
|
39
|
+
to_draft: Черновик
|
40
|
+
to_published: Публиковать
|
41
|
+
to_deleted: Удалить
|
42
|
+
|
43
|
+
no_comments_here: Здесь нет комментариев
|
44
|
+
|
45
|
+
nav:
|
46
|
+
header: "Навигация"
|
47
|
+
|
48
|
+
form:
|
49
|
+
title: "Ваше имя:"
|
50
|
+
contacts: "Контакты (не отображаются на сайте):"
|
51
|
+
content: "Текст комментария* :"
|
52
|
+
create: "Отправить комментарий"
|
53
|
+
thank_you: "Спaсибо!"
|
54
|
+
|
55
|
+
trap: Ловушка
|
56
|
+
trap_message: Должна быть пустой
|
57
|
+
|
58
|
+
tolerance_time: Просмотр времени
|
59
|
+
tolerance_time_message: "Пожалуйста ожидайте %{time} сек. перед отправкой сообщения"
|
60
|
+
|
61
|
+
cookies: Куки
|
62
|
+
cookies_required: 'Включите куки и перезагрузите страницу'
|
63
|
+
|
64
|
+
delete_confirm: Вы уверены?
|
65
|
+
waiting_for_moderation: Ожидает модерации
|
66
|
+
ajax_requests_required: 'Извините, ожидается JavaScript/Ajax запрос'
|
67
|
+
undefined_commentable: Комментируемый объект не определен
|
data/config/routes.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
-
|
2
|
-
resources :ip_black_lists do
|
3
|
-
patch :to_state
|
4
|
-
end
|
5
|
-
|
6
|
-
resources :user_agent_black_lists do
|
7
|
-
patch :to_state
|
8
|
-
end
|
9
|
-
|
1
|
+
TheComments::Engine.routes.draw do
|
10
2
|
resources :comments do
|
11
3
|
member do
|
12
4
|
post :to_spam
|
13
5
|
post :to_draft
|
14
6
|
post :to_published
|
15
|
-
delete :
|
7
|
+
delete :to_deleted
|
16
8
|
end
|
17
9
|
|
18
10
|
collection do
|
19
|
-
get :
|
20
|
-
|
21
|
-
get :
|
11
|
+
get :manage
|
12
|
+
|
13
|
+
get :my_draft
|
14
|
+
get :my_published
|
15
|
+
get :my_comments
|
16
|
+
|
17
|
+
get :total_draft
|
18
|
+
get :total_published
|
19
|
+
get :total_deleted
|
20
|
+
get :total_spam
|
21
|
+
|
22
|
+
get :draft
|
23
|
+
get :published
|
24
|
+
get :deleted
|
25
|
+
get :spam
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# null: false => de-facto db-level validation
|
2
|
+
class ChangeUser < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
change_table :users do |t|
|
5
|
+
# "Written by me" (cache counters)
|
6
|
+
t.integer :my_draft_comments_count, default: 0
|
7
|
+
t.integer :my_published_comments_count, default: 0
|
8
|
+
t.integer :my_comments_count, default: 0 # my_draft_comments_count + my_published_comments_count
|
9
|
+
|
10
|
+
# commentable's comments => comcoms (cache counters)
|
11
|
+
# Relation through Comment#holder_id field
|
12
|
+
t.integer :draft_comcoms_count, default: 0
|
13
|
+
t.integer :published_comcoms_count, default: 0
|
14
|
+
t.integer :deleted_comcoms_count, default: 0
|
15
|
+
t.integer :spam_comcoms_count, default: 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class CreateComments < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :comments do |t|
|
4
|
+
# relations
|
5
|
+
t.integer :user_id
|
6
|
+
t.integer :holder_id
|
7
|
+
|
8
|
+
# polymorphic, commentable object
|
9
|
+
t.integer :commentable_id
|
10
|
+
t.string :commentable_type
|
11
|
+
|
12
|
+
# denormalization
|
13
|
+
t.string :commentable_url
|
14
|
+
t.string :commentable_title
|
15
|
+
t.string :commentable_state
|
16
|
+
|
17
|
+
# comment
|
18
|
+
t.string :anchor
|
19
|
+
|
20
|
+
t.string :title
|
21
|
+
t.string :contacts
|
22
|
+
|
23
|
+
t.text :raw_content
|
24
|
+
t.text :content
|
25
|
+
|
26
|
+
# moderation token
|
27
|
+
t.string :view_token
|
28
|
+
|
29
|
+
# state machine => :draft | :published | :deleted
|
30
|
+
t.string :state, default: :draft
|
31
|
+
|
32
|
+
# base user data (BanHammer power)
|
33
|
+
t.string :ip, default: :undefined
|
34
|
+
t.string :referer, default: :undefined
|
35
|
+
t.string :user_agent, default: :undefined
|
36
|
+
t.integer :tolerance_time
|
37
|
+
|
38
|
+
# unusable: for future versions
|
39
|
+
t.boolean :spam, default: false
|
40
|
+
|
41
|
+
# nested set
|
42
|
+
t.integer :parent_id
|
43
|
+
t.integer :lft
|
44
|
+
t.integer :rgt
|
45
|
+
t.integer :depth, default: 0
|
46
|
+
|
47
|
+
t.timestamps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ChangeCommentable < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
# Uncomment this. Add fields to Commentable Models
|
4
|
+
#
|
5
|
+
# [:users, :posts, :blogs, :articles, :pages].each do |table_name|
|
6
|
+
# change_table table_name do |t|
|
7
|
+
# t.integer :draft_comments_count, default: 0
|
8
|
+
# t.integer :published_comments_count, default: 0
|
9
|
+
# t.integer :deleted_comments_count, default: 0
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
← [documentation](documentation.md)
|
2
|
+
|
3
|
+
## Admin UI installation
|
4
|
+
|
5
|
+
### 1. Gems install
|
6
|
+
|
7
|
+
**Gemfile**
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# TheComments base
|
11
|
+
gem 'the_comments', "~> 2.0"
|
12
|
+
|
13
|
+
gem 'haml' # or gem 'slim'
|
14
|
+
gem 'awesome_nested_set' # or same gem
|
15
|
+
|
16
|
+
# TheComments Admin UI gems
|
17
|
+
|
18
|
+
# pagination
|
19
|
+
gem 'kaminari'
|
20
|
+
|
21
|
+
# bootstrap 3
|
22
|
+
gem 'bootstrap-sass', github: 'thomas-mcdonald/bootstrap-sass'
|
23
|
+
```
|
24
|
+
|
25
|
+
**Bundle**
|
26
|
+
|
27
|
+
```
|
28
|
+
bundle
|
29
|
+
```
|
30
|
+
|
31
|
+
### 2. Assets install
|
32
|
+
|
33
|
+
**app/assets/stylesheets/admin_ui.css**
|
34
|
+
|
35
|
+
```css
|
36
|
+
/*
|
37
|
+
*= require bootstrap
|
38
|
+
*/
|
39
|
+
```
|
40
|
+
|
41
|
+
**app/assets/javascripts/admin_ui.js**
|
42
|
+
|
43
|
+
```js
|
44
|
+
//= require jquery
|
45
|
+
//= require jquery_ujs
|
46
|
+
|
47
|
+
//= require bootstrap
|
48
|
+
//= require the_comments_manage
|
49
|
+
```
|
50
|
+
|
51
|
+
### 3. Admin layout
|
52
|
+
|
53
|
+
You can use following yields to insert TheComments management tools in your Layout.
|
54
|
+
|
55
|
+
```haml
|
56
|
+
= yield :comments_sidebar
|
57
|
+
= yield :comments_main
|
58
|
+
```
|
59
|
+
|
60
|
+
For example:
|
61
|
+
|
62
|
+
```haml
|
63
|
+
!!! 5
|
64
|
+
%html(lang="en")
|
65
|
+
%head
|
66
|
+
%meta(charset="utf-8")
|
67
|
+
%meta(http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1")
|
68
|
+
%meta(name="viewport" content="width=device-width, initial-scale=1.0")
|
69
|
+
%title= content_for?(:title) ? yield(:title) : "Admin Panel"
|
70
|
+
%link(href="favicon.ico" rel="shortcut icon")
|
71
|
+
|
72
|
+
= stylesheet_link_tag :admin_ui
|
73
|
+
= javascript_include_tag :admin_ui
|
74
|
+
= csrf_meta_tags
|
75
|
+
|
76
|
+
%body
|
77
|
+
.container
|
78
|
+
.row
|
79
|
+
.col-md-12
|
80
|
+
%h3= content_for?(:title) ? yield(:title) : "Admin Panel"
|
81
|
+
.row
|
82
|
+
.col-md-3= yield :comments_sidebar
|
83
|
+
.col-md-9= yield :comments_main
|
84
|
+
|
85
|
+
= stylesheet_link_tag "//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css"
|
86
|
+
```
|
87
|
+
|
88
|
+
### 4. Comments controller modifications
|
89
|
+
|
90
|
+
by default your comments controller looks like this:
|
91
|
+
|
92
|
+
**app/controllers/comments_controller.rb**
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
class CommentsController < ApplicationController
|
96
|
+
# layout 'admin'
|
97
|
+
|
98
|
+
# Define your restrict methods and use them like this:
|
99
|
+
#
|
100
|
+
# before_action :user_required, except: %w[index create]
|
101
|
+
# before_action :owner_required, except: %w[index create]
|
102
|
+
# before_action :admin_required, only: %w[total_draft total_published total_deleted total_spam]
|
103
|
+
|
104
|
+
include TheComments::Controller
|
105
|
+
|
106
|
+
# >>> include TheComments::Controller <<<
|
107
|
+
# (!) Almost all methods based on *current_user* method
|
108
|
+
#
|
109
|
+
# 1. Controller's public methods list:
|
110
|
+
# You can redifine it for your purposes
|
111
|
+
# public
|
112
|
+
# %w[ manage index create edit update ]
|
113
|
+
# %w[ my_comments my_draft my_published ]
|
114
|
+
# %w[ draft published deleted spam ]
|
115
|
+
# %w[ to_draft to_published to_deleted to_spam ]
|
116
|
+
# %w[ total_draft total_published total_deleted total_spam ]
|
117
|
+
#
|
118
|
+
#
|
119
|
+
# 2. Controller's private methods list:
|
120
|
+
# You can redifine it for your purposes
|
121
|
+
#
|
122
|
+
# private
|
123
|
+
# %w[ comment_template comment_partial ]
|
124
|
+
# %w[ denormalized_fields request_data_for_comment define_commentable ]
|
125
|
+
# %w[ comment_params patch_comment_params ]
|
126
|
+
# %w[ ajax_requests_required cookies_required ]
|
127
|
+
# %w[ empty_trap_required tolerance_time_required ]
|
128
|
+
|
129
|
+
# KAMINARI pagination:
|
130
|
+
# following methods based on gem "kaminari"
|
131
|
+
# You should redefine them if you use something else
|
132
|
+
#
|
133
|
+
# public
|
134
|
+
# %w[ manage index edit ]
|
135
|
+
# %w[ draft published deleted spam ]
|
136
|
+
# %w[ my_comments my_draft my_published ]
|
137
|
+
# %w[ total_draft total_published total_deleted total_spam ]
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
You must define protection methods to restrict access to Admin UI for regular users.
|
142
|
+
|
143
|
+
### 5. Visit Admin UI
|
144
|
+
|
145
|
+
**localhost:3000/comments/manage**
|
@@ -0,0 +1,182 @@
|
|
1
|
+
← [documentation](documentation.md)
|
2
|
+
|
3
|
+
## Advanced Installation
|
4
|
+
|
5
|
+
### 1. Gems install
|
6
|
+
|
7
|
+
**Gemfile**
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'the_comments', "~> 2.0"
|
11
|
+
|
12
|
+
gem 'haml' # or gem 'slim'
|
13
|
+
gem 'awesome_nested_set' # or same gem
|
14
|
+
```
|
15
|
+
|
16
|
+
**Bundle**
|
17
|
+
|
18
|
+
```
|
19
|
+
bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
### 2. Migrations install
|
23
|
+
|
24
|
+
**Copy migrations**
|
25
|
+
|
26
|
+
```
|
27
|
+
rake the_comments_engine:install:migrations
|
28
|
+
```
|
29
|
+
|
30
|
+
Will create:
|
31
|
+
|
32
|
+
* xxxxx_change_user.rb
|
33
|
+
* xxxxx_create_comments.rb
|
34
|
+
* xxxxx_change_commentable.rb
|
35
|
+
|
36
|
+
:warning: **Open and change xxxxx_change_commentable.rb migration**
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class ChangeCommentable < ActiveRecord::Migration
|
40
|
+
def change
|
41
|
+
# Additional fields to Commentable Models
|
42
|
+
# [:posts, :articles, ... ]
|
43
|
+
|
44
|
+
# There is only Post model is commentable
|
45
|
+
[:posts].each do |table_name|
|
46
|
+
change_table table_name do |t|
|
47
|
+
t.integer :draft_comments_count, default: 0
|
48
|
+
t.integer :published_comments_count, default: 0
|
49
|
+
t.integer :deleted_comments_count, default: 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
**Invoke migrations**
|
57
|
+
|
58
|
+
```
|
59
|
+
rake db:migrate
|
60
|
+
```
|
61
|
+
|
62
|
+
### 3. Code install
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
rails g the_comments install
|
66
|
+
```
|
67
|
+
|
68
|
+
Will create:
|
69
|
+
|
70
|
+
* config/initializers/the_comments.rb
|
71
|
+
* app/controllers/comments_controller.rb
|
72
|
+
* app/models/comment.rb
|
73
|
+
|
74
|
+
:warning: **Open each file and follow an instructions**
|
75
|
+
|
76
|
+
### 4. Models modifictions
|
77
|
+
|
78
|
+
**app/models/user.rb**
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class User < ActiveRecord::Base
|
82
|
+
include TheComments::User
|
83
|
+
|
84
|
+
has_many :posts
|
85
|
+
|
86
|
+
# Your way to define privileged users
|
87
|
+
def admin?
|
88
|
+
self == User.first
|
89
|
+
end
|
90
|
+
|
91
|
+
# Required TheComments methods for users restrictions
|
92
|
+
def comments_admin?
|
93
|
+
admin?
|
94
|
+
end
|
95
|
+
|
96
|
+
def comments_moderator? comment
|
97
|
+
id == comment.holder_id
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
**app/models/post.rb**
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
class Post < ActiveRecord::Base
|
106
|
+
include TheComments::Commentable
|
107
|
+
|
108
|
+
belongs_to :user
|
109
|
+
|
110
|
+
# Denormalization methods
|
111
|
+
# Migration: t.string :title
|
112
|
+
# => "My new awesome post"
|
113
|
+
def commentable_title
|
114
|
+
try(:title) || "Undefined post title"
|
115
|
+
end
|
116
|
+
|
117
|
+
# => your way to build URL
|
118
|
+
# => "/posts/254"
|
119
|
+
def commentable_url
|
120
|
+
['', self.class.to_s.tableize, id].join('/')
|
121
|
+
end
|
122
|
+
|
123
|
+
# gem 'state_machine'
|
124
|
+
# Migration: t.string :state
|
125
|
+
# => "published" | "draft" | "deleted"
|
126
|
+
def commentable_state
|
127
|
+
try(:state) || "published"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
132
|
+
### 5. Mount Engine routes
|
133
|
+
|
134
|
+
**config/routes.rb**
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
MyApp::Application.routes.draw do
|
138
|
+
root 'posts#index'
|
139
|
+
resources :posts
|
140
|
+
|
141
|
+
# ...
|
142
|
+
|
143
|
+
mount TheComments::Engine => '/', as: :comments
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
147
|
+
Please, read [documentation](docs/documentation.md) to learn more
|
148
|
+
|
149
|
+
### 6. Assets install
|
150
|
+
|
151
|
+
**app/assets/stylesheets/application.css**
|
152
|
+
|
153
|
+
```css
|
154
|
+
/*
|
155
|
+
*= require the_comments
|
156
|
+
*/
|
157
|
+
```
|
158
|
+
|
159
|
+
**app/assets/javascripts/application.js**
|
160
|
+
|
161
|
+
```js
|
162
|
+
//= require the_comments
|
163
|
+
```
|
164
|
+
|
165
|
+
### 7. Controller code example
|
166
|
+
|
167
|
+
**app/controllers/posts_controllers.rb**
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
def show
|
171
|
+
@post = Post.find params[:id]
|
172
|
+
@comments = @post.comments.with_state([:draft, :published])
|
173
|
+
end
|
174
|
+
```
|
175
|
+
|
176
|
+
### 8. View code example
|
177
|
+
|
178
|
+
**app/views/posts/show.html.haml**
|
179
|
+
|
180
|
+
```haml
|
181
|
+
= render partial: 'the_comments/tree', locals: { commentable: @post, comments_tree: @comments }
|
182
|
+
```
|
data/docs/comment_api.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
← [documentation](documentation.md)
|
2
|
+
|
3
|
+
### Comment API
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
@comment = Comment.last
|
7
|
+
|
8
|
+
# Comment creator, can be nil (for Guest)
|
9
|
+
@comment.user # => User
|
10
|
+
|
11
|
+
# Comment holder
|
12
|
+
# Owner of commentable object
|
13
|
+
# shouldn't be nil, should be defined on create
|
14
|
+
@comment.holder # => User
|
15
|
+
|
16
|
+
# Commentable object
|
17
|
+
@comment.commentable # => Post
|
18
|
+
|
19
|
+
# Raw user input
|
20
|
+
@comment.raw_content
|
21
|
+
|
22
|
+
# Processed user input
|
23
|
+
# method *prepare_content* should be redefined by developer
|
24
|
+
@comment.content
|
25
|
+
|
26
|
+
# Denormalization fields
|
27
|
+
@comment.commentable_title # => "Harum sint error odit."
|
28
|
+
@comment.commentable_url # => "/posts/7"
|
29
|
+
@comment.commentable_state # => "published"
|
30
|
+
|
31
|
+
# Stat info from request
|
32
|
+
# Can be used for spam detection
|
33
|
+
@comment.user_agent # => Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.10
|
34
|
+
@comment.tolerance_time # => 5 (secs)
|
35
|
+
@comment.referer # => localhost:3000/post/7
|
36
|
+
@comment.ip # => 192.168.0.12
|
37
|
+
|
38
|
+
# State
|
39
|
+
@comment.state # => draft | published | deleted
|
40
|
+
|
41
|
+
# Spam flag
|
42
|
+
@comment.spam # => true
|
43
|
+
|
44
|
+
# Alias for *mark_as_spam*
|
45
|
+
@comment.to_spam
|
46
|
+
|
47
|
+
# mark this comment and all descendants as spam/not spam
|
48
|
+
@comment.mark_as_spam
|
49
|
+
@comment.mark_as_not_spam
|
50
|
+
|
51
|
+
# Comment's creator avatar
|
52
|
+
# this method can be redefined by developer
|
53
|
+
@comment.avatar_url # => "https://2.gravatar.com/avatar/015e ... 2f05?s=42&d=https://identicons.github.com/AVATAR.png"
|
54
|
+
|
55
|
+
# Anchor of comment
|
56
|
+
# this method can be redefined by developer
|
57
|
+
@comment.anchor # => b58020
|
58
|
+
```
|