the_comments 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +248 -0
  5. data/Rakefile +1 -0
  6. data/app/assets/javascripts/the_comments.js.coffee +104 -0
  7. data/app/assets/javascripts/the_comments_manage.js.coffee +59 -0
  8. data/app/assets/stylesheets/the_comments.css.scss +251 -0
  9. data/app/controllers/concerns/the_comments_controller.rb +227 -0
  10. data/app/controllers/concerns/the_comments_ip_controller.rb +17 -0
  11. data/app/controllers/concerns/the_comments_user_agent_controller.rb +17 -0
  12. data/app/helpers/render_comments_tree_helper.rb +113 -0
  13. data/app/models/concerns/the_comments_base.rb +64 -0
  14. data/app/models/concerns/the_comments_black_ip.rb +10 -0
  15. data/app/models/concerns/the_comments_black_user_agent.rb +10 -0
  16. data/app/models/concerns/the_comments_commentable.rb +50 -0
  17. data/app/models/concerns/the_comments_states.rb +64 -0
  18. data/app/models/concerns/the_comments_user.rb +25 -0
  19. data/app/views/ip_black_lists/index.html.haml +17 -0
  20. data/app/views/the_comments/_comment.html.haml +1 -0
  21. data/app/views/the_comments/_comment_body.html.haml +30 -0
  22. data/app/views/the_comments/_form.html.haml +25 -0
  23. data/app/views/the_comments/_manage_controls.html.haml +4 -0
  24. data/app/views/the_comments/_tree.html.haml +4 -0
  25. data/app/views/the_comments/index.html.haml +19 -0
  26. data/app/views/the_comments/manage.html.haml +29 -0
  27. data/app/views/user_agent_black_lists/index.html.haml +17 -0
  28. data/config/locales/en.yml +43 -0
  29. data/config/routes.rb +24 -0
  30. data/db/migrate/20130101010101_create_comments.rb +81 -0
  31. data/lib/generators/the_comments/USAGE +29 -0
  32. data/lib/generators/the_comments/templates/comments_controller.rb +25 -0
  33. data/lib/generators/the_comments/templates/ip_black_lists_controller.rb +10 -0
  34. data/lib/generators/the_comments/templates/the_comments.rb +7 -0
  35. data/lib/generators/the_comments/templates/user_agent_black_lists_controller.rb +10 -0
  36. data/lib/generators/the_comments/the_comments_generator.rb +32 -0
  37. data/lib/generators/the_comments/views_generator.rb +41 -0
  38. data/lib/the_comments/config.rb +21 -0
  39. data/lib/the_comments/version.rb +3 -0
  40. data/lib/the_comments.rb +10 -0
  41. data/the_comments.gemspec +23 -0
  42. data/the_comments.jpg +0 -0
  43. metadata +120 -0
@@ -0,0 +1,4 @@
1
+ .comments#comments
2
+ %ol.comments_tree{ data: { comments: { tolarance_time: TheComments.config.tolerance_time } } }
3
+ = render partial: 'the_comments/comment', locals: { tree: comments_tree }
4
+ = render partial: 'the_comments/form', locals: { commentable: commentable }
@@ -0,0 +1,19 @@
1
+ = paginate @comments
2
+
3
+ %ol.comments_list
4
+ - @comments.each do |comment|
5
+ %li
6
+ .item{ class: comment.state }
7
+ .body
8
+ .commentable
9
+ = comment.commentable_type
10
+ \:
11
+ = link_to comment.commentable_title, comment.commentable_url
12
+ .comment
13
+ .title
14
+ %b from:
15
+ = comment.title.blank? ? t('the_comments.guest_name') : comment.title
16
+ .content
17
+ = comment.content
18
+
19
+ = paginate @comments
@@ -0,0 +1,29 @@
1
+ = paginate @comments
2
+
3
+ %ol.comments_list
4
+ - @comments.each do |comment|
5
+ %li
6
+ .item{ class: comment.state }
7
+ .body
8
+ = render partial: 'the_comments/comment_body', locals: { comment: comment }
9
+ .form.comment{ style: 'display:none' }
10
+ = form_for comment, remote: true do |f|
11
+ .commentable
12
+ = comment.commentable_type
13
+ →
14
+ = link_to comment.commentable_title, comment.commentable_url
15
+ .title
16
+ %label from:
17
+ = f.text_field :title
18
+ .contacts
19
+ %label contacts:
20
+ = f.text_field :contacts
21
+ .content
22
+ = f.text_area :raw_content
23
+ .submit
24
+ = f.submit
25
+ .controls
26
+ = link_to :View, '#', class: :view
27
+ = render partial: 'the_comments/manage_controls', locals: { comment: comment }
28
+
29
+ = paginate @comments
@@ -0,0 +1,17 @@
1
+ - unless @ip_black_lists.blank?
2
+ %ol.black_list
3
+ - @ip_black_lists.each do |black|
4
+ %li{ class: black.state }
5
+ %p
6
+ %b user_agent:
7
+ = black.user_agent
8
+ %b count:
9
+ = black.count
10
+ %b state:
11
+ %span.state= black.state
12
+ %p
13
+ %b action:
14
+ = link_to :warning, user_agent_black_list_to_state_path(black, state: :warning), remote: true, method: :patch, class: :to_warning
15
+ = link_to :banned, user_agent_black_list_to_state_path(black, state: :banned), remote: true, method: :patch, class: :to_banned
16
+ - else
17
+ %p= t('the_comments.item_not_found')
@@ -0,0 +1,43 @@
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
+ trap: Trap
16
+ trap_message: should be empty
17
+
18
+ tolerance_time: Page view time
19
+ tolerance_time_message: "Please wait %{time} seconds before send a comment and try again"
20
+
21
+ cookies: Cookies
22
+ cookies_required: 'Please enable cookies and try to reload page'
23
+
24
+ ajax_requests_required: 'Sorry, JavaScript/Ajax Requests required'
25
+
26
+ black_ip: Black IP adress
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
31
+
32
+ guest_name: Guest
33
+ reply: Reply to this comment
34
+ edit: Edit
35
+ to_spam: Spam!
36
+ to_draft: Draft
37
+ to_published: Publicate
38
+ to_deleted: Delete
39
+
40
+ delete_confirm: Are you sure?
41
+
42
+ waiting_for_moderation: Waiting for moderation
43
+ item_not_found: Black list Item not found
data/config/routes.rb ADDED
@@ -0,0 +1,24 @@
1
+ Rails.application.routes.draw do
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
+
10
+ resources :comments do
11
+ collection do
12
+ get :my
13
+ get :incoming
14
+ get :trash
15
+ end
16
+
17
+ member do
18
+ post :to_spam
19
+ post :to_draft
20
+ post :to_published
21
+ delete :to_trash
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,81 @@
1
+ # null: false => de-facto db-level validation
2
+ class CreateComments < ActiveRecord::Migration
3
+ def change
4
+ create_table :comments do |t|
5
+ # relations
6
+ t.integer :user_id
7
+ t.integer :holder_id
8
+
9
+ # polymorphic, commentable object
10
+ t.integer :commentable_id
11
+ t.string :commentable_type
12
+
13
+ # denormalization
14
+ t.string :commentable_url
15
+ t.string :commentable_title
16
+ t.string :commentable_state
17
+
18
+ # comment
19
+ t.string :anchor
20
+
21
+ t.string :title
22
+ t.string :contacts
23
+
24
+ t.text :raw_content
25
+ t.text :content
26
+
27
+ # moderation token
28
+ t.string :view_token
29
+
30
+ # state machine => :draft | :published | :deleted
31
+ t.string :state, default: :draft
32
+
33
+ # base user data (BanHammer power)
34
+ t.string :ip, default: :undefined
35
+ t.string :referer, default: :undefined
36
+ t.string :user_agent, default: :undefined
37
+ t.integer :tolerance_time
38
+
39
+ # nested set
40
+ t.integer :parent_id
41
+ t.integer :lft
42
+ t.integer :rgt
43
+ t.integer :depth, default: 0
44
+
45
+ t.timestamps
46
+ end
47
+
48
+ # Black Lists
49
+ create_table :ip_black_lists do |t|
50
+ t.string :ip
51
+ t.integer :count, default: 0
52
+ t.string :state, default: :warning
53
+ end
54
+
55
+ create_table :user_agent_black_lists do |t|
56
+ t.string :user_agent
57
+ t.integer :count, default: 0
58
+ t.string :state, default: :warning
59
+ end
60
+
61
+ # Add fields to User and Commentable Object
62
+ change_table :users do |t|
63
+ # commentable's comments => comcoms (cache)
64
+ # Relation through Comment#holder_id field
65
+ t.integer :draft_comcoms_count, default: 0
66
+ t.integer :published_comcoms_count, default: 0
67
+ t.integer :deleted_comcoms_count, default: 0
68
+ end
69
+
70
+ # Uncomment this. Add fields to User model and Commentable models
71
+ #
72
+ # [:users, :posts].each do |table_name|
73
+ # change_table table_name do |t|
74
+ # t.integer :draft_comments_count, default: 0
75
+ # t.integer :published_comments_count, default: 0
76
+ # t.integer :deleted_comments_count, default: 0
77
+ # end
78
+ # end
79
+ end
80
+
81
+ end
@@ -0,0 +1,29 @@
1
+ Description:
2
+ TheComments generator will copy files for organize comment's tree in your web project
3
+
4
+ This text:
5
+ bundle exec rails g the_comments --help
6
+
7
+ Generators:
8
+ bundle exec rails g the_comments install
9
+
10
+ This will create:
11
+ config/initializers/the_comments.rb
12
+ app/controllers/comments_controller.rb
13
+ app/controllers/ip_black_lists_controller.rb
14
+ app/controllers/user_agent_black_lists_controller.rb
15
+
16
+ bundle exec rails g the_comments controllers
17
+
18
+ This will create:
19
+ app/controllers/comments_controller.rb
20
+ app/controllers/ip_black_lists_controller.rb
21
+ app/controllers/user_agent_black_lists_controller.rb
22
+
23
+ View Generators:
24
+ bundle exec rails g the_comments:views assets
25
+ bundle exec rails g the_comments:views helper
26
+ bundle exec rails g the_comments:views views
27
+
28
+ Migrations:
29
+ bundle exec rake the_comments_engine:install:migrations
@@ -0,0 +1,25 @@
1
+ class CommentsController < ApplicationController
2
+ # Define your restrict methods and use them like this:
3
+ #
4
+ # before_action :user_required, except: [:index, :create]
5
+ #
6
+ # before_action :owner_required, only: [:my, :incoming, :edit, :trash]
7
+ # before_action :moderator_required, only: [:update, :to_published, :to_draft, :to_spam, :to_trash]
8
+
9
+ include TheCommentsController::Base
10
+
11
+ # Public methods:
12
+ #
13
+ # [:index, :create]
14
+
15
+ # Application side methods:
16
+ # Overwrite following default methods if it's need
17
+ # Following methods based on *current_user* helper method
18
+ #
19
+ # [:my, :incoming, :edit, :trash]
20
+
21
+ # You must protect following methods
22
+ # Only comments moderator (holder or admin) can invoke following actions
23
+ #
24
+ # [:update, :to_published, :to_draft, :to_spam, :to_trash]
25
+ end
@@ -0,0 +1,10 @@
1
+ class IpBlackListsController < ApplicationController
2
+ # Define your restrict methods and use them like this:
3
+ #
4
+ # before_action :user_required
5
+ # before_action :admin_required
6
+ #
7
+ # Only Admin should have an access to following methods
8
+ # Methods: [:index, :to_state]
9
+ include TheCommentsIpController
10
+ end
@@ -0,0 +1,7 @@
1
+ # TheComments.config.param_name => value
2
+
3
+ TheComments.configure do |config|
4
+ config.max_reply_depth = 3
5
+ config.tolerance_time = 5
6
+ config.empty_inputs = [:commentBody]
7
+ end
@@ -0,0 +1,10 @@
1
+ class UserAgentBlackListsController < ApplicationController
2
+ # Define your restrict methods and use them like this:
3
+ #
4
+ # before_action :user_required
5
+ # before_action :admin_required
6
+ #
7
+ # Only Admin should have an access to following methods
8
+ # Methods: [:index, :to_state]
9
+ include TheCommentsUserAgentController
10
+ end
@@ -0,0 +1,32 @@
1
+ class TheCommentsGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ # argument :xname, type: :string, default: :xname
4
+
5
+ def generate_controllers
6
+ if gen_name == 'install'
7
+ cp_setup
8
+ cp_controllers
9
+ elsif gen_name == 'controllers'
10
+ cp_controllers
11
+ else
12
+ puts 'TheComments Generator - wrong Name'
13
+ puts 'Try to use [install|controllers]'
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def gen_name
20
+ name.to_s.downcase
21
+ end
22
+
23
+ def cp_setup
24
+ copy_file 'the_comments.rb', 'config/initializers/the_comments.rb'
25
+ end
26
+
27
+ def cp_controllers
28
+ copy_file 'comments_controller.rb', 'app/controllers/comments_controller.rb'
29
+ copy_file 'ip_black_lists_controller.rb', 'app/controllers/ip_black_lists_controller.rb'
30
+ copy_file 'user_agent_black_lists_controller.rb', 'app/controllers/user_agent_black_lists_controller.rb'
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ module TheComments
2
+ module Generators
3
+ class ViewsGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('../../../../app/views', __FILE__)
5
+
6
+ def self.banner
7
+ <<-BANNER.chomp
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
12
+
13
+ BANNER
14
+ end
15
+
16
+ def copy_sortable_tree_files
17
+ copy_gem_files
18
+ end
19
+
20
+ private
21
+
22
+ def param_name
23
+ name.downcase
24
+ end
25
+
26
+ 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
+ elsif param_name == 'helper'
33
+ copy_file "../helpers/render_comments_tree_helper.rb", "app/helpers/render_comments_tree_helper.rb"
34
+ else
35
+ puts "Wrong params - use only [assets | views | helper] values"
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
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
+ config_accessor :tolerance_time, :empty_inputs, :max_reply_depth
14
+ end
15
+
16
+ configure do |config|
17
+ config.max_reply_depth = 3
18
+ config.tolerance_time = 5
19
+ config.empty_inputs = [:message]
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module TheComments
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'haml'
2
+ require 'state_machine'
3
+ require 'the_sortable_tree'
4
+
5
+ require 'the_comments/config'
6
+ require 'the_comments/version'
7
+
8
+ module TheComments
9
+ class Engine < Rails::Engine; end
10
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_comments/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "the_comments"
8
+ gem.version = TheComments::VERSION
9
+ gem.authors = ["Ilya N. Zykin"]
10
+ gem.email = ["zykin-ilya@ya.ru"]
11
+ gem.description = %q{ Nested Comments }
12
+ gem.summary = %q{ Nested Comments form TheTeacher }
13
+ gem.homepage = "https://github.com/open-cook/the_comments"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'haml'
21
+ gem.add_dependency 'state_machine'
22
+ gem.add_dependency 'the_sortable_tree'
23
+ end
data/the_comments.jpg ADDED
Binary file
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_comments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ilya N. Zykin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: haml
16
+ requirement: &80817540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *80817540
25
+ - !ruby/object:Gem::Dependency
26
+ name: state_machine
27
+ requirement: &80817330 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *80817330
36
+ - !ruby/object:Gem::Dependency
37
+ name: the_sortable_tree
38
+ requirement: &80817120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *80817120
47
+ description: ! ' Nested Comments '
48
+ email:
49
+ - zykin-ilya@ya.ru
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - app/assets/javascripts/the_comments.js.coffee
60
+ - app/assets/javascripts/the_comments_manage.js.coffee
61
+ - app/assets/stylesheets/the_comments.css.scss
62
+ - app/controllers/concerns/the_comments_controller.rb
63
+ - app/controllers/concerns/the_comments_ip_controller.rb
64
+ - app/controllers/concerns/the_comments_user_agent_controller.rb
65
+ - app/helpers/render_comments_tree_helper.rb
66
+ - app/models/concerns/the_comments_base.rb
67
+ - app/models/concerns/the_comments_black_ip.rb
68
+ - app/models/concerns/the_comments_black_user_agent.rb
69
+ - app/models/concerns/the_comments_commentable.rb
70
+ - app/models/concerns/the_comments_states.rb
71
+ - app/models/concerns/the_comments_user.rb
72
+ - app/views/ip_black_lists/index.html.haml
73
+ - app/views/the_comments/_comment.html.haml
74
+ - app/views/the_comments/_comment_body.html.haml
75
+ - app/views/the_comments/_form.html.haml
76
+ - app/views/the_comments/_manage_controls.html.haml
77
+ - app/views/the_comments/_tree.html.haml
78
+ - app/views/the_comments/index.html.haml
79
+ - app/views/the_comments/manage.html.haml
80
+ - app/views/user_agent_black_lists/index.html.haml
81
+ - config/locales/en.yml
82
+ - config/routes.rb
83
+ - db/migrate/20130101010101_create_comments.rb
84
+ - lib/generators/the_comments/USAGE
85
+ - lib/generators/the_comments/templates/comments_controller.rb
86
+ - lib/generators/the_comments/templates/ip_black_lists_controller.rb
87
+ - lib/generators/the_comments/templates/the_comments.rb
88
+ - lib/generators/the_comments/templates/user_agent_black_lists_controller.rb
89
+ - lib/generators/the_comments/the_comments_generator.rb
90
+ - lib/generators/the_comments/views_generator.rb
91
+ - lib/the_comments.rb
92
+ - lib/the_comments/config.rb
93
+ - lib/the_comments/version.rb
94
+ - the_comments.gemspec
95
+ - the_comments.jpg
96
+ homepage: https://github.com/open-cook/the_comments
97
+ licenses: []
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.15
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Nested Comments form TheTeacher
120
+ test_files: []