lazy_comments 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lazy_comments.gemspec +13 -0
- data/lib/commentable.rb +17 -0
- data/lib/comments.rb +14 -0
- data/lib/generators/comments/USAGE +6 -0
- data/lib/generators/comments/comments_generator.rb +26 -0
- data/lib/generators/comments/templates/comments_table.rb +16 -0
- data/lib/generators/comments/templates/controllers/comments_controller.rb +27 -0
- data/lib/generators/comments/templates/models/comment.rb +6 -0
- data/lib/generators/comments/templates/views/comments/_comment.html.haml +13 -0
- data/lib/generators/comments/templates/views/comments/_form.html.haml +8 -0
- data/lib/generators/comments/templates/views/comments/_list_and_form.html.haml +7 -0
- data/lib/lazy_comments.rb +2 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8f6c334b91ac1efc0fd73bc9f0f650abc8c15a7
|
4
|
+
data.tar.gz: 73854a2bf83f2b9057be97fe3555edb4e568dc12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a31d5c4adeed4a59ef70dc376d727bdf21d7e6feb70201edc9c954bae47b84d9858f63c02ee24e571869981b20f5f03860e949dde49a4700ca886abfc45d32f0
|
7
|
+
data.tar.gz: 4ca3b34ca01d648af7dbbd8c0f752632fbd524ae6931813d093bef562855cff82378b0054fa953a35a1b7c2e96b3e3040fe6be4424bfbf734b28a635824995be
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'lazy_comments'
|
3
|
+
s.version = '0.0.3'
|
4
|
+
s.date = '2013-08-18'
|
5
|
+
s.summary = "A Rails commenting gem that handles mentions"
|
6
|
+
s.description = "Hello world version of a commenting gem"
|
7
|
+
s.authors = ["Damon Aw"]
|
8
|
+
s.email = 'daemonsy@gmail.com'
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
s.homepage = 'http://github.com/daemonsy/lazy_comments'
|
12
|
+
s.license = 'MIT'
|
13
|
+
end
|
data/lib/commentable.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
module Lazy
|
3
|
+
module Commentable
|
4
|
+
def self.included(comment_model)
|
5
|
+
comment_model.extend Finders
|
6
|
+
comment_model.scope :owned_by_user, ->(user) { comment_model.where(user: user) }
|
7
|
+
comment_model.scope :latest_first, -> { comment_model.reorder("created_at DESC")}
|
8
|
+
end
|
9
|
+
|
10
|
+
module Finders
|
11
|
+
def for_subject(subject)
|
12
|
+
where(commentable_type: subject.class.base_class, commentable_id: subject.id)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/comments.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lazy
|
2
|
+
module Comments
|
3
|
+
def self.included(subject)
|
4
|
+
subject.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def has_comments(*args)
|
9
|
+
has_many :comments, as: :commentable, dependent: :destroy
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
ActiveRecord::Base.send(:include, Lazy::Comments)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class CommentsGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@lazy_comments_source_root ||= File.expand_path("../templates", __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_controller
|
15
|
+
copy_file "controllers/comments_controller.rb", "app/controllers/comments_controller.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_model
|
19
|
+
copy_file "models/comment.rb", "app/models/comment.rb"
|
20
|
+
migration_template "comments_table.rb", "db/migrate/create_comments.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_views_and_assets
|
24
|
+
directory "views/comments", "app/views/comments"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateComments < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :comments do |t|
|
4
|
+
t.text :message
|
5
|
+
t.references :user, index: true
|
6
|
+
t.references :commentable, polymorphic: true
|
7
|
+
t.string :groups
|
8
|
+
t.string :mentions
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
add_index :comments, :commentable_type
|
13
|
+
add_index :comments, :commentable_id
|
14
|
+
add_index :comments, :user_id
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class CommentsController < InternalController
|
2
|
+
respond_to :js
|
3
|
+
|
4
|
+
def index
|
5
|
+
Comment.all
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
comment.save ? head(:ok) : head(:unprocessable_entity)
|
10
|
+
end
|
11
|
+
|
12
|
+
def destroy
|
13
|
+
comment.destroy ? head(:ok) : head(:unprocessable_entity)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def comment
|
18
|
+
Comment.owned_by_user(current_user).find_by(id: params[:id]) || Comment.new(comment_params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def comment_params
|
22
|
+
params.require(:comment).permit(
|
23
|
+
:commentable_id,
|
24
|
+
:commentable_type,
|
25
|
+
:message).merge(user_id: current_user.id)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
.comment.row
|
2
|
+
.avatar.col-md-1
|
3
|
+
= image_tag comment.user.avatar_url
|
4
|
+
.message.col-md-9
|
5
|
+
%h4= comment.user.name
|
6
|
+
.row
|
7
|
+
.col-md-12
|
8
|
+
= comment.message
|
9
|
+
.timestamp.muted.col-md-2
|
10
|
+
.time{"data-js-pretty-date" => comment.created_at.iso8601, title: comment.created_at.to_s(:rfc822)}
|
11
|
+
= comment.created_at.iso8601
|
12
|
+
- if comment.user == current_user
|
13
|
+
.pull_right= link_to "Delete", comment_path(comment), class: "js_delete_comment"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_comments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damon Aw
|
@@ -15,7 +15,19 @@ email: daemonsy@gmail.com
|
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
|
-
files:
|
18
|
+
files:
|
19
|
+
- lazy_comments.gemspec
|
20
|
+
- lib/commentable.rb
|
21
|
+
- lib/comments.rb
|
22
|
+
- lib/generators/comments/USAGE
|
23
|
+
- lib/generators/comments/comments_generator.rb
|
24
|
+
- lib/generators/comments/templates/comments_table.rb
|
25
|
+
- lib/generators/comments/templates/controllers/comments_controller.rb
|
26
|
+
- lib/generators/comments/templates/models/comment.rb
|
27
|
+
- lib/generators/comments/templates/views/comments/_comment.html.haml
|
28
|
+
- lib/generators/comments/templates/views/comments/_form.html.haml
|
29
|
+
- lib/generators/comments/templates/views/comments/_list_and_form.html.haml
|
30
|
+
- lib/lazy_comments.rb
|
19
31
|
homepage: http://github.com/daemonsy/lazy_comments
|
20
32
|
licenses:
|
21
33
|
- MIT
|