Sha256: 6e4505545d1b49ea5241413bf31f8f2b1f1b4312177686374facdda142ccb124

Contents?: true

Size: 902 Bytes

Versions: 2

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 = G::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

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.6.0 lib/nitro/builders/rss.rb
nitro-0.7.0 lib/nitro/builders/rss.rb