Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/hotsh/rstat.us
Browse files Browse the repository at this point in the history
  • Loading branch information
caleywoods committed Mar 27, 2011
2 parents 694071f + 9177c6e commit a437d42
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 112 deletions.
Binary file added public/images/404.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 48 additions & 78 deletions rstatus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ def require_login!(opts = {:return => "/"})
redirect opts[:return]
end
end

def set_params_page
params[:page] ||= 1
params[:per_page] ||= 25
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i
end

def set_next_prev_page
@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1}"

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
else
@prev_page = nil
end
end
end

helpers UserHelper
Expand Down Expand Up @@ -111,7 +128,7 @@ class Rstatus < Sinatra::Base
helpers do
[:development, :production, :test].each do |environment|
define_method "#{environment.to_s}?" do
return settings.environment == environment.to_sym
return settings.environment == environment
end
end
end
Expand All @@ -123,17 +140,8 @@ class Rstatus < Sinatra::Base

get '/' do
if logged_in?

params[:page] ||= 1
params[:per_page] ||= 25
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i

@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1}"

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
end
set_params_page
set_next_prev_page

@updates = current_user.timeline(params)

Expand Down Expand Up @@ -171,16 +179,8 @@ class Rstatus < Sinatra::Base

get '/replies' do
if logged_in?
params[:page] ||= 1
params[:per_page] ||= 25
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i

@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1}"

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
end
set_params_page
set_next_prev_page

@replies = current_user.at_replies(params)
haml :replies
Expand Down Expand Up @@ -236,10 +236,7 @@ class Rstatus < Sinatra::Base
end

get '/users' do
params[:page] ||= 1
params[:per_page] ||= 20
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i
set_params_page

if params[:letter] == "other"
@users = User.where(:username => /^[^a-z0-9]/i)
Expand All @@ -257,14 +254,8 @@ class Rstatus < Sinatra::Base
@users = @users.paginate(:page => params[:page], :per_page => params[:per_page])

@next_page = nil
@prev_page = nil

@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1, :letter => params[:letter]}"

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1, :letter => params[:letter]}"
end

set_next_prev_page

haml :"users/index"
end

Expand Down Expand Up @@ -304,10 +295,7 @@ class Rstatus < Sinatra::Base

# show user profile
get "/users/:slug" do
params[:page] ||= 1
params[:per_page] ||= 20
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i
set_params_page

user = User.first :username => params[:slug]
if user.nil?
Expand All @@ -321,13 +309,7 @@ class Rstatus < Sinatra::Base
@updates = Update.where(:feed_id => user.feed.id).order(['created_at', 'descending']).paginate(:page => params[:page], :per_page => params[:per_page])

@next_page = nil
@prev_page = nil

@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1}"

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
end
set_next_prev_page

haml :"users/show"
end
Expand Down Expand Up @@ -372,13 +354,10 @@ class Rstatus < Sinatra::Base
when /^feed:\/\//
feed_url = "http" + params[:url][4..-1]
when /@/

# TODO: ensure caching of finger lookup.
acct = Redfinger.finger(params[:url])
feed_url = acct.links.find { |l| l['rel'] == 'http://schemas.google.com/g/2010#updates-from' }

else

feed_url = params[:url]
end

Expand All @@ -399,10 +378,9 @@ class Rstatus < Sinatra::Base
end

# follow them!

f = current_user.follow! feed_url
unless f
flash[:notice] = "The was a problem following #{params[:url]}."
flash[:notice] = "There was a problem following #{params[:url]}."
redirect request.referrer
return
end
Expand Down Expand Up @@ -497,36 +475,31 @@ class Rstatus < Sinatra::Base

# This lets us see who is following.
get '/users/:name/following' do
params[:page] ||= 1
params[:per_page] ||= 20
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i
set_params_page

feeds = User.first(:username => params[:name]).following

@users = feeds.paginate(:page => params[:page], :per_page => params[:per_page])
@users = feeds.paginate(:page => params[:page], :per_page => params[:per_page], :order => :id.desc)

@next_page = nil
@prev_page = nil

if params[:page]*params[:per_page] < feeds.count
@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1}"
end

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
end

haml :"users/list", :locals => {:title => "Following"}
end

get '/users/:name/followers' do
params[:page] ||= 1
params[:per_page] ||= 20
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i
set_params_page

feeds = User.first(:username => params[:name]).followers

@users = feeds.paginate(:page => params[:page], :per_page => params[:per_page])
@users = feeds.paginate(:page => params[:page], :per_page => params[:per_page], :order => :id.desc)

@next_page = nil
@prev_page = nil
Expand All @@ -539,7 +512,6 @@ class Rstatus < Sinatra::Base
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
end


haml :"users/list", :locals => {:title => "Followers"}
end

Expand Down Expand Up @@ -572,10 +544,12 @@ class Rstatus < Sinatra::Base
# tell hubs there is a new entry
current_user.feed.ping_hubs(url(current_user.feed.url))

if params[:text].length >= 1 and params[:text].length <= 140
flash[:notice] = "Update created."
else
if params[:text].length <= 1
flash[:notice] = "Your status is too short!"
elsif params[:text].length >= 140
flash[:notice] = "Your status is too long!"
else
flash[:notice] = "Update created."
end

redirect "/"
Expand Down Expand Up @@ -667,21 +641,18 @@ class Rstatus < Sinatra::Base
end

not_found do
haml :'404', :layout => false
haml :'error', :layout => false, :locals => {:code => 404, :message => "We couldn't find the page you're looking for"}
end

error do
haml :'error', :layout => false, :locals => {:code => 500, :message => "Something went wrong"}
end

get "/hashtags/:tag" do
@hashtag = params[:tag]
params[:page] ||= 1
params[:per_page] ||= 25
params[:page] = params[:page].to_i
params[:per_page] = params[:per_page].to_i

@next_page = "?#{Rack::Utils.build_query :page => params[:page] + 1}"
set_params_page

if params[:page] > 1
@prev_page = "?#{Rack::Utils.build_query :page => params[:page] - 1}"
end
set_next_prev_page
@updates = Update.hashtag_search(@hashtag, params)
@timeline = true
@update_text = params[:status]
Expand Down Expand Up @@ -710,4 +681,3 @@ class Rstatus < Sinatra::Base
end

end

19 changes: 19 additions & 0 deletions test/rstatus_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ def test_user_unfollow_another_user
assert_match "No longer following #{u2.username}", page.body
end

def test_users_followers_in_order
aardvark = Factory(:user, :username => "aardvark", :created_at => Date.new(2010, 10, 23))
zebra = Factory(:user, :username => "zebra", :created_at => Date.new(2011, 10, 23))
giraffe = Factory(:user, :username => "giraffe", :created_at => Date.new(2011, 10, 23))
leopard = Factory(:user, :username => "leopard", :created_at => Date.new(2011, 10, 23))
a = Factory(:authorization, :user => aardvark)

log_in(aardvark, a.uid)

visit "/users/#{leopard.username}"
click_button "follow-#{leopard.feed.id}"

visit "/users/#{zebra.username}"
click_button "follow-#{zebra.feed.id}"

visit "/users/#{aardvark.username}/following"
assert_match /zebra.*aardvark/m, page.body
end

def test_user_following_paginates
u = Factory(:user)
a = Factory(:authorization, :user => u)
Expand Down
12 changes: 5 additions & 7 deletions views/_updates.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- updates.each do |update|
- mentioned = current_user.nil? ? false : update.mentioned?(current_user.username)
.update{:class => mentioned ? "mention" : "", :id => "update-#{update.id}", "data-id" => update.id, "data-name" => update.author.username}
- mine = current_user.nil? ? false : update.author.user == current_user
.update{:class => (mentioned ? "mention " : "") + (mine ? "mine " : ""), :id => "update-#{update.id}", "data-id" => update.id, "data-name" => update.author.username}
.avatar
%a{:href => update.author.url}
%img{:alt => "avatar", :src => update.author.avatar_url}/
Expand All @@ -27,16 +28,13 @@
%a.reply{:href => "/?reply=#{update.id}"} reply

- if current_user and update.author.id == current_user.author.id
.remove-update
%form{:method => "post", :action => "/updates/#{update.id}"}
%input{:type => "hidden", :name => "_method", :value => "delete"}
%input.remove-update{:type => "submit", :value => "I Regret This"}
%form{:method => "post", :action => "/updates/#{update.id}"}
%input{:type => "hidden", :name => "_method", :value => "delete"}
%input.remove-update{:type => "submit", :value => "I Regret This"}

- if updates.empty?
.empty
There's no updates here yet

- content_for :css do
%link{:href=>"/css/update.css", :media=>"screen", :rel=>"stylesheet"}
- content_for :javascript do
%script{:src=>"/js/updates.show.js"}
7 changes: 5 additions & 2 deletions views/404.haml → views/error.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%html
%head
%meta{:charset => "utf-8"}
%title rstat.us - 404
%title rstat.us - #{code}
%link{:href => "/screen.css", :media => "screen", :rel => "stylesheet"}
%style

Expand All @@ -12,10 +12,13 @@
%h1
Oops!
%h3
Something went wrong.
#{message}

%a{:href => "/"}
Go back to rstat.us

.image404
%img{:src => "/images/404.jpg"}
/
Browsers like Google Chrome and Internet Explorer decide not to display
error pages if the content length of the page is too short. For Internet Explorer,
Expand Down
Loading

0 comments on commit a437d42

Please sign in to comment.