-
Notifications
You must be signed in to change notification settings - Fork 4
/
home.rb
43 lines (38 loc) · 1.1 KB
/
home.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
warn "#{__FILE__} is currently undergoing a merger into lib/"
module Bithug
class Routes < Sinatra::Base
helpers do
def user
User.find(:name => (params[:username] || current_user)).first
end
end
get '/' do
redirect "/#{current_user}"
end
get '/:username/?' do
uzer = user
haml :home, {},
:user => uzer,
:repositories => uzer.repositories,
:writeable_repositories => Repository.writeable_repos(uzer),
:readable_repositories => Repository.readable_repos(uzer),
:following => this_user.following.include?(uzer)
end
post "/:username/?" do
if params["post"]["key"]
Key.add(:user => user,
:name => params["post"]["name"],
:value => params["post"]["key"])
elsif params["post"]["follow"]
uzer = user
uzer.following << params[:username]
uzer.save
elsif params["post"]["unfollow"]
uzer = user
uzer.following.delete(params[:username])
uzer.save
end
redirect request.path_info
end
end
end