2012-12-04 02:50:48 -05:00
|
|
|
require 'time'
|
|
|
|
|
|
|
|
class RDoc::Parser::ChangeLog < RDoc::Parser
|
|
|
|
|
|
|
|
include RDoc::Parser::Text
|
|
|
|
|
|
|
|
parse_files_matching(/(\/|\\|\A)ChangeLog[^\/\\]*\z/)
|
|
|
|
|
2012-12-05 02:07:28 -05:00
|
|
|
def continue_entry_body entry_body, continuation
|
|
|
|
return unless last = entry_body.last
|
|
|
|
|
|
|
|
if last =~ /\)\s*\z/ and continuation =~ /\A\(/ then
|
|
|
|
last.sub!(/\)\s*\z/, ',')
|
|
|
|
continuation.sub!(/\A\(/, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
if last =~ /\s\z/ then
|
|
|
|
last << continuation
|
|
|
|
else
|
|
|
|
last << ' ' << continuation
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-04 02:50:48 -05:00
|
|
|
def create_document groups
|
|
|
|
doc = RDoc::Markup::Document.new
|
|
|
|
doc.file = @top_level
|
|
|
|
|
|
|
|
doc << RDoc::Markup::Heading.new(1, File.basename(@file_name))
|
|
|
|
doc << RDoc::Markup::BlankLine.new
|
|
|
|
|
2012-12-05 02:07:28 -05:00
|
|
|
groups.sort_by do |day,| day end.reverse_each do |day, entries|
|
2012-12-04 02:50:48 -05:00
|
|
|
doc << RDoc::Markup::Heading.new(2, day)
|
|
|
|
doc << RDoc::Markup::BlankLine.new
|
|
|
|
|
|
|
|
doc.concat create_entries entries
|
|
|
|
end
|
|
|
|
|
|
|
|
doc
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_entries entries
|
|
|
|
out = []
|
|
|
|
|
|
|
|
entries.each do |entry, items|
|
|
|
|
out << RDoc::Markup::Heading.new(3, entry)
|
|
|
|
out << RDoc::Markup::BlankLine.new
|
|
|
|
|
|
|
|
out << create_items(items)
|
|
|
|
end
|
|
|
|
|
|
|
|
out
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_items items
|
|
|
|
list = RDoc::Markup::List.new :NOTE
|
|
|
|
|
|
|
|
items.each do |item|
|
2012-12-05 02:07:28 -05:00
|
|
|
title, body = item.split(/:\s*/, 2)
|
2012-12-04 02:50:48 -05:00
|
|
|
paragraph = RDoc::Markup::Paragraph.new body
|
|
|
|
list_item = RDoc::Markup::ListItem.new title, paragraph
|
|
|
|
list << list_item
|
|
|
|
end
|
|
|
|
|
|
|
|
list
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_entries entries
|
|
|
|
entries.group_by do |title, body|
|
|
|
|
Time.parse(title).strftime "%Y-%m-%d"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_entries
|
2012-12-05 02:07:28 -05:00
|
|
|
entries = []
|
2012-12-04 02:50:48 -05:00
|
|
|
entry_name = nil
|
|
|
|
entry_body = []
|
|
|
|
|
|
|
|
@content.each_line do |line|
|
|
|
|
case line
|
2012-12-05 02:07:28 -05:00
|
|
|
when /^\s*$/ then
|
|
|
|
next
|
2012-12-04 02:50:48 -05:00
|
|
|
when /^\w.*/ then
|
2012-12-05 02:07:28 -05:00
|
|
|
entries << [entry_name, entry_body] if entry_name
|
2012-12-04 02:50:48 -05:00
|
|
|
|
|
|
|
entry_name = $&
|
|
|
|
|
|
|
|
begin
|
2012-12-05 02:07:28 -05:00
|
|
|
time = Time.parse entry_name
|
|
|
|
# HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
|
|
|
|
entry_name = nil unless entry_name =~ /#{time.year}/
|
2012-12-04 02:50:48 -05:00
|
|
|
rescue ArgumentError
|
|
|
|
entry_name = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
entry_body = []
|
2012-12-05 02:07:28 -05:00
|
|
|
when /^(\t| {8})?\*\s*(.*)/ then # "\t* file.c (func): ..."
|
2012-12-04 02:50:48 -05:00
|
|
|
entry_body << $2
|
2012-12-05 02:07:28 -05:00
|
|
|
when /^(\t| {8})?\s*(\(.*)/ then # "\t(func): ..."
|
|
|
|
entry = $2
|
2012-12-04 02:50:48 -05:00
|
|
|
|
2012-12-05 02:07:28 -05:00
|
|
|
if entry_body.last =~ /:/ then
|
|
|
|
entry_body << entry
|
2012-12-04 02:50:48 -05:00
|
|
|
else
|
2012-12-05 02:07:28 -05:00
|
|
|
continue_entry_body entry_body, entry
|
2012-12-04 02:50:48 -05:00
|
|
|
end
|
2012-12-05 02:07:28 -05:00
|
|
|
when /^(\t| {8})?\s*(.*)/ then
|
|
|
|
continue_entry_body entry_body, $2
|
2012-12-04 02:50:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-05 02:07:28 -05:00
|
|
|
entries << [entry_name, entry_body] if entry_name
|
2012-12-04 02:50:48 -05:00
|
|
|
|
2012-12-05 02:07:28 -05:00
|
|
|
entries.reject! do |(entry,_)|
|
|
|
|
entry == nil
|
|
|
|
end
|
2012-12-04 02:50:48 -05:00
|
|
|
|
|
|
|
entries
|
|
|
|
end
|
|
|
|
|
|
|
|
def scan
|
|
|
|
entries = parse_entries
|
|
|
|
grouped_entries = group_entries entries
|
|
|
|
|
|
|
|
doc = create_document grouped_entries
|
|
|
|
|
|
|
|
@top_level.comment = doc
|
|
|
|
|
|
|
|
@top_level
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|