# code: # * George Moschovitis # # (c) 2004 Navel, all rights reserved. # $Id: rss.rb 202 2005-01-17 10:44:13Z gmosx $ require 'rss/0.9' module N # = RssBuilder # # Build RSS represenations of ruby object collections. # Utilize duck typing to grab the attributes to render. #-- # TODO: add more options here, 1.0/2.0 support and more. #++ class RssBuilder def self.render(objects) channel = RSS::Rss::Channel.new channel.description = 'Syndication' channel.link = $srv_url for obj in objects item = RSS::Rss::Channel::Item.new item.title = obj.title if obj.respond_to?(:title) item.description = N::StringUtils.head(obj.body, 256) if obj.respond_to?(:body) item.link = "#$srv_url/#{obj.view_uri}" if obj.respond_to?(:view_uri) channel.items << item end rss = RSS::Rss.new '0.9' rss.channel = channel return rss.to_s end end end # module