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!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@status_message = StatusMessage.new
|
||||||
@status_messages = StatusMessage.criteria.all.order_by( [:created_at, :desc] )
|
@status_messages = StatusMessage.criteria.all.order_by( [:created_at, :desc] )
|
||||||
@friends = Friend.all
|
|
||||||
@posts = Post.stream
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,8 @@ module ApplicationHelper
|
||||||
class_name = post.class.name.to_s.underscore
|
class_name = post.class.name.to_s.underscore
|
||||||
"#{class_name.pluralize}/#{class_name}"
|
"#{class_name.pluralize}/#{class_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def how_long_ago(obj)
|
||||||
|
time_ago_in_words(obj.created_at) + " ago."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ module StatusMessagesHelper
|
||||||
def my_latest_message
|
def my_latest_message
|
||||||
message = StatusMessage.my_newest
|
message = StatusMessage.my_newest
|
||||||
unless message.nil?
|
unless message.nil?
|
||||||
return message.message + " " + time_ago_in_words(message.created_at) + " ago."
|
return message.message + " " + how_long_ago(message)
|
||||||
else
|
else
|
||||||
return "No message to display."
|
return "No message to display."
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,12 @@
|
||||||
|
|
||||||
= stylesheet_link_tag "blueprint/screen", :media => 'screen'
|
= stylesheet_link_tag "blueprint/screen", :media => 'screen'
|
||||||
= stylesheet_link_tag "application"
|
= 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"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"
|
||||||
= javascript_include_tag 'rails'
|
= javascript_include_tag 'jquery142', 'rails', 'view'
|
||||||
= javascript_include_tag 'jquery_form'
|
|
||||||
|
|
||||||
- unless request.user_agent.include? "Safari" ||"Chrome"
|
- unless request.user_agent.include? "Safari" ||"Chrome"
|
||||||
= javascript_include_tag 'FABridge'
|
= javascript_include_tag 'FABridge', 'swfobject', 'web_socket'
|
||||||
= javascript_include_tag 'swfobject'
|
|
||||||
= javascript_include_tag 'web_socket'
|
|
||||||
:javascript
|
:javascript
|
||||||
WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf";
|
WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf";
|
||||||
|
|
||||||
|
|
@ -39,35 +37,6 @@
|
||||||
debug("connected...");
|
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
|
%body
|
||||||
%header
|
%header
|
||||||
%a#diaspora_text{:href => root_path}
|
%a#diaspora_text{:href => root_path}
|
||||||
|
|
@ -87,8 +56,7 @@
|
||||||
%h1#user_name
|
%h1#user_name
|
||||||
= link_to User.first.real_name, root_url
|
= link_to User.first.real_name, root_url
|
||||||
%span.description
|
%span.description
|
||||||
- if StatusMessage.my_newest
|
= my_latest_message
|
||||||
= StatusMessage.my_newest.message
|
|
||||||
|
|
||||||
%nav
|
%nav
|
||||||
%ul.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
|
%ul#stream
|
||||||
|
|
||||||
- for status_message in @status_messages
|
- for status_message in @status_messages
|
||||||
= render "status_message", :post => status_message
|
= render "status_message", :post => status_message
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
- title "New Status Message"
|
- title "New Status Message"
|
||||||
|
|
||||||
= form_for @status_message do |f|
|
= form_for @status_message, :remote => true do |f|
|
||||||
= f.error_messages
|
= f.error_messages
|
||||||
%p
|
%p
|
||||||
= f.label :message
|
= f.label :message
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# Load the rails application
|
# Load the rails application
|
||||||
require File.expand_path('../application', __FILE__)
|
require File.expand_path('../application', __FILE__)
|
||||||
|
Haml::Template.options[:format] = :html5
|
||||||
# Initialize the rails application
|
# Initialize the rails application
|
||||||
Diaspora::Application.initialize!
|
Diaspora::Application.initialize!
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ module WebSocket
|
||||||
EM.add_timer(0.1) do
|
EM.add_timer(0.1) do
|
||||||
@channel = EM::Channel.new
|
@channel = EM::Channel.new
|
||||||
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
||||||
|
|
||||||
class << @view
|
class << @view
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
|
@ -16,20 +17,22 @@ module WebSocket
|
||||||
ws.onopen {
|
ws.onopen {
|
||||||
sid = @channel.subscribe { |msg| ws.send msg }
|
sid = @channel.subscribe { |msg| ws.send msg }
|
||||||
|
|
||||||
ws.onmessage { |msg|
|
ws.onmessage { |msg| @channel.push msg}
|
||||||
@channel.push msg
|
|
||||||
}
|
|
||||||
|
|
||||||
ws.onclose {
|
|
||||||
@channel.unsubscribe(sid)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ws.onclose { @channel.unsubscribe(sid) }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
#this should get folded into message queue i think?
|
|
||||||
def self.update_clients(object)
|
def self.update_clients(object)
|
||||||
n = @view.render(:partial => @view.type_partial(object), :locals => {:post => object})
|
@channel.push(WebSocket.view_hash(object).to_json) if @channel
|
||||||
@channel.push({:class =>object.class.to_s.underscore.pluralize, :html => n}.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
|
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}
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
||||||
|
|
||||||
Rspec.configure do |config|
|
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 :mocha
|
||||||
# config.mock_with :flexmock
|
# config.mock_with :flexmock
|
||||||
# config.mock_with :rr
|
# config.mock_with :rr
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue