@@ -132,8 +132,9 @@ def group_entries entries
132
132
def parse_entries
133
133
@time_cache ||= { }
134
134
135
- if /\A (?:.*\n ){,3}commit\s / =~ @content
135
+ if /\A (( ?:.*\n ){,3}) commit\s / =~ @content
136
136
class << self ; prepend Git ; end
137
+ parse_info ( $1)
137
138
return parse_entries
138
139
end
139
140
@@ -208,6 +209,11 @@ def scan
208
209
end
209
210
210
211
module Git
212
+ def parse_info ( info )
213
+ /^\s *base-url\s *=\s *(.*\S )/ =~ info
214
+ @base_url = $1
215
+ end
216
+
211
217
def parse_entries
212
218
entries = [ ]
213
219
@@ -216,7 +222,9 @@ def parse_entries
216
222
if /(\d +)-(\d +)-(\d +) (\d +):(\d +):(\d +) *([-+]\d \d )(\d \d )/ =~ date
217
223
time = Time . new ( $1, $2, $3, $4, $5, $6, "#{ $7} :#{ $8} " )
218
224
@time_cache [ entry_name ] = time
219
- entries << [ entry_name , [ author , date , entry_body ] ]
225
+ author . sub! ( /\s *<(.*)>/ , '' )
226
+ email = $1
227
+ entries << [ entry_name , [ author , email , date , entry_body ] ]
220
228
end
221
229
end
222
230
@@ -226,31 +234,88 @@ def parse_entries
226
234
def create_entries entries
227
235
# git log entries have no strictly itemized style like the old
228
236
# style, just assume Markdown.
229
- out = [ ]
230
- entries . each do |entry , ( author , date , body ) |
231
- title = RDoc ::Markup ::Heading . new ( 3 , "#{ date } #{ author } " )
232
- title . extend ( Aref )
233
- title . aref = "label-#{ entry } "
234
- out << title
235
- out . concat parse_log_entry ( body , entry )
237
+ entries . map do |commit , entry |
238
+ LogEntry . new ( @base_url , commit , *entry )
236
239
end
237
- out
238
240
end
239
241
240
- def parse_log_entry ( content , sha )
241
- RDoc ::Markdown . parse ( content ) . parts . each do |body |
242
- case body
243
- when RDoc ::Markup ::Heading
244
- body . level += 3
245
- label = body . aref . sub ( /\A label-/ , "label-#{ sha } -" )
246
- body . extend ( Aref )
247
- body . aref = label
242
+ LogEntry = Struct . new ( :base , :commit , :author , :email , :date , :contents ) do
243
+ HEADING_LEVEL = 3
244
+
245
+ def initialize ( base , commit , author , email , date , contents )
246
+ case contents
247
+ when String
248
+ contents = RDoc ::Markdown . parse ( contents ) . parts . each do |body |
249
+ case body
250
+ when RDoc ::Markup ::Heading
251
+ body . level += HEADING_LEVEL + 1
252
+ end
253
+ end
254
+ case first = contents [ 0 ]
255
+ when RDoc ::Markup ::Paragraph
256
+ contents [ 0 ] = RDoc ::Markup ::Heading . new ( HEADING_LEVEL + 1 , first . text )
257
+ end
248
258
end
259
+ super
260
+ end
261
+
262
+ def level
263
+ HEADING_LEVEL
264
+ end
265
+
266
+ def aref
267
+ "label-#{ commit } "
249
268
end
250
- end
251
269
252
- module Aref
253
- attr_accessor :aref
270
+ def label context = nil
271
+ aref
272
+ end
273
+
274
+ def text
275
+ case base
276
+ when nil
277
+ "#{ date } "
278
+ when /%s/
279
+ "{#{ date } }[#{ base % commit } ]"
280
+ else
281
+ "{#{ date } }[#{ base } #{ commit } ]"
282
+ end + " {#{ author } }[mailto:#{ email } ]"
283
+ end
284
+
285
+ def accept visitor
286
+ visitor . accept_heading self
287
+ begin
288
+ if visitor . respond_to? ( :code_object= )
289
+ code_object = visitor . code_object
290
+ visitor . code_object = self
291
+ end
292
+ contents . each do |body |
293
+ body . accept visitor
294
+ end
295
+ ensure
296
+ if visitor . respond_to? ( :code_object )
297
+ visitor . code_object = code_object
298
+ end
299
+ end
300
+ end
301
+
302
+ def pretty_print q # :nodoc:
303
+ q . group ( 2 , '[log_entry: ' , ']' ) do
304
+ q . text commit
305
+ q . text ','
306
+ q . breakable
307
+ q . group ( 2 , '[date: ' , ']' ) { q . text date }
308
+ q . text ','
309
+ q . breakable
310
+ q . group ( 2 , '[author: ' , ']' ) { q . text author }
311
+ q . text ','
312
+ q . breakable
313
+ q . group ( 2 , '[email: ' , ']' ) { q . text email }
314
+ q . text ','
315
+ q . breakable
316
+ q . pp contents
317
+ end
318
+ end
254
319
end
255
320
end
256
321
end
0 commit comments