Class: Smeagol::RSS
- Inherits:
-
Object
- Object
- Smeagol::RSS
- Defined in:
- lib/smeagol/helpers/rss.rb
Instance Method Summary collapse
-
#build_rss ⇒ Object
Build an RSS instance using Ruby’s RSS::Maker library.
-
#initialize(ctrl, options = {}) ⇒ RSS
constructor
Initialize a new Smeagol::RSS instance.
- #posts ⇒ Object
-
#rss ⇒ Object
Build the RSS instance and cache the result.
-
#to_s ⇒ Object
Convert the RSS object to XML string.
Constructor Details
#initialize(ctrl, options = {}) ⇒ RSS
Initialize a new Smeagol::RSS instance.
11 12 13 14 15 16 |
# File 'lib/smeagol/helpers/rss.rb', line 11 def initialize(ctrl, ={}) @ctrl = ctrl @wiki = ctrl.wiki @version = [:version] || 'master' @posts = [:posts] end |
Instance Method Details
#build_rss ⇒ Object
Build an RSS instance using Ruby’s RSS::Maker library.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/smeagol/helpers/rss.rb', line 45 def build_rss ::RSS::Maker.make('2.0') do |maker| maker.channel.link = @wiki.settings.url maker.channel.title = @wiki.settings.title maker.channel.description = @wiki.settings.description.to_s maker.channel. = @wiki.settings..to_s maker.channel.updated = Time.now.to_s maker.items.do_sort = true posts.each do |post| html = post.content date = Time.parse(post.post_date) next if date > Time.now unless @wiki.settings.future if i = html.index('</p>') text = html[0..i+4] else text = html end maker.items.new_item do |item| item.title = post.title item.link = File.join(@wiki.settings.url, post.href) item.date = date item.description = text end end end end |
#posts ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/smeagol/helpers/rss.rb', line 84 def posts @ctrl.views(@version).select{ |p| p.post? } #@posts ||= ( # @wiki.pages.map do |page| # next unless page.post? # Smeagol::Views::Post.new(@ctrl, page) # end.compact #) end |
#rss ⇒ Object
Build the RSS instance and cache the result.
36 37 38 |
# File 'lib/smeagol/helpers/rss.rb', line 36 def rss @rss ||= build_rss end |
#to_s ⇒ Object
Convert the RSS object to XML string.
79 80 81 |
# File 'lib/smeagol/helpers/rss.rb', line 79 def to_s rss.to_s end |