ruby / rss

RSS reading and writing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to set content?

dchacke opened this issue · comments

I'm trying to set the content of an item:

maker.items.new_item do |item|
  item.content = '...'
end

But that doesn't work. I see there's a content_encoded= method, but that doesn't result in anything additional being rendered in the XML.

What I need is the ability to set the content as seen in this example GitHub rss feed under feed -> entry -> content.

Could you show a full Ruby script that reproduces this?

Well, there's not really anything to reproduce since this is a feature request (asking for either a present or new feature), not a bug. But if it helps, I've been using the example code from the Readme and just added one line:

require "rss"

rss = RSS::Maker.make("atom") do |maker|
  maker.channel.author = "matz"
  maker.channel.updated = Time.now.to_s
  maker.channel.about = "https://www.ruby-lang.org/en/feeds/news.rss"
  maker.channel.title = "Example Feed"

  maker.items.new_item do |item|
    item.link = "https://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
    item.title = "Ruby 1.9.2-p136 is released"
    item.updated = Time.now.to_s
    
    item.content = '...' # <== this is the new line that doesn't work
  end
end

puts rss
require "rss"

rss = RSS::Maker.make("atom") do |maker|
  maker.channel.author = "matz"
  maker.channel.updated = Time.now.to_s
  maker.channel.about = "https://www.ruby-lang.org/en/feeds/news.rss"
  maker.channel.title = "Example Feed"

  maker.items.new_item do |item|
    item.link = "https://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
    item.title = "Ruby 1.9.2-p136 is released"
    item.updated = Time.now.to_s
    
    item.content.type = 'xhtml'
    item.content.xml = <<-XHTML
<p>Ruby 1.9.2-p136 has been released. This is the second release of Ruby 1.9.2. It fixes many bugs found in
1.9.2-p0. See <a href="https://svn.ruby-lang.org/repos/ruby/tags/v1_9_2_136/ChangeLog">ChangeLog</a> for more detail.</p>
    XHTML
  end
end

puts rss