Class: Pressroom::Feed
- Inherits:
-
Object
- Object
- Pressroom::Feed
- Defined in:
- lib/pressroom/feed.rb
Overview
Builds RSS 2.0 and Atom 1.0 documents from a collection of posts.
The gem does not own public routes, so the caller supplies a block that turns a post into its public URL.
Instance Method Summary collapse
-
#initialize(posts, title:, url:, description:, author: nil, &link_builder) ⇒ Feed
constructor
A new instance of Feed.
- #to_atom ⇒ Object
- #to_rss ⇒ Object
Constructor Details
#initialize(posts, title:, url:, description:, author: nil, &link_builder) ⇒ Feed
Returns a new instance of Feed.
11 12 13 14 15 16 17 18 |
# File 'lib/pressroom/feed.rb', line 11 def initialize(posts, title:, url:, description:, author: nil, &link_builder) @posts = posts @title = title @url = url @description = description @author = || title @link_builder = link_builder || ->(post) { "#{url}/#{post.slug}" } end |
Instance Method Details
#to_atom ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pressroom/feed.rb', line 31 def to_atom RSS::Maker.make("atom") do |maker| maker.channel.id = @url maker.channel.title = @title maker.channel.link = @url maker.channel.description = @description maker.channel. = @author maker.channel.updated = updated_at.to_s add_items(maker) end.to_s end |
#to_rss ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pressroom/feed.rb', line 20 def to_rss RSS::Maker.make("2.0") do |maker| maker.channel.title = @title maker.channel.link = @url maker.channel.description = @description maker.channel.updated = updated_at.to_s add_items(maker) end.to_s end |