Sha256: a24c334bcafd03123fc29468b073e1ea3cf466a3153922ab4ae63b75d854f497
Contents?: true
Size: 1.53 KB
Versions: 5
Compression:
Stored size: 1.53 KB
Contents
# * George Moschovitis <gm@navel.gr> # (c) 2004-2005 Navel, all rights reserved. # $Id: rss.rb 266 2005-02-28 14:50:48Z 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. # Add this mixin to you classes to support RSS rendering. # #-- # TODO: add more options here, 1.0/2.0 support and more. #++ module RssBuilderMixin # === Options # # [+:description+] # Description of the Feed # [+:base+] # Base url of the Feed. # [+:link+] # Link of the Feed. def build_rss_09(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 self << rss.to_s end alias_method :build_rss, :build_rss_09 end # Abstract class for the RssBuilderMixin. class RssBuilder < String include RssBuilderMixin class << self def build_09(objects, options = {}) RssBuilder.new.build_rss_09(objects, options) end alias_method :build, :build_09 end end end
Version data entries
5 entries across 5 versions & 1 rubygems