Class: Smeagol::RSS

Inherits:
Object
  • Object
show all
Defined in:
lib/smeagol/helpers/rss.rb

Instance Method Summary collapse

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, options={})
  @ctrl    = ctrl
  @wiki    = ctrl.wiki
  @version = options[:version] || 'master'
  @posts   = options[:posts]
end

Instance Method Details

#build_rssObject

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

Returns:

  • an RSS::Rss object.


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.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.)

      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

#postsObject


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

#rssObject

Build the RSS instance and cache the result.

Returns:

  • an RSS::Rss object.


36
37
38
# File 'lib/smeagol/helpers/rss.rb', line 36

def rss
  @rss ||= build_rss
end

#to_sObject

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