Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add Atom feed.

  • Loading branch information...
commit 579437ba2c28b10678090ed1b567521182a45c56 1 parent 79732d0
Jason Weathered jasoncodes authored
1  Gemfile
@@ -8,3 +8,4 @@ gem 'thin'
8 8 gem 'rake'
9 9 gem 'haml'
10 10 gem 'redcarpet'
  11 +gem 'builder'
2  Gemfile.lock
@@ -2,6 +2,7 @@ GEM
2 2 remote: http://rubygems.org/
3 3 specs:
4 4 backports (2.6.4)
  5 + builder (3.1.4)
5 6 daemons (1.1.6)
6 7 eventmachine (0.12.10)
7 8 haml (3.1.4)
@@ -35,6 +36,7 @@ PLATFORMS
35 36 ruby
36 37
37 38 DEPENDENCIES
  39 + builder
38 40 haml
39 41 rake
40 42 redcarpet
11 blog.rb
@@ -27,6 +27,10 @@ def latest_posts
27 27 def partial(page, options={})
28 28 haml "_#{page}".to_sym, options.merge!(:layout => false)
29 29 end
  30 +
  31 + def url_base
  32 + "http://#{request.host_with_port}"
  33 + end
30 34 end
31 35
32 36 get '/index.php' do
@@ -63,4 +67,11 @@ def partial(page, options={})
63 67
64 68 haml :archive
65 69 end
  70 +
  71 + get '/feed' do
  72 + @posts = latest_posts.first(10)
  73 +
  74 + content_type 'application/atom+xml'
  75 + builder :feed
  76 + end
66 77 end
27 views/feed.builder
... ... @@ -0,0 +1,27 @@
  1 +xml.instruct!
  2 +xml.feed :xmlns => 'http://www.w3.org/2005/Atom' do
  3 + xml.title TITLE
  4 + xml.link :href => "#{url_base}/feed", :rel => :self, :type => 'application/atom+xml'
  5 + xml.link :href => "#{url_base}/archive", :rel => :alternate, :type => 'text/html'
  6 + xml.id "#{url_base}/"
  7 + xml.updated @posts.first.date.to_time.xmlschema
  8 +
  9 + @posts.each do |post|
  10 + xml.entry do
  11 + url = "#{url_base}/posts/#{post.name}"
  12 + xml.title post.title, :type => :html
  13 + xml.link :href => url, :rel => :alternate, :type => 'text/html'
  14 + xml.published post.date.to_time.xmlschema
  15 + xml.updated post.date.to_time.xmlschema
  16 +
  17 + xml.author do
  18 + xml.name TITLE
  19 + end
  20 +
  21 + xml.id url
  22 + xml.content :type => :html, 'xml:base' => url do
  23 + xml.cdata! post.content
  24 + end
  25 + end
  26 + end
  27 +end
1  views/layout.haml
@@ -16,6 +16,7 @@
16 16 %link{:href=>"/stylesheets/sunburst.css", :rel=>"stylesheet", :type=>"text/css"}
17 17 %link{:href=>"/stylesheets/font-awesome.css", :rel=>"stylesheet", :type=>"text/css"}
18 18 %link{:href=>"/stylesheets/style.css", :rel=>"stylesheet", :type=>"text/css"}
  19 + %link{:href=>"/feed", :rel=>"alternate", :type=>"application/atom+xml", :title=>title}
19 20
20 21 %title #{title}
21 22 %body

0 comments on commit 579437b

Please sign in to comment.
Something went wrong with that request. Please try again.