2014-09-24 34 views
0

我使用ruby的stdlib rss庫創建Atom提要。這個庫基本上是無證的,但我有工作利用設置在this page的例子:Ruby RSS/Atom創建 - 包括內容

require 'rss' 

rss = RSS::Maker.make("atom") do |m| 

    m.channel.author = "Steve Wattam" 
    m.channel.updated = Time.now 
    m.channel.about = "http://stephenwattam.com/blog/" 
    m.channel.title = "Steve W's Blog" 

    storage.posts.each do |p| 
     m.items.new_item do |item| 
      item.link = p.link 
      item.title = p.title 
      item.updated = p.edited 
      item.pubDate = p.date 
      item.summary = p.summary 
     end 
    end 
end 

這工作得很好。但是,我無法添加內容元素。沒有像item.content=這樣的東西,我似乎無法在網上找到任何示例代碼---瀏覽源代碼說明content存儲在該項目(docs here)中,但我缺乏相關知識來挑逗它出。

有沒有人知道我可能會去添加一個內容元素?順便說一句,我知道其他庫存在這樣做,但理想情況下,希望得到這個工作,而不需要任何寶石。

回答

1

通過挖掘庫的來源,我發現item.content產生一個RSS::Maker::Atom::Feed::Items::Item::Content類型的對象。它可以設置該對象的內容:

item.content.content = 'text to set as content' 

這個對象也響應#xml_content

希望這可以幫助別人!