Initial commit of foodsoft 2
This commit is contained in:
commit
5b9a7e05df
657 changed files with 70444 additions and 0 deletions
7
vendor/plugins/acts_as_commentable/CHANGELOG
vendored
Normal file
7
vendor/plugins/acts_as_commentable/CHANGELOG
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
* 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.
|
||||
|
||||
20
vendor/plugins/acts_as_commentable/MIT-LICENSE
vendored
Normal file
20
vendor/plugins/acts_as_commentable/MIT-LICENSE
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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.
|
||||
59
vendor/plugins/acts_as_commentable/README
vendored
Normal file
59
vendor/plugins/acts_as_commentable/README
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
Acts As Commentable
|
||||
=================
|
||||
|
||||
Allows for comments to be added to multiple and different models.
|
||||
|
||||
== Resources
|
||||
|
||||
Install
|
||||
* Run the following command:
|
||||
|
||||
script/plugin install http://juixe.com/svn/acts_as_commentable
|
||||
|
||||
* 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 you 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
|
||||
|
||||
* Each comment reference commentable object
|
||||
|
||||
model = Model.find(1)
|
||||
model.comments.get(0).commtable == model
|
||||
|
||||
== Credits
|
||||
|
||||
Xelipe - This plugin is heavily influced by Acts As Tagglable.
|
||||
|
||||
== More
|
||||
|
||||
http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
|
||||
http://www.juixe.com/projects/acts_as_commentable
|
||||
3
vendor/plugins/acts_as_commentable/init.rb
vendored
Normal file
3
vendor/plugins/acts_as_commentable/init.rb
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Include hook code here
|
||||
require 'acts_as_commentable'
|
||||
ActiveRecord::Base.send(:include, Juixe::Acts::Commentable)
|
||||
1
vendor/plugins/acts_as_commentable/install.rb
vendored
Normal file
1
vendor/plugins/acts_as_commentable/install.rb
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Install hook code here
|
||||
62
vendor/plugins/acts_as_commentable/lib/acts_as_commentable.rb
vendored
Normal file
62
vendor/plugins/acts_as_commentable/lib/acts_as_commentable.rb
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# 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, :order => 'created_at ASC'
|
||||
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.type.name],
|
||||
:order => "created_at DESC"
|
||||
)
|
||||
end
|
||||
|
||||
# Helper method that defaults the submitted time.
|
||||
def add_comment(comment)
|
||||
comments << comment
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
34
vendor/plugins/acts_as_commentable/lib/comment.rb
vendored
Normal file
34
vendor/plugins/acts_as_commentable/lib/comment.rb
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class Comment < ActiveRecord::Base
|
||||
belongs_to :commentable, :polymorphic => true
|
||||
|
||||
# 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
|
||||
|
||||
# Helper class method to lookup all comments assigned
|
||||
# to all commentable types for a given user.
|
||||
def self.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 self.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 self.find_commentable(commentable_str, commentable_id)
|
||||
commentable_str.constantize.find(commentable_id)
|
||||
end
|
||||
end
|
||||
4
vendor/plugins/acts_as_commentable/tasks/acts_as_commentable_tasks.rake
vendored
Normal file
4
vendor/plugins/acts_as_commentable/tasks/acts_as_commentable_tasks.rake
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# desc "Explaining what the task does"
|
||||
# task :acts_as_commentable do
|
||||
# # Task goes here
|
||||
# end
|
||||
8
vendor/plugins/acts_as_commentable/test/acts_as_commentable_test.rb
vendored
Normal file
8
vendor/plugins/acts_as_commentable/test/acts_as_commentable_test.rb
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
require 'test/unit'
|
||||
|
||||
class ActsAsCommentableTest < Test::Unit::TestCase
|
||||
# Replace this with your real tests.
|
||||
def test_this_plugin
|
||||
flunk
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue