Sha256: 1a81c43254cbbb40a359d7ff96d7011023da39a65898c726361d170f25f1de57

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

# Any item shoud respond at least to :title, :link, :pubdate, :category, :guid, :description, :guid_is_permalink.
# 
# The simplest way to achieve that is use a decorator:
# 
# class PostRssItem < Fullstack::Rss::Item
#   
#   # ============
#   # = Required =
#   # ============
#   
#   delegate :title, :to => :object
#   
#   def link
#     site_post_url(object)
#   end
#   
#   def pubdate
#     object.created_at.xmlschema
#   end
#   
#   def category
#     cdata(object.category.title) # cdata helper is provided by Fullstack::Rss::ItemDecorator
#   end
#   
#   def description
#     cdata(object.intro.html_safe)
#   end
#   
#   # ============
#   # = Optional =
#   # ============
#   
#   def guid
#     link # this is the default 
#   end
#   
#   def guid_is_permalink?
#     false # this is also the default
#   end
# 
# end

module Fullstack
  module Rss
    class Item
      
      attr_accessor :object
      def initialize(object)
        @object = object
      end
  
      def guid
        link
      end
        
      def guid_is_permalink?
        false
      end
      
      protected
      
      def cdata(text)
        "<![#{text}]]>".html_safe
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fullstack-rss-0.1.2 lib/fullstack/rss/item.rb
fullstack-rss-0.1.1 lib/fullstack/rss/item.rb