Sha256: b6e644e016570f85857089924e78e33d32b33a92e6b1a2def0d2a8eb00c394d3
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
# * George Moschovitis <gm@navel.gr> # (c) 2004-2005 Navel, all rights reserved. # $Id: rss.rb 249 2005-02-04 14:03:00Z gmosx $ require 'rss/0.9' require 'glue/string' module N # 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 class << self # Options: # # [+:description+] # Description of the Feed # [+:base+] # Base url of the Feed. # [+:link+] # Link of the Feed. def render_0_9(objects, options = {}) c = { :description => 'Syndication' }.update(options) c[:base] ||= c[:link] raise "Option ':base' cannot be infered!" unless c[:base] channel = RSS::Rss::Channel.new channel.description = c[:description] channel.link = c[:link] if c[:link] 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 = "#{c[:base]}/#{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 alias_method :render, :render_0_9 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.10.0 | lib/nitro/builders/rss.rb |