rdoc 6.17.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +193 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/LICENSE.rdoc +4 -0
  5. data/README.md +132 -8
  6. data/RI.md +75 -75
  7. data/doc/markup_reference/markdown.md +659 -0
  8. data/doc/markup_reference/rdoc.rdoc +1169 -0
  9. data/exe/rdoc +2 -2
  10. data/lib/rdoc/code_object/alias.rb +70 -74
  11. data/lib/rdoc/code_object/any_method.rb +308 -293
  12. data/lib/rdoc/code_object/attr.rb +150 -142
  13. data/lib/rdoc/code_object/class_module.rb +802 -715
  14. data/lib/rdoc/code_object/constant.rb +181 -144
  15. data/lib/rdoc/code_object/context/section.rb +140 -130
  16. data/lib/rdoc/code_object/context.rb +925 -941
  17. data/lib/rdoc/code_object/extend.rb +7 -5
  18. data/lib/rdoc/code_object/include.rb +7 -5
  19. data/lib/rdoc/code_object/method_attr.rb +328 -315
  20. data/lib/rdoc/code_object/mixin.rb +97 -92
  21. data/lib/rdoc/code_object/normal_class.rb +77 -78
  22. data/lib/rdoc/code_object/normal_module.rb +61 -59
  23. data/lib/rdoc/code_object/require.rb +23 -39
  24. data/lib/rdoc/code_object/single_class.rb +21 -19
  25. data/lib/rdoc/code_object/top_level.rb +215 -202
  26. data/lib/rdoc/code_object.rb +305 -305
  27. data/lib/rdoc/comment.rb +274 -337
  28. data/lib/rdoc/cross_reference.rb +195 -206
  29. data/lib/rdoc/encoding.rb +105 -103
  30. data/lib/rdoc/erb_partial.rb +13 -11
  31. data/lib/rdoc/erbio.rb +29 -27
  32. data/lib/rdoc/generator/aliki.rb +196 -30
  33. data/lib/rdoc/generator/darkfish.rb +647 -629
  34. data/lib/rdoc/generator/json_index.rb +233 -229
  35. data/lib/rdoc/generator/markup.rb +165 -122
  36. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  37. data/lib/rdoc/generator/pot/po.rb +52 -51
  38. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  39. data/lib/rdoc/generator/pot.rb +85 -81
  40. data/lib/rdoc/generator/ri.rb +23 -19
  41. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  42. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  43. data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
  44. data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
  45. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  46. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  47. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  48. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  49. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
  50. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  51. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  52. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  53. data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
  54. data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
  55. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
  57. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  58. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  59. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  60. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  61. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  62. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  63. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  64. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  65. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  66. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  67. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  68. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  69. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
  70. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  71. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  72. data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
  73. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
  74. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  75. data/lib/rdoc/generator.rb +48 -46
  76. data/lib/rdoc/i18n/locale.rb +99 -95
  77. data/lib/rdoc/i18n/text.rb +109 -105
  78. data/lib/rdoc/i18n.rb +7 -5
  79. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  80. data/lib/rdoc/markdown.kpeg +52 -33
  81. data/lib/rdoc/markdown.rb +365 -177
  82. data/lib/rdoc/markup/blank_line.rb +25 -23
  83. data/lib/rdoc/markup/block_quote.rb +12 -8
  84. data/lib/rdoc/markup/document.rb +127 -123
  85. data/lib/rdoc/markup/element.rb +21 -0
  86. data/lib/rdoc/markup/formatter.rb +220 -203
  87. data/lib/rdoc/markup/hard_break.rb +30 -27
  88. data/lib/rdoc/markup/heading.rb +163 -77
  89. data/lib/rdoc/markup/include.rb +33 -29
  90. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  91. data/lib/rdoc/markup/inline_parser.rb +316 -0
  92. data/lib/rdoc/markup/list.rb +80 -88
  93. data/lib/rdoc/markup/list_item.rb +73 -85
  94. data/lib/rdoc/markup/paragraph.rb +23 -19
  95. data/lib/rdoc/markup/parser.rb +501 -497
  96. data/lib/rdoc/markup/pre_process.rb +284 -305
  97. data/lib/rdoc/markup/raw.rb +52 -55
  98. data/lib/rdoc/markup/rule.rb +16 -12
  99. data/lib/rdoc/markup/table.rb +48 -40
  100. data/lib/rdoc/markup/to_ansi.rb +143 -92
  101. data/lib/rdoc/markup/to_bs.rb +86 -102
  102. data/lib/rdoc/markup/to_html.rb +608 -506
  103. data/lib/rdoc/markup/to_html_crossref.rb +219 -210
  104. data/lib/rdoc/markup/to_html_snippet.rb +210 -205
  105. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  106. data/lib/rdoc/markup/to_label.rb +64 -51
  107. data/lib/rdoc/markup/to_markdown.rb +212 -184
  108. data/lib/rdoc/markup/to_rdoc.rb +341 -277
  109. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  110. data/lib/rdoc/markup/to_test.rb +62 -50
  111. data/lib/rdoc/markup/to_tt_only.rb +83 -92
  112. data/lib/rdoc/markup/verbatim.rb +62 -58
  113. data/lib/rdoc/markup.rb +196 -215
  114. data/lib/rdoc/options.rb +1063 -1076
  115. data/lib/rdoc/parser/c.rb +1039 -1036
  116. data/lib/rdoc/parser/changelog.rb +320 -287
  117. data/lib/rdoc/parser/markdown.rb +17 -13
  118. data/lib/rdoc/parser/rbs.rb +279 -0
  119. data/lib/rdoc/parser/rd.rb +17 -13
  120. data/lib/rdoc/parser/ruby.rb +1231 -2222
  121. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  122. data/lib/rdoc/parser/simple.rb +31 -27
  123. data/lib/rdoc/parser/text.rb +12 -8
  124. data/lib/rdoc/parser.rb +230 -221
  125. data/lib/rdoc/rbs_helper.rb +186 -0
  126. data/lib/rdoc/rd/inline.rb +57 -53
  127. data/lib/rdoc/rd.rb +90 -88
  128. data/lib/rdoc/rdoc.rb +547 -366
  129. data/lib/rdoc/ri/driver.rb +1141 -1130
  130. data/lib/rdoc/ri/formatter.rb +7 -3
  131. data/lib/rdoc/ri/paths.rb +140 -136
  132. data/lib/rdoc/ri/servlet.rb +456 -0
  133. data/lib/rdoc/ri/store.rb +4 -2
  134. data/lib/rdoc/ri/task.rb +55 -51
  135. data/lib/rdoc/ri.rb +14 -11
  136. data/lib/rdoc/rubygems_hook.rb +194 -192
  137. data/lib/rdoc/server.rb +462 -0
  138. data/lib/rdoc/stats/normal.rb +46 -42
  139. data/lib/rdoc/stats/quiet.rb +39 -35
  140. data/lib/rdoc/stats/verbose.rb +35 -31
  141. data/lib/rdoc/stats.rb +363 -338
  142. data/lib/rdoc/store.rb +919 -725
  143. data/lib/rdoc/task.rb +260 -255
  144. data/lib/rdoc/text.rb +164 -240
  145. data/lib/rdoc/token_stream.rb +88 -106
  146. data/lib/rdoc/tom_doc.rb +203 -201
  147. data/lib/rdoc/version.rb +1 -1
  148. data/lib/rdoc.rb +35 -7
  149. data/lib/rubygems_plugin.rb +2 -11
  150. data/rdoc-logo.svg +43 -0
  151. data/rdoc.gemspec +9 -7
  152. metadata +46 -32
  153. data/CONTRIBUTING.rdoc +0 -219
  154. data/ExampleMarkdown.md +0 -39
  155. data/ExampleRDoc.rdoc +0 -210
  156. data/lib/rdoc/code_object/anon_class.rb +0 -10
  157. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  158. data/lib/rdoc/code_object/meta_method.rb +0 -6
  159. data/lib/rdoc/markdown/literals.kpeg +0 -21
  160. data/lib/rdoc/markdown/literals.rb +0 -454
  161. data/lib/rdoc/markup/attr_changer.rb +0 -22
  162. data/lib/rdoc/markup/attr_span.rb +0 -35
  163. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  164. data/lib/rdoc/markup/attributes.rb +0 -70
  165. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  166. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  167. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  168. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  169. data/lib/rdoc/servlet.rb +0 -452
@@ -1,348 +1,381 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ##
4
- # A ChangeLog file parser.
5
- #
6
- # This parser converts a ChangeLog into an RDoc::Markup::Document. When
7
- # viewed as HTML a ChangeLog page will have an entry for each day's entries in
8
- # the sidebar table of contents.
9
- #
10
- # This parser is meant to parse the MRI ChangeLog, but can be used to parse any
11
- # {GNU style Change
12
- # Log}[http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html].
13
-
14
- class RDoc::Parser::ChangeLog < RDoc::Parser
15
-
16
- include RDoc::Parser::Text
17
-
18
- parse_files_matching(/(\/|\\|\A)ChangeLog[^\/\\]*\z/)
19
-
20
- ##
21
- # Attaches the +continuation+ of the previous line to the +entry_body+.
22
- #
23
- # Continued function listings are joined together as a single entry.
24
- # Continued descriptions are joined to make a single paragraph.
25
-
26
- def continue_entry_body(entry_body, continuation)
27
- return unless last = entry_body.last
28
-
29
- if last =~ /\)\s*\z/ and continuation =~ /\A\(/ then
30
- last.sub!(/\)\s*\z/, ',')
31
- continuation = continuation.sub(/\A\(/, '')
32
- end
33
-
34
- if last =~ /\s\z/ then
35
- last << continuation
36
- else
37
- last << ' ' + continuation
38
- end
39
- end
3
+ module RDoc
4
+ class Parser
5
+ ##
6
+ # A ChangeLog file parser.
7
+ #
8
+ # This parser converts a ChangeLog into an RDoc::Markup::Document. When
9
+ # viewed as HTML a ChangeLog page will have an entry for each day's entries in
10
+ # the sidebar table of contents.
11
+ #
12
+ # This parser is meant to parse the MRI ChangeLog, but can be used to parse any
13
+ # {GNU style Change
14
+ # Log}[http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html].
15
+
16
+ class ChangeLog < Parser
17
+
18
+ include Parser::Text
19
+
20
+ parse_files_matching(/(\/|\\|\A)ChangeLog[^\/\\]*\z/)
21
+
22
+ ##
23
+ # Attaches the +continuation+ of the previous line to the +entry_body+.
24
+ #
25
+ # Continued function listings are joined together as a single entry.
26
+ # Continued descriptions are joined to make a single paragraph.
27
+
28
+ def continue_entry_body(entry_body, continuation)
29
+ return unless last = entry_body.last
30
+
31
+ if last =~ /\)\s*\z/ and continuation =~ /\A\(/
32
+ last.sub!(/\)\s*\z/, ',')
33
+ continuation = continuation.sub(/\A\(/, '')
34
+ end
40
35
 
41
- ##
42
- # Creates an RDoc::Markup::Document given the +groups+ of ChangeLog entries.
36
+ if last =~ /\s\z/
37
+ last << continuation
38
+ else
39
+ last << ' ' + continuation
40
+ end
41
+ end
43
42
 
44
- def create_document(groups)
45
- doc = RDoc::Markup::Document.new
46
- doc.omit_headings_below = 2
47
- doc.file = @top_level
43
+ ##
44
+ # Creates an RDoc::Markup::Document given the +groups+ of ChangeLog entries.
48
45
 
49
- doc << RDoc::Markup::Heading.new(1, File.basename(@file_name))
50
- doc << RDoc::Markup::BlankLine.new
46
+ def create_document(groups)
47
+ doc = Markup::Document.new
48
+ doc.omit_headings_below = 2
49
+ doc.file = @top_level
51
50
 
52
- groups.sort_by do |day,| day end.reverse_each do |day, entries|
53
- doc << RDoc::Markup::Heading.new(2, day.dup)
54
- doc << RDoc::Markup::BlankLine.new
51
+ doc << Markup::Heading.new(1, File.basename(@file_name))
52
+ doc << Markup::BlankLine.new
55
53
 
56
- doc.concat create_entries entries
57
- end
54
+ groups.sort_by do |day,| day end.reverse_each do |day, entries|
55
+ doc << Markup::Heading.new(2, day.dup)
56
+ doc << Markup::BlankLine.new
58
57
 
59
- doc
60
- end
58
+ doc.concat create_entries entries
59
+ end
61
60
 
62
- ##
63
- # Returns a list of ChangeLog entries an RDoc::Markup nodes for the given
64
- # +entries+.
61
+ doc
62
+ end
65
63
 
66
- def create_entries(entries)
67
- out = []
64
+ ##
65
+ # Returns a list of ChangeLog entries an RDoc::Markup nodes for the given
66
+ # +entries+.
68
67
 
69
- entries.each do |entry, items|
70
- out << RDoc::Markup::Heading.new(3, entry)
71
- out << RDoc::Markup::BlankLine.new
68
+ def create_entries(entries)
69
+ out = []
72
70
 
73
- out << create_items(items)
74
- end
71
+ entries.each do |entry, items|
72
+ out << Markup::Heading.new(3, entry)
73
+ out << Markup::BlankLine.new
75
74
 
76
- out
77
- end
75
+ out << create_items(items)
76
+ end
78
77
 
79
- ##
80
- # Returns an RDoc::Markup::List containing the given +items+ in the
81
- # ChangeLog
78
+ out
79
+ end
82
80
 
83
- def create_items(items)
84
- list = RDoc::Markup::List.new :NOTE
81
+ ##
82
+ # Returns an RDoc::Markup::List containing the given +items+ in the
83
+ # ChangeLog
85
84
 
86
- items.each do |item|
87
- item =~ /\A(.*?(?:\([^)]+\))?):\s*/
85
+ def create_items(items)
86
+ list = Markup::List.new :NOTE
88
87
 
89
- title = $1
90
- body = $'
88
+ items.each do |item|
89
+ item =~ /\A(.*?(?:\([^)]+\))?):\s*/
91
90
 
92
- paragraph = RDoc::Markup::Paragraph.new body
93
- list_item = RDoc::Markup::ListItem.new title, paragraph
94
- list << list_item
95
- end
91
+ title = $1
92
+ body = $'
96
93
 
97
- list
98
- end
94
+ paragraph = Markup::Paragraph.new body
95
+ list_item = Markup::ListItem.new title, paragraph
96
+ list << list_item
97
+ end
99
98
 
100
- ##
101
- # Groups +entries+ by date.
102
-
103
- def group_entries(entries)
104
- @time_cache ||= {}
105
- entries.group_by do |title, _|
106
- begin
107
- time = @time_cache[title]
108
- (time || parse_date(title)).strftime '%Y-%m-%d'
109
- rescue NoMethodError, ArgumentError
110
- time, = title.split ' ', 2
111
- parse_date(time).strftime '%Y-%m-%d'
99
+ list
112
100
  end
113
- end
114
- end
115
-
116
- ##
117
- # Parse date in ISO-8601, RFC-2822, or default of Git
118
-
119
- def parse_date(date)
120
- case date
121
- when /\A\s*(\d+)-(\d+)-(\d+)(?:[ T](\d+):(\d+):(\d+) *([-+]\d\d):?(\d\d))?\b/
122
- Time.new($1, $2, $3, $4, $5, $6, ("#{$7}:#{$8}" if $7))
123
- when /\A\s*\w{3}, +(\d+) (\w{3}) (\d+) (\d+):(\d+):(\d+) *(?:([-+]\d\d):?(\d\d))\b/
124
- Time.new($3, $2, $1, $4, $5, $6, ("#{$7}:#{$8}" if $7))
125
- when /\A\s*\w{3} (\w{3}) +(\d+) (\d+) (\d+):(\d+):(\d+) *(?:([-+]\d\d):?(\d\d))\b/
126
- Time.new($3, $1, $2, $4, $5, $6, ("#{$7}:#{$8}" if $7))
127
- when /\A\s*\w{3} (\w{3}) +(\d+) (\d+):(\d+):(\d+) (\d+)\b/
128
- Time.new($6, $1, $2, $3, $4, $5)
129
- else
130
- raise ArgumentError, "bad date: #{date}"
131
- end
132
- end
133
-
134
- ##
135
- # Parses the entries in the ChangeLog.
136
- #
137
- # Returns an Array of each ChangeLog entry in order of parsing.
138
- #
139
- # A ChangeLog entry is an Array containing the ChangeLog title (date and
140
- # committer) and an Array of ChangeLog items (file and function changed with
141
- # description).
142
- #
143
- # An example result would be:
144
- #
145
- # [ 'Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
146
- # [ 'README.EXT: Converted to RDoc format',
147
- # 'README.EXT.ja: ditto']]
148
-
149
- def parse_entries
150
- @time_cache ||= {}
151
-
152
- if /\A((?:.*\n){,3})commit\s/ =~ @content
153
- class << self; prepend Git; end
154
- parse_info($1)
155
- return parse_entries
156
- end
157
-
158
- entries = []
159
- entry_name = nil
160
- entry_body = []
161
101
 
162
- @content.each_line do |line|
163
- case line
164
- when /^\s*$/ then
165
- next
166
- when /^\w.*/ then
167
- entries << [entry_name, entry_body] if entry_name
102
+ ##
103
+ # Groups +entries+ by date.
104
+
105
+ def group_entries(entries)
106
+ @time_cache ||= {}
107
+ entries.group_by do |title, _|
108
+ begin
109
+ time = @time_cache[title]
110
+ (time || parse_date(title)).strftime '%Y-%m-%d'
111
+ rescue NoMethodError, ArgumentError
112
+ time, = title.split ' ', 2
113
+ parse_date(time).strftime '%Y-%m-%d'
114
+ end
115
+ end
116
+ end
168
117
 
169
- entry_name = $&
118
+ ##
119
+ # Parse date in ISO-8601, RFC-2822, or default of Git
120
+
121
+ def parse_date(date)
122
+ case date
123
+ when /\A\s*(\d+)-(\d+)-(\d+)(?:[ T](\d+):(\d+):(\d+) *([-+]\d\d):?(\d\d))?\b/
124
+ Time.new($1, $2, $3, $4, $5, $6, ("#{$7}:#{$8}" if $7))
125
+ when /\A\s*\w{3}, +(\d+) (\w{3}) (\d+) (\d+):(\d+):(\d+) *(?:([-+]\d\d):?(\d\d))\b/
126
+ Time.new($3, $2, $1, $4, $5, $6, ("#{$7}:#{$8}" if $7))
127
+ when /\A\s*\w{3} (\w{3}) +(\d+) (\d+) (\d+):(\d+):(\d+) *(?:([-+]\d\d):?(\d\d))\b/
128
+ Time.new($3, $1, $2, $4, $5, $6, ("#{$7}:#{$8}" if $7))
129
+ when /\A\s*\w{3} (\w{3}) +(\d+) (\d+):(\d+):(\d+) (\d+)\b/
130
+ Time.new($6, $1, $2, $3, $4, $5)
131
+ else
132
+ raise ArgumentError, "bad date: #{date}"
133
+ end
134
+ end
170
135
 
171
- begin
172
- time = parse_date entry_name
173
- @time_cache[entry_name] = time
174
- rescue ArgumentError
175
- entry_name = nil
136
+ ##
137
+ # Parses the entries in the ChangeLog.
138
+ #
139
+ # Returns an Array of each ChangeLog entry in order of parsing.
140
+ #
141
+ # A ChangeLog entry is an Array containing the ChangeLog title (date and
142
+ # committer) and an Array of ChangeLog items (file and function changed with
143
+ # description).
144
+ #
145
+ # An example result would be:
146
+ #
147
+ # [ 'Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
148
+ # [ 'README.EXT: Converted to RDoc format',
149
+ # 'README.EXT.ja: ditto']]
150
+
151
+ def parse_entries
152
+ @time_cache ||= {}
153
+
154
+ if /\A((?:.*\n){,3})commit\s/ =~ @content
155
+ class << self; prepend Git; end
156
+ parse_info($1)
157
+ return parse_entries
176
158
  end
177
159
 
160
+ entries = []
161
+ entry_name = nil
178
162
  entry_body = []
179
- when /^(\t| {8})?\*\s*(.*)/ then # "\t* file.c (func): ..."
180
- entry_body << $2.dup
181
- when /^(\t| {8})?\s*(\(.*)/ then # "\t(func): ..."
182
- entry = $2
183
163
 
184
- if entry_body.last =~ /:/ then
185
- entry_body << entry.dup
186
- else
187
- continue_entry_body entry_body, entry
188
- end
189
- when /^(\t| {8})?\s*(.*)/ then
190
- continue_entry_body entry_body, $2
191
- end
192
- end
164
+ @content.each_line do |line|
165
+ case line
166
+ when /^\s*$/
167
+ next
168
+ when /^\w.*/
169
+ entries << [entry_name, entry_body] if entry_name
193
170
 
194
- entries << [entry_name, entry_body] if entry_name
171
+ entry_name = $&
195
172
 
196
- entries.reject! do |(entry, _)|
197
- entry == nil
198
- end
173
+ begin
174
+ time = parse_date entry_name
175
+ @time_cache[entry_name] = time
176
+ rescue ArgumentError
177
+ entry_name = nil
178
+ end
199
179
 
200
- entries
201
- end
180
+ entry_body = []
181
+ when /^(\t| {8})?\*\s*(.*)/ # "\t* file.c (func): ..."
182
+ entry_body << $2.dup
183
+ when /^(\t| {8})?\s*(\(.*)/ # "\t(func): ..."
184
+ entry = $2
202
185
 
203
- ##
204
- # Converts the ChangeLog into an RDoc::Markup::Document
186
+ if entry_body.last =~ /:/
187
+ entry_body << entry.dup
188
+ else
189
+ continue_entry_body entry_body, entry
190
+ end
191
+ when /^(\t| {8})?\s*(.*)/
192
+ continue_entry_body entry_body, $2
193
+ end
194
+ end
205
195
 
206
- def scan
207
- @time_cache = {}
196
+ entries << [entry_name, entry_body] if entry_name
208
197
 
209
- entries = parse_entries
210
- grouped_entries = group_entries entries
198
+ entries.reject! do |(entry, _)|
199
+ entry == nil
200
+ end
211
201
 
212
- doc = create_document grouped_entries
213
- comment = RDoc::Comment.new(@content)
214
- comment.document = doc
215
- @top_level.comment = comment
202
+ entries
203
+ end
216
204
 
217
- @top_level
218
- end
205
+ ##
206
+ # Converts the ChangeLog into an RDoc::Markup::Document
219
207
 
220
- ##
221
- # The extension for Git commit log
208
+ def scan
209
+ @time_cache = {}
222
210
 
223
- module Git
224
- ##
225
- # Parses auxiliary info. Currently `base-url` to expand
226
- # references is effective.
211
+ entries = parse_entries
212
+ grouped_entries = group_entries entries
227
213
 
228
- def parse_info(info)
229
- /^\s*base-url\s*=\s*(.*\S)/ =~ info
230
- @base_url = $1
231
- end
214
+ doc = create_document grouped_entries
215
+ comment = Comment.new(@content)
216
+ comment.document = doc
217
+ @top_level.comment = comment
232
218
 
233
- ##
234
- # Parses the entries in the Git commit logs
235
-
236
- def parse_entries
237
- entries = []
238
-
239
- @content.scan(/^commit\s+(\h{20})\h*\n((?:.+\n)*)\n((?: {4}.*\n+)*)/) do
240
- entry_name, header, entry_body = $1, $2, $3.gsub(/^ {4}/, '')
241
- # header = header.scan(/^ *(\S+?): +(.*)/).to_h
242
- # date = header["CommitDate"] || header["Date"]
243
- date = header[/^ *(?:Author)?Date: +(.*)/, 1]
244
- author = header[/^ *Author: +(.*)/, 1]
245
- begin
246
- time = parse_date(header[/^ *CommitDate: +(.*)/, 1] || date)
247
- @time_cache[entry_name] = time
248
- author.sub!(/\s*<(.*)>/, '')
249
- email = $1
250
- entries << [entry_name, [author, email, date, entry_body]]
251
- rescue ArgumentError
252
- end
219
+ @top_level
253
220
  end
254
221
 
255
- entries
256
- end
222
+ ##
223
+ # The extension for Git commit log
257
224
 
258
- ##
259
- # Returns a list of ChangeLog entries as
260
- # RDoc::Parser::ChangeLog::Git::LogEntry list for the given
261
- # +entries+.
262
-
263
- def create_entries(entries)
264
- # git log entries have no strictly itemized style like the old
265
- # style, just assume Markdown.
266
- entries.map do |commit, entry|
267
- LogEntry.new(@base_url, commit, *entry)
268
- end
269
- end
225
+ module Git
226
+ ##
227
+ # Parses auxiliary info. Currently `base-url` to expand
228
+ # references is effective.
270
229
 
271
- LogEntry = Struct.new(:base, :commit, :author, :email, :date, :contents) do
272
- HEADING_LEVEL = 3
230
+ def parse_info(info)
231
+ /^\s*base-url\s*=\s*(.*\S)/ =~ info
232
+ @base_url = $1
233
+ end
273
234
 
274
- def initialize(base, commit, author, email, date, contents)
275
- case contents
276
- when String
277
- contents = RDoc::Markdown.parse(contents).parts.each do |body|
278
- case body
279
- when RDoc::Markup::Heading
280
- body.level += HEADING_LEVEL + 1
235
+ ##
236
+ # Parses the entries in the Git commit logs
237
+
238
+ def parse_entries
239
+ entries = []
240
+
241
+ @content.scan(/^commit\s+(\h{20})\h*\n((?:.+\n)*)\n((?: {4}.*\n+)*)/) do
242
+ entry_name, header, entry_body = $1, $2, $3.gsub(/^ {4}/, '')
243
+ # header = header.scan(/^ *(\S+?): +(.*)/).to_h
244
+ # date = header["CommitDate"] || header["Date"]
245
+ date = header[/^ *(?:Author)?Date: +(.*)/, 1]
246
+ author = header[/^ *Author: +(.*)/, 1]
247
+ begin
248
+ time = parse_date(header[/^ *CommitDate: +(.*)/, 1] || date)
249
+ @time_cache[entry_name] = time
250
+ author.sub!(/\s*<(.*)>/, '')
251
+ email = $1
252
+ entries << [entry_name, [author, email, date, entry_body]]
253
+ rescue ArgumentError
281
254
  end
282
255
  end
283
- case first = contents[0]
284
- when RDoc::Markup::Paragraph
285
- contents[0] = RDoc::Markup::Heading.new(HEADING_LEVEL + 1, first.text)
256
+
257
+ entries
258
+ end
259
+
260
+ ##
261
+ # Returns a list of ChangeLog entries as
262
+ # RDoc::Parser::ChangeLog::Git::LogEntry list for the given
263
+ # +entries+.
264
+
265
+ def create_entries(entries)
266
+ # git log entries have no strictly itemized style like the old
267
+ # style, just assume Markdown.
268
+ entries.map do |commit, entry|
269
+ LogEntry.new(@base_url, commit, *entry)
286
270
  end
287
271
  end
288
- super
289
- end
290
272
 
291
- def level
292
- HEADING_LEVEL
293
- end
273
+ LogEntry = Struct.new(:base, :commit, :author, :email, :date, :contents) do
274
+ HEADING_LEVEL = 3
275
+
276
+ def initialize(base, commit, author, email, date, contents)
277
+ case contents
278
+ when String
279
+ if base&.match(%r[\A([^:/]+:/+[^/]+/)[^/]+/[^/]+/])
280
+ repo, host = $&, $1
281
+ contents = contents.dup
282
+ # base: https://github.com/ruby/ruby/
283
+ # Fix #15791 -> Fix [#15791](https://github.com/ruby/ruby/pull/15791)
284
+ # GH-15791 -> [GH-15791](https://github.com/ruby/ruby/pull/15791)
285
+ # (#15791) -> ([#15791](https://github.com/ruby/ruby/pull/15791))
286
+ contents.gsub!(/\b(?:(?i:fix(?:e[sd])?) +)\K\#(\d+\b)|\bGH-(\d+)\b|\(\K\#(\d+)(?=\))/) do
287
+ "[#{$&}](#{repo}pull/#{$1 || $2 || $3})"
288
+ end
289
+ # repo#PR, repo@HASH
290
+ # ruby/ruby#15791 -> [ruby/ruby#15791](https://github.com/ruby/ruby/pull/15791)
291
+ # ruby/ruby@a8a989b6 -> [ruby/ruby@a8a989b6](https://github.com/ruby/ruby/commit/a8a989b6)
292
+ # ref in branckets is not extended
293
+ # [ruby/net-imap#543][ruby/ruby#15791] -> [ruby/net-imap#543][ruby/ruby#15791]
294
+ contents.gsub!(%r[(?<![-\w#/@]|\]\[)([-\w]+/[-\w]+)(?:@(\h{8,40})|\#(\d+))(?![-\w#/@]|\]\[)]) do
295
+ path = defined?($2) ? "commit/#{$2}" : "pull/#{$3}"
296
+ "[#{$&}](#{host}#{$1}/#{path})"
297
+ end
298
+ end
299
+
300
+ contents = ::RDoc::Markdown.parse(contents).parts.each do |body|
301
+ case body
302
+ when Markup::Heading
303
+ body.level += HEADING_LEVEL + 1
304
+ end
305
+ end
306
+ case first = contents[0]
307
+ when Markup::Paragraph
308
+ contents[0] = Markup::Heading.new(HEADING_LEVEL + 1, first.text)
309
+ end
310
+ end
311
+ super
312
+ end
294
313
 
295
- def aref
296
- "label-#{commit}"
297
- end
314
+ def level
315
+ HEADING_LEVEL
316
+ end
298
317
 
299
- def label(context = nil)
300
- aref
301
- end
318
+ def aref
319
+ commit
320
+ end
302
321
 
303
- def text
304
- case base
305
- when nil
306
- "#{date}"
307
- when /%s/
308
- "{#{date}}[#{base % commit}]"
309
- else
310
- "{#{date}}[#{base}#{commit}]"
311
- end + " {#{author}}[mailto:#{email}]"
312
- end
322
+ def legacy_aref
323
+ "label-#{commit}"
324
+ end
313
325
 
314
- def accept(visitor)
315
- visitor.accept_heading self
316
- begin
317
- if visitor.respond_to?(:code_object=)
318
- code_object = visitor.code_object
319
- visitor.code_object = self
326
+ def label(context = nil)
327
+ aref
320
328
  end
321
- contents.each do |body|
322
- body.accept visitor
329
+
330
+ def legacy_label(context = nil)
331
+ legacy_aref
323
332
  end
324
- ensure
325
- if visitor.respond_to?(:code_object)
326
- visitor.code_object = code_object
333
+
334
+ def text
335
+ case base
336
+ when nil
337
+ "#{date}"
338
+ when /%s/
339
+ "{#{date}}[#{base % commit}]"
340
+ else
341
+ "{#{date}}[#{base}#{commit}]"
342
+ end + " {#{author}}[mailto:#{email}]"
327
343
  end
328
- end
329
- end
330
344
 
331
- def pretty_print(q) # :nodoc:
332
- q.group(2, '[log_entry: ', ']') do
333
- q.text commit
334
- q.text ','
335
- q.breakable
336
- q.group(2, '[date: ', ']') { q.text date }
337
- q.text ','
338
- q.breakable
339
- q.group(2, '[author: ', ']') { q.text author }
340
- q.text ','
341
- q.breakable
342
- q.group(2, '[email: ', ']') { q.text email }
343
- q.text ','
344
- q.breakable
345
- q.pp contents
345
+ def accept(visitor)
346
+ visitor.accept_heading self
347
+ begin
348
+ if visitor.respond_to?(:code_object=)
349
+ code_object = visitor.code_object
350
+ visitor.code_object = self
351
+ end
352
+ contents.each do |body|
353
+ body.accept visitor
354
+ end
355
+ ensure
356
+ if visitor.respond_to?(:code_object)
357
+ visitor.code_object = code_object
358
+ end
359
+ end
360
+ end
361
+
362
+ def pretty_print(q) # :nodoc:
363
+ q.group(2, '[log_entry: ', ']') do
364
+ q.text commit
365
+ q.text ','
366
+ q.breakable
367
+ q.group(2, '[date: ', ']') { q.text date }
368
+ q.text ','
369
+ q.breakable
370
+ q.group(2, '[author: ', ']') { q.text author }
371
+ q.text ','
372
+ q.breakable
373
+ q.group(2, '[email: ', ']') { q.text email }
374
+ q.text ','
375
+ q.breakable
376
+ q.pp contents
377
+ end
378
+ end
346
379
  end
347
380
  end
348
381
  end