Skip to content

Commit 8bd42d6

Browse files
committed
updating stream links, adding hackers pages
1 parent 48d1b78 commit 8bd42d6

5 files changed

Lines changed: 93 additions & 7 deletions

File tree

models/program.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Program
2+
include MongoMapper::Document
3+
key :creator_username, String
4+
key :title, String
5+
key :slug, String
6+
key :code, String
7+
8+
validate_on_create :slug_check
9+
before_save :make_slug
10+
11+
private
12+
def slug_check
13+
programs = Program.all(:creator_username => creator_username)
14+
unless programs.detect {|p| p.slug == title.to_slug }.nil?
15+
errors.add(:title, "Title needs to be unique")
16+
end
17+
end
18+
19+
20+
def make_slug
21+
self.slug = self.title.to_slug
22+
end
23+
end
24+

views/hackers/followers.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%ul
2+
- @hacker.followers.each do |follower|
3+
%li
4+
%a{:href => "/hackers/#{follower.username}"}= follower.username

views/hackers/following.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%ul
2+
- @hacker.following.each do |followee|
3+
%li
4+
%a{:href => "/hackers/#{followee.username}"}= followee.username

views/hackers/show.haml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%h1= @hacker.username + "'s page"
2+
%img{:src => @hacker.gravatar_url}
3+
%h2 About #{@hacker.username}:
4+
%p= @hacker.about
5+
%hr
6+
%p Following: <a href="/hackers/#{@hacker.username}/following">#{@hacker.following.count}</a>
7+
%p Followers: <a href="/hackers/#{@hacker.username}/followers">#{@hacker.followers.count}</a>
8+
%hr
9+
%h2 Programs:
10+
%ul
11+
- @hacker.programs.each do |program|
12+
%li
13+
%a{:href => "/programs/#{@hacker.username}/#{program.slug}"}= program.title
14+
15+
%hr
16+
- if logged_in?
17+
- if @hacker.username != current_user.username
18+
%a{:href => "/messages/new/to/#{@hacker.username}" }= "Send #{@hacker.username} a message"
19+
- if current_user.following? @hacker
20+
%a{:href => "/hackers/#{@hacker.username}/unfollow"} Unfollow #{@hacker.username}
21+
- else
22+
%a{:href => "/hackers/#{@hacker.username}/follow"} Follow #{@hacker.username}
23+
- else
24+
%h2 Your Account
25+
%p You can use these forms to update your information:
26+
%br
27+
%p
28+
%form{:action => "/hackers/update", :method => "POST"}
29+
%table
30+
%tr
31+
%td
32+
%label{:for => "password[new]"} New Password
33+
%td
34+
%input{:type => "password", :name => "password[new]"}
35+
%tr
36+
%td
37+
%label{:for => "password[confirm]"} Confirm New Password
38+
%td
39+
%input{:type => "password", :name => "password[confirm]"}
40+
%tr
41+
%td
42+
%td
43+
%input{:type => "submit", :value => "Change password"}
44+
%hr
45+
%p
46+
%form{:action => "/hackers/update", :method => "POST"}
47+
%label{:for => "hacker[about]"} About Me
48+
%br
49+
%textarea{:name => "hacker[about]", :rows => 10, :cols => 40}
50+
%br
51+
%input{:type => "submit", :value => "Update About"}
52+

views/stream.haml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
%img{:height => "64", :src => "/images/logo.png", :style => "float:left"}/
33
%p.body{:style => "padding-top:20px;padding-left:80px"} Hackety Hack
44
.span-4.prepend-5.last
5-
%ul
6-
%li{:style => "display:inline"}
7-
%a{:href => "#"} My Page
8-
|
9-
%li{:style => "display:inline"}
10-
%a{:href => "#"} Log out
5+
- if logged_in?
6+
%ul
7+
%li{:style => "display:inline"}
8+
%a{:href => "/hackers/#{current_user.username.to_slug}"} My Page
9+
|
10+
%li{:style => "display:inline"}
11+
%a{:href => "/logout"} Log out
12+
- else
13+
%a{:href => "/login"} Log in
1114
.span-18
12-
%h2 Doing something fun?
1315
%ul#input_list
1416
%li{:style => "display:inline"}
1517
%a#question_button.button{:href => "#"} Ask a question

0 commit comments

Comments
 (0)