fuck_comments 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +30 -0
  3. data/.ruby-gemset.example +1 -0
  4. data/.ruby-version.example +1 -0
  5. data/.rvmrc.example +1 -0
  6. data/.travis.yml +5 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +338 -0
  10. data/Rakefile +1 -0
  11. data/app/assets/javascripts/the_comments.js.coffee +108 -0
  12. data/app/assets/javascripts/the_comments_manage.js.coffee +27 -0
  13. data/app/assets/stylesheets/the_comments.css.scss +248 -0
  14. data/app/controllers/_templates_/comments_controller.rb +44 -0
  15. data/app/controllers/concerns/the_comments/controller.rb +197 -0
  16. data/app/controllers/concerns/the_comments/view_token.rb +20 -0
  17. data/app/helpers/render_comments_tree_helper.rb +111 -0
  18. data/app/models/_templates_/comment.rb +38 -0
  19. data/app/models/concerns/the_comments/comment.rb +116 -0
  20. data/app/models/concerns/the_comments/comment_states.rb +80 -0
  21. data/app/models/concerns/the_comments/commentable.rb +69 -0
  22. data/app/models/concerns/the_comments/user.rb +56 -0
  23. data/app/views/the_comments/_tree.html.erb +3 -0
  24. data/app/views/the_comments/haml/_additional_info.html.haml +13 -0
  25. data/app/views/the_comments/haml/_comment.html.haml +1 -0
  26. data/app/views/the_comments/haml/_comment_body.html.haml +25 -0
  27. data/app/views/the_comments/haml/_comment_edit.html.haml +26 -0
  28. data/app/views/the_comments/haml/_form.html.haml +8 -0
  29. data/app/views/the_comments/haml/_guest_form.html.haml +22 -0
  30. data/app/views/the_comments/haml/_logined_form.html.haml +18 -0
  31. data/app/views/the_comments/haml/_manage_controls.html.haml +30 -0
  32. data/app/views/the_comments/haml/_sidebar.html.haml +9 -0
  33. data/app/views/the_comments/haml/_sidebar_admin.html.haml +12 -0
  34. data/app/views/the_comments/haml/_sidebar_backlink.html.haml +3 -0
  35. data/app/views/the_comments/haml/_sidebar_user.html.haml +29 -0
  36. data/app/views/the_comments/haml/_tree.html.haml +16 -0
  37. data/app/views/the_comments/haml/manage.html.haml +26 -0
  38. data/app/views/the_comments/slim/_additional_info.html.slim +13 -0
  39. data/app/views/the_comments/slim/_comment.html.slim +1 -0
  40. data/app/views/the_comments/slim/_comment_body.html.slim +24 -0
  41. data/app/views/the_comments/slim/_comment_edit.html.slim +26 -0
  42. data/app/views/the_comments/slim/_form.html.slim +8 -0
  43. data/app/views/the_comments/slim/_guest_form.html.slim +22 -0
  44. data/app/views/the_comments/slim/_logined_form.html.slim +18 -0
  45. data/app/views/the_comments/slim/_manage_controls.html.slim +30 -0
  46. data/app/views/the_comments/slim/_sidebar.html.slim +9 -0
  47. data/app/views/the_comments/slim/_sidebar_admin.html.slim +12 -0
  48. data/app/views/the_comments/slim/_sidebar_backlink.html.slim +3 -0
  49. data/app/views/the_comments/slim/_sidebar_user.html.slim +29 -0
  50. data/app/views/the_comments/slim/_tree.html.slim +16 -0
  51. data/app/views/the_comments/slim/index.html.slim +18 -0
  52. data/app/views/the_comments/slim/manage.html.slim +26 -0
  53. data/app/views/the_comments/slim/my_comments.html.slim +28 -0
  54. data/config/initializers/the_comments.rb +15 -0
  55. data/config/locales/en.yml +68 -0
  56. data/config/locales/ru.yml +71 -0
  57. data/config/routes.rb +38 -0
  58. data/db/migrate/20130101010101_the_comments_change_user.rb +18 -0
  59. data/db/migrate/20130101010102_the_comments_create_comments.rb +50 -0
  60. data/db/migrate/20130101010103_the_comments_change_commentable.rb +13 -0
  61. data/docs/admin_ui_installation.md +145 -0
  62. data/docs/advanced_installation.md +185 -0
  63. data/docs/comment_api.md +58 -0
  64. data/docs/commentable_api.md +59 -0
  65. data/docs/config_file.md +27 -0
  66. data/docs/content_preprocessors.md +73 -0
  67. data/docs/customazation_of_views.md +30 -0
  68. data/docs/denormalization_and_recent_comments.md +40 -0
  69. data/docs/documentation.md +29 -0
  70. data/docs/generators.md +74 -0
  71. data/docs/pagination.md +123 -0
  72. data/docs/routes.md +77 -0
  73. data/docs/screencast.jpg +0 -0
  74. data/docs/the_comments.jpg +0 -0
  75. data/docs/the_comments_view_1.gif +0 -0
  76. data/docs/the_comments_view_2.gif +0 -0
  77. data/docs/the_comments_view_3.gif +0 -0
  78. data/docs/the_comments_view_4.gif +0 -0
  79. data/docs/the_comments_view_5.gif +0 -0
  80. data/docs/user_api.md +75 -0
  81. data/docs/what_is_comcoms.md +63 -0
  82. data/docs/whats_wrong_with_other_gems.md +28 -0
  83. data/docs/where_is_example_application.md +37 -0
  84. data/gem_version.rb +3 -0
  85. data/lib/generators/the_comments/USAGE +44 -0
  86. data/lib/generators/the_comments/the_comments_generator.rb +56 -0
  87. data/lib/generators/the_comments/views_generator.rb +79 -0
  88. data/lib/the_comments/config.rb +39 -0
  89. data/lib/the_comments/version.rb +1 -0
  90. data/lib/the_comments.rb +27 -0
  91. data/spec/dummy_app/.gitignore +18 -0
  92. data/spec/dummy_app/.rspec +1 -0
  93. data/spec/dummy_app/Gemfile +43 -0
  94. data/spec/dummy_app/README.md +33 -0
  95. data/spec/dummy_app/Rakefile +6 -0
  96. data/spec/dummy_app/app/assets/images/.keep +0 -0
  97. data/spec/dummy_app/app/assets/javascripts/admin_panel.js +5 -0
  98. data/spec/dummy_app/app/assets/javascripts/application.js +16 -0
  99. data/spec/dummy_app/app/assets/stylesheets/admin_panel.css +3 -0
  100. data/spec/dummy_app/app/assets/stylesheets/app.css.scss +4 -0
  101. data/spec/dummy_app/app/assets/stylesheets/application.css +16 -0
  102. data/spec/dummy_app/app/controllers/application_controller.rb +7 -0
  103. data/spec/dummy_app/app/controllers/comments_controller.rb +28 -0
  104. data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
  105. data/spec/dummy_app/app/controllers/posts_controller.rb +13 -0
  106. data/spec/dummy_app/app/controllers/users_controller.rb +7 -0
  107. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  108. data/spec/dummy_app/app/mailers/.keep +0 -0
  109. data/spec/dummy_app/app/models/.keep +0 -0
  110. data/spec/dummy_app/app/models/comment.rb +32 -0
  111. data/spec/dummy_app/app/models/concerns/.keep +0 -0
  112. data/spec/dummy_app/app/models/post.rb +17 -0
  113. data/spec/dummy_app/app/models/user.rb +21 -0
  114. data/spec/dummy_app/app/views/layouts/admin.html.haml +25 -0
  115. data/spec/dummy_app/app/views/layouts/application.html.haml +20 -0
  116. data/spec/dummy_app/app/views/posts/index.html.haml +22 -0
  117. data/spec/dummy_app/app/views/posts/show.html.haml +7 -0
  118. data/spec/dummy_app/bin/bundle +3 -0
  119. data/spec/dummy_app/bin/rails +4 -0
  120. data/spec/dummy_app/bin/rake +4 -0
  121. data/spec/dummy_app/config/application.rb +23 -0
  122. data/spec/dummy_app/config/boot.rb +4 -0
  123. data/spec/dummy_app/config/database.yml +11 -0
  124. data/spec/dummy_app/config/environment.rb +5 -0
  125. data/spec/dummy_app/config/environments/development.rb +29 -0
  126. data/spec/dummy_app/config/environments/production.rb +80 -0
  127. data/spec/dummy_app/config/environments/test.rb +36 -0
  128. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  129. data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
  130. data/spec/dummy_app/config/initializers/inflections.rb +16 -0
  131. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  132. data/spec/dummy_app/config/initializers/secret_token.rb +12 -0
  133. data/spec/dummy_app/config/initializers/session_store.rb +3 -0
  134. data/spec/dummy_app/config/initializers/sorcery.rb +437 -0
  135. data/spec/dummy_app/config/initializers/the_comments.rb +15 -0
  136. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  137. data/spec/dummy_app/config/locales/en.yml +23 -0
  138. data/spec/dummy_app/config/routes.rb +19 -0
  139. data/spec/dummy_app/config.ru +4 -0
  140. data/spec/dummy_app/db/migrate/20130712061503_sorcery_core.rb +16 -0
  141. data/spec/dummy_app/db/migrate/20130712065951_create_posts.rb +11 -0
  142. data/spec/dummy_app/db/migrate/20131027185332_change_user.the_comments_engine.rb +19 -0
  143. data/spec/dummy_app/db/migrate/20131027185333_create_comments.the_comments_engine.rb +51 -0
  144. data/spec/dummy_app/db/migrate/20131027185334_change_commentable.the_comments_engine.rb +14 -0
  145. data/spec/dummy_app/db/schema.rb +74 -0
  146. data/spec/dummy_app/db/seeds.rb +42 -0
  147. data/spec/dummy_app/lib/assets/.keep +0 -0
  148. data/spec/dummy_app/lib/tasks/.keep +0 -0
  149. data/spec/dummy_app/lib/tasks/app_bootstrap.rake +15 -0
  150. data/spec/dummy_app/log/.keep +0 -0
  151. data/spec/dummy_app/public/404.html +58 -0
  152. data/spec/dummy_app/public/422.html +58 -0
  153. data/spec/dummy_app/public/500.html +57 -0
  154. data/spec/dummy_app/public/favicon.ico +0 -0
  155. data/spec/dummy_app/public/robots.txt +5 -0
  156. data/spec/dummy_app/spec/factories/post.rb +6 -0
  157. data/spec/dummy_app/spec/factories/user.rb +6 -0
  158. data/spec/dummy_app/spec/models/user_counters_spec.rb +339 -0
  159. data/spec/dummy_app/spec/spec_helper.rb +29 -0
  160. data/spec/dummy_app/test/controllers/.keep +0 -0
  161. data/spec/dummy_app/test/fixtures/.keep +0 -0
  162. data/spec/dummy_app/test/helpers/.keep +0 -0
  163. data/spec/dummy_app/test/integration/.keep +0 -0
  164. data/spec/dummy_app/test/mailers/.keep +0 -0
  165. data/spec/dummy_app/test/models/.keep +0 -0
  166. data/spec/dummy_app/test/test_helper.rb +15 -0
  167. data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
  168. data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
  169. data/the_comments.gemspec +23 -0
  170. data/views_converter.rb +16 -0
  171. metadata +332 -0
@@ -0,0 +1,3 @@
1
+ p= link_to t('the_comments.nav.to_root'), root_path
2
+ p= link_to t('the_comments.nav.all_incoming'), manage_comments_url
3
+ hr
@@ -0,0 +1,29 @@
1
+ - cuser = current_user
2
+
3
+ h5=t 'the_comments.written_by_me', num: cuser.my_comments.count
4
+
5
+ p= link_to t("the_comments.published_comments", num: cuser.my_published_comments.count), [:my_published, :comments], class: 'btn btn-success btn-sm'
6
+ p= link_to t("the_comments.draft_comments", num: cuser.my_draft_comments.count), [:my_draft, :comments], class: 'btn btn-info btn-sm'
7
+
8
+ p
9
+ - if cuser.comments_admin?
10
+ = link_to t("the_comments.deleted_comments", num: cuser.my_deleted_comments.count), [:my_deleted, :comments], class: 'btn btn-default btn-sm'
11
+ = link_to t("the_comments.spam_comments", num: cuser.my_spam_comments.count), [:my_spam, :comments], class: 'btn btn-default btn-sm'
12
+ - else
13
+ span.btn.btn-default.btn-sm= t("the_comments.deleted_comments", num: cuser.my_deleted_comments.count)
14
+ span.btn.btn-default.btn-sm= t("the_comments.spam_comments", num: cuser.my_spam_comments.count)
15
+
16
+ br
17
+ h5= t 'the_comments.for_my_posts', num: cuser.comcoms.count
18
+
19
+ p= link_to t("the_comments.published_comments", num: cuser.published_comcoms_count), [:published, :comments], class: 'btn btn-success btn-sm'
20
+ p= link_to t("the_comments.draft_comments", num: cuser.draft_comcoms_count), [:draft, :comments], class: 'btn btn-info btn-sm'
21
+ p
22
+ - if cuser.comments_admin?
23
+ = link_to t("the_comments.deleted_comments", num: cuser.deleted_comcoms_count), [:deleted, :comments], class: 'btn btn-default btn-sm'
24
+ = link_to t("the_comments.spam_comments", num: cuser.spam_comcoms_count), [:spam, :comments], class: 'btn btn-default btn-sm'
25
+ - else
26
+ span.btn.btn-default.btn-sm= t("the_comments.deleted_comments", num: cuser.deleted_comcoms_count)
27
+ span.btn.btn-default.btn-sm= t("the_comments.spam_comments", num: cuser.spam_comcoms_count)
28
+
29
+
@@ -0,0 +1,16 @@
1
+ - if commentable.comments_on?
2
+ h4.comments_sum
3
+ - if commentable.comments_sum.zero?
4
+ | Вы можете стать первым, кто оставит комментарий!
5
+ - else
6
+ | Комментариев: #{ commentable.comments_sum }
7
+
8
+ - unless current_user
9
+ .comments_description
10
+ p &mdash; Комментарий можно оставить <b>без регистрации</b>, для этого достаточно заполнить одно обязательное поле <b class='nobr'>Текст комментария</b>. Анонимные комментарии проходят модерацию и до момента одобрения видны только в браузере автора
11
+ p &mdash; Комментарии зарегистрированных пользователей публикуются сразу после создания
12
+
13
+ .comments#comments
14
+ ol.comments_tree data: { comments: { tolarance_time: TheComments.config.tolerance_time } }
15
+ = render partial: 'the_comments/slim/comment', locals: { tree: comments_tree }
16
+ = render partial: 'the_comments/slim/form', locals: { commentable: commentable }
@@ -0,0 +1,18 @@
1
+ - content_for :title do
2
+ = t "the_comments.management"
3
+
4
+ - content_for :comments_sidebar do
5
+ = render partial: 'the_comments/slim/sidebar'
6
+
7
+ - content_for :comments_main do
8
+ = paginate @comments
9
+
10
+ .comments
11
+ - @comments.each do |comment|
12
+ - klass = { published: :success, draft: :info, deleted: :danger }[comment.state.to_sym]
13
+ .panel class: "panel-#{klass}"
14
+ .panel-heading= comment.header_title
15
+ .panel-body
16
+ = render partial: 'the_comments/slim/comment_body', locals: { comment: comment }
17
+
18
+ = paginate @comments
@@ -0,0 +1,26 @@
1
+ - content_for :title do
2
+ = t "the_comments.management"
3
+
4
+ - content_for :comments_sidebar do
5
+ = render partial: 'the_comments/slim/sidebar'
6
+
7
+ - content_for :comments_main do
8
+ = paginate @comments
9
+
10
+ - if @comments.blank?
11
+ .alert.alert-info= t 'the_comments.no_comments_here'
12
+
13
+ .comments
14
+ - @comments.each do |comment|
15
+ - klass = { published: :success, draft: :info, deleted: :danger }[comment.state.to_sym]
16
+ .panel class: "panel-#{klass}"
17
+ .panel-heading= comment.header_title
18
+ .panel-body
19
+ = render partial: 'the_comments/slim/comment_body', locals: { comment: comment }
20
+
21
+ - if current_user.comments_admin?
22
+ = render partial: 'the_comments/slim/comment_edit', locals: { comment: comment }
23
+ = render partial: 'the_comments/slim/manage_controls', locals: { comment: comment }
24
+ = render partial: 'the_comments/slim/additional_info', locals: { comment: comment }
25
+
26
+ = paginate @comments
@@ -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
@@ -0,0 +1,15 @@
1
+ # TheComments.config.param_name => value
2
+
3
+ TheComments.configure do |config|
4
+ config.max_reply_depth = 3 # comments tree depth
5
+ config.tolerance_time = 10 # sec - after this delay user can post a comment
6
+ config.default_state = :draft # default state for comment
7
+ config.default_owner_state = :published # default state for comment for Moderator
8
+ config.empty_inputs = [:commentBody] # array of spam trap fields
9
+ config.default_title = 'Undefined title' # default commentable_title for denormalization
10
+ config.template_engine = :haml
11
+
12
+ config.empty_trap_protection = true
13
+ config.tolerance_time_protection = true
14
+ config.cookie_domain = :all
15
+ end
@@ -0,0 +1,68 @@
1
+ en:
2
+ activerecord:
3
+ attributes:
4
+ comment:
5
+ raw_content: Content
6
+ errors:
7
+ models:
8
+ comment:
9
+ attributes:
10
+ raw_content:
11
+ blank: 'should not be empty'
12
+ # blank: '%{attribute} should not be empty'
13
+
14
+ the_comments:
15
+ incoming: "Incoming:"
16
+ in_system: "In system:"
17
+ written_by_me: "Written by me:"
18
+ back_to_root: "&larr; To root"
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})"
25
+
26
+ management: Comments management
27
+ new: "New comment"
28
+ update: "Update comment"
29
+ additional_info: "Additional info"
30
+ cancel: "Cancel"
31
+
32
+ title: "Title on name:"
33
+ contacts: "Contacts:"
34
+ content: "Message:"
35
+
36
+ guest_name: Guest
37
+ reply: Reply to this comment
38
+ edit: Edit
39
+ to_spam: Spam!
40
+ to_draft: Draft
41
+ to_published: Publicate
42
+ to_deleted: Delete
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
+
62
+ delete_confirm: Are you sure?
63
+
64
+ cookies: Cookies
65
+ cookies_required: 'Please enable cookies and try to reload page'
66
+ ajax_requests_required: 'Sorry, JavaScript/Ajax Requests required'
67
+ waiting_for_moderation: Waiting for moderation
68
+ undefined_commentable: Commentable object is undefined
@@ -0,0 +1,71 @@
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: "Все в системе: %{num}"
16
+ written_by_me: "Написаны мной: %{num}"
17
+ for_my_posts: "К моим постам: %{num}"
18
+ back_to_root: "&larr; На главную"
19
+
20
+ my_comments: "Мои комментарии %{num}"
21
+ draft_comments: "На модерации: %{num}"
22
+ published_comments: "Опубликованы: %{num}"
23
+ deleted_comments: "Удалены: %{num}"
24
+ spam_comments: "Спам: %{num}"
25
+
26
+ waiting_for_moderation: Комментарий ожидает проверки
27
+ management: Управление комментариями
28
+ new: "Написать новый комментарий"
29
+ update: "Обновить"
30
+ additional_info: "Подробнее"
31
+ cancel: "Отмена"
32
+
33
+ title: "Имя или тема:"
34
+ contacts: "Контакты:"
35
+ content: "Сообщение:"
36
+
37
+ guest_name: Гость
38
+ reply: Ответить на этот комментарий
39
+ edit: Править
40
+ to_spam: Спам!
41
+ to_draft: Черновик
42
+ to_published: Публиковать
43
+ to_deleted: Удалить
44
+
45
+ no_comments_here: Здесь нет комментариев
46
+
47
+ nav:
48
+ header: Комментарии
49
+ to_root: На главную
50
+ all_incoming: Все входящие
51
+
52
+ form:
53
+ title: "Ваше имя:"
54
+ contacts: "Контакты (не отображаются на сайте):"
55
+ content: "Текст комментария* :"
56
+ create: "Отправить комментарий"
57
+ thank_you: "Спaсибо!"
58
+
59
+ trap: Ловушка
60
+ trap_message: Должна быть пустой
61
+
62
+ tolerance_time: Просмотр времени
63
+ tolerance_time_message: "Пожалуйста ожидайте %{time} сек. перед отправкой сообщения"
64
+
65
+ cookies: Куки
66
+ cookies_required: 'Включите куки и перезагрузите страницу'
67
+
68
+ delete_confirm: Вы уверены?
69
+ waiting_for_moderation: Ожидает модерации
70
+ ajax_requests_required: 'Извините, ожидается JavaScript/Ajax запрос'
71
+ undefined_commentable: Комментируемый объект не определен
data/config/routes.rb ADDED
@@ -0,0 +1,38 @@
1
+ module TheComments
2
+ class UserRoutes
3
+ def call mapper, options = {}
4
+ mapper.collection do
5
+ mapper.get :manage
6
+ mapper.get :my_comments
7
+
8
+ mapper.get :my_draft
9
+ mapper.get :my_published
10
+ mapper.get :my_deleted
11
+ mapper.get :my_spam
12
+
13
+ mapper.get :draft
14
+ mapper.get :published
15
+ mapper.get :deleted
16
+ mapper.get :spam
17
+ end
18
+
19
+ mapper.member do
20
+ mapper.post :to_spam
21
+ mapper.post :to_draft
22
+ mapper.post :to_published
23
+ mapper.delete :to_deleted
24
+ end
25
+ end
26
+ end
27
+
28
+ class AdminRoutes
29
+ def call mapper, options = {}
30
+ mapper.collection do
31
+ mapper.get :total_draft
32
+ mapper.get :total_published
33
+ mapper.get :total_deleted
34
+ mapper.get :total_spam
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ # null: false => de-facto db-level validation
2
+ class TheCommentsChangeUser < 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 TheCommentsCreateComments < 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 TheCommentsChangeCommentable < 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
+ &larr; &nbsp; [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**