Permalink
Browse files

flesh out a few more things

  • Loading branch information...
1 parent f8fccfe commit 4c5be743588f67629f000e36b9a6d90382e79bb8 @atmos committed Apr 9, 2009
@@ -12,6 +12,23 @@ def oauth_consumer
def current_user
session[:user_id].nil? ? nil : ::Lifeline::User.get(session[:user_id])
end
+ def distance_of_time_in_words(from_time, to_time)
+ distance_in_minutes = ((to_time - from_time) / 60).round
+
+ case distance_in_minutes
+ when 0 then "less than a minute"
+ when 1 then "1 minute"
+ when 2..45 then "#{distance_in_minutes} minutes"
+ when 46..90 then "about 1 hour"
+ when 90..1440 then "about #{(distance_in_minutes.to_f / 60.0).round} hours"
+ when 1441..2880 then "1 day"
+ else "#{(distance_in_minutes / 1440).round} days"
+ end
+ end
+
+ def distance_of_time_in_words_to_now(from_time)
+ distance_of_time_in_words(Time.parse(from_time), Time.now)
+ end
end
error do
@@ -44,6 +61,23 @@ def current_user
end
end
+ get '/application.js' do
+ <<-EOF
+$(function() {
+ function refresh_page(since_id) {
+ $.get("/refresh/"+since_id, function(html) {
+ $('ol.statuses').prepend(html)
+ $(html).show('Explode',{},500);
+ });
+ };
+
+ $('ol.statuses').everyTime(50000, function(i) {
+ refresh_page($('ol.statuses li')[0]['id'].replace('status_', ''));
+ })
+});
+ EOF
+ end
+
get '/signup' do
Lifeline.retryable(:times => 2) do
request_token = oauth_consumer.get_request_token
@@ -56,7 +90,6 @@ def current_user
get '/' do
if current_user
@friends_timeline = current_user.friends_timeline[0..25]
- @since_date = Time.now.to_i
haml :home
else
haml :about
@@ -66,7 +99,8 @@ def current_user
get '/refresh/:since' do
if current_user
@friends_timeline = current_user.friends_timeline(params['since'])
- result = JSON(:updates => @friends_timeline, :since => Time.now.to_i)
+ @friends_timeline = @friends_timeline.reject { |entry| entry['id'] <= params['since'].to_i }.compact
+ haml :refresh, :layout => false
end
end
@@ -1,17 +1,13 @@
-.tab
- %ol.statuses{:id => 'timeline'}
- - @friends_timeline.each do |entry|
- - screen_name = entry['user']['screen_name']
- %li.hentry.status{:id => "status_#{entry['status']}"}
- %span.thumb.author
- %a.url{:href => "http://twitter.com/#{screen_name}"}
- %img.photo{:alt => entry['user']['name'], :width => "48", :height => "48", :src => entry['user']['profile_image_url'] }
- %span.status-body
- %strong
- %a.screen-name{:href => "http://twitter.com/#{screen_name}", :title => entry['user']['name']}= screen_name
- %span.entry-content= entry['text']
- %span.meta.entry-meta
- %a.entry-date{:href => "http://twitter.com/#{screen_name}/status/#{entry['id']}", :rel => "bookmark"}
- %span.published= entry['created_at']
- %span= "from #{entry['source']}"
-
+%ol.statuses{:id => 'timeline'}
+ - @friends_timeline.each do |entry|
+ - screen_name = entry['user']['screen_name']
+ %li.entry.selfclear{:id => "status_#{entry['id']}"}
+ %span.thumb
+ %a.url{:href => "http://twitter.com/#{screen_name}"}
+ %img.photo{:alt => entry['user']['name'], :width => "48", :height => "48", :src => entry['user']['profile_image_url'] }
+ %span.entry-content= entry['text']
+ %span.entry-meta
+ = "about #{distance_of_time_in_words_to_now(entry['created_at'])} ago from"
+ %a{:href => "http://twitter.com/#{screen_name}"}
+ %strong= entry['user']['name']
+ = "from #{entry['source']}"
@@ -1,39 +1,53 @@
%html{:xmlns=> "http://www.w3.org/1999/xhtml", 'xml:lang' => "en", :lang => "en"}
%head
%meta{'http-equiv' => "Content-Type", 'content' => "text/html; charset=utf-8"}
- %title lifeline.atmos.org - Your friends timeline
+ - if current_user
+ %title= "#{current_user.name}'s Lifeline"
+ - else
+ %title lifeline.atmos.org - Your friends timeline
+ %script{:type => 'text/javascript', :src => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'}
+ %script{:type => 'text/javascript', :src => 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js'}
+ %script{:type => 'text/javascript', :src => 'http://jquery.offput.ca/js/jquery.timers.js'}
+ %script{:type => 'text/javascript', :src => '/application.js'}
+
%link{:href => '/css/screen.css', :media => 'screen', :rel => 'stylesheet', :type => 'text/css', :media => 'screen, projection'}
- %link{:href => '/css/print.css', :media => 'screen', :rel => 'stylesheet', :type => 'text/css', :media => 'print' }
- /[if IE]
- %link{:href => '/css/ie.css', :media => 'screen', :rel => 'stylesheet', :type => 'text/css', :media => 'screen,projection' }
- %link{:href => '/css/style.css', :media => 'screen', :rel => 'stylesheet', :type => 'text/css', :media => 'screen, projection' }
%body
- #container.container
- #header.span-22.prefix-1
- %h1.caps
- %a{:href => 'http://lifeline.atmos.org'} Friends Timeline
+ #header.selfclear
+ %h1 Lifeline
+ #bubble
+ %p
+ - if current_user
+ Hi
+ = current_user.name
+ , Here's what your friends on twitter are saying.
+ - else
+ Hey there. Do you know what your friends are up to?
- #content.span-17.suffix-2.prefix-2
+ #content.selfclear
+ #left
= yield
- #footer.span-24.last.center
- %p
- Lifeline uses
- %a{:href => 'http://twitter.com'} twitter's
- %a{:href => 'http://apiwiki.twitter.com/'} oauth api
- to simplify organizing events with your friends.
- %a{:href => '/about'} Learn
- more.
- %p
- Another
- %a{:href => 'http://oauth.org'} oauth
- experiment brought to you by
- %a{:href => 'http://atmos.org'} atmos,
- source code available on
- %a{:href => 'http://github.com/atmos/lifeline'} github,
- hosted on
- %a{:href => 'http://engineyard.com/solo'} EY Solo.
- - if current_user
+ #right
+ .right_notes
+ %p
+ Lifeline uses
+ %a{:href => 'http://twitter.com'} twitter's
+ %a{:href => 'http://apiwiki.twitter.com/'} oauth api
+ to constantly refresh your friend timeline.
+ %a{:href => '/about'} Learn
+ more.
%p
- Do me a favor and
- %a{:href => '/peace'} delete these cookies.
+ Another
+ %a{:href => 'http://oauth.org'} oauth
+ experiment brought to you by
+ %a{:href => 'http://twitter.com/atmos'} @atmos,
+ designed by
+ %a{:href => 'http://twitter.com/rustin'} @rustin,
+ source code available on
+ %a{:href => 'http://github.com/atmos/lifeline'} github,
+ hosted on
+ %a{:href => 'http://engineyard.com/solo'} EY Solo.
+ - if current_user
+ %p
+ Do me a favor and
+ %a{:href => '/peace'} delete these cookies.
@@ -0,0 +1,12 @@
+- @friends_timeline.each do |entry|
+ - screen_name = entry['user']['screen_name']
+ %li.entry.selfclear{:id => "status_#{entry['id']}"}
+ %span.thumb
+ %a.url{:href => "http://twitter.com/#{screen_name}"}
+ %img.photo{:alt => entry['user']['name'], :width => "48", :height => "48", :src => entry['user']['profile_image_url'] }
+ %span.entry-content= entry['text']
+ %span.entry-meta
+ = "about #{distance_of_time_in_words_to_now(entry['created_at'])} ago from"
+ %a{:href => "http://twitter.com/#{screen_name}"}
+ %strong= entry['user']['name']
+ = "from #{entry['source']}"
@@ -10,9 +10,9 @@
get '/'
last_response.should have_selector("ol.statuses#timeline")
- last_response.should have_selector("ol.statuses#timeline > li.hentry > span.thumb.author > a > img")
- last_response.should have_selector("ol.statuses#timeline > li.hentry > span.status-body > span.entry-content")
- last_response.should have_selector("ol.statuses#timeline > li.hentry > span.status-body > span.entry-meta")
+ last_response.should have_selector("ol.statuses#timeline > li.entry > span.thumb > a > img")
+ last_response.should have_selector("ol.statuses#timeline > li.entry > span.entry-content")
+ last_response.should have_selector("ol.statuses#timeline > li.entry > span.entry-meta")
end
before(:all) do
@json_data =
@@ -10,9 +10,9 @@
get '/'
last_response.should have_selector("ol.statuses#timeline")
- last_response.should have_selector("ol.statuses#timeline > li.hentry > span.thumb.author > a > img")
- last_response.should have_selector("ol.statuses#timeline > li.hentry > span.status-body > span.entry-content")
- last_response.should have_selector("ol.statuses#timeline > li.hentry > span.status-body > span.entry-meta")
+ last_response.should have_selector("ol.statuses#timeline > li.entry > span.thumb > a > img")
+ last_response.should have_selector("ol.statuses#timeline > li.entry > span.entry-content")
+ last_response.should have_selector("ol.statuses#timeline > li.entry > span.entry-meta")
since = Time.now - 45
get "/refresh/#{since.to_i}"

0 comments on commit 4c5be74

Please sign in to comment.