# ActsAsChattable
# ===============
#
# ActsAsChattable is a plugin with make web chatting easy.
#
# With this plugin, you can add a user-to-user chatting system into your Rails app
# within 3-minutes.
#
# It uses some codes from Chatten project (http://rubyforge.org/projects/chatten/),
# So let's give our thanks to the author of Chatten: Jacob Pedersen.
#
# Version: 0.1.0 - beta
# Author: Yuanyi Zhang -- http://elctech.com
# Contributors:
# License: Ruby MIT
#
# ==Installation
#
# ./script/plugin install https://svn.elctech.com/svn/public/plugins/acts_as_chattable
#
# ==Demo
#
# svn co https://svn.elctech.com/svn/public/demo/acts_as_chattable
#
# ==Usage
#
# * At first, I assume you have a model named User and a controller named UsersController,
# I also assume you have a helper named 'current_user' which will return the current
# user (it should be there if you use restful_auth). If you don't have these yet,
# create them and let's go!
#
# * create chat_message model and migration:
#
# script/generate chattable
#
# * add acts_as_chattable to user model
#
# class User
# acts_as_chattable
# ...
#
# def name
# ...
# end
# end
#
# You'd better to define name method for User, or all users' name will be displayed as 'Unknown'.
#
# * include chat system in users controller
#
# class UsersController
# include ChatSystem
# ...
# end
#
# * render chat in views
#
# <%= render_chat(friends, use_yui) %>
# <%= buddy_list(friends, use_yui) %>
#
# friends should be an array of user with presents current user's friends.
# use_yui indicate if YUI should be used to get a better look, default is true.
#
# You can get more info about these two helpers with rdoc.
#
# * It's done, open your browser and start to enjoy the chatting.
#
# ===================================
# For more detailed examples with sample images visit http://elctech.com/blog
# All Feedbacks/Comments/Issues are welcome.
module ActsAsChattable # :nodoc
module ViewHelpers # :nodoc
# This helper will render chat views for specific page.
#
# friends is an array of user which should presents current user's friends.
# use_yui indicate if YUI should be used to get a better look, default is true.
#
# *Examples*
#
# # users_controller.rb
# def index
# @friends = current_user.friends
# end
#
# # index.html.erb
# <%= render_chat @friends %>
#
def render_chat(user, friends)
chat = <<-JS
JS
chat += <<-JS