Sha256: 90cc7227b7d44b839277427b327257026ce1f1df052eba44cde0f5fc2f9de1a9
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
require 'cgi' require 'rss/0.9' require 'facet/string/first_char' require 'nitro/mixin/markup' 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 include Nitro::Markup # === 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 = markup(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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.22.0 | lib/nitro/mixin/rss.rb |