Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rails 3 version of acts_as_commentable gem

  • Loading branch information...
commit 6b13285eef55b2a31781f7bb542fbb412b21b846 1 parent 81a6dd0
@warp warp authored
Showing with 3 additions and 424 deletions.
  1. +1 −0  Gemfile
  2. +2 −0  Gemfile.lock
  3. +0 −13 vendor/plugins/acts_as_commentable/CHANGELOG
  4. +0 −20 vendor/plugins/acts_as_commentable/MIT-LICENSE
  5. +0 −65 vendor/plugins/acts_as_commentable/OLD_README
  6. +0 −73 vendor/plugins/acts_as_commentable/README
  7. +0 −47 vendor/plugins/acts_as_commentable/Rakefile
  8. +0 −29 vendor/plugins/acts_as_commentable/acts_as_commentable.gemspec
  9. +0 −13 vendor/plugins/acts_as_commentable/generators/comment/comment_generator.rb
  10. +0 −16 vendor/plugins/acts_as_commentable/generators/comment/templates/comment.rb
  11. +0 −19 vendor/plugins/acts_as_commentable/generators/comment/templates/create_comments.rb
  12. +0 −1  vendor/plugins/acts_as_commentable/init.rb
  13. +0 −2  vendor/plugins/acts_as_commentable/install.rb
  14. +0 −2  vendor/plugins/acts_as_commentable/lib/acts_as_commentable.rb
  15. +0 −43 vendor/plugins/acts_as_commentable/lib/comment_methods.rb
  16. +0 −67 vendor/plugins/acts_as_commentable/lib/commentable_methods.rb
  17. +0 −4 vendor/plugins/acts_as_commentable/lib/tasks/acts_as_commentable_tasks.rake
  18. +0 −2  vendor/plugins/acts_as_commentable/rails/init.rb
  19. +0 −8 vendor/plugins/acts_as_commentable/test/acts_as_commentable_test.rb
View
1  Gemfile
@@ -2,6 +2,7 @@ source 'http://rubygems.org'
gem 'rails', '>=3.0.0.rc'
+gem 'acts_as_commentable'
gem 'acts-as-taggable-on'
gem 'authlogic', '>=2.1.6'
gem 'faker', '0.3.1'
View
2  Gemfile.lock
@@ -29,6 +29,7 @@ GEM
activesupport (= 3.0.0.rc)
activesupport (3.0.0.rc)
acts-as-taggable-on (2.0.6)
+ acts_as_commentable (3.0.0)
archive-tar-minitar (0.5.2)
arel (0.4.0)
activesupport (>= 3.0.0.beta)
@@ -101,6 +102,7 @@ PLATFORMS
DEPENDENCIES
acts-as-taggable-on
+ acts_as_commentable
authlogic (>= 2.1.6)
faker (= 0.3.1)
haml
View
13 vendor/plugins/acts_as_commentable/CHANGELOG
@@ -1,13 +0,0 @@
-* Changes in version 72c1a4b3dfffaebe2dc25fcea09f9481305fc7e3
- - bumped version to 2.0.2
- - moved the setting of the default order for comments from inside the plugin
- to the generated Comment model. This will help with the current bug in Rails
- that prevents people from overriding this. Now they can just delete from the model,
- set it differently, etc.
-* revision 8: Changed has_many :dependent => true to :dependent => :destroy for Rails 1.2.2
- + Thanks Josh Martin
- Added an order clause in the has_many relationship.
- Made comment column type to text from string in migration example in README
- + Thanks Patrick Crowley
- Added this CHANGELOG file.
-
View
20 vendor/plugins/acts_as_commentable/MIT-LICENSE
@@ -1,20 +0,0 @@
-Copyright (c) 2006 Cosmin Radoi
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
65 vendor/plugins/acts_as_commentable/OLD_README
@@ -1,65 +0,0 @@
-Acts As Commentable
-=================
-
-Allows for comments to be added to multiple and different models.
-
-== Resources
-
-Install
-
- * To install as a plugin:
-
- script/plugin install http://juixe.com/svn/acts_as_commentable
-
- * To install as a gem:
-
- rake install
-
- * Create a new rails migration and add the following self.up and self.down methods
-
- def self.up
- create_table "comments", :force => true do |t|
- t.column "title", :string, :limit => 50, :default => ""
- t.column "comment", :text, :default => ""
- t.column "created_at", :datetime, :null => false
- t.column "commentable_id", :integer, :default => 0, :null => false
- t.column "commentable_type", :string, :limit => 15, :default => "", :null => false
- t.column "user_id", :integer, :default => 0, :null => false
- end
-
- add_index "comments", ["user_id"], :name => "fk_comments_user"
- end
-
- def self.down
- drop_table :comments
- end
-
-== Usage
-
- * Make your ActiveRecord model act as commentable.
-
- class Model < ActiveRecord::Base
- acts_as_commentable
- end
-
- * Add a comment to a model instance
-
- model = Model.new
- comment = Comment.new
- comment.comment = 'Some comment'
- model.comments << comment
-
- # Following doesn't work/make sense to me. Leaving for historical sake -- Jack
- # * Each comment reference commentable object
- #
- # model = Model.find(1)
- # model.comments.get(0).commentable == model
-
-== Credits
-
-Xelipe - This plugin is heavily influenced by Acts As Taggable.
-
-== More
-
-http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
-http://www.juixe.com/projects/acts_as_commentable
View
73 vendor/plugins/acts_as_commentable/README
@@ -1,73 +0,0 @@
-Acts As Commentable
-=================
-
-Allows for comments to be added to multiple and different models.
-
-== Resources
-
-Install
-
- Rails
-
- * To install as a plugin:
-
- script/plugin install http://github.com/jackdempsey/acts_as_commentable.git
-
- * To install as a gem
- sudo gem install
-
- Merb/Rails
-
- * To install as a gem:
- Run the following if you haven't already:
- gem sources -a http://gems.github.com
-
- Install the gem(s):
- sudo gem install jackdempsey-acts_as_commentable
-
- add the folloowing line to your environment.rb
- config.gem 'jackdempsey-acts_as_commentable', :lib => 'acts_as_commentable', :source => "http://gems.github.com"
-
-
- Generate your comment model:
-
- script/generate comment
-
- Then migrate your database:
-
- rake db:migrate
-
-== Usage
- Merb Users:
- * add 'dependency "acts_as_commentable"' to your init.rb or dependencies.rb if using merb-stack
-
- * Make your ActiveRecord model act as commentable.
-
- class Model < ActiveRecord::Base
- acts_as_commentable
- end
-
- * Add a comment to a model instance
-
- commentable = Model.create
- commentable.comments.create(:title => "First comment.", :comment => "This is the first comment.")
-
- * Fetch comments for a commentable model:
-
- commentable = Model.find(1)
- comments = commentable.comments.recent.limit(10).all
-
- # Following doesn't work/make sense to me. Leaving for historical sake -- Jack
- # * Each comment reference commentable object
- #
- # model = Model.find(1)
- # model.comments.get(0).commentable == model
-
-== Credits
-
-Xelipe - This plugin is heavily influenced by Acts As Taggable.
-
-== More
-
-http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
-http://www.juixe.com/projects/acts_as_commentable
View
47 vendor/plugins/acts_as_commentable/Rakefile
@@ -1,47 +0,0 @@
-require 'rubygems'
-require 'rake/gempackagetask'
-
-PLUGIN = "acts_as_commentable"
-GEM = "acts_as_commentable"
-GEM_VERSION = "2.0.1"
-EMAIL = "unknown@juixe.com"
-HOMEPAGE = "http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/"
-SUMMARY = "Plugin/gem that provides comment functionality"
-
-spec = Gem::Specification.new do |s|
- s.name = GEM
- s.version = GEM_VERSION
- s.platform = Gem::Platform::RUBY
- s.has_rdoc = false
- s.extra_rdoc_files = ["README", "MIT-LICENSE"]
- s.summary = SUMMARY
- s.description = s.summary
- s.author = 'Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein'
- s.email = EMAIL
- s.homepage = HOMEPAGE
-
- # Uncomment this to add a dependency
- # s.add_dependency "foo"
-
- s.require_path = 'lib'
- s.autorequire = GEM
- s.files = %w(MIT-LICENSE README) + Dir.glob("{generators,lib,tasks}/**/*") + %w(init.rb install.rb)
-end
-
-
-Rake::GemPackageTask.new(spec) do |pkg|
- pkg.gem_spec = spec
-end
-
-desc "Install the gem"
-task :install => [:package] do
- sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
-end
-
-desc "Regenerate gemspec"
-task :gemspec do
- File.open("#{GEM}.gemspec", 'w') do |f|
- f.write(spec.to_ruby)
- end
-end
-
View
29 vendor/plugins/acts_as_commentable/acts_as_commentable.gemspec
@@ -1,29 +0,0 @@
-# -*- encoding: utf-8 -*-
-
-Gem::Specification.new do |s|
- s.name = %q{acts_as_commentable}
- s.version = "2.0.2"
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein"]
- s.autorequire = %q{acts_as_commentable}
- s.date = %q{2009-07-01}
- s.description = %q{Plugin/gem that provides comment functionality}
- s.email = %q{unknown@juixe.com}
- s.extra_rdoc_files = ["README", "MIT-LICENSE"]
- s.files = ["MIT-LICENSE", "README", "generators/comment", "generators/comment/comment_generator.rb", "generators/comment/templates", "generators/comment/templates/comment.rb", "generators/comment/templates/create_comments.rb", "lib/acts_as_commentable.rb", "lib/comment_methods.rb", "lib/commentable_methods.rb", "tasks/acts_as_commentable_tasks.rake", "init.rb", "install.rb"]
- s.homepage = %q{http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/}
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.4}
- s.summary = %q{Plugin/gem that provides comment functionality}
-
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- else
- end
- else
- end
-end
View
13 vendor/plugins/acts_as_commentable/generators/comment/comment_generator.rb
@@ -1,13 +0,0 @@
-class CommentGenerator < Rails::Generator::Base
- def manifest
- record do |m|
- m.directory 'app/models'
- m.file 'comment.rb', 'app/models/comment.rb'
- m.migration_template "create_comments.rb", "db/migrate"
- end
- end
- # ick what a hack.
- def file_name
- "create_comments"
- end
- end
View
16 vendor/plugins/acts_as_commentable/generators/comment/templates/comment.rb
@@ -1,16 +0,0 @@
-class Comment < ActiveRecord::Base
-
- include ActsAsCommentable::Comment
-
- belongs_to :commentable, :polymorphic => true
-
- default_scope :order => 'created_at ASC'
-
- # NOTE: install the acts_as_votable plugin if you
- # want user to vote on the quality of comments.
- #acts_as_voteable
-
- # NOTE: Comments belong to a user
- belongs_to :user
-
-end
View
19 vendor/plugins/acts_as_commentable/generators/comment/templates/create_comments.rb
@@ -1,19 +0,0 @@
-class CreateComments < ActiveRecord::Migration
- def self.up
- create_table :comments do |t|
- t.string :title, :limit => 50, :default => ""
- t.text :comment, :default => ""
- t.references :commentable, :polymorphic => true
- t.references :user
- t.timestamps
- end
-
- add_index :comments, :commentable_type
- add_index :comments, :commentable_id
- add_index :comments, :user_id
- end
-
- def self.down
- drop_table :comments
- end
-end
View
1  vendor/plugins/acts_as_commentable/init.rb
@@ -1 +0,0 @@
-require File.join(File.dirname(__FILE__), 'rails', 'init')
View
2  vendor/plugins/acts_as_commentable/install.rb
@@ -1,2 +0,0 @@
-puts "To create the comment model please run:"
-puts "script/generate comment"
View
2  vendor/plugins/acts_as_commentable/lib/acts_as_commentable.rb
@@ -1,2 +0,0 @@
-require 'commentable_methods'
-require 'comment_methods'
View
43 vendor/plugins/acts_as_commentable/lib/comment_methods.rb
@@ -1,43 +0,0 @@
-module ActsAsCommentable
- # including this module into your Comment model will give you finders and named scopes
- # useful for working with Comments.
- # The named scopes are:
- # in_order: Returns comments in the order they were created (created_at ASC).
- # recent: Returns comments by how recently they were created (created_at DESC).
- # limit(N): Return no more than N comments.
- module Comment
-
- def self.included(comment_model)
- comment_model.extend Finders
- comment_model.named_scope :in_order, {:order => 'created_at ASC'}
- comment_model.named_scope :recent, {:order => "created_at DESC"}
- comment_model.named_scope :limit, lambda {|limit| {:limit => limit}}
- end
-
- module Finders
- # Helper class method to lookup all comments assigned
- # to all commentable types for a given user.
- def find_comments_by_user(user)
- find(:all,
- :conditions => ["user_id = ?", user.id],
- :order => "created_at DESC"
- )
- end
-
- # Helper class method to look up all comments for
- # commentable class name and commentable id.
- def find_comments_for_commentable(commentable_str, commentable_id)
- find(:all,
- :conditions => ["commentable_type = ? and commentable_id = ?", commentable_str, commentable_id],
- :order => "created_at DESC"
- )
- end
-
- # Helper class method to look up a commentable object
- # given the commentable class name and id
- def find_commentable(commentable_str, commentable_id)
- commentable_str.constantize.find(commentable_id)
- end
- end
- end
-end
View
67 vendor/plugins/acts_as_commentable/lib/commentable_methods.rb
@@ -1,67 +0,0 @@
-require 'active_record'
-
-# ActsAsCommentable
-module Juixe
- module Acts #:nodoc:
- module Commentable #:nodoc:
-
- def self.included(base)
- base.extend ClassMethods
- end
-
- module ClassMethods
- def acts_as_commentable
- has_many :comments, :as => :commentable, :dependent => :destroy
- include Juixe::Acts::Commentable::InstanceMethods
- extend Juixe::Acts::Commentable::SingletonMethods
- end
- end
-
- # This module contains class methods
- module SingletonMethods
- # Helper method to lookup for comments for a given object.
- # This method is equivalent to obj.comments.
- def find_comments_for(obj)
- commentable = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s
-
- Comment.find(:all,
- :conditions => ["commentable_id = ? and commentable_type = ?", obj.id, commentable],
- :order => "created_at DESC"
- )
- end
-
- # Helper class method to lookup comments for
- # the mixin commentable type written by a given user.
- # This method is NOT equivalent to Comment.find_comments_for_user
- def find_comments_by_user(user)
- commentable = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s
-
- Comment.find(:all,
- :conditions => ["user_id = ? and commentable_type = ?", user.id, commentable],
- :order => "created_at DESC"
- )
- end
- end
-
- # This module contains instance methods
- module InstanceMethods
- # Helper method to sort comments by date
- def comments_ordered_by_submitted
- Comment.find(:all,
- :conditions => ["commentable_id = ? and commentable_type = ?", id, self.class.name],
- :order => "created_at DESC"
- )
- end
-
- # Helper method that defaults the submitted time.
- def add_comment(comment)
- comments << comment
- end
- end
-
- end
- end
-end
-
-ActiveRecord::Base.send(:include, Juixe::Acts::Commentable)
-
View
4 vendor/plugins/acts_as_commentable/lib/tasks/acts_as_commentable_tasks.rake
@@ -1,4 +0,0 @@
-# desc "Explaining what the task does"
-# task :acts_as_commentable do
-# # Task goes here
-# end
View
2  vendor/plugins/acts_as_commentable/rails/init.rb
@@ -1,2 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'acts_as_commentable')
-
View
8 vendor/plugins/acts_as_commentable/test/acts_as_commentable_test.rb
@@ -1,8 +0,0 @@
-require 'test/unit'
-
-class ActsAsCommentableTest < Test::Unit::TestCase
- # Replace this with your real tests.
- def test_this_plugin
- flunk
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.