Sha256: 85bf0d2acc4c77e555af4ce47f5023c17c0e04d1660159692db67181691d68c9
Contents?: true
Size: 1.62 KB
Versions: 4
Compression:
Stored size: 1.62 KB
Contents
require 'cgi' require 'rss/0.9' require 'facet/string/first_char' require 'glue/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 RssHelper include Glue::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 = { :title => 'Syndication', :description => 'Syndication' }.update(options) c[:base] ||= c[:link] raise "Option ':base' cannot be infered!" unless c[:base] channel = RSS::Rss::Channel.new channel.title = c[:title] 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.28.0 | lib/nitro/helper/rss.rb |
nitro-0.29.0 | lib/nitro/helper/rss.rb |
nitro-0.30.0 | lib/nitro/helper/rss.rb |
nitro-0.31.0 | lib/nitro/helper/rss.rb |