Sha256: a459bd97272a1169dcbe1ab0dc6e6b14191661061455fe5f1f373852f3fab23e

Contents?: true

Size: 1.46 KB

Versions: 24

Compression:

Stored size: 1.46 KB

Contents

require 'rss'

module Nwiki
  module Frontend
    class Feed
      attr_reader :articles_path

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

      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
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
nwiki-0.3.3 lib/nwiki/frontend/app/feed.rb
nwiki-0.3.2 lib/nwiki/frontend/app/feed.rb
nwiki-0.3.1 lib/nwiki/frontend/app/feed.rb
nwiki-0.3.0 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.11 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.10 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.9 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.8 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.7 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.6 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.5 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.4 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.3 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.2 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.1 lib/nwiki/frontend/app/feed.rb
nwiki-0.2.0 lib/nwiki/frontend/app/feed.rb
nwiki-0.1.11 lib/nwiki/frontend/app/feed.rb
nwiki-0.1.10 lib/nwiki/frontend/app/feed.rb
nwiki-0.1.9 lib/nwiki/frontend/app/feed.rb
nwiki-0.1.8 lib/nwiki/frontend/app/feed.rb