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.
Files changed (172) hide show
  1. data/.rvmrc.example +1 -0
  2. data/.travis.yml +5 -0
  3. data/README.md +105 -425
  4. data/app/assets/javascripts/the_comments.js.coffee +12 -9
  5. data/app/assets/javascripts/the_comments_manage.js.coffee +19 -49
  6. data/app/assets/stylesheets/the_comments.css.scss +20 -29
  7. data/app/controllers/_templates_/comments_controller.rb +44 -0
  8. data/app/controllers/concerns/controller.rb +216 -0
  9. data/app/helpers/render_comments_tree_helper.rb +4 -7
  10. data/app/models/_templates_/comment.rb +38 -0
  11. data/app/models/concerns/comment.rb +103 -0
  12. data/app/models/concerns/comment_states.rb +80 -0
  13. data/app/models/concerns/commentable.rb +69 -0
  14. data/app/models/concerns/user.rb +52 -0
  15. data/app/views/the_comments/_tree.html.erb +3 -0
  16. data/app/views/the_comments/haml/_additional_info.html.haml +13 -0
  17. data/app/views/the_comments/{_comment.html.haml → haml/_comment.html.haml} +0 -0
  18. data/app/views/the_comments/haml/_comment_body.html.haml +20 -0
  19. data/app/views/the_comments/haml/_comment_edit.html.haml +26 -0
  20. data/app/views/the_comments/{_form.html.haml → haml/_form.html.haml} +8 -6
  21. data/app/views/the_comments/haml/_manage_controls.html.haml +27 -0
  22. data/app/views/the_comments/haml/_sidebar.html.haml +28 -0
  23. data/app/views/the_comments/haml/_tree.html.haml +4 -0
  24. data/app/views/the_comments/haml/index.html.haml +18 -0
  25. data/app/views/the_comments/haml/manage.html.haml +25 -0
  26. data/app/views/the_comments/haml/my_comments.html.haml +28 -0
  27. data/app/views/the_comments/slim/_additional_info.html.slim +13 -0
  28. data/app/views/the_comments/slim/_comment.html.slim +1 -0
  29. data/app/views/the_comments/slim/_comment_body.html.slim +20 -0
  30. data/app/views/the_comments/slim/_comment_edit.html.slim +26 -0
  31. data/app/views/the_comments/slim/_form.html.slim +27 -0
  32. data/app/views/the_comments/slim/_manage_controls.html.slim +27 -0
  33. data/app/views/the_comments/slim/_sidebar.html.slim +28 -0
  34. data/app/views/the_comments/slim/_tree.html.slim +4 -0
  35. data/app/views/the_comments/slim/index.html.slim +18 -0
  36. data/app/views/the_comments/slim/manage.html.slim +25 -0
  37. data/app/views/the_comments/slim/my_comments.html.slim +28 -0
  38. data/{lib/generators/the_comments/templates → config/initializers}/the_comments.rb +3 -0
  39. data/config/locales/en.yml +39 -14
  40. data/config/locales/ru.yml +67 -0
  41. data/config/routes.rb +17 -13
  42. data/db/migrate/20130101010101_change_user.rb +18 -0
  43. data/db/migrate/20130101010102_create_comments.rb +50 -0
  44. data/db/migrate/20130101010103_change_commentable.rb +13 -0
  45. data/docs/admin_ui_installation.md +145 -0
  46. data/docs/advanced_installation.md +182 -0
  47. data/docs/comment_api.md +58 -0
  48. data/docs/commentable_api.md +59 -0
  49. data/docs/config_file.md +27 -0
  50. data/docs/content_preprocessors.md +73 -0
  51. data/docs/customazation_of_views.md +30 -0
  52. data/docs/denormalization_and_recent_comments.md +40 -0
  53. data/docs/documentation.md +28 -0
  54. data/docs/mountable_routes.md +80 -0
  55. data/docs/pagination.md +123 -0
  56. data/docs/screencast.jpg +0 -0
  57. data/docs/user_api.md +75 -0
  58. data/docs/what_is_comcoms.md +63 -0
  59. data/docs/whats_wrong_with_other_gems.md +18 -0
  60. data/docs/where_is_example_application.md +37 -0
  61. data/gem_version.rb +3 -0
  62. data/lib/generators/the_comments/USAGE +31 -20
  63. data/lib/generators/the_comments/the_comments_generator.rb +35 -18
  64. data/lib/generators/the_comments/views_generator.rb +52 -16
  65. data/lib/the_comments/config.rb +14 -1
  66. data/lib/the_comments/version.rb +1 -3
  67. data/lib/the_comments.rb +10 -0
  68. data/spec/dummy_app/.gitignore +17 -0
  69. data/spec/dummy_app/.rspec +1 -0
  70. data/spec/dummy_app/.ruby-gemset +1 -0
  71. data/spec/dummy_app/.ruby-version +1 -0
  72. data/spec/dummy_app/Gemfile +43 -0
  73. data/spec/dummy_app/README.md +50 -0
  74. data/spec/dummy_app/Rakefile +6 -0
  75. data/spec/dummy_app/app/assets/images/.keep +0 -0
  76. data/spec/dummy_app/app/assets/javascripts/admin_panel.js +5 -0
  77. data/spec/dummy_app/app/assets/javascripts/application.js +16 -0
  78. data/spec/dummy_app/app/assets/stylesheets/admin_panel.css +3 -0
  79. data/spec/dummy_app/app/assets/stylesheets/app.css.scss +4 -0
  80. data/spec/dummy_app/app/assets/stylesheets/application.css +16 -0
  81. data/spec/dummy_app/app/controllers/application_controller.rb +7 -0
  82. data/{lib/generators/the_comments/templates → spec/dummy_app/app/controllers}/comments_controller.rb +3 -1
  83. data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
  84. data/spec/dummy_app/app/controllers/posts_controller.rb +13 -0
  85. data/spec/dummy_app/app/controllers/users_controller.rb +7 -0
  86. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  87. data/spec/dummy_app/app/mailers/.keep +0 -0
  88. data/spec/dummy_app/app/models/.keep +0 -0
  89. data/spec/dummy_app/app/models/comment.rb +32 -0
  90. data/spec/dummy_app/app/models/concerns/.keep +0 -0
  91. data/spec/dummy_app/app/models/post.rb +17 -0
  92. data/spec/dummy_app/app/models/user.rb +21 -0
  93. data/spec/dummy_app/app/views/layouts/admin.html.haml +25 -0
  94. data/spec/dummy_app/app/views/layouts/application.html.haml +20 -0
  95. data/spec/dummy_app/app/views/posts/index.html.haml +22 -0
  96. data/spec/dummy_app/app/views/posts/show.html.haml +7 -0
  97. data/spec/dummy_app/bin/bundle +3 -0
  98. data/spec/dummy_app/bin/rails +4 -0
  99. data/spec/dummy_app/bin/rake +4 -0
  100. data/spec/dummy_app/config/application.rb +23 -0
  101. data/spec/dummy_app/config/boot.rb +4 -0
  102. data/spec/dummy_app/config/database.yml +11 -0
  103. data/spec/dummy_app/config/environment.rb +5 -0
  104. data/spec/dummy_app/config/environments/development.rb +29 -0
  105. data/spec/dummy_app/config/environments/production.rb +80 -0
  106. data/spec/dummy_app/config/environments/test.rb +36 -0
  107. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  108. data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
  109. data/spec/dummy_app/config/initializers/inflections.rb +16 -0
  110. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  111. data/spec/dummy_app/config/initializers/secret_token.rb +12 -0
  112. data/spec/dummy_app/config/initializers/session_store.rb +3 -0
  113. data/spec/dummy_app/config/initializers/sorcery.rb +437 -0
  114. data/spec/dummy_app/config/initializers/the_comments.rb +13 -0
  115. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  116. data/spec/dummy_app/config/locales/en.yml +23 -0
  117. data/spec/dummy_app/config/routes.rb +15 -0
  118. data/spec/dummy_app/config.ru +4 -0
  119. data/spec/dummy_app/db/migrate/20130712061503_sorcery_core.rb +16 -0
  120. data/spec/dummy_app/db/migrate/20130712065951_create_posts.rb +11 -0
  121. data/spec/dummy_app/db/migrate/20131027185332_change_user.the_comments_engine.rb +19 -0
  122. data/spec/dummy_app/db/migrate/20131027185333_create_comments.the_comments_engine.rb +51 -0
  123. data/spec/dummy_app/db/migrate/20131027185334_change_commentable.the_comments_engine.rb +14 -0
  124. data/spec/dummy_app/db/schema.rb +74 -0
  125. data/spec/dummy_app/db/seeds.rb +42 -0
  126. data/spec/dummy_app/lib/assets/.keep +0 -0
  127. data/spec/dummy_app/lib/tasks/.keep +0 -0
  128. data/spec/dummy_app/lib/tasks/app_bootstrap.rake +15 -0
  129. data/spec/dummy_app/log/.keep +0 -0
  130. data/spec/dummy_app/public/404.html +58 -0
  131. data/spec/dummy_app/public/422.html +58 -0
  132. data/spec/dummy_app/public/500.html +57 -0
  133. data/spec/dummy_app/public/favicon.ico +0 -0
  134. data/spec/dummy_app/public/robots.txt +5 -0
  135. data/spec/dummy_app/spec/factories/post.rb +6 -0
  136. data/spec/dummy_app/spec/factories/user.rb +6 -0
  137. data/spec/dummy_app/spec/models/user_counters_spec.rb +339 -0
  138. data/spec/dummy_app/spec/spec_helper.rb +29 -0
  139. data/spec/dummy_app/test/controllers/.keep +0 -0
  140. data/spec/dummy_app/test/fixtures/.keep +0 -0
  141. data/spec/dummy_app/test/helpers/.keep +0 -0
  142. data/spec/dummy_app/test/integration/.keep +0 -0
  143. data/spec/dummy_app/test/mailers/.keep +0 -0
  144. data/spec/dummy_app/test/models/.keep +0 -0
  145. data/spec/dummy_app/test/test_helper.rb +15 -0
  146. data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
  147. data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
  148. data/views_converter.rb +16 -0
  149. metadata +223 -45
  150. data/app/controllers/concerns/the_comments_controller.rb +0 -229
  151. data/app/controllers/concerns/the_comments_ip_controller.rb +0 -17
  152. data/app/controllers/concerns/the_comments_user_agent_controller.rb +0 -15
  153. data/app/models/concerns/the_comments_base.rb +0 -69
  154. data/app/models/concerns/the_comments_black_ip.rb +0 -9
  155. data/app/models/concerns/the_comments_black_user_agent.rb +0 -9
  156. data/app/models/concerns/the_comments_commentable.rb +0 -66
  157. data/app/models/concerns/the_comments_states.rb +0 -65
  158. data/app/models/concerns/the_comments_user.rb +0 -32
  159. data/app/views/ip_black_lists/index.html.haml +0 -17
  160. data/app/views/the_comments/_comment_body.html.haml +0 -30
  161. data/app/views/the_comments/_manage_controls.html.haml +0 -4
  162. data/app/views/the_comments/_tree.html.haml +0 -4
  163. data/app/views/the_comments/index.html.haml +0 -19
  164. data/app/views/the_comments/manage.html.haml +0 -29
  165. data/app/views/user_agent_black_lists/index.html.haml +0 -17
  166. data/db/migrate/20130101010101_create_comments.rb +0 -90
  167. data/lib/generators/the_comments/templates/ip_black_list.rb +0 -3
  168. data/lib/generators/the_comments/templates/ip_black_lists_controller.rb +0 -10
  169. data/lib/generators/the_comments/templates/the_comments_black_ip.rb +0 -9
  170. data/lib/generators/the_comments/templates/the_comments_black_user_agent.rb +0 -9
  171. data/lib/generators/the_comments/templates/user_agent_black_list.rb +0 -3
  172. data/lib/generators/the_comments/templates/user_agent_black_lists_controller.rb +0 -10
@@ -1,33 +1,44 @@
1
1
  Description:
2
- TheComments generator will copy files for organize comment's tree in your web project
2
+ TheComments: generators will copy files for organize comments tree in your web project
3
3
 
4
- This text:
5
- bundle exec rails g the_comments --help
4
+ Usage: [bundle exec] rails g the_comments NAME
5
+ Usage: [bundle exec] rails g the_comments:views NAME
6
6
 
7
- Generators:
8
- bundle exec rails g the_comments install
7
+ # This text:
8
+ > rails g the_comments --help
9
+
10
+ # Main generators:
11
+ > rails g the_comments install
9
12
 
10
13
  This will create:
11
14
  config/initializers/the_comments.rb
12
-
13
- app/models/ip_black_list.rb
14
- app/models/user_agent_black_list.rb
15
-
16
15
  app/controllers/comments_controller.rb
17
- app/controllers/ip_black_lists_controller.rb
18
- app/controllers/user_agent_black_lists_controller.rb
16
+ app/models/comment.rb
19
17
 
20
- bundle exec rails g the_comments controllers
18
+ # Controller generators:
19
+ > rails g the_comments controllers
21
20
 
22
21
  This will create:
23
22
  app/controllers/comments_controller.rb
24
- app/controllers/ip_black_lists_controller.rb
25
- app/controllers/user_agent_black_lists_controller.rb
23
+
24
+ # Model generators:
25
+ > rails g the_comments models
26
+
27
+ This will create:
28
+ app/models/comment.rb
29
+
30
+ # Config generators:
31
+ > rails g the_comments config
32
+
33
+ # Locals generators:
34
+ > rails g the_comments locales
26
35
 
27
- View Generators:
28
- bundle exec rails g the_comments:views assets
29
- bundle exec rails g the_comments:views helper
30
- bundle exec rails g the_comments:views views
36
+ # View Generators:
37
+ > rails g the_comments:views js
38
+ > rails g the_comments:views css
39
+ > rails g the_comments:views assets
40
+ > rails g the_comments:views helper
41
+ > rails g the_comments:views views
31
42
 
32
- Migrations:
33
- bundle exec rake the_comments_engine:install:migrations
43
+ # Migrations:
44
+ > rake the_comments_engine:install:migrations
@@ -2,38 +2,55 @@ class TheCommentsGenerator < Rails::Generators::NamedBase
2
2
  source_root File.expand_path('../templates', __FILE__)
3
3
  # argument :xname, type: :string, default: :xname
4
4
 
5
+ # > rails g the_comments NAME
5
6
  def generate_controllers
6
- if gen_name == 'install'
7
- cp_setup
8
- cp_controllers
9
- elsif gen_name == 'controllers'
10
- cp_controllers
11
- elsif gen_name == 'models'
12
- cp_models
13
- else
14
- puts 'TheComments Generator - wrong Name'
15
- puts 'Try to use [install|controllers]'
7
+ case gen_name
8
+ when 'locales'
9
+ cp_locales
10
+ when 'models'
11
+ cp_models
12
+ when 'controllers'
13
+ cp_controllers
14
+ when 'config'
15
+ cp_config
16
+ when 'install'
17
+ cp_config
18
+ cp_models
19
+ cp_controllers
20
+ else
21
+ puts 'TheComments Generator - wrong Name'
22
+ puts 'Try to use [ install | config | controllers | models ]'
16
23
  end
17
24
  end
18
25
 
19
26
  private
20
27
 
28
+ def root_path; TheComments::Engine.root; end
29
+
21
30
  def gen_name
22
31
  name.to_s.downcase
23
32
  end
24
33
 
25
- def cp_setup
26
- copy_file 'the_comments.rb', 'config/initializers/the_comments.rb'
34
+ def cp_config
35
+ copy_file "#{root_path}/config/initializers/the_comments.rb",
36
+ "config/initializers/the_comments.rb"
27
37
  end
28
38
 
29
39
  def cp_models
30
- copy_file 'ip_black_list.rb', 'app/models/ip_black_list.rb'
31
- copy_file 'user_agent_black_list.rb', 'app/models/user_agent_black_list.rb'
40
+ copy_file "#{root_path}/app/models/_templates_/comment.rb",
41
+ "app/models/comment.rb"
32
42
  end
33
43
 
34
44
  def cp_controllers
35
- copy_file 'comments_controller.rb', 'app/controllers/comments_controller.rb'
36
- copy_file 'ip_black_lists_controller.rb', 'app/controllers/ip_black_lists_controller.rb'
37
- copy_file 'user_agent_black_lists_controller.rb', 'app/controllers/user_agent_black_lists_controller.rb'
45
+ copy_file "#{root_path}/app/controllers/_templates_/comments_controller.rb",
46
+ "app/controllers/comments_controller.rb"
47
+ end
48
+
49
+ def cp_locales
50
+ copy_file "#{root_path}/config/locales/en.yml",
51
+ "config/locales/en.the_comments.yml"
52
+
53
+ copy_file "#{root_path}/config/locales/ru.yml",
54
+ "config/locales/ru.the_comments.yml"
38
55
  end
39
- end
56
+ end
@@ -1,14 +1,21 @@
1
1
  module TheComments
2
2
  module Generators
3
3
  class ViewsGenerator < Rails::Generators::NamedBase
4
- source_root File.expand_path('../../../../app/views', __FILE__)
4
+ source_root TheComments::Engine.root
5
5
 
6
6
  def self.banner
7
7
  <<-BANNER.chomp
8
8
 
9
- bundle exec rails g the_comments:views assets
10
- bundle exec rails g the_comments:views views
11
- bundle exec rails g the_comments:views helper
9
+ USAGE: [bundle exec] rails g the_comments:views NAME
10
+
11
+ > rails g the_comments:views js
12
+ > rails g the_comments:views css
13
+ > rails g the_comments:views assets
14
+
15
+ > rails g the_comments:views views
16
+ > rails g the_comments:views helper
17
+
18
+ > rails g the_comments:views all
12
19
 
13
20
  BANNER
14
21
  end
@@ -24,20 +31,49 @@ BANNER
24
31
  end
25
32
 
26
33
  def copy_gem_files
27
- if param_name == 'assets'
28
- copy_file "../assets/javascripts/the_comments", "app/assets/javascripts/the_comments"
29
- copy_file "../assets/stylesheets/the_comments", "app/assets/stylesheets/the_comments"
30
- elsif param_name == 'views'
31
- directory "../views/the_comments", "app/views/the_comments"
32
- directory "../views/ip_black_lists", "app/views/ip_black_lists"
33
- directory "../views/user_agent_black_lists", "app/views/user_agent_black_lists"
34
- elsif param_name == 'helper'
35
- copy_file "../helpers/render_comments_tree_helper.rb", "app/helpers/render_comments_tree_helper.rb"
36
- else
37
- puts "Wrong params - use only [assets | views | helper] values"
34
+ case param_name
35
+ when 'js'
36
+ js_copy
37
+ when 'css'
38
+ css_copy
39
+ when 'assets'
40
+ js_copy; css_copy
41
+ when 'views'
42
+ views_copy
43
+ when 'helper'
44
+ helper_copy
45
+ when 'all'
46
+ js_copy
47
+ css_copy
48
+ views_copy
49
+ helper_copy
50
+ else
51
+ puts 'TheComments View Generator - wrong Name'
52
+ puts "Wrong params - use only [ js | css | assets | views | helper | all ] values"
38
53
  end
39
54
  end
40
55
 
56
+ def js_copy
57
+ f1 = "app/assets/javascripts/the_comments.js.coffee"
58
+ f2 = "app/assets/javascripts/the_comments_manage.js.coffee"
59
+ copy_file f1, f1
60
+ copy_file f2, f2
61
+ end
62
+
63
+ def css_copy
64
+ f1 = "app/assets/stylesheets/the_comments.css.scss"
65
+ copy_file f1, f1
66
+ end
67
+
68
+ def views_copy
69
+ d1 = "app/views/the_comments"
70
+ directory d1, d1
71
+ end
72
+
73
+ def helper_copy
74
+ f1 = "app/helpers/render_comments_tree_helper.rb"
75
+ copy_file f1, f1
76
+ end
41
77
  end
42
78
  end
43
- end
79
+ end
@@ -10,7 +10,16 @@ module TheComments
10
10
  # Configuration class
11
11
  class Configuration
12
12
  include ActiveSupport::Configurable
13
- config_accessor :tolerance_time, :empty_inputs, :max_reply_depth, :default_state, :default_owner_state, :default_title
13
+
14
+ config_accessor :max_reply_depth,
15
+ :tolerance_time,
16
+ :default_state,
17
+ :default_owner_state,
18
+ :empty_inputs,
19
+ :default_title,
20
+ :template_engine,
21
+ :empty_trap_protection,
22
+ :tolerance_time_protection
14
23
  end
15
24
 
16
25
  configure do |config|
@@ -20,5 +29,9 @@ module TheComments
20
29
  config.default_owner_state = :published
21
30
  config.empty_inputs = [:message]
22
31
  config.default_title = 'Undefined title'
32
+ config.template_engine = :haml
33
+
34
+ config.empty_trap_protection = true
35
+ config.tolerance_time_protection = true
23
36
  end
24
37
  end
@@ -1,3 +1 @@
1
- module TheComments
2
- VERSION = "1.1.0"
3
- end
1
+ require File.expand_path('../../../gem_version', __FILE__)
data/lib/the_comments.rb CHANGED
@@ -7,3 +7,13 @@ require 'the_comments/version'
7
7
  module TheComments
8
8
  class Engine < Rails::Engine; end
9
9
  end
10
+
11
+ # Loading of concerns
12
+
13
+ # controllers
14
+ require "../../app/controllers/concerns/controller"
15
+
16
+ # models
17
+ %w[ comment_states comment user commentable ].each do |concern|
18
+ require "../../app/models/concerns/#{concern}"
19
+ end
@@ -0,0 +1,17 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.db
12
+ /db/*.sqlite3
13
+ /db/*.sqlite3-journal
14
+
15
+ # Ignore all logfiles and tempfiles.
16
+ /log/*.log
17
+ /tmp
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1 @@
1
+ the_comments
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
@@ -0,0 +1,43 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Base gems
4
+ gem 'rails', '4.0.1' #github: 'rails/rails', branch: 'master'
5
+ gem 'sqlite3'
6
+
7
+ gem 'jquery-rails'
8
+ gem 'jbuilder', '~> 1.2'
9
+
10
+ gem 'uglifier', '>= 1.3.0'
11
+ gem 'sass-rails', '~> 4.0.0'
12
+ gem 'coffee-rails', '~> 4.0.0'
13
+
14
+ gem 'thin', group: [:development]
15
+ gem 'therubyracer', platforms: :ruby
16
+ gem 'sdoc', require: false, group: [:doc]
17
+
18
+ # App gems
19
+ gem 'haml'
20
+ gem 'sorcery'
21
+ gem 'kaminari'
22
+ gem 'haml-rails'
23
+
24
+ # TheComments requires
25
+ gem 'the_comments',
26
+ path: '../../'
27
+
28
+ gem 'bootstrap-sass',
29
+ github: 'thomas-mcdonald/bootstrap-sass'
30
+
31
+ gem 'awesome_nested_set',
32
+ git: 'https://github.com/collectiveidea/awesome_nested_set.git',
33
+ branch: 'master'
34
+
35
+ # Test gems
36
+ group :development, :test do
37
+ gem 'faker'
38
+ gem 'factory_girl'
39
+ gem "factory_girl_rails"
40
+ gem 'rspec-rails', '~> 2.0'
41
+
42
+ # gem 'database_cleaner'
43
+ end
@@ -0,0 +1,50 @@
1
+ ## TheComments Dummy App
2
+
3
+ ### First step
4
+
5
+ ```
6
+ git clone https://github.com/the-teacher/the_comments.git
7
+
8
+ cd the_comments/spec/dummy_app/
9
+
10
+ bundle
11
+ ```
12
+
13
+ ### App start
14
+
15
+ ```
16
+ rake db:bootstrap_and_seed
17
+
18
+ rails s -p 3000 -b localhost
19
+ ```
20
+
21
+ Browser
22
+
23
+ ```
24
+ http://localhost:3000/
25
+ ```
26
+
27
+ ### Tests start
28
+
29
+ ```
30
+ rake db:bootstrap RAILS_ENV=test
31
+
32
+ rspec --format documentation
33
+ ```
34
+
35
+ ### Only for me (don't read this)
36
+
37
+ base install commands
38
+
39
+ ```
40
+ rails g sorcery:install
41
+ rails generate rspec:install
42
+
43
+ rails g the_comments install
44
+ rails g the_comments:views views
45
+ rails g model post user_id:integer title:string content:text
46
+
47
+ rake the_comments_engine:install:migrations (EDIT!)
48
+
49
+ rake db:bootstrap
50
+ ```
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ App::Application.load_tasks
File without changes
@@ -0,0 +1,5 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+
4
+ //= require bootstrap
5
+ //= require the_comments_manage
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+
16
+ //= require the_comments
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require bootstrap
3
+ */
@@ -0,0 +1,4 @@
1
+ .body{
2
+ margin: auto;
3
+ width: 800px;
4
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+
12
+ *= require_self
13
+ *= require app
14
+ *= require the_comments
15
+
16
+ */
@@ -0,0 +1,7 @@
1
+ class ApplicationController < ActionController::Base
2
+ include TheComments::ViewToken
3
+
4
+ # Prevent CSRF attacks by raising an exception.
5
+ # For APIs, you may want to use :null_session instead.
6
+ protect_from_forgery with: :exception
7
+ end
@@ -6,7 +6,9 @@ class CommentsController < ApplicationController
6
6
  # before_action :owner_required, only: [:my, :incoming, :edit, :trash]
7
7
  # before_action :moderator_required, only: [:update, :to_published, :to_draft, :to_spam, :to_trash]
8
8
 
9
- include TheCommentsController::Base
9
+ layout 'admin'
10
+
11
+ include TheComments::Controller
10
12
 
11
13
  # Public methods:
12
14
  #
File without changes
@@ -0,0 +1,13 @@
1
+ class PostsController < ApplicationController
2
+ def index
3
+ @posts = Post.all
4
+ @recent_comments = Comment.with_state(:published)
5
+ .where(commentable_state: [:published])
6
+ .recent.page(params[:page])
7
+ end
8
+
9
+ def show
10
+ @post = Post.find params[:id]
11
+ @comments = @post.comments.with_state([:draft, :published]).nested_set
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ class UsersController < ApplicationController
2
+ def autologin
3
+ user = User.find params[:id]
4
+ auto_login user if user
5
+ redirect_to request.referrer || root_path
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,32 @@
1
+ class Comment < ActiveRecord::Base
2
+ include TheComments::Comment
3
+ # ---------------------------------------------------
4
+ # Define comment's avatar url
5
+ # Usually we use Comment#user (owner of comment) to define avatar
6
+ # @blog.comments.includes(:user) <= use includes(:user) to decrease queries count
7
+ # comment#user.avatar_url
8
+ # ---------------------------------------------------
9
+
10
+ # ---------------------------------------------------
11
+ # Simple way to define avatar url
12
+
13
+ # def avatar_url
14
+ # hash = Digest::MD5.hexdigest self.id.to_s
15
+ # "http://www.gravatar.com/avatar/#{hash}?s=30&d=identicon"
16
+ # end
17
+ # ---------------------------------------------------
18
+
19
+ # ---------------------------------------------------
20
+ # Define your filters for content
21
+ # Expample for: gem 'RedCloth', gem 'sanitize'
22
+ # your personal SmilesProcessor
23
+
24
+ # def prepare_content
25
+ # text = self.raw_content
26
+ # text = RedCloth.new(text).to_html
27
+ # text = SmilesProcessor.new(text)
28
+ # text = Sanitize.clean(text, Sanitize::Config::RELAXED)
29
+ # self.content = text
30
+ # end
31
+ # ---------------------------------------------------
32
+ end
File without changes
@@ -0,0 +1,17 @@
1
+ class Post < ActiveRecord::Base
2
+ include TheComments::Commentable
3
+
4
+ belongs_to :user
5
+
6
+ def commentable_title
7
+ title
8
+ end
9
+
10
+ def commentable_url
11
+ ['', self.class.to_s.tableize, id].join('/')
12
+ end
13
+
14
+ def commentable_state
15
+ :published.to_s
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ class User < ActiveRecord::Base
2
+ include TheComments::User
3
+ include TheComments::Commentable
4
+
5
+ authenticates_with_sorcery!
6
+
7
+ has_many :posts
8
+
9
+ # can be replaced to TheCommentsUser as default
10
+ def admin?
11
+ self == User.first
12
+ end
13
+
14
+ def comments_admin?
15
+ admin?
16
+ end
17
+
18
+ def comments_moderator? comment
19
+ id == comment.holder_id
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ !!! 5
2
+ %html(lang="ru")
3
+ %head
4
+ %meta(charset="utf-8")
5
+ %meta(http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1")
6
+ %meta(name="viewport" content="width=device-width, initial-scale=1.0")
7
+ %title= content_for?(:title) ? yield(:title) : "Admin Panel"
8
+ %link(href="favicon.ico" rel="shortcut icon")
9
+
10
+ = stylesheet_link_tag :admin_panel
11
+ = javascript_include_tag :admin_panel
12
+ = csrf_meta_tags
13
+
14
+ %body
15
+ .container
16
+ .row
17
+ .col-md-12
18
+ %h3= content_for?(:title) ? yield(:title) : "Admin Panel"
19
+ .row
20
+ .col-md-3
21
+ = yield :comments_sidebar
22
+ .col-md-9
23
+ = yield :comments_main
24
+
25
+ = stylesheet_link_tag "//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css"
@@ -0,0 +1,20 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title TheComments Dummy App
5
+ = stylesheet_link_tag :application, media: :all
6
+ = javascript_include_tag :application
7
+ = csrf_meta_tags
8
+
9
+ %body
10
+ .body
11
+ %p
12
+ = link_to 'Home', root_path
13
+ \|
14
+ - if current_user
15
+ User: #{current_user.username}
16
+ \|
17
+ = link_to "Comments Manage (+#{current_user.draft_comcoms_count})", comments.manage_comments_path
18
+ - else
19
+ Guest
20
+ = yield
@@ -0,0 +1,22 @@
1
+ %h3 Posts:
2
+ %ul
3
+ - @posts.each do |post|
4
+ %li
5
+ = link_to post_url(post) do
6
+ = "#{post.title} (#{post.comments_sum})"
7
+
8
+ %h3 Autologin Users:
9
+ %ul
10
+ - User.all.each do |user|
11
+ %li
12
+ = link_to autologin_url(user) do
13
+ - admin = user.comments_admin? ? '[Admin]' : nil
14
+ = "#{user.username} (#{user.draft_comcoms_count}) #{admin}"
15
+
16
+ %h3 Recent Comments:
17
+ %ul
18
+ - @recent_comments.each do |comment|
19
+ %p
20
+ %b= link_to comment.commentable_title, comment.commentable_url
21
+ %br
22
+ %i= comment.content