Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Atom feed.

  • Loading branch information...
commit 579437ba2c28b10678090ed1b567521182a45c56 1 parent 79732d0
@jasoncodes jasoncodes authored
View
1  Gemfile
@@ -8,3 +8,4 @@ gem 'thin'
gem 'rake'
gem 'haml'
gem 'redcarpet'
+gem 'builder'
View
2  Gemfile.lock
@@ -2,6 +2,7 @@ GEM
remote: http://rubygems.org/
specs:
backports (2.6.4)
+ builder (3.1.4)
daemons (1.1.6)
eventmachine (0.12.10)
haml (3.1.4)
@@ -35,6 +36,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ builder
haml
rake
redcarpet
View
11 blog.rb
@@ -27,6 +27,10 @@ def latest_posts
def partial(page, options={})
haml "_#{page}".to_sym, options.merge!(:layout => false)
end
+
+ def url_base
+ "http://#{request.host_with_port}"
+ end
end
get '/index.php' do
@@ -63,4 +67,11 @@ def partial(page, options={})
haml :archive
end
+
+ get '/feed' do
+ @posts = latest_posts.first(10)
+
+ content_type 'application/atom+xml'
+ builder :feed
+ end
end
View
27 views/feed.builder
@@ -0,0 +1,27 @@
+xml.instruct!
+xml.feed :xmlns => 'http://www.w3.org/2005/Atom' do
+ xml.title TITLE
+ xml.link :href => "#{url_base}/feed", :rel => :self, :type => 'application/atom+xml'
+ xml.link :href => "#{url_base}/archive", :rel => :alternate, :type => 'text/html'
+ xml.id "#{url_base}/"
+ xml.updated @posts.first.date.to_time.xmlschema
+
+ @posts.each do |post|
+ xml.entry do
+ url = "#{url_base}/posts/#{post.name}"
+ xml.title post.title, :type => :html
+ xml.link :href => url, :rel => :alternate, :type => 'text/html'
+ xml.published post.date.to_time.xmlschema
+ xml.updated post.date.to_time.xmlschema
+
+ xml.author do
+ xml.name TITLE
+ end
+
+ xml.id url
+ xml.content :type => :html, 'xml:base' => url do
+ xml.cdata! post.content
+ end
+ end
+ end
+end
View
1  views/layout.haml
@@ -16,6 +16,7 @@
%link{:href=>"/stylesheets/sunburst.css", :rel=>"stylesheet", :type=>"text/css"}
%link{:href=>"/stylesheets/font-awesome.css", :rel=>"stylesheet", :type=>"text/css"}
%link{:href=>"/stylesheets/style.css", :rel=>"stylesheet", :type=>"text/css"}
+ %link{:href=>"/feed", :rel=>"alternate", :type=>"application/atom+xml", :title=>title}
%title #{title}
%body
Please sign in to comment.
Something went wrong with that request. Please try again.