Sha256: fd8275335d8840fde83b9cf49f159f408cac8f55837cc9e80d74d49f9ca94864
Contents?: true
Size: 1.52 KB
Versions: 2
Compression:
Stored size: 1.52 KB
Contents
require 'cgi' require 'rss/0.9' require 'facet/string/first_char' module Nitro # 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. # use custom version to add headers like the following. # <?xml version="1.0" encoding="UTF-8"?> # <?xml-stylesheet href="rss.css" type="text/css"?> #++ module RssMixin # === 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) if obj.respond_to? :body and body = obj.body item.description = CGI.escape(body.first_char(256)) end if obj.respond_to? :to_href item.link = "#{c[:base]}/#{obj.to_href}" end channel.items << item end rss = RSS::Rss.new '0.9' rss.channel = channel return rss.to_s end alias_method :build_rss, :build_rss_09 alias_method :rss, :build_rss_09 end end # * George Moschovitis <gm@navel.gr>
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.21.0 | lib/nitro/mixin/rss.rb |
nitro-0.21.2 | lib/nitro/mixin/rss.rb |