rdoc 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (95) hide show
  1. data.tar.gz.sig +2 -0
  2. data/.document +4 -0
  3. data/History.txt +35 -0
  4. data/Manifest.txt +36 -15
  5. data/README.txt +11 -27
  6. data/Rakefile +3 -0
  7. data/lib/rdoc.rb +1 -1
  8. data/lib/rdoc/cache.rb +32 -0
  9. data/lib/rdoc/code_objects.rb +121 -59
  10. data/lib/rdoc/generator.rb +196 -133
  11. data/lib/rdoc/generator/darkfish.rb +471 -0
  12. data/lib/rdoc/generator/html.rb +71 -60
  13. data/lib/rdoc/generator/html/html.rb +115 -115
  14. data/lib/rdoc/generator/html/one_page_html.rb +56 -56
  15. data/lib/rdoc/generator/ri.rb +2 -0
  16. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  17. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +302 -0
  18. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +114 -0
  19. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  20. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  21. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  22. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  23. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  24. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  25. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  26. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  27. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  28. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  29. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  30. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  31. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  32. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  33. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  34. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  35. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  36. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  37. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  38. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  39. data/lib/rdoc/generator/template/darkfish/index.rhtml +57 -0
  40. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +116 -0
  41. data/lib/rdoc/generator/template/darkfish/js/jquery.js +32 -0
  42. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +114 -0
  43. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +10 -0
  44. data/lib/rdoc/generator/template/darkfish/rdoc.css +696 -0
  45. data/lib/rdoc/generator/xml.rb +19 -12
  46. data/lib/rdoc/generator/xml/rdf.rb +50 -50
  47. data/lib/rdoc/generator/xml/xml.rb +58 -58
  48. data/lib/rdoc/known_classes.rb +0 -1
  49. data/lib/rdoc/markup/preprocess.rb +4 -3
  50. data/lib/rdoc/markup/to_html.rb +4 -1
  51. data/lib/rdoc/markup/to_html_crossref.rb +28 -31
  52. data/lib/rdoc/options.rb +25 -20
  53. data/lib/rdoc/parser.rb +10 -2
  54. data/lib/rdoc/parser/c.rb +38 -29
  55. data/lib/rdoc/parser/f95.rb +32 -32
  56. data/lib/rdoc/parser/ruby.rb +5 -2
  57. data/lib/rdoc/parser/simple.rb +1 -0
  58. data/lib/rdoc/rdoc.rb +99 -47
  59. data/lib/rdoc/ri/cache.rb +6 -6
  60. data/lib/rdoc/ri/display.rb +22 -75
  61. data/lib/rdoc/ri/driver.rb +237 -78
  62. data/lib/rdoc/stats.rb +91 -28
  63. data/lib/rdoc/template.rb +6 -2
  64. data/test/test.ja.rdoc +8 -0
  65. data/test/test.ja.txt +8 -0
  66. data/test/test_attribute_manager.rb +9 -6
  67. data/test/test_rdoc_markup.rb +4 -2
  68. data/test/test_rdoc_markup_attribute_manager.rb +13 -3
  69. data/test/test_rdoc_markup_to_html.rb +18 -2
  70. data/test/test_rdoc_markup_to_html_crossref.rb +186 -249
  71. data/test/test_rdoc_parser.rb +17 -1
  72. data/test/test_rdoc_parser_c.rb +65 -10
  73. data/test/test_rdoc_parser_perl.rb +4 -2
  74. data/test/test_rdoc_parser_ruby.rb +6 -4
  75. data/test/test_rdoc_ri_attribute_formatter.rb +4 -2
  76. data/test/test_rdoc_ri_default_display.rb +8 -4
  77. data/test/test_rdoc_ri_driver.rb +4 -2
  78. data/test/test_rdoc_ri_formatter.rb +6 -4
  79. data/test/test_rdoc_ri_overstrike_formatter.rb +4 -2
  80. metadata +84 -33
  81. metadata.gz.sig +0 -0
  82. data/lib/rdoc/generator/chm.rb +0 -113
  83. data/lib/rdoc/generator/chm/chm.rb +0 -100
  84. data/lib/rdoc/generator/html/frameless.rb +0 -92
  85. data/lib/rdoc/generator/html/hefss.rb +0 -150
  86. data/lib/rdoc/generator/html/kilmer.rb +0 -151
  87. data/lib/rdoc/generator/html/kilmerfactory.rb +0 -427
  88. data/lib/rdoc/generator/texinfo.rb +0 -81
  89. data/lib/rdoc/generator/texinfo/class.texinfo.erb +0 -44
  90. data/lib/rdoc/generator/texinfo/file.texinfo.erb +0 -6
  91. data/lib/rdoc/generator/texinfo/method.texinfo.erb +0 -6
  92. data/lib/rdoc/generator/texinfo/texinfo.erb +0 -28
  93. data/test/rdoc_markup_to_html_crossref_reference.rb +0 -31
  94. data/test/test_rdoc_info_formatting.rb +0 -175
  95. data/test/test_rdoc_info_sections.rb +0 -136
@@ -0,0 +1,471 @@
1
+ #!ruby
2
+
3
+ require 'rubygems'
4
+ gem 'rdoc', '>= 2.3'
5
+
6
+ require 'pp'
7
+ require 'pathname'
8
+ require 'fileutils'
9
+ require 'erb'
10
+ require 'yaml'
11
+
12
+ require 'rdoc/rdoc'
13
+ require 'rdoc/generator/xml'
14
+ require 'rdoc/generator/html'
15
+
16
+ #
17
+ # Darkfish RDoc HTML Generator
18
+ #
19
+ # $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
20
+ #
21
+ # == Author/s
22
+ # * Michael Granger (ged@FaerieMUD.org)
23
+ #
24
+ # == Contributors
25
+ # * Mahlon E. Smith (mahlon@martini.nu)
26
+ # * Eric Hodel (drbrain@segment7.net)
27
+ #
28
+ # == License
29
+ #
30
+ # Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
31
+ #
32
+ # Redistribution and use in source and binary forms, with or without
33
+ # modification, are permitted provided that the following conditions are met:
34
+ #
35
+ # * Redistributions of source code must retain the above copyright notice,
36
+ # this list of conditions and the following disclaimer.
37
+ #
38
+ # * Redistributions in binary form must reproduce the above copyright notice,
39
+ # this list of conditions and the following disclaimer in the documentation
40
+ # and/or other materials provided with the distribution.
41
+ #
42
+ # * Neither the name of the author/s, nor the names of the project's
43
+ # contributors may be used to endorse or promote products derived from this
44
+ # software without specific prior written permission.
45
+ #
46
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
50
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
52
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
+ #
57
+ class RDoc::Generator::Darkfish < RDoc::Generator::XML
58
+
59
+ RDoc::RDoc.add_generator( self )
60
+
61
+ include ERB::Util
62
+
63
+ # Subversion rev
64
+ SVNRev = %$Rev: 52 $
65
+
66
+ # Subversion ID
67
+ SVNId = %$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
68
+
69
+ # Path to this file's parent directory. Used to find templates and other
70
+ # resources.
71
+ GENERATOR_DIR = Pathname.new( __FILE__ ).expand_path.dirname
72
+
73
+ # Release Version
74
+ VERSION = '1.1.6'
75
+
76
+ # Directory where generated classes live relative to the root
77
+ CLASS_DIR = nil
78
+
79
+ # Directory where generated files live relative to the root
80
+ FILE_DIR = nil
81
+
82
+
83
+ #################################################################
84
+ ### C L A S S M E T H O D S
85
+ #################################################################
86
+
87
+ ### Standard generator factory method
88
+ def self::for( options )
89
+ new( options )
90
+ end
91
+
92
+
93
+ #################################################################
94
+ ### I N S T A N C E M E T H O D S
95
+ #################################################################
96
+
97
+ ### Initialize a few instance variables before we start
98
+ def initialize( options )
99
+ @template = nil
100
+ @template_dir = GENERATOR_DIR + 'template/darkfish'
101
+
102
+ @files = []
103
+ @classes = []
104
+ @hyperlinks = {}
105
+
106
+ @basedir = Pathname.pwd.expand_path
107
+
108
+ options.inline_source = true
109
+ options.diagram = false
110
+
111
+ super
112
+ end
113
+
114
+
115
+ ######
116
+ public
117
+ ######
118
+
119
+ # The output directory
120
+ attr_reader :outputdir
121
+
122
+
123
+ ### Output progress information if debugging is enabled
124
+ def debug_msg( *msg )
125
+ return unless $DEBUG
126
+ $stderr.puts( *msg )
127
+ end
128
+
129
+
130
+ ### Create the directories the generated docs will live in if
131
+ ### they don't already exist.
132
+ def gen_sub_directories
133
+ @outputdir.mkpath
134
+ end
135
+
136
+
137
+ ### Copy over the stylesheet into the appropriate place in the
138
+ ### output directory.
139
+ def write_style_sheet
140
+ debug_msg "Copying over static files"
141
+ staticfiles = %w[rdoc.css js images]
142
+ staticfiles.each do |path|
143
+ FileUtils.cp_r( @template_dir + path, '.', :verbose => $DEBUG, :noop => $dryrun )
144
+ end
145
+ end
146
+
147
+
148
+
149
+ ### Build the initial indices and output objects
150
+ ### based on an array of TopLevel objects containing
151
+ ### the extracted information.
152
+ def generate( toplevels )
153
+ @outputdir = Pathname.new( @options.op_dir ).expand_path( @basedir )
154
+ if RDoc::Generator::Context.respond_to?( :build_indicies)
155
+ @files, @classes = RDoc::Generator::Context.build_indicies( toplevels, @options )
156
+ else
157
+ @files, @classes = RDoc::Generator::Context.build_indices( toplevels, @options )
158
+ end
159
+
160
+ # Now actually write the output
161
+ generate_xhtml( @options, @files, @classes )
162
+
163
+ rescue StandardError => err
164
+ debug_msg "%s: %s\n %s" % [ err.class.name, err.message, err.backtrace.join("\n ") ]
165
+ raise
166
+ end
167
+
168
+
169
+ ### No-opped
170
+ def load_html_template # :nodoc:
171
+ end
172
+
173
+
174
+ ### Generate output
175
+ def generate_xhtml( options, files, classes )
176
+ files = gen_into( @files )
177
+ classes = gen_into( @classes )
178
+
179
+ # Make a hash of class info keyed by class name
180
+ classes_by_classname = classes.inject({}) {|hash, classinfo|
181
+ hash[ classinfo[:full_name] ] = classinfo
182
+ hash[ classinfo[:full_name] ][:outfile] =
183
+ classinfo[:full_name].gsub( /::/, '/' ) + '.html'
184
+ hash
185
+ }
186
+
187
+ # Make a hash of file info keyed by path
188
+ files_by_path = files.inject({}) {|hash, fileinfo|
189
+ hash[ fileinfo[:full_path] ] = fileinfo
190
+ hash[ fileinfo[:full_path] ][:outfile] = fileinfo[:full_path] + '.html'
191
+ hash
192
+ }
193
+
194
+ self.write_style_sheet
195
+ self.generate_index( options, files_by_path, classes_by_classname )
196
+ self.generate_class_files( options, files_by_path, classes_by_classname )
197
+ self.generate_file_files( options, files_by_path, classes_by_classname )
198
+ end
199
+
200
+
201
+
202
+ #########
203
+ protected
204
+ #########
205
+
206
+ ### Return a list of the documented modules sorted by salience first, then by name.
207
+ def get_sorted_module_list( classes )
208
+ nscounts = classes.keys.inject({}) do |counthash, name|
209
+ toplevel = name.gsub( /::.*/, '' )
210
+ counthash[toplevel] ||= 0
211
+ counthash[toplevel] += 1
212
+
213
+ counthash
214
+ end
215
+
216
+ # Sort based on how often the toplevel namespace occurs, and then on the name
217
+ # of the module -- this works for projects that put their stuff into a
218
+ # namespace, of course, but doesn't hurt if they don't.
219
+ return classes.keys.sort_by do |name|
220
+ toplevel = name.gsub( /::.*/, '' )
221
+ [
222
+ nscounts[ toplevel ] * -1,
223
+ name
224
+ ]
225
+ end
226
+ end
227
+
228
+
229
+ ### Generate an index page which lists all the classes which
230
+ ### are documented.
231
+ def generate_index( options, files, classes )
232
+ debug_msg "Rendering the index page..."
233
+
234
+ templatefile = @template_dir + 'index.rhtml'
235
+ template_src = templatefile.read
236
+ template = ERB.new( template_src, nil, '<>' )
237
+ template.filename = templatefile.to_s
238
+ context = binding()
239
+
240
+ modsort = self.get_sorted_module_list( classes )
241
+ output = nil
242
+ begin
243
+ output = template.result( context )
244
+ rescue NoMethodError => err
245
+ raise "Error while evaluating %s: %s (at %p)" % [
246
+ templatefile,
247
+ err.message,
248
+ eval( "_erbout[-50,50]", context )
249
+ ]
250
+ end
251
+
252
+ outfile = @basedir + @options.op_dir + 'index.html'
253
+ unless $dryrun
254
+ debug_msg "Outputting to %s" % [outfile.expand_path]
255
+ outfile.open( 'w', 0644 ) do |fh|
256
+ fh.print( output )
257
+ end
258
+ else
259
+ debug_msg "Would have output to %s" % [outfile.expand_path]
260
+ end
261
+ end
262
+
263
+
264
+
265
+ ### Generate a documentation file for each class present in the
266
+ ### given hash of +classes+.
267
+ def generate_class_files( options, files, classes )
268
+ debug_msg "Generating class documentation in #@outputdir"
269
+ templatefile = @template_dir + 'classpage.rhtml'
270
+ outputdir = @outputdir
271
+
272
+ modsort = self.get_sorted_module_list( classes )
273
+
274
+ classes.sort_by {|k,v| k }.each do |classname, classinfo|
275
+ debug_msg " working on %s (%s)" % [ classname, classinfo[:outfile] ]
276
+ outfile = outputdir + classinfo[:outfile]
277
+ rel_prefix = outputdir.relative_path_from( outfile.dirname )
278
+ svninfo = self.get_svninfo( classinfo )
279
+
280
+ debug_msg " rendering #{outfile}"
281
+ self.render_template( templatefile, binding(), outfile )
282
+ end
283
+ end
284
+
285
+
286
+ ### Generate a documentation file for each file present in the
287
+ ### given hash of +files+.
288
+ def generate_file_files( options, files, classes )
289
+ debug_msg "Generating file documentation in #@outputdir"
290
+ templatefile = @template_dir + 'filepage.rhtml'
291
+
292
+ modsort = self.get_sorted_module_list( classes )
293
+
294
+ files.sort_by {|k,v| k }.each do |path, fileinfo|
295
+ outfile = @outputdir + fileinfo[:outfile]
296
+ debug_msg " working on %s (%s)" % [ path, outfile ]
297
+ rel_prefix = @outputdir.relative_path_from( outfile.dirname )
298
+ context = binding()
299
+
300
+ debug_msg " rendering #{outfile}"
301
+ self.render_template( templatefile, binding(), outfile )
302
+ end
303
+ end
304
+
305
+
306
+ ### Return a string describing the amount of time in the given number of
307
+ ### seconds in terms a human can understand easily.
308
+ def time_delta_string( seconds )
309
+ return 'less than a minute' if seconds < 1.minute
310
+ return (seconds / 1.minute).to_s + ' minute' + (seconds/60 == 1 ? '' : 's') if seconds < 50.minutes
311
+ return 'about one hour' if seconds < 90.minutes
312
+ return (seconds / 1.hour).to_s + ' hours' if seconds < 18.hours
313
+ return 'one day' if seconds < 1.day
314
+ return 'about one day' if seconds < 2.days
315
+ return (seconds / 1.day).to_s + ' days' if seconds < 1.week
316
+ return 'about one week' if seconds < 2.week
317
+ return (seconds / 1.week).to_s + ' weeks' if seconds < 3.months
318
+ return (seconds / 1.month).to_s + ' months' if seconds < 1.year
319
+ return (seconds / 1.year).to_s + ' years'
320
+ end
321
+
322
+
323
+ # %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $"
324
+ SVNID_PATTERN = /
325
+ \$Id:\s
326
+ (\S+)\s # filename
327
+ (\d+)\s # rev
328
+ (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
329
+ (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ)
330
+ (\w+)\s # committer
331
+ \$$
332
+ /x
333
+
334
+ ### Try to extract Subversion information out of the first constant whose value looks like
335
+ ### a subversion Id tag. If no matching constant is found, and empty hash is returned.
336
+ def get_svninfo( classinfo )
337
+ return {} unless classinfo[:sections]
338
+ constants = classinfo[:sections].first[:constants] or return {}
339
+
340
+ constants.find {|c| c[:value] =~ SVNID_PATTERN } or return {}
341
+
342
+ filename, rev, date, time, committer = $~.captures
343
+ commitdate = Time.parse( date + ' ' + time )
344
+
345
+ return {
346
+ :filename => filename,
347
+ :rev => Integer( rev ),
348
+ :commitdate => commitdate,
349
+ :commitdelta => time_delta_string( Time.now.to_i - commitdate.to_i ),
350
+ :committer => committer,
351
+ }
352
+ end
353
+
354
+
355
+ ### Load and render the erb template in the given +templatefile+ within the specified
356
+ ### +context+ (a Binding object) and write it out to +outfile+. Both +templatefile+ and
357
+ ### +outfile+ should be Pathname-like objects.
358
+ def render_template( templatefile, context, outfile )
359
+ template_src = templatefile.read
360
+ template = ERB.new( template_src, nil, '<>' )
361
+ template.filename = templatefile.to_s
362
+
363
+ output = begin
364
+ template.result( context )
365
+ rescue NoMethodError => err
366
+ raise "Error while evaluating %s: %s (at %p)" % [
367
+ templatefile.to_s,
368
+ err.message,
369
+ eval( "_erbout[-50,50]", context )
370
+ ]
371
+ end
372
+
373
+ unless $dryrun
374
+ outfile.dirname.mkpath
375
+ outfile.open( 'w', 0644 ) do |ofh|
376
+ ofh.print( output )
377
+ end
378
+ else
379
+ debug_msg " would have written %d bytes to %s" %
380
+ [ output.length, outfile ]
381
+ end
382
+ end
383
+
384
+ end # Roc::Generator::Darkfish
385
+
386
+ # :stopdoc:
387
+
388
+ ### Time constants
389
+ module TimeConstantMethods # :nodoc:
390
+
391
+ ### Number of seconds (returns receiver unmodified)
392
+ def seconds
393
+ return self
394
+ end
395
+ alias_method :second, :seconds
396
+
397
+ ### Returns number of seconds in <receiver> minutes
398
+ def minutes
399
+ return self * 60
400
+ end
401
+ alias_method :minute, :minutes
402
+
403
+ ### Returns the number of seconds in <receiver> hours
404
+ def hours
405
+ return self * 60.minutes
406
+ end
407
+ alias_method :hour, :hours
408
+
409
+ ### Returns the number of seconds in <receiver> days
410
+ def days
411
+ return self * 24.hours
412
+ end
413
+ alias_method :day, :days
414
+
415
+ ### Return the number of seconds in <receiver> weeks
416
+ def weeks
417
+ return self * 7.days
418
+ end
419
+ alias_method :week, :weeks
420
+
421
+ ### Returns the number of seconds in <receiver> fortnights
422
+ def fortnights
423
+ return self * 2.weeks
424
+ end
425
+ alias_method :fortnight, :fortnights
426
+
427
+ ### Returns the number of seconds in <receiver> months (approximate)
428
+ def months
429
+ return self * 30.days
430
+ end
431
+ alias_method :month, :months
432
+
433
+ ### Returns the number of seconds in <receiver> years (approximate)
434
+ def years
435
+ return (self * 365.25.days).to_i
436
+ end
437
+ alias_method :year, :years
438
+
439
+
440
+ ### Returns the Time <receiver> number of seconds before the
441
+ ### specified +time+. E.g., 2.hours.before( header.expiration )
442
+ def before( time )
443
+ return time - self
444
+ end
445
+
446
+
447
+ ### Returns the Time <receiver> number of seconds ago. (e.g.,
448
+ ### expiration > 2.hours.ago )
449
+ def ago
450
+ return self.before( ::Time.now )
451
+ end
452
+
453
+
454
+ ### Returns the Time <receiver> number of seconds after the given +time+.
455
+ ### E.g., 10.minutes.after( header.expiration )
456
+ def after( time )
457
+ return time + self
458
+ end
459
+
460
+ # Reads best without arguments: 10.minutes.from_now
461
+ def from_now
462
+ return self.after( ::Time.now )
463
+ end
464
+ end # module TimeConstantMethods
465
+
466
+
467
+ # Extend Numeric with time constants
468
+ class Numeric # :nodoc:
469
+ include TimeConstantMethods
470
+ end
471
+