Class: Nwiki::Frontend::Feed

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Feed.



26
27
28
29
30
# File 'lib/nwiki/frontend/app.rb', line 26

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

Instance Attribute Details

#articles_pathObject (readonly)

Returns the value of attribute articles_path.



24
25
26
# File 'lib/nwiki/frontend/app.rb', line 24

def articles_path
  @articles_path
end

Instance Method Details

#call(env) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/nwiki/frontend/app.rb', line 32

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 = Time.parse('2014-02-06')
        maker.channel.id = Rack::Request.new(env).url

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

        log = @wiki.access.repo.log
        log.each do |commit|
          date = commit.date
          commit.show.each do |diff|
            next unless diff.new_file

            path = Nwiki::Core::Wiki.canonicalize_path(diff.b_path)
            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 = File.basename(path)
              item.date = date
            end
          end
        end
      }.to_s
    ]
  ]
end