Permalink
Browse files

Added basics for using markdown to send html rich messages

  • Loading branch information...
1 parent f7174c3 commit 5195dc2b315d0b03fcb883201ae5e2ce1fd77d25 @baphled committed Apr 28, 2011
View
@@ -12,6 +12,8 @@ gem "compass", ">= 0.10.4"
gem "compass-960-plugin", :git => "git://github.com/chriseppstein/compass-960-plugin.git"
gem 'pusher'
+gem 'rdiscount'
+gem 'redcarpet'
group :development, :test do
gem 'nifty-generators'
View
@@ -144,6 +144,8 @@ GEM
thor (~> 0.14.4)
rake (0.8.7)
rb-fsevent (0.4.0)
+ rdiscount (1.6.8)
+ redcarpet (1.11.4)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
@@ -202,6 +204,8 @@ DEPENDENCIES
pusher
rails (= 3.0.6)
rb-fsevent
+ rdiscount
+ redcarpet
rspec-rails (>= 2.0.0.beta.20)
sqlite3
timecop!
@@ -11,6 +11,8 @@ def new
end
def create
+ params[:chat_engine_message][:body] = "#{params[:chat_engine_message][:from]}: #{params[:chat_engine_message][:body]}"
+ p params[:chat_engine_message]
@message = ChatEngine::Message.new params[:chat_engine_message]
if @message.save
Pusher['messages'].trigger('new-message', @message.attributes)
@@ -1,10 +1,13 @@
+require 'mongoid/markdown'
+
module ChatEngine
class Message
include Mongoid::Document
+ include Mongoid::Markdown
field :from
field :sent, :default => Time.now
- field :body
+ field :body, :markdown => true
validates_presence_of :body, :on => :create
end
@@ -1,17 +1,15 @@
<section id="main">
<section id="chat">
- <% if @messages.present? %>
<ul class="messages">
<% @messages.each do |message| %>
<li>
- <%= message.from %>: <%= message.body %>
+ <%=raw message.body %>
</li>
<% end %>
</ul>
- <% end %>
</section>
<section id="input">
- <% form_for(@message, :url => chat_engine_messages_path, :method => :post, :remote => true) do |f| %>
+ <%= form_for(@message, :url => chat_engine_messages_path, :method => :post, :remote => true) do |f| %>
<%= f.hidden_field :from %>
<%= f.text_field :body, :placeholder => "Enter your message here..." %>
<%= f.submit "Send", :disable_with => 'Sending...' %>
View
@@ -1,3 +1,5 @@
+require 'redcarpet'
+
module ChatEngine
require 'chat_engine/engine' if defined?(Rails)
end
@@ -9,6 +9,7 @@ def copy_assets
# JavaScript
copy_file"public/javascripts/chat-engine.js","public/javascripts/chat-engine.js"
+ copy_file"public/javascripts/showdown.js","public/javascripts/showdown.js"
copy_file"public/javascripts/jquery.cssemoticons.min.js","public/javascripts/jquery.cssemoticons.min.js"
# Stylesheets
@@ -1,8 +1,11 @@
$(document).ready(function(){
- var pusher = new Pusher('1760cc2007fea206f2df');
+ var pusher = new Pusher('YOUR PUSHER APP ID');
var channel = pusher.subscribe('messages');
channel.bind('new-message', function(data) {
- $new_message = $('<li>').append(data['from'] + ": " + data['body']);
+ var converter = new Showdown.converter();
+ var html = converter.makeHtml(data['body']);
+
+ $new_message = $('<li>').append(html);
$('ul.messages').prepend($new_message);
});
Oops, something went wrong.

0 comments on commit 5195dc2

Please sign in to comment.