Initial commit of foodsoft 2
This commit is contained in:
commit
5b9a7e05df
657 changed files with 70444 additions and 0 deletions
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue