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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76bf6805fee015737ecf52d1197313081ab0e2d0
4
- data.tar.gz: 1421370ce37228ec47de0c708a539df79d5eb728
3
+ metadata.gz: e8f6c334b91ac1efc0fd73bc9f0f650abc8c15a7
4
+ data.tar.gz: 73854a2bf83f2b9057be97fe3555edb4e568dc12
5
5
  SHA512:
6
- metadata.gz: 4671003dabd2593133826bba0541f2908a0d43dbd0ceedda3b677e1db9310be7c61e305bc499c6b79e7e479ef4f93ad4b91cd0efde2aff05bfccce409b95900e
7
- data.tar.gz: 6196cb8d6e923130462ea1b6d3331d9aebf788dae5aff8f27d5c0426affacf01881a28fea4c44a163fc43edae7414b8f30e779e035a6e9a2a37c3edb2cbeb1c4
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
@@ -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,6 @@
1
+ Description:
2
+ Copies comment.rb to app/models/.
3
+ Copies create_comment.rb to db/migrate
4
+
5
+ Examples:
6
+ `rails generate comment`
@@ -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,6 @@
1
+ class Comment < ActiveRecord::Base
2
+ include Lazy::Commentable
3
+
4
+ belongs_to :commentable, :polymorphic => true
5
+ belongs_to :user
6
+ 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"
@@ -0,0 +1,8 @@
1
+ = form_for comment do |f|
2
+ = f.hidden_field :commentable_type
3
+ = f.hidden_field :commentable_id
4
+
5
+ .comment_input
6
+ = f.text_area :message, required: true, placeholder: "Enter Comments", class: "form-control"
7
+
8
+ = f.submit "Comment", class: "btn-success btn"
@@ -0,0 +1,7 @@
1
+ %section#comments.clearfix
2
+ %h3 Comments
3
+ .js_comments_wall
4
+ = render partial: "comments/comment", collection: comments, as: :comment
5
+ .row
6
+ .col-md-11
7
+ = render partial: "comments/form", locals: { comment: subject.comments.build }
@@ -0,0 +1,2 @@
1
+ require 'comments'
2
+ require 'commentable'
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.2
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