Class: Nwiki::Frontend::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/nwiki/frontend/app/feed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git_repo_path, opts = {}) ⇒ Feed

Returns a new instance of Feed.



8
9
10
11
# File 'lib/nwiki/frontend/app/feed.rb', line 8

def initialize git_repo_path, opts = {}
  @wiki = Nwiki::Core::Wiki.new git_repo_path
  @articles_path = opts[:articles_path] || ''
end

Instance Attribute Details

#articles_pathObject (readonly)

Returns the value of attribute articles_path.



6
7
8
# File 'lib/nwiki/frontend/app/feed.rb', line 6

def articles_path
  @articles_path
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nwiki/frontend/app/feed.rb', line 13

def call env
  [
    200,
    { 'Content-Type' => "application/atom+xml; charset=#{Nwiki::Core::Wiki.repo_filename_encoding}" },
    [
      RSS::Maker.make('atom') { |maker|
        maker.channel.title = @wiki.title
        maker.channel.description = @wiki.subtitle
        maker.channel.link = Rack::Request.new(env).url

        maker.channel.author = @wiki.author
        maker.channel.date = @wiki.log.max_by(&:time).time
        maker.channel.id = Rack::Request.new(env).url

        maker.items.do_sort = true
        maker.items.max_size = 50

        @wiki.log.each do |diff|
          path = Nwiki::Core::Wiki.canonicalize_path(diff.path)
          next if path =~ /\.gif|png|jpg$/ # FIXME Don't display binary file at feed
          path.gsub!(/\.org$/, '')

          maker.items.new_item do |item|
            item.link = Rack::Request.new(env).url.gsub(Regexp.new(Rack::Request.new(env).fullpath), "#{articles_path}/#{path}")
            item.title = path
            item.date = diff.time
          end
        end
      }.to_s
    ]
  ]
end