class Smeagol::RSS

Public Class Methods

new(ctrl, options={}) click to toggle source

Initialize a new Smeagol::RSS instance.

# File lib/smeagol/helpers/rss.rb, line 11
def initialize(ctrl, options={})
  @ctrl    = ctrl
  @wiki    = ctrl.wiki
  @version = options[:version] || 'master'
  @posts   = options[:posts]
end

Public Instance Methods

build_rss() click to toggle source

Build an RSS instance using Ruby's RSS::Maker library.

Returns an RSS::Rss object.

# 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.author       = @wiki.settings.author.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() click to toggle source
# 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() click to toggle source

Build the RSS instance and cache the result.

Returns an RSS::Rss object.

# File lib/smeagol/helpers/rss.rb, line 36
def rss
  @rss ||= build_rss
end
to_s() click to toggle source

Convert the RSS object to XML string.

# File lib/smeagol/helpers/rss.rb, line 79
def to_s
  rss.to_s
end