What would be a good way to implement emoticons/smiley's in a simple messaging system? I came out on red cloth as a valuable solution.
The messages will be saved in the DB like ;), :) ;( * like described here but this is old: http://flip.netzbeben.de/2008/07/smilies-in-rails-using-redcloth/ I try that any comments on that solution in safety etc?
UPDATE: Created a helper method , this one works
def emoticons(text)
emoticons = { ":)" => "<img src='/assets/emoticons/smile.gif' class='emoticon'>",
":(" => "<img src='/assets/emoticons/cry.gif' class='emoticon'>"
}
[emoticons.keys, emoticons.values].transpose.each do |search, replace|
text.gsub!(search, replace)
end
return raw text
end
Any way to more improve this? the replacement works although the
This
emoticons = {":)" => "[happy/]", ":(" => "[sad/]"}
text = "test :) :("
[emoticons.keys, emoticons.values].transpose.each do |search, replace|
text.gsub!(search, replace)
end
p text
will output
test [happy/] [sad/]
you can play with gsub
to get HTML output instead of pseudo BB code