acts_as_debatable 0.0.1

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
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,76 @@
1
+ Acts\_as\_debatable
2
+ ===================
3
+
4
+ This plugin is still on its pre-alpha stage, which means that you may use it on your own risk.
5
+
6
+ ## Install
7
+
8
+ First of all you'll need to add some gems. Add this to your app's Gemfile **before** adding this gem:
9
+
10
+ gem 'devise'
11
+ gem 'ancestry'
12
+
13
+ then add:
14
+
15
+ gem 'acts_as_debatable', :git => 'git://github.com/espresse/acts_as_debatable.git'
16
+
17
+ Run
18
+
19
+ bundle install
20
+ rails g acts_as_debatable:migrations
21
+ rake db:migrate
22
+
23
+ Now you're ready to rock your models.
24
+
25
+ ## Use
26
+
27
+ To all models that you desired having comments add this line
28
+
29
+ acts_as_debatable
30
+
31
+ additionaly, to your User model add
32
+
33
+ acts_as_debater
34
+
35
+ So far so good. Next, let's show comments on the page.
36
+
37
+ In your show.html.erb file add these partials:
38
+
39
+ <%= render :partial => "comments/show", :locals => {:model => @article} %>
40
+ <%= render :partial => "comments/form", :locals => {:model => @article} %>
41
+ Change @article according to your model variable.
42
+
43
+ You can overwrite them in yours app/views/comments/.
44
+
45
+ As there is no autoinstall yet, you have to copy all files from public/* to your app public folder. This will change in future versions.
46
+
47
+ You can also use those methods:
48
+
49
+ Your\_class.latest\_debate - this will give you 10 last comments on Model
50
+ Your\_class.count\_comments - self-explaining; a number of all comments on Model
51
+
52
+ @your\_class\_object.has\_comments? - returns true if there is at least one comment and false if not
53
+ @your\_class\_object.latest\_debate - returns last 10 comments for this object
54
+
55
+ ## I18n
56
+
57
+ Take a look at config/locales/en.yml in this gem. You'll need to translate the file to have it localized.
58
+
59
+ ## TODO
60
+
61
+ - better db indexing
62
+ - better validation
63
+ - comments approval system
64
+ - CSS/JS
65
+ - better use of ancestry gem
66
+ - ajax for creating/updating comments
67
+ - akismet spam checking
68
+ - recaptcha
69
+ - User model should have a field username/login/full_name, now we are displaying user's email address, which is not so wise...
70
+ - for approval there's a need to have an admin field in User's model?
71
+
72
+ ##Bugs? Features?
73
+
74
+ Please post an issue on http://github.com/espresse/acts_as_debatable/issues
75
+
76
+ Copyright © 2011 Michał Ostrowski, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = false
19
+ end
20
+
21
+ task :default => :test
22
+
23
+ Rake::RDocTask.new(:rdoc) do |rdoc|
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = 'Acts_as_debatable'
26
+ rdoc.options << '--line-numbers' << '--inline-source'
27
+ rdoc.rdoc_files.include('README.rdoc')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
@@ -0,0 +1,41 @@
1
+ module ActsAsDebatable
2
+ module Debate
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_debatable(options = {})
10
+ has_many :comments, :as => :commentable, :dependent => :destroy
11
+ end
12
+
13
+ def acts_as_debater
14
+ has_many :comments
15
+ end
16
+
17
+ def latest_debate
18
+ Comment.where(:commentable_type => self.name).order("created_at desc").limit(10)
19
+ end
20
+
21
+ def count_comments
22
+ Comment.where(:commentable_type => self.name).count
23
+ end
24
+ end
25
+
26
+ def has_comments?
27
+ if self.comments.count > 0
28
+ true
29
+ else
30
+ false
31
+ end
32
+ end
33
+
34
+ def latest_debate
35
+ self.comments.order("created_at desc").limit(10)
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ ActiveRecord::Base.send :include, ActsAsDebatable::Debate
@@ -0,0 +1,23 @@
1
+ require 'acts_as_debatable/debate'
2
+
3
+ module ActsAsDebatable
4
+ class Engine < Rails::Engine
5
+
6
+ config.autoload_paths += %W(#{config.root}/lib)
7
+
8
+ def self.activate
9
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
10
+ Rails.env.production? ? require(c) : load(c)
11
+ end
12
+
13
+ end
14
+
15
+ config.to_prepare do
16
+ ApplicationController.helper(CommentsHelper)
17
+ end
18
+
19
+ config.to_prepare &method(:activate).to_proc
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,31 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module ActsAsDebatable
4
+ class MigrationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ desc "Generates migration for Comment method"
8
+
9
+ def self.orm
10
+ Rails::Generators.options[:rails][:orm]
11
+ end
12
+
13
+ def self.source_root
14
+ File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
15
+ end
16
+
17
+ def self.orm_has_migration?
18
+ [:active_record].include? orm
19
+ end
20
+
21
+ def self.next_migration_number(path)
22
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
23
+ end
24
+
25
+ def create_migration_file
26
+ if self.class.orm_has_migration?
27
+ migration_template 'migration.rb', 'db/migrate/acts_as_debatable_migration'
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ class ActsAsDebatableMigration < ActiveRecord::Migration
2
+ def self.up
3
+
4
+ create_table :comments do |t|
5
+
6
+ t.references :commentable, :polymorphic => true
7
+
8
+ t.text :content
9
+
10
+ #this is for anonymous users
11
+ t.string :author
12
+ t.string :author_email
13
+ t.string :author_url
14
+ t.string :user_ip
15
+ t.string :user_agent
16
+
17
+ #this is for logged users
18
+ t.integer :user_id
19
+
20
+ #we use ancestry!
21
+ t.string :ancestry
22
+ t.integer :ancestry_depth, :default => 0
23
+
24
+ #for akismet
25
+ t.boolean :spam
26
+
27
+ #if user is not registered site owner has to approve the comment
28
+ t.boolean :approved
29
+
30
+ t.timestamps
31
+ end
32
+ add_index :comments, :ancestry
33
+ end
34
+
35
+ def self.down
36
+ drop_table :comments
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_debatable
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Michal Ostrowski
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-27 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Ruby on Rails gem to provide simple and easy commenting system for any model.
22
+ email:
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/generators/acts_as_debatable/migration_generator.rb
31
+ - lib/generators/acts_as_debatable/templates/active_record/migration.rb
32
+ - lib/acts_as_debatable/debate.rb
33
+ - lib/acts_as_debatable.rb
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - README.md
37
+ has_rdoc: true
38
+ homepage:
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.6
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Comment system for Ruby On Rails
67
+ test_files: []
68
+