the_comments_ruby 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) 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 +14 -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 +37 -0
  89. data/lib/the_comments/version.rb +1 -0
  90. data/lib/the_comments.rb +28 -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 +14 -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 +25 -0
  170. data/the_comments.yml.teamocil.example +11 -0
  171. data/views_converter.rb +16 -0
  172. metadata +333 -0
data/docs/routes.md ADDED
@@ -0,0 +1,77 @@
1
+ ←   [documentation](documentation.md)
2
+
3
+ ## TheComments Routes
4
+
5
+ **config/routes.rb**
6
+
7
+ ```ruby
8
+ MyApp::Application.routes.draw do
9
+ root 'posts#index'
10
+ resources :posts
11
+
12
+ # ...
13
+
14
+ # TheComments routes
15
+ concern :user_comments, TheComments::UserRoutes.new
16
+ concern :admin_comments, TheComments::AdminRoutes.new
17
+ resources :comments, concerns: [:user_comments, :admin_comments]
18
+ end
19
+ ```
20
+
21
+ And after that you can see routes:
22
+
23
+ ```ruby
24
+ rake routes | grep comments
25
+ ```
26
+
27
+ ```ruby
28
+ comments / TheComments::Engine
29
+ to_spam_comment POST /comments/:id/to_spam(.:format) comments#to_spam
30
+ to_draft_comment POST /comments/:id/to_draft(.:format) comments#to_draft
31
+ to_published_comment POST /comments/:id/to_published(.:format) comments#to_published
32
+ to_deleted_comment DELETE /comments/:id/to_deleted(.:format) comments#to_deleted
33
+ manage_comments GET /comments/manage(.:format) comments#manage
34
+ my_draft_comments GET /comments/my_draft(.:format) comments#my_draft
35
+ my_published_comments GET /comments/my_published(.:format) comments#my_published
36
+ my_comments_comments GET /comments/my_comments(.:format) comments#my_comments
37
+ total_draft_comments GET /comments/total_draft(.:format) comments#total_draft
38
+ total_published_comments GET /comments/total_published(.:format) comments#total_published
39
+ total_deleted_comments GET /comments/total_deleted(.:format) comments#total_deleted
40
+ total_spam_comments GET /comments/total_spam(.:format) comments#total_spam
41
+ draft_comments GET /comments/draft(.:format) comments#draft
42
+ published_comments GET /comments/published(.:format) comments#published
43
+ deleted_comments GET /comments/deleted(.:format) comments#deleted
44
+ spam_comments GET /comments/spam(.:format) comments#spam
45
+ comments GET /comments(.:format) comments#index
46
+ POST /comments(.:format) comments#create
47
+ new_comment GET /comments/new(.:format) comments#new
48
+ edit_comment GET /comments/:id/edit(.:format) comments#edit
49
+ comment GET /comments/:id(.:format) comments#show
50
+ PATCH /comments/:id(.:format) comments#update
51
+ PUT /comments/:id(.:format) comments#update
52
+ DELETE /comments/:id(.:format) comments#destroy
53
+ ```
54
+
55
+ And now you can use url helpers with 2 ways:
56
+
57
+ ### Way 1. Url Helpers
58
+
59
+ ```ruby
60
+ = link_to 'link', comments_path
61
+ = link_to 'link', manage_comments_path
62
+ = link_to 'link', new_comment_path
63
+
64
+ = link_to 'link', comment_path(@comment)
65
+ = link_to 'link', to_spam_comment_path(@comment)
66
+ ```
67
+
68
+ ### Way 2. Array notation
69
+
70
+ ```ruby
71
+ = link_to 'link', [:index, :comments]
72
+ = link_to 'link', [:manage, :comments]
73
+ = link_to 'link', [:draft, :comments]
74
+
75
+ = link_to 'link', [@comment]
76
+ = link_to 'link', [:to_spam, @comment]
77
+ ```
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/docs/user_api.md ADDED
@@ -0,0 +1,75 @@
1
+ ←   [documentation](documentation.md)
2
+
3
+ ### User API
4
+
5
+ **When User is not commentable model**
6
+
7
+ ```ruby
8
+ class User < ActiveRecord::Base
9
+ include TheCommentsUser
10
+
11
+ has_many :posts # commentable model
12
+ has_many :products # commentable model
13
+ end
14
+ ```
15
+
16
+ :warning: &nbsp; Please, read this: [What is ComComs?](what_is_comcoms.md)
17
+
18
+
19
+ We can use following methods
20
+
21
+ ```ruby
22
+ @user = User.first
23
+
24
+ @user.comcoms #=> all comments for posts and products, where user is owner
25
+
26
+ # cache counters
27
+ @user.draft_comcoms_count # => 1
28
+ @user.published_comcoms_count # => 5
29
+ @user.deleted_comcoms_count # => 3
30
+ @user.spam_comcoms_count # => 2
31
+
32
+ # equal values, but with request to database
33
+ @user.comcoms.with_state([:draft]).count # => 1
34
+ @user.comcoms.with_state([:published]).count # => 5
35
+ @user.comcoms.with_state([:deleted]).count # => 3
36
+ @user.comcoms.where(spam: true).count # => 2
37
+
38
+ # draft and published comments
39
+ # written by this user
40
+ @user.my_comments # => ActiveRecord::Relation
41
+
42
+ # cache counters for comments
43
+ # written by this user
44
+ # there is no cache counter for deleted state!
45
+ @user.my_draft_comments_count # => 3
46
+ @user.my_published_comments_count # => 7
47
+
48
+ # equal values, but with request to database
49
+ @user.my_draft_comments.count # => 3
50
+ @user.my_published_comments.count # => 7
51
+ @user.my_deleted_comments.count # => 1
52
+
53
+ # helper methods to get comments
54
+ # written by this user
55
+ @user.my_draft_comments # => ActiveRecord::Relation
56
+ @user.my_published_comments # => ActiveRecord::Relation
57
+ @user.my_deleted_comments # => ActiveRecord::Relation
58
+
59
+ # recalculate cache counters
60
+ @user.recalculate_my_comments_counter!
61
+ ```
62
+
63
+ **When User is commentable model**
64
+
65
+ ```ruby
66
+ class User < ActiveRecord::Base
67
+ include TheCommentsUser
68
+ include TheCommentsCommentable
69
+
70
+ has_many :posts # commentable model
71
+ has_many :products # commentable model
72
+ end
73
+ ```
74
+
75
+ you should to use following instruction [Commentable API](commentable_api.md)
@@ -0,0 +1,63 @@
1
+ &larr; &nbsp; [documentation](documentation.md)
2
+
3
+ ### What is ComComs?
4
+
5
+ :warning: &nbsp; **comcoms** - is main method to get all comments related with user's commentable models.
6
+
7
+ :warning: &nbsp; **comments** - is main method to get comments related with any commentable model.
8
+
9
+ **ComComs** - **com**ments of **com**mentable models
10
+
11
+ ComComs are all incoming comments for all models, where this user is owner.
12
+
13
+ For example, some user **has_many :posts**, and **has_many :products** - all comments for all user's posts and all user's products called as **comcoms**.
14
+
15
+ #### Why we need ComComs?
16
+
17
+ User model can be commentable too. For example to build user's "public wall" (like tweets list for current user).
18
+
19
+ And we should to separate **comments** attached to user model (tweets) and comments attached to any another user's model.
20
+
21
+ That is why User model in-fact has following relationship declarations:
22
+
23
+ ```ruby
24
+ class User < ActiveRecord::Base
25
+ has_many :comcoms, class_name: :Comment, foreign_key: :holder_id
26
+
27
+ # and if User model is commentable model
28
+ # has_many :comments, as: :commentable
29
+
30
+ has_many :posts
31
+ has_many :products
32
+ end
33
+ ```
34
+
35
+ in real application it should be described like this:
36
+
37
+ ```ruby
38
+ class User < ActiveRecord::Base
39
+ include TheCommentsUser
40
+ include TheCommentsCommentable
41
+
42
+ has_many :posts
43
+ has_many :products
44
+ end
45
+ ```
46
+
47
+ But in most popular situation User model should not be commentable, and you should use only **comcoms** method to get all comments related with this user:
48
+
49
+ ```ruby
50
+ class User < ActiveRecord::Base
51
+ include TheCommentsUser
52
+
53
+ has_many :posts
54
+ has_many :products
55
+ end
56
+ ```
57
+
58
+ and later in your application
59
+
60
+ ```ruby
61
+ @user = User.find params[:id]
62
+ @user.comcoms.count # => 42
63
+ ```
@@ -0,0 +1,28 @@
1
+ &larr; &nbsp; [documentation](documentation.md)
2
+
3
+ ### What's wrong with other gems?
4
+
5
+ Take a look at [Ruby-Toolbox](https://www.ruby-toolbox.com/categories/rails_comments). What can we see?
6
+
7
+ * [Acts as commentable with threading](https://github.com/elight/acts_as_commentable_with_threading) - Where is the render helper for the tree? There is no helper! Am I supposed to write a render helper for the tree myself? Nooooo!!! I'm sorry, I can't use this gem.
8
+ * [acts_as_commentable](https://github.com/jackdempsey/acts_as_commentable) - I can see the code for models. But I can't see the code for controllers and views. Unfortunately, there is no threading. This isn't enough for me.
9
+ * [opinio](https://github.com/Draiken/opinio) - Better, but still no threading. I can do better!
10
+ * [has_threaded_comments](https://github.com/aarongough/has_threaded_comments) - A solid gem. Has model, controller and view helpers for tree rendering! **But** last activity was 2 years ago, it still needs a few features - I can do better.
11
+
12
+ ### Why is TheComments better than other gems?
13
+
14
+ 1. TheComments allows for threaded comments
15
+ 2. **Only TheComments has special helper for tree rendering** (based on [TheSortableTree](https://github.com/the-teacher/the_sortable_tree)).
16
+ 3. TheComments is designed to reduce database requests. Helpful for cache counters.
17
+ 4. TheComments has a solution for [building Recent Comments](https://github.com/the-teacher/the_comments/blob/master/docs/denormalization_and_recent_comments.md) (for polymorphic relations)
18
+ 5. TheComments is designed for text preprocessors (Textile, Markdown, Sanitize, Coderay etc.)
19
+ 6. TheComments has an admin UI based on bootstrap 3
20
+ 7. TheComments is an "all-in-one" solution.<br>
21
+ It has: Models and Controllers logic (via concerns), Generators, Views, Helper for fast Tree rendering and Admin UI.
22
+ 8. If you have problems with TheComments, I'll try to help you via skype: **ilya.killich**
23
+
24
+ ### TheComments based on:
25
+
26
+ 1. [AwesomeNestedSet](https://github.com/collectiveidea/awesome_nested_set) - for comments threading
27
+ 2. [TheSortableTree](https://github.com/the-teacher/the_sortable_tree) - for fast rendering of comments tree
28
+ 3. [State Machine](https://github.com/pluginaweek/state_machine) - to provide easy and correct recalculation cache counters on states transitions
@@ -0,0 +1,37 @@
1
+ &larr; &nbsp; [documentation](documentation.md)
2
+
3
+ ### Dummy Application
4
+
5
+ TheComments repository contains a dummy application for development and testing.
6
+
7
+ It's here: [Dummy App](https://github.com/the-teacher/the_comments/tree/master/spec/dummy_app)
8
+
9
+ To run the dummy app:
10
+
11
+ ```ruby
12
+ git clone https://github.com/the-teacher/the_comments.git
13
+
14
+ cd the_comments/spec/dummy_app/
15
+
16
+ bundle
17
+
18
+ rake db:bootstrap_and_seed
19
+
20
+ rails s -p 3000 -b localhost
21
+ ```
22
+
23
+ ### Run tests
24
+
25
+ To run the RSPEC tests:
26
+
27
+ ```ruby
28
+ git clone https://github.com/the-teacher/the_comments.git
29
+
30
+ cd the_comments/spec/dummy_app/
31
+
32
+ bundle
33
+
34
+ rake db:bootstrap RAILS_ENV=test
35
+
36
+ rspec --format documentation
37
+ ```
data/gem_version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module TheComments
2
+ VERSION = "2.3.3"
3
+ end
@@ -0,0 +1,44 @@
1
+ Description:
2
+ TheComments: generators will copy files for organize comments tree in your web project
3
+
4
+ Usage: [bundle exec] rails g the_comments NAME
5
+ Usage: [bundle exec] rails g the_comments:views NAME
6
+
7
+ # This text:
8
+ > rails g the_comments --help
9
+
10
+ # Main generators:
11
+ > rails g the_comments install
12
+
13
+ This will create:
14
+ config/initializers/the_comments.rb
15
+ app/controllers/comments_controller.rb
16
+ app/models/comment.rb
17
+
18
+ # Controller generators:
19
+ > rails g the_comments controllers
20
+
21
+ This will create:
22
+ app/controllers/comments_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
35
+
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
42
+
43
+ # Migrations:
44
+ > rake the_comments_engine:install:migrations
@@ -0,0 +1,56 @@
1
+ class TheCommentsGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ # argument :xname, type: :string, default: :xname
4
+
5
+ # > rails g the_comments NAME
6
+ def generate_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 ]'
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def root_path; TheComments::Engine.root; end
29
+
30
+ def gen_name
31
+ name.to_s.downcase
32
+ end
33
+
34
+ def cp_config
35
+ copy_file "#{root_path}/config/initializers/the_comments.rb",
36
+ "config/initializers/the_comments.rb"
37
+ end
38
+
39
+ def cp_models
40
+ copy_file "#{root_path}/app/models/_templates_/comment.rb",
41
+ "app/models/comment.rb"
42
+ end
43
+
44
+ def cp_controllers
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"
55
+ end
56
+ end
@@ -0,0 +1,79 @@
1
+ module TheComments
2
+ module Generators
3
+ class ViewsGenerator < Rails::Generators::NamedBase
4
+ source_root TheComments::Engine.root
5
+
6
+ def self.banner
7
+ <<-BANNER.chomp
8
+
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
19
+
20
+ BANNER
21
+ end
22
+
23
+ def copy_sortable_tree_files
24
+ copy_gem_files
25
+ end
26
+
27
+ private
28
+
29
+ def param_name
30
+ name.downcase
31
+ end
32
+
33
+ def copy_gem_files
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"
53
+ end
54
+ end
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
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,37 @@
1
+ module TheComments
2
+ def self.configure(&block)
3
+ yield @config ||= TheComments::Configuration.new
4
+ end
5
+
6
+ def self.config
7
+ @config
8
+ end
9
+
10
+ # Configuration class
11
+ class Configuration
12
+ include ActiveSupport::Configurable
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
23
+ end
24
+
25
+ configure do |config|
26
+ config.max_reply_depth = 3
27
+ config.tolerance_time = 5
28
+ config.default_state = :draft
29
+ config.default_owner_state = :published
30
+ config.empty_inputs = [:message]
31
+ config.default_title = 'Undefined title'
32
+ config.template_engine = :haml
33
+
34
+ config.empty_trap_protection = true
35
+ config.tolerance_time_protection = true
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('../../../gem_version', __FILE__)
@@ -0,0 +1,28 @@
1
+ require 'state_machine'
2
+ require 'state_machine/version'
3
+
4
+ require 'the_simple_sort'
5
+ require 'the_sortable_tree'
6
+
7
+ require 'the_comments/config'
8
+ require 'the_comments/version'
9
+
10
+ module TheComments
11
+ COMMENTS_COOKIES_TOKEN = 'JustTheCommentsCookies'
12
+
13
+ class Engine < Rails::Engine
14
+ config.autoload_paths += Dir["#{config.root}/app/controllers/concerns/**/"]
15
+ config.autoload_paths += Dir["#{config.root}/app/models/concerns/**/"]
16
+ end
17
+ end
18
+
19
+ # Loading of concerns
20
+ _root_ = File.expand_path('../../', __FILE__)
21
+ require "#{_root_}/config/routes.rb"
22
+
23
+ if StateMachine::VERSION.to_f <= 1.2
24
+ module StateMachine::Integrations::ActiveModel
25
+ puts "You should not in here"
26
+ public :around_validation
27
+ end
28
+ end
@@ -0,0 +1,18 @@
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
+ .rvmrc
10
+
11
+ # Ignore the default SQLite database.
12
+ /db/*.db
13
+ /db/*.sqlite3
14
+ /db/*.sqlite3-journal
15
+
16
+ # Ignore all logfiles and tempfiles.
17
+ /log/*.log
18
+ /tmp
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,43 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Base gems
4
+ gem 'rails', '4.1.4 ' #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,33 @@
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
+ ```
@@ -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