Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add changes from Barry by moving directory straight over from spaced-…
…ed rails2.3 project
  • Loading branch information
John Metta committed May 23, 2012
1 parent 3a1537d commit 9506eb0
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 335 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
pkg
*.gem
.DS_Store
Empty file modified CHANGELOG 100644 → 100755
Empty file.
Empty file modified MIT-LICENSE 100644 → 100755
Empty file.
65 changes: 65 additions & 0 deletions OLD_README
@@ -0,0 +1,65 @@
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
73 changes: 73 additions & 0 deletions README
@@ -0,0 +1,73 @@
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
62 changes: 0 additions & 62 deletions README.rdoc

This file was deleted.

15 changes: 3 additions & 12 deletions Rakefile 100644 → 100755
@@ -1,10 +1,9 @@
require 'rubygems'
require 'rake/gempackagetask'
require 'rake/testtask'

PLUGIN = "acts_as_commentable"
GEM = "acts_as_commentable"
GEM_VERSION = "3.0.1"
GEM_VERSION = "2.1.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"
Expand All @@ -14,7 +13,7 @@ spec = Gem::Specification.new do |s|
s.version = GEM_VERSION
s.platform = Gem::Platform::RUBY
s.has_rdoc = false
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE"]
s.extra_rdoc_files = ["README", "MIT-LICENSE"]
s.summary = SUMMARY
s.description = s.summary
s.author = 'Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein'
Expand All @@ -26,7 +25,7 @@ spec = Gem::Specification.new do |s|

s.require_path = 'lib'
s.autorequire = GEM
s.files = %w(MIT-LICENSE README.rdoc) + Dir.glob("{generators,lib,tasks}/**/*") + %w(init.rb install.rb)
s.files = %w(MIT-LICENSE README) + Dir.glob("{generators,lib,tasks}/**/*") + %w(init.rb install.rb)
end


Expand All @@ -46,11 +45,3 @@ task :gemspec do
end
end

desc 'Test the acts_as_commentable plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end


12 changes: 6 additions & 6 deletions acts_as_commentable.gemspec 100644 → 100755
Expand Up @@ -2,27 +2,27 @@

Gem::Specification.new do |s|
s.name = %q{acts_as_commentable}
s.version = "3.0.0"
s.version = "2.1.1"

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{2010-03-13}
s.date = %q{2010-10-07}
s.description = %q{Plugin/gem that provides comment functionality}
s.email = %q{unknown@juixe.com}
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE"]
s.files = ["MIT-LICENSE", "README.rdoc", "lib/acts_as_commentable.rb", "lib/comment_methods.rb", "lib/commentable_methods.rb", "lib/generators", "lib/generators/comment", "lib/generators/comment/comment_generator.rb", "lib/generators/comment/templates", "lib/generators/comment/templates/comment.rb", "lib/generators/comment/templates/create_comments.rb", "lib/generators/comment/USEGA", "tasks/acts_as_commentable_tasks.rake", "init.rb", "install.rb"]
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", "lib/tasks", "lib/tasks/acts_as_commentable_tasks.rake", "init.rb", "install.rb"]
s.has_rdoc = false
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.6}
s.rubygems_version = %q{1.3.7}
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
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
else
end
else
Expand Down
13 changes: 13 additions & 0 deletions generators/comment/comment_generator.rb
@@ -0,0 +1,13 @@
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
Expand Up @@ -12,4 +12,5 @@ class Comment < ActiveRecord::Base

# NOTE: Comments belong to a user
belongs_to :user

end
Expand Up @@ -2,10 +2,9 @@ class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.string :title, :limit => 50, :default => ""
t.text :comment
t.text :comment, :default => ""
t.references :commentable, :polymorphic => true
t.references :user
t.string :role, :default => "comments"
t.timestamps
end

Expand Down
Empty file modified init.rb 100644 → 100755
Empty file.
Empty file modified install.rb 100644 → 100755
Empty file.
Empty file modified lib/acts_as_commentable.rb 100644 → 100755
Empty file.
34 changes: 20 additions & 14 deletions lib/comment_methods.rb 100644 → 100755
Expand Up @@ -9,32 +9,38 @@ module Comment

def self.included(comment_model)
comment_model.extend Finders
comment_model.scope :in_order, comment_model.order('created_at ASC')
comment_model.scope :recent, comment_model.order('created_at DESC')
end

def is_comment_type?(type)
type.to_s == role.singularize.to_s
comment_model.named_scope :published, {:conditions => {:published => true}}
comment_model.named_scope :unpublished, {:conditions => {:published => false}}
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}}
comment_model.named_scope :owner, lambda { |user| {:conditions => {:user_id => user.id}}}
comment_model.named_scope :published_or_owned, lambda { |user| {:conditions => ["published = true or user_id = ?", user ? user.id : nil]}}
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, role = "comments")
where(["user_id = ? and role = ?", user.id, role]).order("created_at DESC")
def find_comments_by_user(user)
find(:all,
:conditions => ["user_id = ?", user.id],
:order => "created_at DESC", :published => true
)
end

# Helper class method to look up all comments for
# Helper class method to look up all comments for
# commentable class name and commentable id.
def find_comments_for_commentable(commentable_str, commentable_id, role = "comments")
where(["commentable_type = ? and commentable_id = ? and role = ?", commentable_str, commentable_id, role]).order("created_at DESC")
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", :published => true
)
end

# Helper class method to look up a commentable object
# given the commentable class name and id
# given the commentable class name and id
def find_commentable(commentable_str, commentable_id)
model = commentable_str.constantize
model.respond_to?(:find_comments_for) ? model.find(commentable_id) : nil
commentable_str.constantize.find(commentable_id)
end
end
end
Expand Down

0 comments on commit 9506eb0

Please sign in to comment.