Skip to content

Commit 1d98da1

Browse files
committed
Adding rss feed back in.
1 parent 94abf16 commit 1d98da1

5 files changed

Lines changed: 99 additions & 63 deletions

File tree

controllers/posts.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,18 @@
106106
#go back to the page for that post
107107
redirect "/posts/#{@post.slug}"
108108
end
109+
110+
#this is for the rss feed. We're using the builder gem to create it
111+
get "/posts.rss" do
112+
#we want them to be in reverse order
113+
@posts = Post.all.sort{|a,b| a.created_at <=> b.created_at }.reverse
114+
115+
#we need to set the proper content-type so that browsers know it's not
116+
#a regular old html page
117+
content_type "application/rss+xml"
118+
119+
require 'builder'
120+
121+
#we don't want to render our normal layout
122+
builder :"posts/index.atom", :layout => false
123+
end

helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def gravatar_url_for email
6565
require 'md5'
6666
"http://www.gravatar.com/avatar/#{MD5::md5(email.downcase)}"
6767
end
68-
68+
6969
#THIS IS NOT DRY!!!!
7070
#These two functions are also in models/discussion.rb
7171
#I'm not sure of the best way to combine them. Anyone want to write a patch?

models/discussion.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Discussion
2626

2727
before_save :make_slug
2828
validate_on_create :author_check
29-
29+
3030
#THIS IS NOT DRY!!!!
3131
#These two functions are also in helpers.rb.
3232
#I'm not sure of the best way to combine them. Anyone want to write a patch?
33-
33+
3434
#gives a printable forum name from a slug
3535
def forum_name
3636
case forum

views/posts/index.atom.builder

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
xml.rss :version => "2.0", "xmlns:atom" => "http://www.w3.org/2005/Atom" do
2+
xml.channel do
3+
xml.send(:"atom:link", :href => "http://feeds.feedburner.com/HacketyHack", :rel => "self", :type => "application/rss+xml")
4+
xml.title "Hackety Hack: Blog"
5+
xml.link 'http://hackety-hack.com'
6+
xml.description "The official blog of the little coder's starter kit."
7+
xml.language 'en'
8+
xml.pubDate @posts.first.created_at.to_s(:rfc822)
9+
xml.lastBuildDate @posts.first.created_at.to_s(:rfc822)
10+
11+
@posts.each do |post|
12+
xml.item do
13+
xml.title post.title
14+
xml.content post.body
15+
xml.pubDate post.created_at.to_s(:rfc822)
16+
xml.link "http://hackety-hack.com/posts/#{post.slug}"
17+
xml.guid({:isPermaLink => "false"}, "http://hackety-hack.com/posts/#{post.slug}")
18+
end
19+
end
20+
end
21+
end

views/stylesheets/site.sass

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
11
body
2-
font-family: Arial, Verdana, sans
3-
background-image: url('/images/hhhello.png')
4-
background-repeat: no-repeat
5-
background-position: 100% 0%
6-
a
7-
color: #40ADA6
2+
font-family: Arial, Verdana, sans
3+
background-image: url('/images/hhhello.png')
4+
background-repeat: no-repeat
5+
background-position: 100% 0%
6+
a
7+
color: #40ADA6
88

99
div#content
10-
border-style: solid
11-
border: 1px
10+
border-style: solid
11+
border: 1px
1212

1313
nav
14-
position: absolute
15-
right: 170px
16-
top: 10px
17-
a
18-
text-decoration: none
19-
font-weight: bold
14+
position: absolute
15+
right: 170px
16+
top: 10px
17+
a
18+
text-decoration: none
19+
font-weight: bold
2020

2121
#pitch
22-
position: absolute
23-
max-width: 600px
24-
left: 20px
25-
top: 50px
26-
font-family: Arial, Verdana, sans
27-
background: #FFFFFF
28-
padding: 1em
29-
border: #000000 solid thick
30-
h1
31-
font-size: 1.5em
32-
h2
33-
padding: 1em 0em 0em 0em
22+
position: absolute
23+
max-width: 600px
24+
left: 20px
25+
top: 50px
26+
font-family: Arial, Verdana, sans
27+
background: #FFFFFF
28+
padding: 1em
29+
border: #000000 solid thick
30+
h1
31+
font-size: 1.5em
32+
h2
33+
padding: 1em 0em 0em 0em
3434

3535
.post
36-
font-family: Arial, Verdana, sans
37-
p
38-
padding: .5em
39-
margin: .25em
40-
font-size: 1.2em
41-
h1
42-
font-size: 2em
43-
h2
44-
font-size: 1.5em
36+
font-family: Arial, Verdana, sans
37+
p
38+
padding: .5em
39+
margin: .25em
40+
font-size: 1.2em
41+
h1
42+
font-size: 2em
43+
h2
44+
font-size: 1.5em
4545

4646
td
47-
padding: 0.5em 0em 0.5em 0.5em
47+
padding: 0.5em 0em 0.5em 0.5em
4848

4949
ul li
50-
list-style-type: disc
51-
margin-left: 20px
52-
padding: 3px
50+
list-style-type: disc
51+
margin-left: 20px
52+
padding: 3px
5353
ul
54-
margin: 20px
54+
margin: 20px
5555

5656
ol li
57-
list-style-type: decimal
58-
margin-left: 1em
59-
margin-bottom: 1em
60-
margin-top: 1em
57+
list-style-type: decimal
58+
margin-left: 1em
59+
margin-bottom: 1em
60+
margin-top: 1em
6161

6262
blockquote
63-
padding: 10px
64-
margin: 20px
65-
border: 2px solid #000
63+
padding: 10px
64+
margin: 20px
65+
border: 2px solid #000
6666

6767
.left
68-
float: left
68+
float: left
6969

7070
.right
71-
float: right
71+
float: right
7272

7373
.comment_gravatar
74-
height: 50px
75-
width: 50px
76-
padding: 10px
77-
position: relative
78-
top: -15px
74+
height: 50px
75+
width: 50px
76+
padding: 10px
77+
position: relative
78+
top: -15px
7979

8080
.comment
81-
p
82-
margin-left: 5em
83-
padding-bottom: 1em
81+
p
82+
margin-left: 5em
83+
padding-bottom: 1em
8484

8585
p.help
86-
margin-top: .5em
87-
margin-bottom: .5em
86+
margin-top: .5em
87+
margin-bottom: .5em
8888

8989
.question
90-
font-weight: bold
90+
font-weight: bold
9191
.answer

0 commit comments

Comments
 (0)