From 60fa7e3ac4a95ce579ab57e3db21105253c5a31d Mon Sep 17 00:00:00 2001 From: maxwell <maxwell@joindiaspora.com> Date: Wed, 23 Jun 2010 01:26:00 -0700 Subject: [PATCH] view stuffs --- app/controllers/status_messages_controller.rb | 4 +- app/helpers/application_helper.rb | 4 ++ app/helpers/status_messages_helper.rb | 2 +- app/views/layouts/application.html.haml | 42 +++---------------- .../status_messages/_new_status_message.haml | 6 +++ app/views/status_messages/index.erb.js | 0 app/views/status_messages/index.html.haml | 4 +- app/views/status_messages/new.html.haml | 2 +- config/environment.rb | 2 +- config/initializers/socket.rb | 25 ++++++----- public/javascripts/view.js | 19 +++++++++ spec/spec_helper.rb | 4 -- 12 files changed, 56 insertions(+), 58 deletions(-) create mode 100644 app/views/status_messages/_new_status_message.haml create mode 100644 app/views/status_messages/index.erb.js create mode 100644 public/javascripts/view.js diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 063a3ba79a..c0507fcdac 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -2,9 +2,9 @@ class StatusMessagesController < ApplicationController before_filter :authenticate_user! def index + @status_message = StatusMessage.new @status_messages = StatusMessage.criteria.all.order_by( [:created_at, :desc] ) - @friends = Friend.all - @posts = Post.stream + respond_to do |format| format.html diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9ae4b3f947..645627ecc8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,4 +37,8 @@ module ApplicationHelper class_name = post.class.name.to_s.underscore "#{class_name.pluralize}/#{class_name}" end + + def how_long_ago(obj) + time_ago_in_words(obj.created_at) + " ago." + end end diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index a2b81e2e3d..32a742d9e9 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -3,7 +3,7 @@ module StatusMessagesHelper def my_latest_message message = StatusMessage.my_newest unless message.nil? - return message.message + " " + time_ago_in_words(message.created_at) + " ago." + return message.message + " " + how_long_ago(message) else return "No message to display." end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index cd54311262..b6169196c7 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -7,14 +7,12 @@ = stylesheet_link_tag "blueprint/screen", :media => 'screen' = stylesheet_link_tag "application" - = javascript_include_tag 'jquery142' /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" - = javascript_include_tag 'rails' - = javascript_include_tag 'jquery_form' + = javascript_include_tag 'jquery142', 'rails', 'view' + + - unless request.user_agent.include? "Safari" ||"Chrome" - = javascript_include_tag 'FABridge' - = javascript_include_tag 'swfobject' - = javascript_include_tag 'web_socket' + = javascript_include_tag 'FABridge', 'swfobject', 'web_socket' :javascript WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf"; @@ -39,35 +37,6 @@ debug("connected..."); }; }); - - :javascript - $(document).ready(function(){ - - $('a').hover(function(){ - $(this).fadeTo(60, 0.5); - }, function(){ - $(this).fadeTo(80, 1); - }); - $('ul.nav li').hover(function(){ - $(this).fadeTo(60, 0.5); - }, function(){ - $(this).fadeTo(80, 1); - }); - - // wait for the DOM to be loaded - // bind 'myForm' and provide a simple callback function - $('#new_status_message').ajaxForm(function() { - alert("Thank you for your comment!"); - }); - $('#new_bookmark').ajaxForm(function() { - alert("Thank you for your comment!"); - }); - - $('#new_blog').ajaxForm(function() { - alert("Thank you for your comment!"); - }); - }); - %body %header %a#diaspora_text{:href => root_path} @@ -87,8 +56,7 @@ %h1#user_name = link_to User.first.real_name, root_url %span.description - - if StatusMessage.my_newest - = StatusMessage.my_newest.message + = my_latest_message %nav %ul.nav diff --git a/app/views/status_messages/_new_status_message.haml b/app/views/status_messages/_new_status_message.haml new file mode 100644 index 0000000000..5e3ac86638 --- /dev/null +++ b/app/views/status_messages/_new_status_message.haml @@ -0,0 +1,6 @@ += form_for status_message, :remote => true do |f| + = f.error_messages + %p + /= f.label :message + = f.text_field :message, :value => "tell me something good" + = f.submit 'oh yeah!', :class => 'button' \ No newline at end of file diff --git a/app/views/status_messages/index.erb.js b/app/views/status_messages/index.erb.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/status_messages/index.html.haml b/app/views/status_messages/index.html.haml index 940352f06b..6773a6ffad 100644 --- a/app/views/status_messages/index.html.haml +++ b/app/views/status_messages/index.html.haml @@ -1,5 +1,7 @@ -%h1.big_text= link_to "new status message", new_status_message_path +%h1.big_text status messages += render "status_messages/new_status_message", :status_message => @status_message %ul#stream + - for status_message in @status_messages = render "status_message", :post => status_message diff --git a/app/views/status_messages/new.html.haml b/app/views/status_messages/new.html.haml index 9f8e9fe2d3..2e9c884749 100644 --- a/app/views/status_messages/new.html.haml +++ b/app/views/status_messages/new.html.haml @@ -1,6 +1,6 @@ - title "New Status Message" -= form_for @status_message do |f| += form_for @status_message, :remote => true do |f| = f.error_messages %p = f.label :message diff --git a/config/environment.rb b/config/environment.rb index 5cc56e741d..3303b3ac5e 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the rails application require File.expand_path('../application', __FILE__) - +Haml::Template.options[:format] = :html5 # Initialize the rails application Diaspora::Application.initialize! diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index f02c12f4a6..9e6d7ff59c 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -6,6 +6,7 @@ module WebSocket EM.add_timer(0.1) do @channel = EM::Channel.new @view = ActionView::Base.new(ActionController::Base.view_paths, {}) + class << @view include ApplicationHelper include Rails.application.routes.url_helpers @@ -16,20 +17,22 @@ module WebSocket ws.onopen { sid = @channel.subscribe { |msg| ws.send msg } - ws.onmessage { |msg| - @channel.push msg - } - - ws.onclose { - @channel.unsubscribe(sid) - } + ws.onmessage { |msg| @channel.push msg} + ws.onclose { @channel.unsubscribe(sid) } } end } - #this should get folded into message queue i think? + def self.update_clients(object) - n = @view.render(:partial => @view.type_partial(object), :locals => {:post => object}) - @channel.push({:class =>object.class.to_s.underscore.pluralize, :html => n}.to_json) if @channel + @channel.push(WebSocket.view_hash(object).to_json) if @channel + end + + def self.view_hash(object) + {:class =>object.class.to_s.underscore.pluralize, :html => WebSocket.view_for(object)} + end + + def self.view_for(object) + @view.render(:partial => @view.type_partial(object), :locals => {:post => object}) end -end +end \ No newline at end of file diff --git a/public/javascripts/view.js b/public/javascripts/view.js new file mode 100644 index 0000000000..3ddcca4a53 --- /dev/null +++ b/public/javascripts/view.js @@ -0,0 +1,19 @@ +$(document).ready(function(){ + + $('a').hover(function(){ + $(this).fadeTo(60, 0.5); + }, function(){ + $(this).fadeTo(80, 1); + }); + + $('ul.nav li').hover(function(){ + $(this).fadeTo(60, 0.5); + }, function(){ + $(this).fadeTo(80, 1); + }); + +$('#status_message_message').click(function() { + $(this).val("") +}); + +}); \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aee2538363..4c24f07521 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,10 +12,6 @@ include Devise::TestHelpers Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} Rspec.configure do |config| - # == Mock Framework - # - # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: - #this is a dumb hax TODO #config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr -- GitLab