diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-01-21 01:25:56 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-01-24 16:46:15 +0900 |
commit | bb570ce6d80d28cfc7131dcb72885eed2f989b30 (patch) | |
tree | c6c5cde79c6b074080a726b0712d43f9217ddd05 /lib/rdoc | |
parent | 68e7dc532d8c658050fa513bbf6c80126832b070 (diff) |
[ruby/rdoc] Support ChangeLog generated by `git log`
https://github.com/ruby/rdoc/commit/5e0a123ca1
Diffstat (limited to 'lib/rdoc')
-rw-r--r-- | lib/rdoc/parser/changelog.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb index 167892f543..3634b6a6eb 100644 --- a/lib/rdoc/parser/changelog.rb +++ b/lib/rdoc/parser/changelog.rb @@ -131,6 +131,12 @@ class RDoc::Parser::ChangeLog < RDoc::Parser def parse_entries @time_cache ||= {} + + if /\A(?:.*\n){,3}commit\s/ =~ @content + class << self; prepend Git; end + return parse_entries + end + entries = [] entry_name = nil entry_body = [] @@ -190,6 +196,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser def scan @time_cache = {} + entries = parse_entries grouped_entries = group_entries entries @@ -200,5 +207,33 @@ class RDoc::Parser::ChangeLog < RDoc::Parser @top_level end + module Git + def parse_entries + entries = [] + + @content.scan(/^commit\s+(\h+)\n *Author: *(.+)\n *Date: *(.+)\n\n((?: {4}.*\n+)*)/) do + entry_name, author, date, entry_body = $1, $2, $3, $4.gsub(/^ {4}/, '') + if /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d)/ =~ date + time = Time.new($1, $2, $3, $4, $5, $6, "#{$7}:#{$8}") + @time_cache[entry_name] = time + entries << [entry_name, [author, date, entry_body]] + end + end + + entries + end + + def create_entries entries + # git log entries have no strictly itemized style like the old + # style, just assume Markdown. + entries.map do |entry, (author, date, body)| + list = RDoc::Markup::List.new(:NOTE) + author = RDoc::Markup::Paragraph.new(author) + list << RDoc::Markup::ListItem.new(date, author) + RDoc::Markdown.parse(body).parts.each {|b| list << b} + list + end + end + end end |