#! /usr/bin/ruby
# Save the array of feed items as an XML file.
# If the requested type is RSS, a standard RSS feed will be created.
# Otherwise the file requested will include the full feed title and link for use
# in generating the web page.
def make_xml(itemlist, type)
file = File.new( type + '.xml','w')
file.puts('<?xml version="1.0"?>')
if type == 'rss'
file.puts('<rss version="2.0">')
else
file.puts('<' + type + '>')
end
# Write out the XML header.
file.puts(' <channel>')
file.puts(' <title>' + get_param('rubyriver.yml','sitetitle') + '</title>')
file.puts(' <link>' + get_param('rubyriver.yml','sitelink') + '</link>')
file.puts(' <description>' + get_param('rubyriver.yml','sitedescription') + '</description>')
file.puts(' <language>' + get_param('rubyriver.yml','sitelanguage') + '</language>')
file.puts(' <copyright>' + get_param('rubyriver.yml','sitecopyright') + '</copyright>')
file.puts(' <pubDate>' + Time.now.rfc2822 + '</pubDate>')
file.puts(' <lastBuildDate>' + Time.now.rfc2822 + '</lastBuildDate>')
file.puts(' <generator>RubyRiver 0.1</generator>')
# Write out each feed item.
itemlist.each do |item|
# Each element of the itemlist array has the following structure:
# [pubdate, {pubdate,title,description,link,feedlink,feedtitle}]
# The hash containing the item's data will be used to generate a new RSS item.
current_item = item[1]
file.puts(' <item>')
if type != 'rss'
file.puts(' <feedtitle>' + current_item['feedtitle'] + '</feedtitle>')
file.puts(' <feedlink>' + current_item['feedlink'] + '</feedlink>')
end
file.puts(' <pubDate>' + current_item['pubdate'] + '</pubDate>')
file.puts(' <title>' + current_item['title'] + '</title>')
file.puts(' <link>' + current_item['link'] + '</link>')
file.puts(' <description>' + current_item['description'] + '</description>')
file.puts(' <guid>' + current_item['link'] + '</guid>')
file.puts(' </item>')
end
file.puts(' </channel>')
file.puts('</' + type + '>')
file.close
end