1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/rdoc] Add links to the commits

https://github.com/ruby/rdoc/commit/1821628076
This commit is contained in:
Nobuyoshi Nakada 2021-01-22 10:13:08 +09:00
parent f3f1a666c7
commit fa048a0f85
2 changed files with 107 additions and 36 deletions

View file

@ -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
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
end
module Aref
attr_accessor :aref
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

View file

@ -281,7 +281,7 @@ ChangeLog
expected = [
[ "709bed2afaee50e2ce80",
[ "git <svn-admin@ruby-lang.org>",
[ "git", "svn-admin@ruby-lang.org",
"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 <kuwabara@pocke.me>
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 <svn-admin@ruby-lang.org>'),
list(:BULLET, item(nil, para('2021-01-21 [ci skip]'))),
log_entry(nil, '709bed2afaee50e2ce80',
'git', 'svn-admin@ruby-lang.org', '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 <svn-admin@ruby-lang.org>'),
list(:BULLET, item(nil, para('2021-01-20 [ci skip]'))),
log_entry(nil, 'a8dc5156e183489c5121',
'git', 'svn-admin@ruby-lang.org', '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 <kuwabara@pocke.me>'),
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', 'kuwabara@pocke.me', '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