make_commentable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/commentable/Gemfile +4 -0
- data/commentable/LICENSE +1 -0
- data/commentable/README.md +29 -0
- data/commentable/Rakefile +2 -0
- data/commentable/commentable.gemspec +21 -0
- data/commentable/lib/commentable/comment_methods.rb +23 -0
- data/commentable/lib/commentable/commentable.rb +23 -0
- data/commentable/lib/commentable/version.rb +3 -0
- data/commentable/lib/generators/comment/USEGA +6 -0
- data/commentable/lib/generators/comment/comment_generator.rb +18 -0
- data/commentable/lib/generators/comment/templates/comment.rb +11 -0
- data/commentable/lib/generators/comment/templates/create_comments.rb +22 -0
- metadata +89 -0
data/commentable/Gemfile
ADDED
data/commentable/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Copyright (c) 2012 Unitmedia
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Commentable
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'commentable'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install commentable
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/commentable/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Unitmedia"]
|
6
|
+
gem.email = ["admin@unitmedia.ru"]
|
7
|
+
gem.description = %q{gem for comments with awesome_nested_set}
|
8
|
+
gem.summary = %q{a gem for usage comments with awesome_nested_set}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = Dir['commentable/**/*'].to_a
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "make_commentable"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Commentable::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency('awesome_nested_set', '>= 2.1.3')
|
19
|
+
gem.add_development_dependency('rails', '>= 3.2.1')
|
20
|
+
gem.rubygems_version = '>= 1.8.22'
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Commentable
|
2
|
+
# including this module into your Comment model will give you finders and named scopes
|
3
|
+
# useful for working with Comments.
|
4
|
+
# The named scopes are:
|
5
|
+
# in_order: Returns comments in the order they were created (created_at ASC).
|
6
|
+
# recent: Returns comments by how recently they were created (created_at DESC).
|
7
|
+
# limit(N): Return no more than N comments.
|
8
|
+
module Comment
|
9
|
+
|
10
|
+
def self.included(comment_model)
|
11
|
+
comment_model.extend Finders
|
12
|
+
end
|
13
|
+
|
14
|
+
module Finders
|
15
|
+
# Helper class method to look up a commentable object
|
16
|
+
# given the commentable class name and id
|
17
|
+
def find_commentable(commentable_str, commentable_id)
|
18
|
+
model = commentable_str.constantize
|
19
|
+
model.respond_to?(:find_comments_for) ? model.find(commentable_id) : nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'version'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module Commentable
|
5
|
+
module ClassMethods
|
6
|
+
def mark_as_commentable(options={})
|
7
|
+
has_many :comments, {:as => :commentable, :dependent => :destroy}.merge(options)
|
8
|
+
accepts_nested_attributes_for :comments, :allow_destroy => true
|
9
|
+
|
10
|
+
include Commentable::InstanceMethods
|
11
|
+
extend Commentable::SingletonMethods
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
#This module contains class methods
|
16
|
+
module SingletonMethods
|
17
|
+
end
|
18
|
+
|
19
|
+
# This module contains instance methods
|
20
|
+
module InstanceMethods
|
21
|
+
end
|
22
|
+
end
|
23
|
+
ActiveRecord::Base.send(:include, Commentable)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class CommentGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@_acts_as_commentable_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 create_model_file
|
15
|
+
template "comment.rb", "app/models/comment.rb"
|
16
|
+
migration_template "create_comments.rb", "db/migrate/create_comments.rb"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateComments < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :comments do |t|
|
4
|
+
t.string :content, :null => false
|
5
|
+
|
6
|
+
t.references :commentable, :polymorphic => true
|
7
|
+
t.references :user
|
8
|
+
|
9
|
+
# awesome nested set options
|
10
|
+
t.integer :parent_id
|
11
|
+
t.integer :lft
|
12
|
+
t.integer :rgt
|
13
|
+
t.integer :depth # this is optional.
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
drop_table :comments
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: make_commentable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Unitmedia
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: awesome_nested_set
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.1.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.1.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.2.1
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.2.1
|
46
|
+
description: gem for comments with awesome_nested_set
|
47
|
+
email:
|
48
|
+
- admin@unitmedia.ru
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- commentable/Rakefile
|
54
|
+
- commentable/lib/generators/comment/USEGA
|
55
|
+
- commentable/lib/generators/comment/templates/create_comments.rb
|
56
|
+
- commentable/lib/generators/comment/templates/comment.rb
|
57
|
+
- commentable/lib/generators/comment/comment_generator.rb
|
58
|
+
- commentable/lib/commentable/comment_methods.rb
|
59
|
+
- commentable/lib/commentable/version.rb
|
60
|
+
- commentable/lib/commentable/commentable.rb
|
61
|
+
- commentable/README.md
|
62
|
+
- commentable/LICENSE
|
63
|
+
- commentable/commentable.gemspec
|
64
|
+
- commentable/Gemfile
|
65
|
+
homepage: ''
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.24
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: a gem for usage comments with awesome_nested_set
|
89
|
+
test_files: []
|