comments 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +43 -0
- data/app/assets/stylesheets/comments.scss +54 -0
- data/app/controllers/comments/application_controller.rb +18 -0
- data/app/controllers/comments/comments_controller.rb +48 -0
- data/app/models/comment.rb +6 -0
- data/app/views/comments/_comment.html.erb +33 -0
- data/app/views/comments/_comments.html.erb +11 -0
- data/app/views/comments/_form.html.erb +21 -0
- data/app/views/comments/comments/create.js.erb +14 -0
- data/app/views/comments/comments/destroy.js.erb +2 -0
- data/app/views/comments/comments/reply.js.erb +5 -0
- data/config/initializers/comments.rb +22 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20160331035951_create_comments.rb +19 -0
- data/lib/comments.rb +31 -0
- data/lib/comments/configuration.rb +46 -0
- data/lib/comments/engine.rb +5 -0
- data/lib/comments/model.rb +36 -0
- data/lib/comments/version.rb +3 -0
- data/lib/comments/view_helpers.rb +14 -0
- data/lib/generators/comments/controllers_generator.rb +22 -0
- data/lib/generators/comments/install_generator.rb +33 -0
- data/lib/generators/comments/templates/config/initializers/comments.rb +24 -0
- data/lib/generators/comments/views_generator.rb +22 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b69f183e6db423112985c8c233a7da74454c0fc3
|
4
|
+
data.tar.gz: c289b5f8b723643fe25dc21b24f7219892e583dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29eb19e867928a24074ac93c1579967113f1565bd5a62e5341a26c821a322c895d7829842f74aa76ff91f0b090475a823a052fea6d8d5eedb905bab79ae1b0f1
|
7
|
+
data.tar.gz: 186b63afb693e135d1c6f248880c64431804ad8fc872cd256a3ccc7938603bc3503c73f20ffe1998381f7a46335c92c28a50b8e68b81d73e9b58fbb0de4c17ee
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Jason Lee
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Comments
|
2
|
+
|
3
|
+
Comment feature for any applications's any models.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/comments.svg)](https://badge.fury.io/rb/comments) [![Build Status](https://travis-ci.org/rails-engine/comments.svg)](https://travis-ci.org/rails-engine/comments) [![Code Climate](https://codeclimate.com/github/rails-engine/comments/badges/gpa.svg)](https://codeclimate.com/github/rails-engine/comments) [![codecov.io](https://codecov.io/github/rails-engine/comments/coverage.svg?branch=master)](https://codecov.io/github/rails-engine/comments?branch=master) [![](http://inch-ci.org/github/rails-engine/comments.svg?branch=master)](http://inch-ci.org/github/rails-engine/comments?branch=master)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'comments'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
## Mount engine
|
22
|
+
|
23
|
+
in `config/routes.rb`
|
24
|
+
|
25
|
+
```rb
|
26
|
+
mount Comments::Engine => "/comments"
|
27
|
+
```
|
28
|
+
|
29
|
+
## In view, render comment list:
|
30
|
+
|
31
|
+
```erb
|
32
|
+
# app/views/posts/show.html.erb
|
33
|
+
|
34
|
+
<%= comments_tag(@post) %>
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Contribution directions go here.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,54 @@
|
|
1
|
+
.comments {
|
2
|
+
border-radius: 3px;
|
3
|
+
|
4
|
+
.heading {
|
5
|
+
padding: 10px;
|
6
|
+
font-size: 20px;
|
7
|
+
}
|
8
|
+
|
9
|
+
.comment {
|
10
|
+
margin-bottom: 10px;
|
11
|
+
padding: 10px;
|
12
|
+
border-top: 1px solid #eee;
|
13
|
+
color: #999;
|
14
|
+
|
15
|
+
@for $i from 1 through 20 {
|
16
|
+
&.comment-depth-#{$i} {
|
17
|
+
margin-left: 40px * $i;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
a { color: #555; }
|
22
|
+
|
23
|
+
|
24
|
+
.media-content {
|
25
|
+
color: #333;
|
26
|
+
p:last-chind {
|
27
|
+
margin-bottom: 0;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
.media-heading {
|
32
|
+
.opts {
|
33
|
+
a { padding: 1px 6px; display:inline-block; }
|
34
|
+
a:link,
|
35
|
+
a:visited { color: #555; }
|
36
|
+
a:hover { text-decoration: none; background: #f0f0f0; }
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
.user-avatar {
|
41
|
+
img { width: 32px; height: 32px; border-radius: 120px; }
|
42
|
+
}
|
43
|
+
|
44
|
+
.media-right {
|
45
|
+
min-width: 100px;
|
46
|
+
color: #AAA;
|
47
|
+
font-size: 13px;
|
48
|
+
}
|
49
|
+
|
50
|
+
form {
|
51
|
+
margin-left: 40px;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Comments
|
2
|
+
class ApplicationController < ::ApplicationController
|
3
|
+
helper_method :current_user
|
4
|
+
|
5
|
+
alias_method :origin_current_user, Comments.config.current_user_method.to_sym
|
6
|
+
alias_method :origin_authenticate_user!, Comments.config.authenticate_user_method.to_sym
|
7
|
+
|
8
|
+
before_action :authenticate_user!
|
9
|
+
|
10
|
+
def current_user
|
11
|
+
origin_current_user
|
12
|
+
end
|
13
|
+
|
14
|
+
def authenticate_user!
|
15
|
+
origin_authenticate_user!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Comments
|
2
|
+
class CommentsController < ApplicationController
|
3
|
+
before_action :authenticate_user!
|
4
|
+
before_action :set_comment, only: [:edit, :update, :destroy]
|
5
|
+
|
6
|
+
# GET /comments
|
7
|
+
def index
|
8
|
+
@comments = Comment.order('id asc').page(params[:page])
|
9
|
+
end
|
10
|
+
|
11
|
+
# POST /comments
|
12
|
+
def create
|
13
|
+
@comment = Comment.new(comment_params)
|
14
|
+
@comment.user = current_user
|
15
|
+
@comment.save
|
16
|
+
end
|
17
|
+
|
18
|
+
# PATCH/PUT /comments/1
|
19
|
+
def update
|
20
|
+
@success = @comment.update(comment_params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def reply
|
24
|
+
@parent = Comment.find(params[:id])
|
25
|
+
@comment = Comment.new(parent_id: @parent.id, commentable: @parent.commentable)
|
26
|
+
end
|
27
|
+
|
28
|
+
# DELETE /comments/1
|
29
|
+
def destroy
|
30
|
+
if @comment.user_id != current_user.id
|
31
|
+
raise ActiveRecord::RecordNotFound
|
32
|
+
end
|
33
|
+
|
34
|
+
@comment.destroy
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
# Use callbacks to share common setup or constraints between actions.
|
39
|
+
def set_comment
|
40
|
+
@comment = Comment.find(params[:id])
|
41
|
+
end
|
42
|
+
|
43
|
+
# Only allow a trusted parameter "white list" through.
|
44
|
+
def comment_params
|
45
|
+
params.require(:comment).permit(:commentable_type, :commentable_id, :parent_id, :body)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<div id="comment-<%= comment.id %>"
|
2
|
+
class="comment comment-depth-<%= comment.depth %> media"
|
3
|
+
data-parent-id="<%= comment.parent_id %>">
|
4
|
+
<div class="media-left">
|
5
|
+
<%= link_to image_tag(comment.user_avatar_url), comment.user_profile_url,
|
6
|
+
title: comment.user_name,
|
7
|
+
class: 'user-avatar' %>
|
8
|
+
</div>
|
9
|
+
<div class="media-body">
|
10
|
+
<div class="media-heading">
|
11
|
+
<span class="name">
|
12
|
+
<%= link_to comment.user_name, comment.user_profile_url,
|
13
|
+
title: comment.user_name,
|
14
|
+
class: 'user-avatar' %>
|
15
|
+
</span>
|
16
|
+
<span class="time">
|
17
|
+
<%= l comment.created_at, format: :long %>
|
18
|
+
</span>
|
19
|
+
<span class="opts pull-xs-right">
|
20
|
+
<% if comment.can_reply? %>
|
21
|
+
<%= link_to raw('<i class="fa fa-reply"></i>'), comments.reply_comment_path(comment), data: { remote: true } %>
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
<% if current_user.id == comment.user_id %>
|
25
|
+
<%= link_to raw('<i class="fa fa-trash"></i>'), comments.comment_path(comment), data: { method: 'delete', remote: true, confirm: "Are you sure?" } %>
|
26
|
+
<% end %>
|
27
|
+
</span>
|
28
|
+
</div>
|
29
|
+
<div class="media-content markdown">
|
30
|
+
<%= simple_format comment.body %>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="comments comments-<%= commentable.class.name.dasherize %>">
|
2
|
+
<div class="heading">Comments</div>
|
3
|
+
<div class="comments-list">
|
4
|
+
<%= render partial: '/comments/comment', collection: comments, as: :comment %>
|
5
|
+
</div>
|
6
|
+
<div class="comments-footer">
|
7
|
+
<%= will_paginate comments %>
|
8
|
+
</div>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<%= render partial: '/comments/form', locals: { comment: comments.new } %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%= form_for(comment, remote: true) do |f| %>
|
2
|
+
<div style="display:none">
|
3
|
+
<%= f.hidden_field :commentable_type %>
|
4
|
+
<%= f.hidden_field :commentable_id %>
|
5
|
+
<%= f.hidden_field :parent_id %>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<div class="form-group row">
|
9
|
+
<div class="col-sm-9">
|
10
|
+
<%= f.text_area :body, class: 'form-control' %>
|
11
|
+
</div>
|
12
|
+
<div class="col-sm-3">
|
13
|
+
<% if comment.parent_id.blank? %>
|
14
|
+
<%= f.submit class: 'btn btn-primary btn-block' %>
|
15
|
+
<% else %>
|
16
|
+
<%= f.submit 'Reply', class: 'btn btn-primary' %>
|
17
|
+
<a href="#" class="btn btn-secondary" onclick="$(this).closest('.new_comment').remove(); return false;">Cancel</a>
|
18
|
+
<% end %>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
var html = '<%= j(render(partial: '/comments/comment', locals: { comment: @comment })) %>';
|
2
|
+
<% if @comment.parent_id %>
|
3
|
+
var children = $('.comments .comment[data-parent-id=<%= @comment.parent_id %>]');
|
4
|
+
console.log(children);
|
5
|
+
if (children.length > 0) {
|
6
|
+
children.last().after(html);
|
7
|
+
} else {
|
8
|
+
$('#comment-<%= @comment.parent_id %>').after(html);
|
9
|
+
}
|
10
|
+
<% else %>
|
11
|
+
$('.comments').append(html);
|
12
|
+
<% end %>
|
13
|
+
$(".comment .new_comment").remove();
|
14
|
+
$('.new_comment [name="comment[body]"]').val('');
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# comments Config
|
2
|
+
Comments.configure do
|
3
|
+
# Class name of you User model, default: 'User'
|
4
|
+
# self.user_class = 'User'
|
5
|
+
|
6
|
+
# Method of user name in User model, default: 'name'
|
7
|
+
# self.user_name_method = 'name'
|
8
|
+
|
9
|
+
# Method of user avatar in User model, default: nil
|
10
|
+
# self.user_avatar_url_method = nil
|
11
|
+
|
12
|
+
# Method name of user profile page path, in User model, default: 'profile_url'
|
13
|
+
# self.user_profile_url_method = 'profile_url'
|
14
|
+
|
15
|
+
# authenticate_user method in your Controller, default: 'authenticate_user!'
|
16
|
+
# If you use Devise, authenticate_user! is correct
|
17
|
+
# self.authenticate_user_method = 'authenticate_user!'
|
18
|
+
|
19
|
+
# current_user method name in your Controller, default: 'current_user'
|
20
|
+
# If you use Devise, current_user is correct
|
21
|
+
# self.current_user_method = 'current_user'
|
22
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateComments < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :comments do |t|
|
4
|
+
t.integer :user_id
|
5
|
+
t.string :commentable_type
|
6
|
+
t.integer :commentable_id
|
7
|
+
t.text :body
|
8
|
+
t.integer :parent_id, :lft, :rgt
|
9
|
+
t.integer :depth, default: 0, null: false
|
10
|
+
|
11
|
+
t.timestamps null: false
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :comments, [:commentable_type, :commentable_id]
|
15
|
+
add_index :comments, :parent_id
|
16
|
+
add_index :comments, :lft
|
17
|
+
add_index :comments, :rgt
|
18
|
+
end
|
19
|
+
end
|
data/lib/comments.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'comments/configuration'
|
2
|
+
require 'comments/version'
|
3
|
+
require 'comments/model'
|
4
|
+
require 'comments/view_helpers'
|
5
|
+
require 'comments/engine'
|
6
|
+
require 'awesome_nested_set'
|
7
|
+
require 'will_paginate'
|
8
|
+
require 'will_paginate/active_record'
|
9
|
+
|
10
|
+
module Comments
|
11
|
+
class << self
|
12
|
+
def config
|
13
|
+
return @config if defined?(@config)
|
14
|
+
@config = Configuration.new
|
15
|
+
@config.user_class = 'User'
|
16
|
+
@config.user_name_method = 'name'
|
17
|
+
@config.user_avatar_url_method = nil
|
18
|
+
@config.user_profile_url_method = 'profile_url'
|
19
|
+
@config.authenticate_user_method = 'authenticate_user!'
|
20
|
+
@config.current_user_method = 'current_user'
|
21
|
+
@config.max_reply_depth = 10
|
22
|
+
@config
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure(&block)
|
26
|
+
config.instance_exec(&block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ActionController::Base.send(:helper, Comments::ViewHelpers)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Comments
|
2
|
+
class Configuration
|
3
|
+
# class name of you User model, default: 'User'
|
4
|
+
attr_accessor :user_class
|
5
|
+
|
6
|
+
# method of user name in User model, default: 'name'
|
7
|
+
attr_accessor :user_name_method
|
8
|
+
|
9
|
+
# method of user avatar in User model, default: nil
|
10
|
+
#
|
11
|
+
# We suggest you give image size more than 48x48 px.
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
#
|
15
|
+
# class User
|
16
|
+
# def avatar_url
|
17
|
+
# self.avatar.url('48x48')
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# config.user_avatar_url_method = :avatar_url
|
22
|
+
#
|
23
|
+
attr_accessor :user_avatar_url_method
|
24
|
+
|
25
|
+
# method name of user profile page path, in User model, default: 'profile_url'
|
26
|
+
# Example:
|
27
|
+
#
|
28
|
+
# class User
|
29
|
+
# def profile_url
|
30
|
+
# "http://www.host.com/u/#{self.username}"
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# config.user_profile_url_method = 'profile_url'
|
35
|
+
attr_accessor :user_profile_url_method
|
36
|
+
|
37
|
+
# current_user method name in your Controller, default: 'current_user'
|
38
|
+
attr_accessor :current_user_method
|
39
|
+
|
40
|
+
# authenticate_user method in your Controller, default: 'authenticate_user!'
|
41
|
+
attr_accessor :authenticate_user_method
|
42
|
+
|
43
|
+
# Limit of reply depth, default: 10
|
44
|
+
attr_accessor :max_reply_depth
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Comments
|
2
|
+
module Model
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
DEFAULT_AVATAR = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAMAAAAJixmgAAAAFVBMVEWkpKSnp6eqqqq3t7fS0tLV1dXZ2dmshcKEAAAAtklEQVR4Ae3XsRGAAAjAQFRk/5HtqaTz5H+DlInvAQAAAAAAAAAAAAAAAAAAAACymiveO6o7BQsWLFiwYMGCBS8PFixYsGDBggULFixYsGDBggULFixYsGDBggULFixYsGDBc4IFCxYsWLBgwYIFC14ZfOeAPRQ8IliwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQsWLFiwYMGCBQv+JQAAAAAAAAAAAAAAAAAAAOAB4KJfdHmj+kwAAAAASUVORK5CYII='
|
6
|
+
|
7
|
+
included do
|
8
|
+
acts_as_nested_set scope: [:commentable_type, :commentable_id]
|
9
|
+
|
10
|
+
belongs_to :commentable, polymorphic: true, touch: true
|
11
|
+
belongs_to :user, class_name: Comments.config.user_class
|
12
|
+
|
13
|
+
validates :body, presence: true
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_name
|
17
|
+
return "" if self.user.blank?
|
18
|
+
self.user.send(Comments.config.user_name_method)
|
19
|
+
end
|
20
|
+
|
21
|
+
def user_avatar_url
|
22
|
+
return DEFAULT_AVATAR if Comments.config.user_avatar_url_method.blank?
|
23
|
+
return DEFAULT_AVATAR if self.user.blank?
|
24
|
+
self.user.send(Comments.config.user_avatar_url_method)
|
25
|
+
end
|
26
|
+
|
27
|
+
def user_profile_url
|
28
|
+
return '#' if self.user.blank?
|
29
|
+
self.user.send(Comments.config.user_profile_url_method)
|
30
|
+
end
|
31
|
+
|
32
|
+
def can_reply?
|
33
|
+
self.depth <= Comments.config.max_reply_depth
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Comments
|
2
|
+
module ViewHelpers
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
end
|
7
|
+
|
8
|
+
def comments_tag(commentable, opts = {})
|
9
|
+
comments = Comment.where(commentable: commentable).includes(:user).order("lft asc, id asc").page(params[:page])
|
10
|
+
|
11
|
+
render partial: '/comments/comments', locals: { commentable: commentable, comments: comments }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Comments
|
4
|
+
module Generators
|
5
|
+
class ControllsGenerator < Rails::Generators::Base #:nodoc:
|
6
|
+
source_root File.expand_path("../../../../app/controllers", __FILE__)
|
7
|
+
desc "Used to copy Comments's controllers to your application's controllers."
|
8
|
+
|
9
|
+
def copy_controllers
|
10
|
+
%w(comments).each do |fname|
|
11
|
+
path = "#{Rails.root}/app/controllers/comments/#{fname}_controller.rb"
|
12
|
+
if File.exists?(path)
|
13
|
+
puts "Skipping comments/#{fname}_controller.rb creation, as file already exists!"
|
14
|
+
else
|
15
|
+
puts "Adding model (comments/#{fname}_controller.rb)..."
|
16
|
+
template "comments/#{fname}_controller.rb", path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module Comments
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
desc "Create Comments's base files"
|
6
|
+
source_root File.expand_path("../../../../", __FILE__)
|
7
|
+
|
8
|
+
def add_initializer
|
9
|
+
path = "#{Rails.root}/config/initializers/comments.rb"
|
10
|
+
if File.exists?(path)
|
11
|
+
puts "Skipping config/initializers/comments.rb creation, as file already exists!"
|
12
|
+
else
|
13
|
+
puts "Adding Comments initializer (config/initializers/comments.rb)..."
|
14
|
+
template "config/initializers/comments.rb", path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_models
|
19
|
+
path = "#{Rails.root}/app/models/comment.rb"
|
20
|
+
if File.exists?(path)
|
21
|
+
puts "Skipping app/models/comment.rb creation, as file already exists!"
|
22
|
+
else
|
23
|
+
puts "Adding Comments model (app/models/comment.rb)..."
|
24
|
+
template "app/models/comment.rb", path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_migrations
|
29
|
+
exec("rails comments:install:migrations")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Comments.configure do
|
2
|
+
# Page Size
|
3
|
+
# self.per_page = 32
|
4
|
+
|
5
|
+
# Class name of you User model, default: 'User'
|
6
|
+
# self.user_class = 'User'
|
7
|
+
|
8
|
+
# Method of user name in User model, default: 'name'
|
9
|
+
# self.user_name_method = 'name'
|
10
|
+
|
11
|
+
# Method of user avatar in User model, default: nil
|
12
|
+
# self.user_avatar_url_method = nil
|
13
|
+
|
14
|
+
# Method name of user profile page path, in User model, default: 'profile_url'
|
15
|
+
# self.user_profile_url_method = 'profile_url'
|
16
|
+
|
17
|
+
# authenticate_user method in your Controller, default: 'authenticate_user!'
|
18
|
+
# If you use Devise, authenticate_user! is correct
|
19
|
+
# self.authenticate_user_method = 'authenticate_user!'
|
20
|
+
|
21
|
+
# current_user method name in your Controller, default: 'current_user'
|
22
|
+
# If you use Devise, current_user is correct
|
23
|
+
# self.current_user_method = 'current_user'
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Comments
|
4
|
+
module Generators
|
5
|
+
class ViewsGenerator < Rails::Generators::Base #:nodoc:
|
6
|
+
source_root File.expand_path("../../../../app/views", __FILE__)
|
7
|
+
desc "Used to copy Comments's views to your application's controllers."
|
8
|
+
|
9
|
+
def copy_views
|
10
|
+
%w(comments).each do |fname|
|
11
|
+
path = "#{Rails.root}/app/views/comments"
|
12
|
+
if File.exists?(path)
|
13
|
+
puts "Skipping app/views/comments creation, as file already exists!"
|
14
|
+
else
|
15
|
+
puts "Adding views..."
|
16
|
+
directory "comments/", path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: comments
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.2.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: will_paginate
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.0.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.0.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: awesome_nested_set
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.1.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.1.0
|
61
|
+
description: Comment feature for any applications's any models.
|
62
|
+
email:
|
63
|
+
- huacnlee@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- MIT-LICENSE
|
69
|
+
- README.md
|
70
|
+
- app/assets/stylesheets/comments.scss
|
71
|
+
- app/controllers/comments/application_controller.rb
|
72
|
+
- app/controllers/comments/comments_controller.rb
|
73
|
+
- app/models/comment.rb
|
74
|
+
- app/views/comments/_comment.html.erb
|
75
|
+
- app/views/comments/_comments.html.erb
|
76
|
+
- app/views/comments/_form.html.erb
|
77
|
+
- app/views/comments/comments/create.js.erb
|
78
|
+
- app/views/comments/comments/destroy.js.erb
|
79
|
+
- app/views/comments/comments/reply.js.erb
|
80
|
+
- config/initializers/comments.rb
|
81
|
+
- config/routes.rb
|
82
|
+
- db/migrate/20160331035951_create_comments.rb
|
83
|
+
- lib/comments.rb
|
84
|
+
- lib/comments/configuration.rb
|
85
|
+
- lib/comments/engine.rb
|
86
|
+
- lib/comments/model.rb
|
87
|
+
- lib/comments/version.rb
|
88
|
+
- lib/comments/view_helpers.rb
|
89
|
+
- lib/generators/comments/controllers_generator.rb
|
90
|
+
- lib/generators/comments/install_generator.rb
|
91
|
+
- lib/generators/comments/templates/config/initializers/comments.rb
|
92
|
+
- lib/generators/comments/views_generator.rb
|
93
|
+
homepage: https://github.com/rails-engine/comments
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.6.3
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Comment feature for any applications's any models.
|
117
|
+
test_files: []
|