From a683a2c1aae8a60ca351afe5bf2336e207076b11 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 29 Jun 2010 11:45:41 -0700 Subject: [PATCH 1/5] RS MS added goog analytics --- app/views/layouts/application.html.haml | 2 +- config/initializers/socket.rb | 35 +++---------------------- public/javascripts/google.js | 14 ++++++++++ spec/lib/web_socket_spec.rb | 16 +---------- 4 files changed, 20 insertions(+), 47 deletions(-) create mode 100644 public/javascripts/google.js diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 31b14138f..be9535559 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -9,7 +9,7 @@ = stylesheet_link_tag "blueprint/screen", :media => 'screen' = stylesheet_link_tag "application" /= 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 'jquery142', 'rails', 'view', 'google' = javascript_include_tag 'tiny_mce/tiny_mce.js' diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 701cc0502..22086046d 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -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 - #this should really be a controller - @view = ActionView::Base.new(ActionController::Base.view_paths, {}) + include SocketRenderer - class << @view - include ApplicationHelper - include Rails.application.routes.url_helpers - include ActionController::RequestForgeryProtection::ClassMethods - def protect_against_forgery? - false - end - end 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 diff --git a/public/javascripts/google.js b/public/javascripts/google.js new file mode 100644 index 000000000..2ea0010bb --- /dev/null +++ b/public/javascripts/google.js @@ -0,0 +1,14 @@ + diff --git a/spec/lib/web_socket_spec.rb b/spec/lib/web_socket_spec.rb index 55e383a73..4613dc98a 100644 --- a/spec/lib/web_socket_spec.rb +++ b/spec/lib/web_socket_spec.rb @@ -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 \ No newline at end of file + From 1b2745e788df56bfe6f05f11512f5fb9dcac1e72 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 29 Jun 2010 11:46:08 -0700 Subject: [PATCH 2/5] added socket renderer spec and slight refactor --- config/initializers/socket.rb | 2 +- lib/socket_render.rb | 35 ++++++++++++++++++++++++++++++++ spec/lib/socket_renderer_spec.rb | 23 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 lib/socket_render.rb create mode 100644 spec/lib/socket_renderer_spec.rb diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 22086046d..3c716ef05 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -6,9 +6,9 @@ module WebSocket EM.add_timer(0.1) do @channel = EM::Channel.new puts @channel.inspect - include SocketRenderer + SocketRenderer.instantiate_view end EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>true) do |ws| diff --git a/lib/socket_render.rb b/lib/socket_render.rb new file mode 100644 index 000000000..0bcc6371c --- /dev/null +++ b/lib/socket_render.rb @@ -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 diff --git a/spec/lib/socket_renderer_spec.rb b/spec/lib/socket_renderer_spec.rb new file mode 100644 index 000000000..19144d852 --- /dev/null +++ b/spec/lib/socket_renderer_spec.rb @@ -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 From 19e03c707793fe56472612bd6d87e88932659b1c Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 29 Jun 2010 12:33:00 -0700 Subject: [PATCH 3/5] person now has a url, and they cant add themselves any longer.... you need to add a url to your old development user, and we need to set it in the field --- app/models/friend.rb | 19 ------------------- app/models/person.rb | 25 ++++++++++++++++++++++--- app/models/user.rb | 9 +++------ spec/factories.rb | 2 +- spec/models/post_spec.rb | 2 +- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/app/models/friend.rb b/app/models/friend.rb index d7809ac6c..e98971890 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index 7428e9b5f..09e16d8dc 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 1751f15a1..6fdb5e4ea 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index b75cdbc92..37032592f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 38d206ddd..b3df7552f 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -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") From 60336bd520778c5bf4476dfff8f2a287f28746f3 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 29 Jun 2010 13:45:54 -0700 Subject: [PATCH 4/5] trying to get GS working --- app/views/layouts/application.html.haml | 15 ++++++++------- public/javascripts/google.js | 4 ---- public/javascripts/satisfaction.js | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 public/javascripts/satisfaction.js diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 58c87be19..745f9ae23 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -41,6 +41,7 @@ debug("connected..."); }; }); + = javascript_include_tag 'satisfaction' %body - flash.each do |name, msg| = content_tag :div, msg, :id => "flash_#{name}" @@ -50,13 +51,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 #header_below .container diff --git a/public/javascripts/google.js b/public/javascripts/google.js index 2ea0010bb..3c01e09b6 100644 --- a/public/javascripts/google.js +++ b/public/javascripts/google.js @@ -1,5 +1,3 @@ - diff --git a/public/javascripts/satisfaction.js b/public/javascripts/satisfaction.js new file mode 100644 index 000000000..16dcf52e8 --- /dev/null +++ b/public/javascripts/satisfaction.js @@ -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); From 6532962c1c25fac90b7390fe495745d2147c20c8 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 29 Jun 2010 13:58:36 -0700 Subject: [PATCH 5/5] trying to get google analytics working --- app/views/layouts/application.html.haml | 14 ++++++++++++-- public/javascripts/google.js | 10 ---------- 2 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 public/javascripts/google.js diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 745f9ae23..ebfc78da6 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -9,10 +9,20 @@ = stylesheet_link_tag "blueprint/screen", :media => 'screen' = stylesheet_link_tag "application" /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" - = javascript_include_tag 'jquery142', 'rails', 'view', 'google' + = 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 diff --git a/public/javascripts/google.js b/public/javascripts/google.js deleted file mode 100644 index 3c01e09b6..000000000 --- a/public/javascripts/google.js +++ /dev/null @@ -1,10 +0,0 @@ - var _gaq = _gaq || []; - _gaq.push(['_setAccount', 'UA-17207587-1']); - _gaq.push(['_setDomainName', '.joindiaspora.com']); - _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); - })();