lukeredpath (owner)

Revisions

gist: 64712 Download_button fork
public
Public Clone URL: git://gist.github.com/64712.git
Embed All Files: show embed
Importing mephisto comments into disqus using RSS and Sinatra.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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