Sha256: 871d86bbe2361585586af9d9692d6492765185180c63857a4584049e5861d0a2

Contents?: true

Size: 902 Bytes

Versions: 1

Compression:

Stored size: 902 Bytes

Contents

# code:
# * George Moschovitis  <gm@navel.gr>
#
# (c) 2004 Navel, all rights reserved.
# $Id: rss.rb 185 2004-12-10 13:29:09Z 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.8.0 lib/nitro/builders/rss.rb