[ruby/rdoc] Add links to the commits
https://github.com/ruby/rdoc/commit/1821628076
This commit is contained in:
parent
f3f1a666c7
commit
fa048a0f85
@ -132,8 +132,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
|||||||
def parse_entries
|
def parse_entries
|
||||||
@time_cache ||= {}
|
@time_cache ||= {}
|
||||||
|
|
||||||
if /\A(?:.*\n){,3}commit\s/ =~ @content
|
if /\A((?:.*\n){,3})commit\s/ =~ @content
|
||||||
class << self; prepend Git; end
|
class << self; prepend Git; end
|
||||||
|
parse_info($1)
|
||||||
return parse_entries
|
return parse_entries
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -208,6 +209,11 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
|||||||
end
|
end
|
||||||
|
|
||||||
module Git
|
module Git
|
||||||
|
def parse_info(info)
|
||||||
|
/^\s*base-url\s*=\s*(.*\S)/ =~ info
|
||||||
|
@base_url = $1
|
||||||
|
end
|
||||||
|
|
||||||
def parse_entries
|
def parse_entries
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
@ -216,7 +222,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
|||||||
if /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d)/ =~ date
|
if /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d)/ =~ date
|
||||||
time = Time.new($1, $2, $3, $4, $5, $6, "#{$7}:#{$8}")
|
time = Time.new($1, $2, $3, $4, $5, $6, "#{$7}:#{$8}")
|
||||||
@time_cache[entry_name] = time
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -226,31 +234,88 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
|||||||
def create_entries entries
|
def create_entries entries
|
||||||
# git log entries have no strictly itemized style like the old
|
# git log entries have no strictly itemized style like the old
|
||||||
# style, just assume Markdown.
|
# style, just assume Markdown.
|
||||||
out = []
|
entries.map do |commit, entry|
|
||||||
entries.each do |entry, (author, date, body)|
|
LogEntry.new(@base_url, commit, *entry)
|
||||||
title = RDoc::Markup::Heading.new(3, "#{date} #{author}")
|
|
||||||
title.extend(Aref)
|
|
||||||
title.aref = "label-#{entry}"
|
|
||||||
out << title
|
|
||||||
out.concat parse_log_entry(body, entry)
|
|
||||||
end
|
end
|
||||||
out
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_log_entry(content, sha)
|
LogEntry = Struct.new(:base, :commit, :author, :email, :date, :contents) do
|
||||||
RDoc::Markdown.parse(content).parts.each do |body|
|
HEADING_LEVEL = 3
|
||||||
case body
|
|
||||||
when RDoc::Markup::Heading
|
def initialize(base, commit, author, email, date, contents)
|
||||||
body.level += 3
|
case contents
|
||||||
label = body.aref.sub(/\Alabel-/, "label-#{sha}-")
|
when String
|
||||||
body.extend(Aref)
|
contents = RDoc::Markdown.parse(contents).parts.each do |body|
|
||||||
body.aref = label
|
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
|
end
|
||||||
end
|
|
||||||
|
|
||||||
module Aref
|
def pretty_print q # :nodoc:
|
||||||
attr_accessor :aref
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -281,7 +281,7 @@ ChangeLog
|
|||||||
|
|
||||||
expected = [
|
expected = [
|
||||||
[ "709bed2afaee50e2ce80",
|
[ "709bed2afaee50e2ce80",
|
||||||
[ "git <svn-admin@ruby-lang.org>",
|
[ "git", "svn-admin@ruby-lang.org",
|
||||||
"2021-01-21 01:03:52 +0900",
|
"2021-01-21 01:03:52 +0900",
|
||||||
"* 2021-01-21 [ci skip]\n"]]]
|
"* 2021-01-21 [ci skip]\n"]]]
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ commit\ a8dc5156e183489c5121fb1759bda5d9406d9175
|
|||||||
|
|
||||||
* 2021-01-20 [ci skip]
|
* 2021-01-20 [ci skip]
|
||||||
|
|
||||||
commit de5f8a92d5001799bedb3b1a271a2d9b23c6c8fb
|
commit\ de5f8a92d5001799bedb3b1a271a2d9b23c6c8fb
|
||||||
Author: Masataka Pocke Kuwabara <kuwabara@pocke.me>
|
Author: Masataka Pocke Kuwabara <kuwabara@pocke.me>
|
||||||
Date: 2021-01-01 14:25:08 +0900
|
Date: 2021-01-01 14:25:08 +0900
|
||||||
|
|
||||||
@ -372,23 +372,26 @@ ChangeLog
|
|||||||
blank_line,
|
blank_line,
|
||||||
head(2, '2021-01-21'),
|
head(2, '2021-01-21'),
|
||||||
blank_line,
|
blank_line,
|
||||||
head(3, '2021-01-21 01:03:52 +0900 git <svn-admin@ruby-lang.org>'),
|
log_entry(nil, '709bed2afaee50e2ce80',
|
||||||
list(:BULLET, item(nil, para('2021-01-21 [ci skip]'))),
|
'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'),
|
head(2, '2021-01-20'),
|
||||||
blank_line,
|
blank_line,
|
||||||
head(3, '2021-01-20 01:58:26 +0900 git <svn-admin@ruby-lang.org>'),
|
log_entry(nil, 'a8dc5156e183489c5121',
|
||||||
list(:BULLET, item(nil, para('2021-01-20 [ci skip]'))),
|
'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'),
|
head(2, '2021-01-01'),
|
||||||
blank_line,
|
blank_line,
|
||||||
head(3, '2021-01-01 14:25:08 +0900 Masataka Pocke Kuwabara <kuwabara@pocke.me>'),
|
log_entry(nil, 'de5f8a92d5001799bedb',
|
||||||
para('Make args info for RubyVM::AST to available on endless method without parens'),
|
'Masataka Pocke Kuwabara', 'kuwabara@pocke.me', '2021-01-01 14:25:08 +0900',
|
||||||
head(4, 'Problem'),
|
[head(4, 'Make args info for RubyVM::AST to available on endless method without parens'),
|
||||||
para("Arguments information is missing for endless method without parens.\n" +
|
head(5, 'Problem'),
|
||||||
"For example:"),
|
para("Arguments information is missing for endless method without parens.\n" +
|
||||||
verb("# ok\n").tap {|v| v.format = :ruby},
|
"For example:"),
|
||||||
para('It causes an error if a program expects <code>args</code> node exists.'),
|
verb("# ok\n").tap {|v| v.format = :ruby},
|
||||||
head(4, 'Solution'),
|
para('It causes an error if a program expects <code>args</code> node exists.'),
|
||||||
para('Call <code>new_args</code> on this case.'))
|
head(5, 'Solution'),
|
||||||
|
para('Call <code>new_args</code> on this case.')]))
|
||||||
|
|
||||||
expected.file = @top_level
|
expected.file = @top_level
|
||||||
|
|
||||||
@ -400,5 +403,8 @@ ChangeLog
|
|||||||
@top_level, @tempfile.path, content, @options, @stats
|
@top_level, @tempfile.path, content, @options, @stats
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_entry(*a)
|
||||||
|
RDoc::Parser::ChangeLog::Git::LogEntry.new(*a)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user