diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 95dff0a71..9ae4b3f94 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -32,4 +32,9 @@ module ApplicationHelper def mine?(post) post.owner == User.first.email end + + def type_partial(post) + class_name = post.class.name.to_s.underscore + "#{class_name.pluralize}/#{class_name}" + end end diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb index 810c2b74f..4e26c74d8 100644 --- a/app/helpers/dashboard_helper.rb +++ b/app/helpers/dashboard_helper.rb @@ -1,8 +1,5 @@ module DashboardHelper - def type_partial(post) - class_name = post.class.name.to_s.underscore - "#{class_name.pluralize}/#{class_name}" - end + end diff --git a/app/models/post.rb b/app/models/post.rb index a03d3736c..6ea021e46 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -41,7 +41,7 @@ class Post protected def send_to_view - WebSocket.update_clients (self.to_json) + WebSocket.update_clients(self) end def set_defaults diff --git a/app/views/bookmarks/_bookmark.html.haml b/app/views/bookmarks/_bookmark.html.haml index f1fcc1b4d..88a7b82f7 100644 --- a/app/views/bookmarks/_bookmark.html.haml +++ b/app/views/bookmarks/_bookmark.html.haml @@ -4,7 +4,10 @@ %b shared a link %br = post.title - = link_to post.link + /- (foo = post.link.to_s) + /- (bar = post.link) + %a{:href => "#{post.link}"} + = post.link %div.time= link_to "#{time_ago_in_words(post.updated_at)} ago", bookmark_path(post) - if mine?(post) = link_to 'Destroy', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 441a285bc..acfb64372 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -10,6 +10,15 @@ = javascript_include_tag 'jquery142' /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" = javascript_include_tag 'rails' + + - unless request.user_agent.include? "Safari" ||"Chrome" + = javascript_include_tag 'FABridge' + = javascript_include_tag 'swfobject' + = javascript_include_tag 'web_socket' + :javascript + WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf"; + + = javascript_include_tag 'socket' if user_signed_in? = csrf_meta_tag = yield(:head) @@ -42,6 +51,7 @@ = link_to "login", new_user_session_path #header_below + - if user_signed_in? %h1#user_name = link_to User.first.real_name, root_url diff --git a/app/views/shared/_post.html.haml b/app/views/posts/_post.html.haml similarity index 100% rename from app/views/shared/_post.html.haml rename to app/views/posts/_post.html.haml diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index a9ed0e9b5..2770ba631 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -26,8 +26,14 @@ module WebSocket end } #this should get folded into message queue i think? - def self.update_clients(json) - @channel.push(json) if @channel + def self.update_clients(object) + view = ActionView::Base.new(ActionController::Base.view_paths, {}) + class << view + include ApplicationHelper + include Rails.application.routes.url_helpers + end + n = view.render(:partial =>view.type_partial(object), :locals => {:post => object}) + @channel.push(n) if @channel end end diff --git a/public/javascripts/socket.js b/public/javascripts/socket.js index a4d6e04bb..6f66507f3 100644 --- a/public/javascripts/socket.js +++ b/public/javascripts/socket.js @@ -1,8 +1,10 @@ -$(document).ready(function(){ + $(document).ready(function(){ function debug(str){ $("#debug").append("
" + str); }; ws = new WebSocket("ws://localhost:8080/"); - ws.onmessage = function(evt) { $(".msg").prepend("
"+evt.data+"
"); }; + ws.onmessage = function(evt) { + $("#stream").prepend($(evt.data).fadeIn("fast")); + }; ws.onclose = function() { debug("socket closed"); }; ws.onopen = function() { debug("connected..."); diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 836898582..c8304d1ad 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -125,14 +125,14 @@ ul#stream { ul#stream > li { list-style: none; padding: 1em; - border-bottom: 1px solid #f1f1f1; } + border-bottom: 1px solid #f1f1f1; + margin-bottom: 5px; } li.message { line-height: 140%; font-size: 120%; font-family: "Lucida Grande"; - color: #999999; - margin-bottom: 5px; } + color: #999999; } li.message span.from { color: black; font-weight: bold; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index e6b4dde87..3915ee700 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -151,6 +151,7 @@ ul#stream :padding 1em :border :bottom 1px solid #f1f1f1 + :margin-bottom 5px li.message :line-height 140% @@ -158,7 +159,7 @@ li.message :size 120% :family 'Lucida Grande' :color #999 - :margin-bottom 5px + span.from :color #000 diff --git a/spec/controllers/bookmarks_controller_spec.rb b/spec/controllers/bookmarks_controller_spec.rb index ba62b588c..0259c32d1 100644 --- a/spec/controllers/bookmarks_controller_spec.rb +++ b/spec/controllers/bookmarks_controller_spec.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../spec_helper' describe BookmarksController do before do #TODO(dan) Mocking Warden; this is a temp fix + request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user) @bob = Factory.build(:user) @bookmark = Factory.build(:bookmark) @@ -31,7 +32,7 @@ describe BookmarksController do it "update action should redirect when model is valid" do #TODO(dan) look into why we need to create a new bookmark object here Bookmark.any_instance.stubs(:valid?).returns(true) - n = Factory.create(:bookmark, :link => "http://hotub.com") + n = Factory.create(:bookmark, :link => "http://hotub.com/") n.save put :update, :id => Bookmark.first.id response.should redirect_to(bookmark_url(assigns[:bookmark])) diff --git a/spec/lib/common_spec.rb b/spec/lib/common_spec.rb index ec9433119..bc5bdf41d 100644 --- a/spec/lib/common_spec.rb +++ b/spec/lib/common_spec.rb @@ -39,7 +39,7 @@ describe Diaspora do describe "body" do before do - @post = Factory.create(:post) + @post = Factory.create(:status_message) end it "should add the following methods to Post on inclusion" do @@ -71,7 +71,7 @@ describe Diaspora do it "should check that it does not send a friends post to an owners friends" do Post.stub(:build_xml_for).and_return(true) Post.should_not_receive(:build_xml_for) - Factory.create(:post, :owner => "nottheowner@post.com") + Factory.create(:status_message, :owner => "nottheowner@post.com") end it "should ensure one url is created for every friend" do diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 79457ab03..f8908e23e 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -10,7 +10,9 @@ describe Post do describe 'defaults' do before do - @post = Factory.create(:post, :owner => nil, :source => nil, :snippet => nil) + WebSocket.stub!(:update_clients) + @post = Factory.create(:post, :owner => nil, :source => nil, :snippet => nil) + end it "should add an owner if none is present" do