jfish 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.document +3 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +26 -0
  5. data/README.md +57 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +11 -0
  8. data/VERSION +1 -0
  9. data/jfish.gemspec +38 -0
  10. data/lib/jfish.rb +720 -0
  11. data/lib/template/jfish/_footer.rhtml +5 -0
  12. data/lib/template/jfish/_head.rhtml +16 -0
  13. data/lib/template/jfish/_sidebar_VCS_info.rhtml +18 -0
  14. data/lib/template/jfish/_sidebar_classes.rhtml +9 -0
  15. data/lib/template/jfish/_sidebar_extends.rhtml +16 -0
  16. data/lib/template/jfish/_sidebar_in_files.rhtml +8 -0
  17. data/lib/template/jfish/_sidebar_includes.rhtml +16 -0
  18. data/lib/template/jfish/_sidebar_installed.rhtml +14 -0
  19. data/lib/template/jfish/_sidebar_methods.rhtml +12 -0
  20. data/lib/template/jfish/_sidebar_navigation.rhtml +10 -0
  21. data/lib/template/jfish/_sidebar_pages.rhtml +12 -0
  22. data/lib/template/jfish/_sidebar_parent.rhtml +10 -0
  23. data/lib/template/jfish/_sidebar_search.rhtml +10 -0
  24. data/lib/template/jfish/_sidebar_sections.rhtml +10 -0
  25. data/lib/template/jfish/_sidebar_table_of_contents.rhtml +19 -0
  26. data/lib/template/jfish/class.rhtml +179 -0
  27. data/lib/template/jfish/images/add.png +0 -0
  28. data/lib/template/jfish/images/arrow_up.png +0 -0
  29. data/lib/template/jfish/images/brick.png +0 -0
  30. data/lib/template/jfish/images/brick_link.png +0 -0
  31. data/lib/template/jfish/images/bug.png +0 -0
  32. data/lib/template/jfish/images/bullet_black.png +0 -0
  33. data/lib/template/jfish/images/bullet_toggle_minus.png +0 -0
  34. data/lib/template/jfish/images/bullet_toggle_plus.png +0 -0
  35. data/lib/template/jfish/images/date.png +0 -0
  36. data/lib/template/jfish/images/delete.png +0 -0
  37. data/lib/template/jfish/images/find.png +0 -0
  38. data/lib/template/jfish/images/loadingAnimation.gif +0 -0
  39. data/lib/template/jfish/images/logo.png +0 -0
  40. data/lib/template/jfish/images/macFFBgHack.png +0 -0
  41. data/lib/template/jfish/images/package.png +0 -0
  42. data/lib/template/jfish/images/page_green.png +0 -0
  43. data/lib/template/jfish/images/page_white_text.png +0 -0
  44. data/lib/template/jfish/images/page_white_width.png +0 -0
  45. data/lib/template/jfish/images/plugin.png +0 -0
  46. data/lib/template/jfish/images/ruby.png +0 -0
  47. data/lib/template/jfish/images/tag_blue.png +0 -0
  48. data/lib/template/jfish/images/tag_green.png +0 -0
  49. data/lib/template/jfish/images/transparent.png +0 -0
  50. data/lib/template/jfish/images/wrench.png +0 -0
  51. data/lib/template/jfish/images/wrench_orange.png +0 -0
  52. data/lib/template/jfish/images/zoom.png +0 -0
  53. data/lib/template/jfish/index.rhtml +19 -0
  54. data/lib/template/jfish/js/darkfish.js +155 -0
  55. data/lib/template/jfish/js/jquery.js +18 -0
  56. data/lib/template/jfish/js/search.js +94 -0
  57. data/lib/template/jfish/page.rhtml +18 -0
  58. data/lib/template/jfish/rdoc.css +557 -0
  59. data/lib/template/jfish/servlet_not_found.rhtml +18 -0
  60. data/lib/template/jfish/servlet_root.rhtml +37 -0
  61. data/lib/template/jfish/table_of_contents.rhtml +55 -0
  62. metadata +135 -0
data/lib/jfish.rb ADDED
@@ -0,0 +1,720 @@
1
+ # -*- mode: ruby; ruby-indent-level: 2; tab-width: 2 -*-
2
+
3
+ require 'erb'
4
+ require 'fileutils'
5
+ require 'pathname'
6
+ require 'rdoc/generator/markup'
7
+
8
+ ##
9
+ # JFish RDoc HTML Generator
10
+ #
11
+ # $Id: jfish.rb 52 2009-01-07 02:08:11Z deveiant $
12
+ #
13
+ # == Author/s
14
+ # * Michael Granger (ged@FaerieMUD.org)
15
+ #
16
+ # == Contributors
17
+ # * Mahlon E. Smith (mahlon@martini.nu)
18
+ # * Eric Hodel (drbrain@segment7.net)
19
+ #
20
+ # == License
21
+ #
22
+ # Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
23
+ #
24
+ # Redistribution and use in source and binary forms, with or without
25
+ # modification, are permitted provided that the following conditions are met:
26
+ #
27
+ # * Redistributions of source code must retain the above copyright notice,
28
+ # this list of conditions and the following disclaimer.
29
+ #
30
+ # * Redistributions in binary form must reproduce the above copyright notice,
31
+ # this list of conditions and the following disclaimer in the documentation
32
+ # and/or other materials provided with the distribution.
33
+ #
34
+ # * Neither the name of the author/s, nor the names of the project's
35
+ # contributors may be used to endorse or promote products derived from this
36
+ # software without specific prior written permission.
37
+ #
38
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
42
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
+ #
49
+ # == Attributions
50
+ #
51
+ # JFish uses the {Silk Icons}[http://www.famfamfam.com/lab/icons/silk/] set
52
+ # by Mark James.
53
+
54
+ class RDoc::Generator::JFish
55
+
56
+ RDoc::RDoc.add_generator self
57
+
58
+ include ERB::Util
59
+
60
+ ##
61
+ # Path to this file's parent directory. Used to find templates and other
62
+ # resources.
63
+
64
+ GENERATOR_DIR = File.join 'rdoc', 'generator'
65
+
66
+ ##
67
+ # Release Version
68
+
69
+ VERSION = '3'
70
+
71
+ ##
72
+ # Description of this generator
73
+
74
+ DESCRIPTION = 'HTML generator, written by Michael Granger'
75
+
76
+ ##
77
+ # The relative path to style sheets and javascript. By default this is set
78
+ # the same as the rel_prefix.
79
+
80
+ attr_accessor :asset_rel_path
81
+
82
+ ##
83
+ # The path to generate files into, combined with <tt>--op</tt> from the
84
+ # options for a full path.
85
+
86
+ attr_reader :base_dir
87
+
88
+ ##
89
+ # Classes and modules to be used by this generator, not necessarily
90
+ # displayed. See also #modsort
91
+
92
+ attr_reader :classes
93
+
94
+ ##
95
+ # No files will be written when dry_run is true.
96
+
97
+ attr_accessor :dry_run
98
+
99
+ ##
100
+ # When false the generate methods return a String instead of writing to a
101
+ # file. The default is true.
102
+
103
+ attr_accessor :file_output
104
+
105
+ ##
106
+ # Files to be displayed by this generator
107
+
108
+ attr_reader :files
109
+
110
+ ##
111
+ # The JSON index generator for this JFish generator
112
+
113
+ attr_reader :json_index
114
+
115
+ ##
116
+ # Methods to be displayed by this generator
117
+
118
+ attr_reader :methods
119
+
120
+ ##
121
+ # Sorted list of classes and modules to be displayed by this generator
122
+
123
+ attr_reader :modsort
124
+
125
+ ##
126
+ # The RDoc::Store that is the source of the generated content
127
+
128
+ attr_reader :store
129
+
130
+ ##
131
+ # The output directory
132
+
133
+ attr_reader :outputdir
134
+
135
+ ##
136
+ # Initialize a few instance variables before we start
137
+
138
+ def initialize store, options
139
+ @store = store
140
+ @options = options
141
+
142
+ @asset_rel_path = ''
143
+ @base_dir = Pathname.pwd.expand_path
144
+ @dry_run = @options.dry_run
145
+ @file_output = true
146
+ @template_dir = Pathname.new File.join(File.dirname(__FILE__), 'template', 'jfish')
147
+ @template_cache = {}
148
+
149
+ @classes = nil
150
+ @context = nil
151
+ @files = nil
152
+ @methods = nil
153
+ @modsort = nil
154
+
155
+ @json_index = RDoc::Generator::JsonIndex.new self, options
156
+ end
157
+
158
+ ##
159
+ # Output progress information if debugging is enabled
160
+
161
+ def debug_msg *msg
162
+ return unless $DEBUG_RDOC
163
+ $stderr.puts(*msg)
164
+ end
165
+
166
+ ##
167
+ # Directory where generated class HTML files live relative to the output
168
+ # dir.
169
+
170
+ def class_dir
171
+ nil
172
+ end
173
+
174
+ ##
175
+ # Directory where generated class HTML files live relative to the output
176
+ # dir.
177
+
178
+ def file_dir
179
+ nil
180
+ end
181
+
182
+ ##
183
+ # Create the directories the generated docs will live in if they don't
184
+ # already exist.
185
+
186
+ def gen_sub_directories
187
+ @outputdir.mkpath
188
+ end
189
+
190
+ ##
191
+ # Copy over the stylesheet into the appropriate place in the output
192
+ # directory.
193
+
194
+ def write_style_sheet
195
+ debug_msg "Copying static files"
196
+ options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
197
+
198
+ FileUtils.cp @template_dir + 'rdoc.css', '.', options
199
+
200
+ Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
201
+ next if File.directory? path
202
+ next if File.basename(path) =~ /^\./
203
+
204
+ dst = Pathname.new(path).relative_path_from @template_dir
205
+
206
+ # I suck at glob
207
+ dst_dir = dst.dirname
208
+ FileUtils.mkdir_p dst_dir, options unless File.exist? dst_dir
209
+
210
+ FileUtils.cp @template_dir + path, dst, options
211
+ end
212
+ end
213
+
214
+ ##
215
+ # Build the initial indices and output objects based on an array of TopLevel
216
+ # objects containing the extracted information.
217
+
218
+ def generate
219
+ setup
220
+
221
+ write_style_sheet
222
+ generate_index
223
+ generate_class_files
224
+ generate_file_files
225
+ generate_table_of_contents
226
+ @json_index.generate
227
+
228
+ copy_static
229
+
230
+ rescue => e
231
+ debug_msg "%s: %s\n %s" % [
232
+ e.class.name, e.message, e.backtrace.join("\n ")
233
+ ]
234
+
235
+ raise
236
+ end
237
+
238
+ ##
239
+ # Copies static files from the static_path into the output directory
240
+
241
+ def copy_static
242
+ return if @options.static_path.empty?
243
+
244
+ fu_options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
245
+
246
+ @options.static_path.each do |path|
247
+ unless File.directory? path then
248
+ FileUtils.install path, @outputdir, fu_options.merge(:mode => 0644)
249
+ next
250
+ end
251
+
252
+ Dir.chdir path do
253
+ Dir[File.join('**', '*')].each do |entry|
254
+ dest_file = @outputdir + entry
255
+
256
+ if File.directory? entry then
257
+ FileUtils.mkdir_p entry, fu_options
258
+ else
259
+ FileUtils.install entry, dest_file, fu_options.merge(:mode => 0644)
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ ##
267
+ # Return a list of the documented modules sorted by salience first, then
268
+ # by name.
269
+
270
+ def get_sorted_module_list classes
271
+ classes.select do |klass|
272
+ klass.display?
273
+ end.sort
274
+ end
275
+
276
+ ##
277
+ # Generate an index page which lists all the classes which are documented.
278
+
279
+ def generate_index
280
+ setup
281
+
282
+ template_file = @template_dir + 'index.rhtml'
283
+ return unless template_file.exist?
284
+
285
+ debug_msg "Rendering the index page..."
286
+
287
+ out_file = @base_dir + @options.op_dir + 'index.html'
288
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
289
+ search_index_rel_prefix = rel_prefix
290
+ search_index_rel_prefix += @asset_rel_path if @file_output
291
+
292
+ # suppress 1.9.3 warning
293
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
294
+
295
+ @title = @options.title
296
+
297
+ render_template template_file, out_file do |io| binding end
298
+ rescue => e
299
+ error = RDoc::Error.new \
300
+ "error generating index.html: #{e.message} (#{e.class})"
301
+ error.set_backtrace e.backtrace
302
+
303
+ raise error
304
+ end
305
+
306
+ ##
307
+ # Generates a class file for +klass+
308
+
309
+ def generate_class klass, template_file = nil
310
+ setup
311
+
312
+ current = klass
313
+
314
+ template_file ||= @template_dir + 'class.rhtml'
315
+
316
+ debug_msg " working on %s (%s)" % [klass.full_name, klass.path]
317
+ out_file = @outputdir + klass.path
318
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
319
+ search_index_rel_prefix = rel_prefix
320
+ search_index_rel_prefix += @asset_rel_path if @file_output
321
+
322
+ # suppress 1.9.3 warning
323
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
324
+ svninfo = svninfo = get_svninfo(current)
325
+
326
+ @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
327
+
328
+ debug_msg " rendering #{out_file}"
329
+ render_template template_file, out_file do |io| binding end
330
+ end
331
+
332
+ ##
333
+ # Generate a documentation file for each class and module
334
+
335
+ def generate_class_files
336
+ setup
337
+
338
+ template_file = @template_dir + 'class.rhtml'
339
+ template_file = @template_dir + 'classpage.rhtml' unless
340
+ template_file.exist?
341
+ return unless template_file.exist?
342
+ debug_msg "Generating class documentation in #{@outputdir}"
343
+
344
+ current = nil
345
+
346
+ @classes.each do |klass|
347
+ current = klass
348
+
349
+ generate_class klass, template_file
350
+ end
351
+ rescue => e
352
+ error = RDoc::Error.new \
353
+ "error generating #{current.path}: #{e.message} (#{e.class})"
354
+ error.set_backtrace e.backtrace
355
+
356
+ raise error
357
+ end
358
+
359
+ ##
360
+ # Generate a documentation file for each file
361
+
362
+ def generate_file_files
363
+ setup
364
+
365
+ page_file = @template_dir + 'page.rhtml'
366
+ fileinfo_file = @template_dir + 'fileinfo.rhtml'
367
+
368
+ # for legacy templates
369
+ filepage_file = @template_dir + 'filepage.rhtml' unless
370
+ page_file.exist? or fileinfo_file.exist?
371
+
372
+ return unless
373
+ page_file.exist? or fileinfo_file.exist? or filepage_file.exist?
374
+
375
+ debug_msg "Generating file documentation in #{@outputdir}"
376
+
377
+ out_file = nil
378
+ current = nil
379
+
380
+ @files.each do |file|
381
+ current = file
382
+
383
+ if file.text? and page_file.exist? then
384
+ generate_page file
385
+ next
386
+ end
387
+
388
+ template_file = nil
389
+ out_file = @outputdir + file.path
390
+ debug_msg " working on %s (%s)" % [file.full_name, out_file]
391
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
392
+ search_index_rel_prefix = rel_prefix
393
+ search_index_rel_prefix += @asset_rel_path if @file_output
394
+
395
+ # suppress 1.9.3 warning
396
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
397
+
398
+ unless filepage_file then
399
+ if file.text? then
400
+ next unless page_file.exist?
401
+ template_file = page_file
402
+ @title = file.page_name
403
+ else
404
+ next unless fileinfo_file.exist?
405
+ template_file = fileinfo_file
406
+ @title = "File: #{file.base_name}"
407
+ end
408
+ end
409
+
410
+ @title += " - #{@options.title}"
411
+ template_file ||= filepage_file
412
+
413
+ render_template template_file, out_file do |io| binding end
414
+ end
415
+ rescue => e
416
+ error =
417
+ RDoc::Error.new "error generating #{out_file}: #{e.message} (#{e.class})"
418
+ error.set_backtrace e.backtrace
419
+
420
+ raise error
421
+ end
422
+
423
+ ##
424
+ # Generate a page file for +file+
425
+
426
+ def generate_page file
427
+ setup
428
+
429
+ template_file = @template_dir + 'page.rhtml'
430
+
431
+ out_file = @outputdir + file.path
432
+ debug_msg " working on %s (%s)" % [file.full_name, out_file]
433
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
434
+ search_index_rel_prefix = rel_prefix
435
+ search_index_rel_prefix += @asset_rel_path if @file_output
436
+
437
+ # suppress 1.9.3 warning
438
+ current = current = file
439
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
440
+
441
+ @title = "#{file.page_name} - #{@options.title}"
442
+
443
+ debug_msg " rendering #{out_file}"
444
+ render_template template_file, out_file do |io| binding end
445
+ end
446
+
447
+ ##
448
+ # Generates the 404 page for the RDoc servlet
449
+
450
+ def generate_servlet_not_found path
451
+ setup
452
+
453
+ template_file = @template_dir + 'servlet_not_found.rhtml'
454
+ return unless template_file.exist?
455
+
456
+ debug_msg "Rendering the servlet 404 Not Found page..."
457
+
458
+ rel_prefix = rel_prefix = ''
459
+ search_index_rel_prefix = rel_prefix
460
+ search_index_rel_prefix += @asset_rel_path if @file_output
461
+
462
+ # suppress 1.9.3 warning
463
+ asset_rel_prefix = asset_rel_prefix = ''
464
+
465
+ @title = 'Not Found'
466
+
467
+ render_template template_file do |io| binding end
468
+ rescue => e
469
+ error = RDoc::Error.new \
470
+ "error generating servlet_not_found: #{e.message} (#{e.class})"
471
+ error.set_backtrace e.backtrace
472
+
473
+ raise error
474
+ end
475
+
476
+ ##
477
+ # Generates the servlet root page for the RDoc servlet
478
+
479
+ def generate_servlet_root installed
480
+ setup
481
+
482
+ template_file = @template_dir + 'servlet_root.rhtml'
483
+ return unless template_file.exist?
484
+
485
+ debug_msg 'Rendering the servlet root page...'
486
+
487
+ rel_prefix = '.'
488
+ asset_rel_prefix = rel_prefix
489
+ search_index_rel_prefix = asset_rel_prefix
490
+ search_index_rel_prefix += @asset_rel_path if @file_output
491
+
492
+ @title = 'Local RDoc Documentation'
493
+
494
+ render_template template_file do |io| binding end
495
+ rescue => e
496
+ error = RDoc::Error.new \
497
+ "error generating servlet_root: #{e.message} (#{e.class})"
498
+ error.set_backtrace e.backtrace
499
+
500
+ raise error
501
+ end
502
+
503
+ ##
504
+ # Generate an index page which lists all the classes which are documented.
505
+
506
+ def generate_table_of_contents
507
+ setup
508
+
509
+ template_file = @template_dir + 'table_of_contents.rhtml'
510
+ return unless template_file.exist?
511
+
512
+ debug_msg "Rendering the Table of Contents..."
513
+
514
+ out_file = @outputdir + 'table_of_contents.html'
515
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
516
+ search_index_rel_prefix = rel_prefix
517
+ search_index_rel_prefix += @asset_rel_path if @file_output
518
+
519
+ # suppress 1.9.3 warning
520
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
521
+
522
+ @title = "Table of Contents - #{@options.title}"
523
+
524
+ render_template template_file, out_file do |io| binding end
525
+ rescue => e
526
+ error = RDoc::Error.new \
527
+ "error generating table_of_contents.html: #{e.message} (#{e.class})"
528
+ error.set_backtrace e.backtrace
529
+
530
+ raise error
531
+ end
532
+
533
+ ##
534
+ # Prepares for generation of output from the current directory
535
+
536
+ def setup
537
+ return if instance_variable_defined? :@outputdir
538
+
539
+ @outputdir = Pathname.new(@options.op_dir).expand_path @base_dir
540
+
541
+ return unless @store
542
+
543
+ @classes = @store.all_classes_and_modules.sort
544
+ @files = @store.all_files.sort
545
+ @methods = @classes.map { |m| m.method_list }.flatten.sort
546
+ @modsort = get_sorted_module_list @classes
547
+ end
548
+
549
+ ##
550
+ # Return a string describing the amount of time in the given number of
551
+ # seconds in terms a human can understand easily.
552
+
553
+ def time_delta_string seconds
554
+ return 'less than a minute' if seconds < 60
555
+ return "#{seconds / 60} minute#{seconds / 60 == 1 ? '' : 's'}" if
556
+ seconds < 3000 # 50 minutes
557
+ return 'about one hour' if seconds < 5400 # 90 minutes
558
+ return "#{seconds / 3600} hours" if seconds < 64800 # 18 hours
559
+ return 'one day' if seconds < 86400 # 1 day
560
+ return 'about one day' if seconds < 172800 # 2 days
561
+ return "#{seconds / 86400} days" if seconds < 604800 # 1 week
562
+ return 'about one week' if seconds < 1209600 # 2 week
563
+ return "#{seconds / 604800} weeks" if seconds < 7257600 # 3 months
564
+ return "#{seconds / 2419200} months" if seconds < 31536000 # 1 year
565
+ return "#{seconds / 31536000} years"
566
+ end
567
+
568
+ # %q$Id: jfish.rb 52 2009-01-07 02:08:11Z deveiant $"
569
+ SVNID_PATTERN = /
570
+ \$Id:\s
571
+ (\S+)\s # filename
572
+ (\d+)\s # rev
573
+ (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
574
+ (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ)
575
+ (\w+)\s # committer
576
+ \$$
577
+ /x
578
+
579
+ ##
580
+ # Try to extract Subversion information out of the first constant whose
581
+ # value looks like a subversion Id tag. If no matching constant is found,
582
+ # and empty hash is returned.
583
+
584
+ def get_svninfo klass
585
+ constants = klass.constants or return {}
586
+
587
+ constants.find { |c| c.value =~ SVNID_PATTERN } or return {}
588
+
589
+ filename, rev, date, time, committer = $~.captures
590
+ commitdate = Time.parse "#{date} #{time}"
591
+
592
+ return {
593
+ :filename => filename,
594
+ :rev => Integer(rev),
595
+ :commitdate => commitdate,
596
+ :commitdelta => time_delta_string(Time.now - commitdate),
597
+ :committer => committer,
598
+ }
599
+ end
600
+
601
+ ##
602
+ # Creates a template from its components and the +body_file+.
603
+ #
604
+ # For backwards compatibility, if +body_file+ contains "<html" the body is
605
+ # used directly.
606
+
607
+ def assemble_template body_file
608
+ body = body_file.read
609
+ return body if body =~ /<html/
610
+
611
+ head_file = @template_dir + '_head.rhtml'
612
+ footer_file = @template_dir + '_footer.rhtml'
613
+
614
+ <<-TEMPLATE
615
+ <!DOCTYPE html>
616
+
617
+ <html>
618
+ <head>
619
+ #{head_file.read}
620
+
621
+ #{body}
622
+
623
+ #{footer_file.read}
624
+ TEMPLATE
625
+ end
626
+
627
+ ##
628
+ # Renders the ERb contained in +file_name+ relative to the template
629
+ # directory and returns the result based on the current context.
630
+
631
+ def render file_name
632
+ template_file = @template_dir + file_name
633
+
634
+ template = template_for template_file, false, RDoc::ERBPartial
635
+
636
+ template.filename = template_file.to_s
637
+
638
+ template.result @context
639
+ end
640
+
641
+ ##
642
+ # Load and render the erb template in the given +template_file+ and write
643
+ # it out to +out_file+.
644
+ #
645
+ # Both +template_file+ and +out_file+ should be Pathname-like objects.
646
+ #
647
+ # An io will be yielded which must be captured by binding in the caller.
648
+
649
+ def render_template template_file, out_file = nil # :yield: io
650
+ io_output = out_file && !@dry_run && @file_output
651
+ erb_klass = io_output ? RDoc::ERBIO : ERB
652
+
653
+ template = template_for template_file, true, erb_klass
654
+
655
+ if io_output then
656
+ debug_msg "Outputting to %s" % [out_file.expand_path]
657
+
658
+ out_file.dirname.mkpath
659
+ out_file.open 'w', 0644 do |io|
660
+ io.set_encoding @options.encoding if Object.const_defined? :Encoding
661
+
662
+ @context = yield io
663
+
664
+ template_result template, @context, template_file
665
+ end
666
+ else
667
+ @context = yield nil
668
+
669
+ output = template_result template, @context, template_file
670
+
671
+ debug_msg " would have written %d characters to %s" % [
672
+ output.length, out_file.expand_path
673
+ ] if @dry_run
674
+
675
+ output
676
+ end
677
+ end
678
+
679
+ ##
680
+ # Creates the result for +template+ with +context+. If an error is raised a
681
+ # Pathname +template_file+ will indicate the file where the error occurred.
682
+
683
+ def template_result template, context, template_file
684
+ template.filename = template_file.to_s
685
+ template.result context
686
+ rescue NoMethodError => e
687
+ raise RDoc::Error, "Error while evaluating %s: %s" % [
688
+ template_file.expand_path,
689
+ e.message,
690
+ ], e.backtrace
691
+ end
692
+
693
+ ##
694
+ # Retrieves a cache template for +file+, if present, or fills the cache.
695
+
696
+ def template_for file, page = true, klass = ERB
697
+ template = @template_cache[file]
698
+
699
+ return template if template
700
+
701
+ if page then
702
+ template = assemble_template file
703
+ erbout = 'io'
704
+ else
705
+ template = file.read
706
+ template = template.encode @options.encoding if
707
+ Object.const_defined? :Encoding
708
+
709
+ file_var = File.basename(file).sub(/\..*/, '')
710
+
711
+ erbout = "_erbout_#{file_var}"
712
+ end
713
+
714
+ template = klass.new template, nil, '<>', erbout
715
+ @template_cache[file] = template
716
+ template
717
+ end
718
+
719
+ end
720
+
@@ -0,0 +1,5 @@
1
+ <footer id="validator-badges">
2
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
3
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> <%= RDoc::VERSION %>.
4
+ <p>Generated with the <a href="http://deveiate.org/projects/JFish-Rdoc/">JFish Rdoc Generator</a> <%= RDoc::Generator::JFish::VERSION %>.
5
+ </footer>