summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2021-01-22 10:13:08 +0900
committerNobuyoshi Nakada <[email protected]>2021-01-24 16:46:23 +0900
commitfa048a0f8523cefde5428805dd334691486319e6 (patch)
treea5121d9b0951f306530d8e6d23950696dcc8c1dd
parentf3f1a666c77f8c528b0adc9ccf78e4b9910bd6e0 (diff)
[ruby/rdoc] Add links to the commits
https://github.com/ruby/rdoc/commit/1821628076
-rw-r--r--lib/rdoc/parser/changelog.rb107
-rw-r--r--test/rdoc/test_rdoc_parser_changelog.rb36
2 files changed, 107 insertions, 36 deletions
diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb
index d0701a6772..b393805040 100644
--- a/lib/rdoc/parser/changelog.rb
+++ b/lib/rdoc/parser/changelog.rb
@@ -132,8 +132,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
def parse_entries
@time_cache ||= {}
- if /\A(?:.*\n){,3}commit\s/ =~ @content
+ if /\A((?:.*\n){,3})commit\s/ =~ @content
class << self; prepend Git; end
+ parse_info($1)
return parse_entries
end
@@ -208,6 +209,11 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
end
module Git
+ def parse_info(info)
+ /^\s*base-url\s*=\s*(.*\S)/ =~ info
+ @base_url = $1
+ end
+
def parse_entries
entries = []
@@ -216,7 +222,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
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]]
+ author.sub!(/\s*<(.*)>/, '')
+ email = $1
+ entries << [entry_name, [author, email, date, entry_body]]
end
end
@@ -226,31 +234,88 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
def create_entries entries
# git log entries have no strictly itemized style like the old
# style, just assume Markdown.
- out = []
- entries.each do |entry, (author, date, body)|
- title = RDoc::Markup::Heading.new(3, "#{date} #{author}")
- title.extend(Aref)
- title.aref = "label-#{entry}"
- out << title
- out.concat parse_log_entry(body, entry)
+ entries.map do |commit, entry|
+ LogEntry.new(@base_url, commit, *entry)
end
- out
end
- def parse_log_entry(content, sha)
- RDoc::Markdown.parse(content).parts.each do |body|
- case body
- when RDoc::Markup::Heading
- body.level += 3
- label = body.aref.sub(/\Alabel-/, "label-#{sha}-")
- body.extend(Aref)
- body.aref = label
+ LogEntry = Struct.new(:base, :commit, :author, :email, :date, :contents) do
+ HEADING_LEVEL = 3
+
+ def initialize(base, commit, author, email, date, contents)
+ case contents
+ when String
+ contents = RDoc::Markdown.parse(contents).parts.each do |body|
+ case body
+ when RDoc::Markup::Heading
+ body.level += HEADING_LEVEL + 1
+ end
+ end
+ case first = contents[0]
+ when RDoc::Markup::Paragraph
+ contents[0] = RDoc::Markup::Heading.new(HEADING_LEVEL + 1, first.text)
+ end
end
+ super
+ end
+
+ def level
+ HEADING_LEVEL
+ end
+
+ def aref
+ "label-#{commit}"
end
- end
- module Aref
- attr_accessor :aref
+ def label context = nil
+ aref
+ end
+
+ def text
+ case base
+ when nil
+ "#{date}"
+ when /%s/
+ "{#{date}}[#{base % commit}]"
+ else
+ "{#{date}}[#{base}#{commit}]"
+ end + " {#{author}}[mailto:#{email}]"
+ end
+
+ def accept visitor
+ visitor.accept_heading self
+ begin
+ if visitor.respond_to?(:code_object=)
+ code_object = visitor.code_object
+ visitor.code_object = self
+ end
+ contents.each do |body|
+ body.accept visitor
+ end
+ ensure
+ if visitor.respond_to?(:code_object)
+ visitor.code_object = code_object
+ end
+ end
+ end
+
+ def pretty_print q # :nodoc:
+ q.group(2, '[log_entry: ', ']') do
+ q.text commit
+ q.text ','
+ q.breakable
+ q.group(2, '[date: ', ']') { q.text date }
+ q.text ','
+ q.breakable
+ q.group(2, '[author: ', ']') { q.text author }
+ q.text ','
+ q.breakable
+ q.group(2, '[email: ', ']') { q.text email }
+ q.text ','
+ q.breakable
+ q.pp contents
+ end
+ end
end
end
end
diff --git a/test/rdoc/test_rdoc_parser_changelog.rb b/test/rdoc/test_rdoc_parser_changelog.rb
index e1fd459249..fd19566064 100644
--- a/test/rdoc/test_rdoc_parser_changelog.rb
+++ b/test/rdoc/test_rdoc_parser_changelog.rb
@@ -281,7 +281,7 @@ ChangeLog
expected = [
[ "709bed2afaee50e2ce80",
- [ "git <[email protected]>",
+ [ "git", "[email protected]",
"2021-01-21 01:03:52 +0900",
"* 2021-01-21 [ci skip]\n"]]]
@@ -341,7 +341,7 @@ commit\ a8dc5156e183489c5121fb1759bda5d9406d9175
* 2021-01-20 [ci skip]
-commit de5f8a92d5001799bedb3b1a271a2d9b23c6c8fb
+commit\ de5f8a92d5001799bedb3b1a271a2d9b23c6c8fb
Author: Masataka Pocke Kuwabara <[email protected]>
Date: 2021-01-01 14:25:08 +0900
@@ -372,23 +372,26 @@ ChangeLog
blank_line,
head(2, '2021-01-21'),
blank_line,
- head(3, '2021-01-21 01:03:52 +0900 git <[email protected]>'),
- list(:BULLET, item(nil, para('2021-01-21 [ci skip]'))),
+ log_entry(nil, '709bed2afaee50e2ce80',
+ 'git', '[email protected]', '2021-01-21 01:03:52 +0900',
+ [list(:BULLET, item(nil, para('2021-01-21 [ci skip]')))]),
head(2, '2021-01-20'),
blank_line,
- head(3, '2021-01-20 01:58:26 +0900 git <[email protected]>'),
- list(:BULLET, item(nil, para('2021-01-20 [ci skip]'))),
+ log_entry(nil, 'a8dc5156e183489c5121',
+ 'git', '[email protected]', '2021-01-20 01:58:26 +0900',
+ [list(:BULLET, item(nil, para('2021-01-20 [ci skip]')))]),
head(2, '2021-01-01'),
blank_line,
- head(3, '2021-01-01 14:25:08 +0900 Masataka Pocke Kuwabara <[email protected]>'),
- para('Make args info for RubyVM::AST to available on endless method without parens'),
- head(4, 'Problem'),
- para("Arguments information is missing for endless method without parens.\n" +
- "For example:"),
- verb("# ok\n").tap {|v| v.format = :ruby},
- para('It causes an error if a program expects <code>args</code> node exists.'),
- head(4, 'Solution'),
- para('Call <code>new_args</code> on this case.'))
+ log_entry(nil, 'de5f8a92d5001799bedb',
+ 'Masataka Pocke Kuwabara', '[email protected]', '2021-01-01 14:25:08 +0900',
+ [head(4, 'Make args info for RubyVM::AST to available on endless method without parens'),
+ head(5, 'Problem'),
+ para("Arguments information is missing for endless method without parens.\n" +
+ "For example:"),
+ verb("# ok\n").tap {|v| v.format = :ruby},
+ para('It causes an error if a program expects <code>args</code> node exists.'),
+ head(5, 'Solution'),
+ para('Call <code>new_args</code> on this case.')]))
expected.file = @top_level
@@ -400,5 +403,8 @@ ChangeLog
@top_level, @tempfile.path, content, @options, @stats
end
+ def log_entry(*a)
+ RDoc::Parser::ChangeLog::Git::LogEntry.new(*a)
+ end
end