rdoc 8.0.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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -3
  3. data/RI.md +75 -75
  4. data/exe/rdoc +2 -2
  5. data/lib/rdoc/code_object/alias.rb +71 -69
  6. data/lib/rdoc/code_object/any_method.rb +305 -303
  7. data/lib/rdoc/code_object/attr.rb +150 -148
  8. data/lib/rdoc/code_object/class_module.rb +798 -792
  9. data/lib/rdoc/code_object/constant.rb +175 -173
  10. data/lib/rdoc/code_object/context/section.rb +142 -138
  11. data/lib/rdoc/code_object/context.rb +926 -958
  12. data/lib/rdoc/code_object/extend.rb +7 -5
  13. data/lib/rdoc/code_object/include.rb +7 -5
  14. data/lib/rdoc/code_object/method_attr.rb +326 -319
  15. data/lib/rdoc/code_object/mixin.rb +97 -95
  16. data/lib/rdoc/code_object/normal_class.rb +77 -78
  17. data/lib/rdoc/code_object/normal_module.rb +61 -59
  18. data/lib/rdoc/code_object/require.rb +23 -39
  19. data/lib/rdoc/code_object/single_class.rb +21 -19
  20. data/lib/rdoc/code_object/top_level.rb +212 -219
  21. data/lib/rdoc/code_object.rb +305 -303
  22. data/lib/rdoc/comment.rb +275 -273
  23. data/lib/rdoc/cross_reference.rb +192 -190
  24. data/lib/rdoc/encoding.rb +105 -103
  25. data/lib/rdoc/erb_partial.rb +13 -11
  26. data/lib/rdoc/erbio.rb +29 -27
  27. data/lib/rdoc/generator/aliki.rb +161 -153
  28. data/lib/rdoc/generator/darkfish.rb +645 -635
  29. data/lib/rdoc/generator/json_index.rb +233 -229
  30. data/lib/rdoc/generator/markup.rb +164 -146
  31. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  32. data/lib/rdoc/generator/pot/po.rb +52 -51
  33. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  34. data/lib/rdoc/generator/pot.rb +85 -81
  35. data/lib/rdoc/generator/ri.rb +23 -19
  36. data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
  37. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  38. data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
  39. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  40. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  41. data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
  42. data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  44. data/lib/rdoc/generator.rb +48 -46
  45. data/lib/rdoc/i18n/locale.rb +99 -95
  46. data/lib/rdoc/i18n/text.rb +109 -105
  47. data/lib/rdoc/i18n.rb +7 -5
  48. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  49. data/lib/rdoc/markdown.kpeg +15 -11
  50. data/lib/rdoc/markdown.rb +40 -47
  51. data/lib/rdoc/markup/block_quote.rb +12 -8
  52. data/lib/rdoc/markup/document.rb +127 -123
  53. data/lib/rdoc/markup/formatter.rb +219 -215
  54. data/lib/rdoc/markup/include.rb +33 -29
  55. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  56. data/lib/rdoc/markup/inline_parser.rb +281 -277
  57. data/lib/rdoc/markup/list.rb +80 -88
  58. data/lib/rdoc/markup/list_item.rb +73 -85
  59. data/lib/rdoc/markup/paragraph.rb +23 -19
  60. data/lib/rdoc/markup/parser.rb +501 -497
  61. data/lib/rdoc/markup/pre_process.rb +283 -279
  62. data/lib/rdoc/markup/raw.rb +2 -2
  63. data/lib/rdoc/markup/rule.rb +16 -12
  64. data/lib/rdoc/markup/to_ansi.rb +143 -139
  65. data/lib/rdoc/markup/to_bs.rb +72 -68
  66. data/lib/rdoc/markup/to_html.rb +594 -565
  67. data/lib/rdoc/markup/to_html_crossref.rb +234 -230
  68. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  69. data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
  70. data/lib/rdoc/markup/to_label.rb +63 -59
  71. data/lib/rdoc/markup/to_markdown.rb +212 -208
  72. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  73. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  74. data/lib/rdoc/markup/to_test.rb +60 -56
  75. data/lib/rdoc/markup/to_tt_only.rb +84 -80
  76. data/lib/rdoc/markup/verbatim.rb +62 -58
  77. data/lib/rdoc/markup.rb +198 -196
  78. data/lib/rdoc/options.rb +1063 -1061
  79. data/lib/rdoc/parser/c.rb +1039 -1037
  80. data/lib/rdoc/parser/changelog.rb +319 -315
  81. data/lib/rdoc/parser/markdown.rb +17 -13
  82. data/lib/rdoc/parser/rbs.rb +239 -235
  83. data/lib/rdoc/parser/rd.rb +17 -13
  84. data/lib/rdoc/parser/ruby.rb +1245 -1124
  85. data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
  86. data/lib/rdoc/parser/simple.rb +31 -27
  87. data/lib/rdoc/parser/text.rb +12 -8
  88. data/lib/rdoc/parser.rb +228 -220
  89. data/lib/rdoc/rbs_helper.rb +1 -1
  90. data/lib/rdoc/rd/inline.rb +57 -53
  91. data/lib/rdoc/rd.rb +90 -88
  92. data/lib/rdoc/rdoc.rb +500 -491
  93. data/lib/rdoc/ri/driver.rb +1140 -1135
  94. data/lib/rdoc/ri/formatter.rb +7 -3
  95. data/lib/rdoc/ri/paths.rb +140 -136
  96. data/lib/rdoc/ri/servlet.rb +354 -350
  97. data/lib/rdoc/ri/store.rb +4 -2
  98. data/lib/rdoc/ri/task.rb +55 -51
  99. data/lib/rdoc/ri.rb +14 -12
  100. data/lib/rdoc/rubygems_hook.rb +183 -181
  101. data/lib/rdoc/server.rb +349 -347
  102. data/lib/rdoc/stats/normal.rb +46 -42
  103. data/lib/rdoc/stats/quiet.rb +39 -35
  104. data/lib/rdoc/stats/verbose.rb +35 -31
  105. data/lib/rdoc/stats.rb +365 -363
  106. data/lib/rdoc/store.rb +888 -902
  107. data/lib/rdoc/task.rb +260 -256
  108. data/lib/rdoc/text.rb +135 -133
  109. data/lib/rdoc/token_stream.rb +101 -93
  110. data/lib/rdoc/tom_doc.rb +203 -201
  111. data/lib/rdoc/version.rb +1 -1
  112. metadata +4 -5
  113. data/lib/rdoc/markdown/literals.kpeg +0 -21
  114. data/lib/rdoc/markdown/literals.rb +0 -454
@@ -1,377 +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
101
 
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
-
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
273
-
274
- def initialize(base, commit, author, email, date, contents)
275
- case contents
276
- when String
277
- if base&.match(%r[\A([^:/]+:/+[^/]+/)[^/]+/[^/]+/])
278
- repo, host = $&, $1
279
- contents = contents.dup
280
- # base: https://github.com/ruby/ruby/
281
- # Fix #15791 -> Fix [#15791](https://github.com/ruby/ruby/pull/15791)
282
- # GH-15791 -> [GH-15791](https://github.com/ruby/ruby/pull/15791)
283
- # (#15791) -> ([#15791](https://github.com/ruby/ruby/pull/15791))
284
- contents.gsub!(/\b(?:(?i:fix(?:e[sd])?) +)\K\#(\d+\b)|\bGH-(\d+)\b|\(\K\#(\d+)(?=\))/) do
285
- "[#{$&}](#{repo}pull/#{$1 || $2 || $3})"
286
- end
287
- # repo#PR, repo@HASH
288
- # ruby/ruby#15791 -> [ruby/ruby#15791](https://github.com/ruby/ruby/pull/15791)
289
- # ruby/ruby@a8a989b6 -> [ruby/ruby@a8a989b6](https://github.com/ruby/ruby/commit/a8a989b6)
290
- # ref in branckets is not extended
291
- # [ruby/net-imap#543][ruby/ruby#15791] -> [ruby/net-imap#543][ruby/ruby#15791]
292
- contents.gsub!(%r[(?<![-\w#/@]|\]\[)([-\w]+/[-\w]+)(?:@(\h{8,40})|\#(\d+))(?![-\w#/@]|\]\[)]) do
293
- path = defined?($2) ? "commit/#{$2}" : "pull/#{$3}"
294
- "[#{$&}](#{host}#{$1}/#{path})"
295
- end
296
- end
230
+ def parse_info(info)
231
+ /^\s*base-url\s*=\s*(.*\S)/ =~ info
232
+ @base_url = $1
233
+ end
297
234
 
298
- contents = RDoc::Markdown.parse(contents).parts.each do |body|
299
- case body
300
- when RDoc::Markup::Heading
301
- 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
302
254
  end
303
255
  end
304
- case first = contents[0]
305
- when RDoc::Markup::Paragraph
306
- contents[0] = RDoc::Markup::Heading.new(HEADING_LEVEL + 1, first.text)
307
- end
256
+
257
+ entries
308
258
  end
309
- super
310
- end
311
259
 
312
- def level
313
- HEADING_LEVEL
314
- end
260
+ ##
261
+ # Returns a list of ChangeLog entries as
262
+ # RDoc::Parser::ChangeLog::Git::LogEntry list for the given
263
+ # +entries+.
315
264
 
316
- def aref
317
- commit
318
- end
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)
270
+ end
271
+ end
319
272
 
320
- def legacy_aref
321
- "label-#{commit}"
322
- 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
323
313
 
324
- def label(context = nil)
325
- aref
326
- end
314
+ def level
315
+ HEADING_LEVEL
316
+ end
327
317
 
328
- def legacy_label(context = nil)
329
- legacy_aref
330
- end
318
+ def aref
319
+ commit
320
+ end
331
321
 
332
- def text
333
- case base
334
- when nil
335
- "#{date}"
336
- when /%s/
337
- "{#{date}}[#{base % commit}]"
338
- else
339
- "{#{date}}[#{base}#{commit}]"
340
- end + " {#{author}}[mailto:#{email}]"
341
- end
322
+ def legacy_aref
323
+ "label-#{commit}"
324
+ end
342
325
 
343
- def accept(visitor)
344
- visitor.accept_heading self
345
- begin
346
- if visitor.respond_to?(:code_object=)
347
- code_object = visitor.code_object
348
- visitor.code_object = self
326
+ def label(context = nil)
327
+ aref
349
328
  end
350
- contents.each do |body|
351
- body.accept visitor
329
+
330
+ def legacy_label(context = nil)
331
+ legacy_aref
352
332
  end
353
- ensure
354
- if visitor.respond_to?(:code_object)
355
- 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}]"
356
343
  end
357
- end
358
- end
359
344
 
360
- def pretty_print(q) # :nodoc:
361
- q.group(2, '[log_entry: ', ']') do
362
- q.text commit
363
- q.text ','
364
- q.breakable
365
- q.group(2, '[date: ', ']') { q.text date }
366
- q.text ','
367
- q.breakable
368
- q.group(2, '[author: ', ']') { q.text author }
369
- q.text ','
370
- q.breakable
371
- q.group(2, '[email: ', ']') { q.text email }
372
- q.text ','
373
- q.breakable
374
- 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
375
379
  end
376
380
  end
377
381
  end