Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lukeredpath/64712 to your computer and use it in GitHub Desktop.
Save lukeredpath/64712 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'activerecord'
require 'builder'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:database => 'mephisto'
)
class Content < ActiveRecord::Base
end
class Article < Content
end
class Comment < Content
belongs_to :article
named_scope :approved, :conditions => {:approved => true}
def permalink
article.permalink
end
end
hostname = 'lukeredpath.co.uk'
blog_title = "confessions of a ruby programmer"
comments = Comment.approved
xml = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
xml.instruct! :xml, :version => '1.0'
xml.feed :'xml:lang' => 'en-US', :xmlns => 'http://www.w3.org/2005/Atom' do
xml.id "http://#{hostname}/feed/comments"
xml.link :type => 'text/html', :href => "http://#{hostname}", :rel => 'alternate'
xml.link :type => 'application/atom+xml', :href => "http://#{hostname}/feed/comments", :rel => 'self'
xml.title "Comments for #{blog_title}"
xml.subtitle "#{hostname}"
xml.updated(comments.first ? comments.first.created_at.xmlschema : Time.now.utc.xmlschema) if comments.first
comments.each_with_index do |comment, index|
xml.entry do |entry|
entry.id "http://#{hostname}/blog/#{comment.permalink}.html#comment_#{index}"
xml.updated comment.created_at.xmlschema
entry.link :type => 'text/html', :href => "http://#{hostname}/blog/#{comment.permalink}.html#comment_#{index}", :rel => 'alternate'
entry.title "Comment on #{comment.article.title} by #{comment.author}"
entry.content comment.body_html, :type => 'html'
entry.author do |author|
author.name comment.author
author.uri(comment.author_url) if comment.author_url =~ /^[a-z]/
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment