view stuffs
This commit is contained in:
parent
a6b36cb93e
commit
60fa7e3ac4
12 changed files with 56 additions and 58 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
6
app/views/status_messages/_new_status_message.haml
Normal file
6
app/views/status_messages/_new_status_message.haml
Normal file
|
|
@ -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'
|
||||
0
app/views/status_messages/index.erb.js
Normal file
0
app/views/status_messages/index.erb.js
Normal file
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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
|
||||
19
public/javascripts/view.js
Normal file
19
public/javascripts/view.js
Normal file
|
|
@ -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("")
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue