Merge branch 'master' of github.com:diaspora/diaspora_rails

Conflicts:
	app/views/layouts/application.html.haml
This commit is contained in:
danielvincent 2010-06-29 14:36:46 -07:00
commit 67123c664a
13 changed files with 126 additions and 93 deletions

View file

@ -1,23 +1,4 @@
class Friend < Person
xml_accessor :url
key :url, String
validates_presence_of :url
validates_format_of :url, :with =>
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
#validate {self.url ! = User.first.url}
before_validation :clean_url
protected
def clean_url
if self.url
self.url = 'http://' + self.url unless self.url.match('http://' || 'https://')
self.url = self.url + '/' if self.url[-1,1] != '/'
end
end
end

View file

@ -3,15 +3,34 @@ class Person
include ROXML
xml_accessor :email
xml_accessor :url
key :email, String
key :url, String, :unique => true
one :profile, :class_name => 'Profile', :foreign_key => :person_id
many :posts, :class_name => 'Post', :foreign_key => :person_id
timestamps!
validates_presence_of :url
validates_format_of :url, :with =>
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
validates_presence_of :email
before_validation :clean_url
def real_name
self.profile.first_name + " " + self.profile.last_name
end
end
protected
def clean_url
self.url ||= "http://localhost:3000/" if self.class == User
if self.url
self.url = 'http://' + self.url unless self.url.match('http://' || 'https://')
self.url = self.url + '/' if self.url[-1,1] != '/'
end
end
end

View file

@ -1,14 +1,11 @@
class User < Person
include MongoMapper::Document
timestamps!
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
def comment(text, options = {})
raise "Comment on what, motherfucker?" unless options[:on]
Comment.new(:person_id => self.id, :text => text, :post => options[:on]).save

View file

@ -11,8 +11,18 @@
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
= javascript_include_tag 'jquery142', 'rails', 'view'
= javascript_include_tag 'tiny_mce/tiny_mce.js'
:javascript
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17207587-1']);
_gaq.push(['_setDomainName', '#{root_url}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
- unless request.user_agent.include? "Safari" ||"Chrome"
= javascript_include_tag 'FABridge', 'swfobject', 'web_socket'
:javascript
@ -49,6 +59,7 @@
});
});
= javascript_include_tag 'satisfaction'
%body
- flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_#{name}"
@ -58,13 +69,13 @@
%a#diaspora_text{:href => root_path}
%img{:src => '/images/diaspora_white.png'}
#session_action
- if user_signed_in?
=User.first.email
|
= link_to "logout", destroy_user_session_path
- else
= link_to "login", new_user_session_path
#session_action
- if user_signed_in?
=User.first.email
|
= link_to "logout", destroy_user_session_path
- else
= link_to "login", new_user_session_path
.container

View file

@ -1,23 +1,14 @@
require 'em-websocket'
require 'eventmachine'
require 'lib/socket_render'
module WebSocket
EM.next_tick {
EM.add_timer(0.1) do
@channel = EM::Channel.new
puts @channel.inspect
include SocketRenderer
#this should really be a controller
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << @view
include ApplicationHelper
include Rails.application.routes.url_helpers
include ActionController::RequestForgeryProtection::ClassMethods
def protect_against_forgery?
false
end
end
SocketRenderer.instantiate_view
end
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>true) do |ws|
@ -32,26 +23,8 @@ module WebSocket
}
def self.update_clients(object)
@channel.push(WebSocket.view_hash(object).to_json) if @channel
@channel.push(SocketRenderer.view_hash(object).to_json) if @channel
end
def self.view_hash(object)
begin
puts "I be working hard"
v = WebSocket.view_for(object)
puts v.inspect
rescue Exception => e
puts "in failzord " + v.inspect
puts object.inspect
puts e.message
raise e
end
puts "i made it here"
{:class =>object.class.to_s.underscore.pluralize, :html => v}
end
def self.view_for(object)
@view.render @view.type_partial(object), :post => object
end
end

35
lib/socket_render.rb Normal file
View file

@ -0,0 +1,35 @@
module SocketRenderer
require 'app/helpers/application_helper'
def self.instantiate_view
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << @view
include ApplicationHelper
include Rails.application.routes.url_helpers
include ActionController::RequestForgeryProtection::ClassMethods
def protect_against_forgery?
false
end
end
end
def self.view_hash(object)
begin
puts "I be working hard"
v = view_for(object)
puts v.inspect
rescue Exception => e
puts "in failzord " + v.inspect
puts object.inspect
puts e.message
raise e
end
puts "i made it here"
{:class =>object.class.to_s.underscore.pluralize, :html => v}
end
def self.view_for(object)
@view.render @view.type_partial(object), :post => object
end
end

View file

@ -0,0 +1,14 @@
var is_ssl = ("https:" == document.location.protocol);
var asset_host = is_ssl ? "https://s3.amazonaws.com/getsatisfaction.com/" : "http://s3.amazonaws.com/getsatisfaction.com/";
document.write(unescape("%3Cscript src='" + asset_host + "javascripts/feedback-v2.js' type='text/javascript'%3E%3C/script%3E"));
var feedback_widget_options = {};
feedback_widget_options.display = "inline";
feedback_widget_options.company = "diaspora";
feedback_widget_options.placement = "left";
feedback_widget_options.color = "#222";
feedback_widget_options.style = "idea";
var feedback_widget = new GSFN.feedback_widget(feedback_widget_options);

View file

@ -138,8 +138,7 @@ h1 {
position: relative;
font-size: 21px;
font-weight: bold;
line-height: 36px;
text-shadow: 0 1px 1px #cccccc; }
line-height: 36px; }
h1 p.description, h1 span.description {
font-weight: 200;
font-family: "helvetica neue", "lucida grande", "sans-serif";
@ -149,8 +148,7 @@ h1 {
h3 {
position: relative;
font-size: 18px;
font-weight: bold;
text-shadow: 0 1px 1px #cccccc; }
font-weight: bold; }
#publish input#thought {
font-size: 30px;

View file

@ -166,16 +166,12 @@ h1
:family 'helvetica neue', 'lucida grande', 'sans-serif'
:color #999
:padding 0.1em
:text
:shadow 0 1px 1px #ccc
h3
:position relative
:font
:size 18px
:weight bold
:text
:shadow 0 1px 1px #ccc
#publish
input#thought

View file

@ -23,7 +23,7 @@ end
Factory.define :friend do |f|
f.email 'max@max.com'
f.url 'http://max.com/'
f.sequence(:url) {|n|"http://max#{n}.com/"}
f.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" )
end

View file

@ -0,0 +1,23 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe SocketRenderer do
before do
SocketRenderer.instantiate_view
@user = Factory.create(:user, :email => "bob@jones.com")
@user.profile = Factory.build(:profile, :person => @user)
end
it 'should render a partial for a status message' do
message = Factory.create(:status_message, :person => @user)
html = SocketRenderer.view_for message
html.include? message.message
end
it 'should prepare a class/view hash' do
message = Factory.create(:status_message, :person => @user)
hash = SocketRenderer.view_hash(message)
hash[:class].should == "status_messages"
end
end

View file

@ -2,18 +2,4 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe WebSocket do
it 'should prepare a view along with an objects class in json' do
EventMachine.run {
include WebSocket
user = Factory.create(:user)
post = Factory.create(:status_message)
json = WebSocket.view_hash(post)
json.should include post.message
EventMachine.stop
}
end
end

View file

@ -48,7 +48,7 @@ describe Post do
describe "stream" do
before do
@owner = Factory.create(:user, :email => "robert@grimm.com")
@owner = Factory.build(:user)
@friend_one = Factory.create(:friend, :email => "some@dudes.com")
@friend_two = Factory.create(:friend, :email => "other@dudes.com")