diff --git a/README.md b/README.md index 1bd83234..b4c0a86c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ Gollum is a simple wiki system built on top of Git. A Gollum Wiki is simply a gi * Annotations using [CriticMarkup](https://github.com/gollum/gollum/wiki#criticmarkup-annotations) * Mathematics via [MathJax](https://github.com/gollum/gollum/wiki#mathematics) * [Macros](https://github.com/gollum/gollum/wiki/Standard-Macros) - * [Redirects](https://github.com/gollum/gollum/wiki/5.0-release-notes#support-for-redirects) + * [Redirects](https://github.com/gollum/gollum/wiki#redirects) + * [RSS Feed](https://github.com/gollum/gollum/wiki/5.0-release-notes#rss-feed) of latest changes * ...and [more](https://github.com/gollum/gollum/wiki) ### SYSTEM REQUIREMENTS diff --git a/gollum.gemspec b/gollum.gemspec index c66ae883..4e38c636 100644 --- a/gollum.gemspec +++ b/gollum.gemspec @@ -37,6 +37,7 @@ Gem::Specification.new do |s| s.add_dependency 'sass', '~> 3.5' s.add_dependency 'uglifier', '~> 3.2' s.add_dependency 'sprockets-helpers', '~> 1.2' + s.add_dependency 'rss', '~> 0.2.9' s.add_development_dependency 'rack-test', '~> 0.6.3' s.add_development_dependency 'shoulda', '~> 3.6.0' diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 9e1db70d..31219103 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -19,7 +19,7 @@ require 'gollum/views/editable' require 'gollum/views/has_page' require 'gollum/views/has_user_icons' require 'gollum/views/pagination' - +require 'gollum/views/rss.rb' require File.expand_path '../helpers', __FILE__ @@ -44,6 +44,7 @@ module Precious register Mustache::Sinatra register Sinatra::Namespace include Precious::Helpers + dir = File.dirname(File.expand_path(__FILE__)) set :sprockets, ::Precious::Assets.sprockets(dir) @@ -77,6 +78,8 @@ module Precious @critic_markup = settings.wiki_options[:critic_markup] @redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true) @per_page_uploads = settings.wiki_options[:per_page_uploads] + + @wiki_title = settings.wiki_options.fetch(:title, 'Gollum Wiki') forbid unless @allow_editing || request.request_method == 'GET' Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir] @@ -111,7 +114,16 @@ module Precious end namespace '/gollum' do - + get '/feed/' do + url = "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}" + changes = wiki_new.latest_changes(::Gollum::Page.log_pagination_options( + per_page: settings.wiki_options.fetch(:pagination_count, 10), + page_num: 0) + ) + content_type :rss + RSSView.new(@base_url, @wiki_title, url, changes).render + end + get '/assets/mathjax/*' do env['PATH_INFO'].sub!("/gollum/assets/mathjax", '') Rack::Static.new(not_found_proc, {:root => @mathjax_path, :urls => ['']}).call(env) diff --git a/lib/gollum/views/rss.rb b/lib/gollum/views/rss.rb new file mode 100644 index 00000000..73ad9d2c --- /dev/null +++ b/lib/gollum/views/rss.rb @@ -0,0 +1,43 @@ +require 'rss' + +class RSSView + + include Precious::Views::AppHelpers + include Precious::Views::RouteHelpers + + attr_reader :base_url + + def initialize(base_url, wiki_title, url, changes) + @base_url = base_url + @wiki_title = wiki_title + @url = url + @changes = changes + end + + def render + latest_changes = "#{@url}#{latest_changes_path}" + RSS::Maker.make('2.0') do |maker| + maker.channel.author = 'Gollum Wiki' + maker.channel.updated = @changes.first.authored_date + maker.channel.title = "#{@wiki_title} Latest Changes" + maker.channel.description = "Latest Changes in #{@wiki_title}" + maker.channel.link = latest_changes + @changes.each do |change| + maker.items.new_item do |item| + item.link = latest_changes + item.title = change.message + item.updated = change.authored_date + id = change.id + files = change.stats.files.map do |files| + [files[:old_file], files[:new_file]].compact.map do |file| + f = extract_page_dir(file) + "
  • #{f}
  • " + end + end + item.description = "Commited by: #{change.author.name}
    Commit ID: #{id[0..6]}

    Affected files:" + end + end + end.to_s + end + +end \ No newline at end of file diff --git a/test/test_app.rb b/test/test_app.rb index c1fb75fc..39fa9860 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -63,6 +63,21 @@ context "Frontend" do assert_match /#{expected}/, actual end + + test 'rss feed' do + channel_title = <Gollum Wiki Latest Changes +EOF + item = <Commited by: <a href="mailto:dawa.ometto@phil.uu.nl">Dawa Ometto</a><br/>Commit ID: 02796b1<br/><br/>Affected files:<ul><li><a href="http://example.org/custom.css/02796b1450691f90db5d6dc6a816a4980ce80d07">custom.css</a></li><li><a href="http://example.org/custom.js/02796b1450691f90db5d6dc6a816a4980ce80d07">custom.js</a></li></ul> +EOF + get '/gollum/feed/' + assert last_response.ok? + assert_equal 'application/rss+xml', last_response.headers['Content-Type'] + assert last_response.body.start_with?('
    1. Home
    2. \n
    3. Mordor
    4. \n
    5. Eye-Of-Sauron
    6. \n
    7. Saruman
    8. \n
    ", @page.breadcrumb end