Permalink
Browse files

Rss output

  • Loading branch information...
1 parent 85597bc commit 8a7c6d776e1510fa36f6c611ba712ef64c3ed0ca @hanklords committed Apr 3, 2012
Showing with 39 additions and 0 deletions.
  1. +1 −0 lib/openreqs/diff.rb
  2. +21 −0 openreqs.rb
  3. +17 −0 views/openreqs/doc_history_rss.haml
View
1 lib/openreqs/diff.rb
@@ -51,6 +51,7 @@ def tokenize
end
class DocDiff < ContentDiff
+ attr_reader :doc_old, :doc_new
def initialize(doc_old, doc_new, options = {})
@doc_old, @doc_new = doc_old, doc_new
super(@doc_old.content, @doc_new.content, options)
View
21 openreqs.rb
@@ -424,6 +424,27 @@ def mongo; settings.mongo end
@dates.map {|d| d.xmlschema(2)}.to_json
end
+get '/d/:doc/history.rss' do
+ @doc = Doc.new(mongo, params[:doc], :context => self)
+ not_found if !@doc.exist?
+
+ @name = params[:doc]
+ @dates = mongo["docs"].find({"_name" => params[:doc]}, {:fields => "date", :sort => ["date", :asc]}).map {|doc| doc["date"]}
+ req_names = CreolaExtractURL.new(@doc["_content"]).to_a
+ @dates.concat mongo["requirements"].find({
+ "_name" => {"$in" => req_names},
+ "date"=> {"$gt" => @dates[0]}
+ }, {:fields => "date"}).map {|req| req["date"]}
+
+ @dates = @dates.sort.reverse
+ @date = @dates[0]
+ @docs = @dates.map {|date| Doc.new(mongo, params[:doc], :date => date, :context => self)}
+ @doc_diffs = @docs.each_cons(2).map {|doc_a, doc_b| DocDiff.new(doc_b, doc_a, :context => self) }
+
+ content_type :rss
+ haml :doc_history_rss
+end
+
get '/d/:doc/history' do
@doc = Doc.new(mongo, params[:doc], :context => self)
not_found if !@doc.exist?
View
17 views/openreqs/doc_history_rss.haml
@@ -0,0 +1,17 @@
+!!! XML
+%rss{:version=>"2.0"}
+ %channel
+ %link= to("/d/#@name/history")
+ %title= @name
+ %description History of the document '#{@name}'
+ %pubDate= @date.rfc822
+ %generator OpenReqs
+
+ - @doc_diffs.each do |diff|
+ - date = diff.doc_new.date
+ %item
+ %pubDate= date.rfc822
+ %guid= to("/d/#@name/history##{date.iso8601}")
+ %link= to("/d/#@name/#{date.iso8601}")
+ %title= date.strftime("%F %T")
+ %description&= diff.to_html

0 comments on commit 8a7c6d7

Please sign in to comment.