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
@@ -1,6 +1,12 @@
1
+ require 'abbrev'
1
2
  require 'optparse'
2
3
  require 'yaml'
3
4
 
5
+ begin
6
+ require 'readline'
7
+ rescue LoadError
8
+ end
9
+
4
10
  require 'rdoc/ri'
5
11
  require 'rdoc/ri/paths'
6
12
  require 'rdoc/ri/formatter'
@@ -11,29 +17,29 @@ require 'rdoc/markup/to_flow'
11
17
 
12
18
  class RDoc::RI::Driver
13
19
 
14
- #
15
- # This class offers both Hash and OpenStruct functionality.
16
- # We convert from the Core Hash to this before calling any of
17
- # the display methods, in order to give the display methods
18
- # a cleaner API for accessing the data.
19
- #
20
+ ##
21
+ # This class offers both Hash and OpenStruct functionality. We convert from
22
+ # the Core Hash to this before calling any of the display methods, in order
23
+ # to give the display methods a cleaner API for accessing the data.
24
+
20
25
  class OpenStructHash < Hash
21
- #
26
+
27
+ ##
22
28
  # This method converts from a Hash to an OpenStructHash.
23
- #
29
+
24
30
  def self.convert(object)
25
31
  case object
26
32
  when Hash then
27
33
  new_hash = new # Convert Hash -> OpenStructHash
28
34
 
29
35
  object.each do |key, value|
30
- new_hash[key] = convert(value)
36
+ new_hash[key] = convert value
31
37
  end
32
38
 
33
39
  new_hash
34
40
  when Array then
35
41
  object.map do |element|
36
- convert(element)
42
+ convert element
37
43
  end
38
44
  else
39
45
  object
@@ -77,6 +83,9 @@ class RDoc::RI::Driver
77
83
 
78
84
  attr_accessor :homepath # :nodoc:
79
85
 
86
+ ##
87
+ # Default options for ri
88
+
80
89
  def self.default_options
81
90
  options = {}
82
91
  options[:use_stdout] = !$stdout.tty?
@@ -95,6 +104,9 @@ class RDoc::RI::Driver
95
104
  return options
96
105
  end
97
106
 
107
+ ##
108
+ # Parses +argv+ and returns a Hash of options
109
+
98
110
  def self.process_args(argv)
99
111
  options = default_options
100
112
 
@@ -294,6 +306,9 @@ Options may also be set in the 'RI' environment variable.
294
306
  exit 1
295
307
  end
296
308
 
309
+ ##
310
+ # Runs the ri command line executable using +argv+
311
+
297
312
  def self.run(argv = ARGV)
298
313
  options = process_args argv
299
314
  ri = new options
@@ -329,6 +344,9 @@ Options may also be set in the 'RI' environment variable.
329
344
  options[:use_stdout])
330
345
  end
331
346
 
347
+ ##
348
+ # Cache of classes ri knows about
349
+
332
350
  def class_cache
333
351
  return @class_cache if @class_cache
334
352
 
@@ -374,6 +392,9 @@ Options may also be set in the 'RI' environment variable.
374
392
  @class_cache
375
393
  end
376
394
 
395
+ ##
396
+ # Creates the class cache if it is empty
397
+
377
398
  def create_class_cache
378
399
  class_cache = OpenStructHash.new
379
400
 
@@ -387,7 +408,7 @@ Options may also be set in the 'RI' environment variable.
387
408
  end
388
409
 
389
410
  classes = map_dirs('**/cdesc*.yaml') { |f| Dir[f] }
390
- warn "Updating class cache with #{classes.size} classes..."
411
+ warn "Updating ri class cache with #{classes.size} classes..."
391
412
  populate_class_cache class_cache, classes
392
413
 
393
414
  write_cache class_cache, class_cache_file_path
@@ -395,6 +416,10 @@ Options may also be set in the 'RI' environment variable.
395
416
  class_cache
396
417
  end
397
418
 
419
+ ##
420
+ # Populates +class_cache+ with +classes+, adding +extension+ data for found
421
+ # methods when asked
422
+
398
423
  def populate_class_cache(class_cache, classes, extension = false)
399
424
  classes.each do |cdesc|
400
425
  desc = read_yaml cdesc
@@ -420,32 +445,187 @@ Options may also be set in the 'RI' environment variable.
420
445
  end
421
446
  end
422
447
 
448
+ ##
449
+ # Path to the class_cache
450
+
423
451
  def class_cache_file_path
424
452
  File.join cache_file_path, @class_cache_name
425
453
  end
426
454
 
455
+ ##
456
+ # Path to the cache file for +klassname+
457
+
427
458
  def cache_file_for(klassname)
428
459
  File.join cache_file_path, klassname.gsub(/:+/, "-")
429
460
  end
430
461
 
462
+ ##
463
+ # Directory where cache files live
464
+
431
465
  def cache_file_path
432
466
  File.join @homepath, 'cache'
433
467
  end
434
468
 
469
+ ##
470
+ # Displays the module, class or method +name+. For methods, locates the
471
+ # method in the ancestors list if it isn't in the named module.
472
+
473
+ def display_name(name)
474
+ if class_cache.key? name then
475
+ method_map = display_class name
476
+ elsif name =~ /::|\#|\./ then
477
+ method = nil
478
+ klass, = parse_name name
479
+
480
+ klass = expand_klass klass unless class_cache.key? klass
481
+
482
+ orig_klass = klass
483
+ orig_name = name
484
+
485
+ loop do
486
+ method = lookup_method name, klass
487
+
488
+ break if method
489
+
490
+ ancestor = lookup_ancestor klass, orig_klass
491
+
492
+ break unless ancestor
493
+
494
+ name = name.sub klass, ancestor
495
+ klass = ancestor
496
+ end
497
+
498
+ raise NotFoundError, orig_name unless method
499
+
500
+ display_method method
501
+ else
502
+ methods = select_methods(/#{name}/)
503
+
504
+ if methods.size == 0
505
+ raise NotFoundError, name
506
+ elsif methods.size == 1
507
+ display_method methods[0]
508
+ else
509
+ @display.display_method_list methods
510
+ end
511
+ end
512
+ end
513
+
514
+ ##
515
+ # Displays info for class or module +name+
516
+
435
517
  def display_class(name)
436
518
  klass = class_cache[name]
437
519
  @display.display_class_info klass
438
520
  end
439
521
 
522
+ ##
523
+ # Displays info for method +method+
524
+
440
525
  def display_method(method)
441
526
  @display.display_method_info method
442
527
  end
443
528
 
444
- def get_info_for(arg)
445
- @names = [arg]
446
- run
529
+ ##
530
+ # Runs ri interactively using Readline if it is available.
531
+
532
+ def interactive
533
+ formatter = @display.formatter
534
+
535
+ if defined? Readline then
536
+ # prepare abbreviations for tab completion
537
+ klasses = class_cache.keys
538
+
539
+ Readline.completion_proc = proc do |name|
540
+ case name
541
+ when /(#|\.|::)([^A-Z]|$)/ then
542
+ methods = []
543
+ method_type = $1 == '.' ? '#|::' : $1
544
+
545
+ klass, method = if $2.empty? then
546
+ [$`, '']
547
+ else
548
+ parse_name name
549
+ end
550
+
551
+ cache = load_cache_for klass
552
+
553
+ methods += cache.keys.select do |name|
554
+ name =~ /^#{klass}#{method_type}#{method}/
555
+ end
556
+
557
+ # TODO ancestor lookup
558
+
559
+ if method_type == '::' and method.empty? then
560
+ methods += klasses.grep(/^#{klass}::/)
561
+ end
562
+
563
+ methods
564
+ when /^[A-Z]\w*/ then
565
+ klasses.grep(/^#{name}/)
566
+ else
567
+ []
568
+ end
569
+ end
570
+ end
571
+
572
+ formatter.raw_print_line "\nEnter the method name you want to look up.\n"
573
+
574
+ if defined? Readline then
575
+ formatter.raw_print_line "You can use tab to autocomplete.\n"
576
+ end
577
+
578
+ formatter.raw_print_line "Enter a blank line to exit.\n\n"
579
+
580
+ loop do
581
+ name = if defined? Readline then
582
+ Readline.readline ">> "
583
+ else
584
+ formatter.raw_print_line ">> "
585
+ $stdin.gets
586
+ end
587
+
588
+ return if name.nil? or name.empty?
589
+
590
+ name = name.strip
591
+
592
+ begin
593
+ display_name name
594
+ rescue NotFoundError => e
595
+ formatter.raw_print_line "#{e.message}\n"
596
+ end
597
+ end
598
+
599
+ rescue Interrupt
600
+ exit
601
+ end
602
+
603
+ ##
604
+ # Expands abbreviated klass +klass+ into a fully-qualified klass. "Zl::Da"
605
+ # will be expanded to Zlib::DataError.
606
+
607
+ def expand_klass(klass)
608
+ klass.split('::').inject '' do |expanded, klass_part|
609
+ expanded << '::' unless expanded.empty?
610
+ expanded << klass_part
611
+
612
+ subset = class_cache.keys.select do |klass|
613
+ klass =~ /^#{expanded}[^:]*$/
614
+ end
615
+
616
+ abbrevs = Abbrev.abbrev subset
617
+
618
+ expanded = abbrevs[expanded].dup
619
+
620
+ raise NotFoundError, expanded unless expanded
621
+
622
+ expanded
623
+ end
447
624
  end
448
625
 
626
+ ##
627
+ # Loads the cache for +klassname+
628
+
449
629
  def load_cache_for(klassname)
450
630
  path = cache_file_for klassname
451
631
 
@@ -472,6 +652,9 @@ Options may also be set in the 'RI' environment variable.
472
652
  cache
473
653
  end
474
654
 
655
+ ##
656
+ # Writes a cache file for +klassname+ to +path+
657
+
475
658
  def create_cache_for(klassname, path)
476
659
  klass = class_cache[klassname]
477
660
  return nil unless klass
@@ -490,13 +673,17 @@ Options may also be set in the 'RI' environment variable.
490
673
  if system_file then
491
674
  method["source_path"] = "Ruby #{RDoc::RI::Paths::VERSION}"
492
675
  else
493
- if(f =~ %r%gems/[\d.]+/doc/([^/]+)%) then
494
- ext_path = "gem #{$1}"
495
- else
496
- ext_path = f
676
+ gem = Gem.path.any? do |path|
677
+ pattern = File.join Regexp.escape(path), 'doc', '(.*?)', ''
678
+
679
+ f =~ /^#{pattern}/
497
680
  end
498
681
 
499
- method["source_path"] = ext_path
682
+ method["source_path"] = if gem then
683
+ "gem #{$1}"
684
+ else
685
+ f
686
+ end
500
687
  end
501
688
 
502
689
  name = method["full_name"]
@@ -511,12 +698,11 @@ Options may also be set in the 'RI' environment variable.
511
698
  # Finds the next ancestor of +orig_klass+ after +klass+.
512
699
 
513
700
  def lookup_ancestor(klass, orig_klass)
514
- # This is a bit hacky, but ri will go into an infinite
515
- # loop otherwise, since Object has an Object ancestor
516
- # for some reason. Depending on the documentation state, I've seen
517
- # Kernel as an ancestor of Object and not as an ancestor of Object.
518
- if ((orig_klass == "Object") &&
519
- ((klass == "Kernel") || (klass == "Object")))
701
+ # This is a bit hacky, but ri will go into an infinite loop otherwise,
702
+ # since Object has an Object ancestor for some reason. Depending on the
703
+ # documentation state, I've seen Kernel as an ancestor of Object and not
704
+ # as an ancestor of Object.
705
+ if orig_klass == "Object" && (klass == "Kernel" || klass == "Object") then
520
706
  return nil
521
707
  end
522
708
 
@@ -527,8 +713,8 @@ Options may also be set in the 'RI' environment variable.
527
713
  ancestors = [orig_klass]
528
714
  ancestors.push(*cache.includes.map { |inc| inc['name'] })
529
715
  ancestors << cache.superclass
530
-
531
- ancestor_index = ancestors.index(klass)
716
+
717
+ ancestor_index = ancestors.index klass
532
718
 
533
719
  if ancestor_index
534
720
  ancestor = ancestors[ancestors.index(klass) + 1]
@@ -570,6 +756,10 @@ Options may also be set in the 'RI' environment variable.
570
756
  [klass, meth]
571
757
  end
572
758
 
759
+ ##
760
+ # Reads ri YAML data from +path+, converting RDoc 1.x classes to RDoc 2.x
761
+ # classes
762
+
573
763
  def read_yaml(path)
574
764
  data = File.read path
575
765
 
@@ -578,69 +768,32 @@ Options may also be set in the 'RI' environment variable.
578
768
  data = data.gsub(/ \!ruby\/(object|struct):(RDoc::RI|RI).*/, '')
579
769
  data = data.gsub(/ \!ruby\/(object|struct):SM::(\S+)/,
580
770
  ' !ruby/\1:RDoc::Markup::\2')
581
- OpenStructHash.convert(YAML.load(data))
771
+
772
+ OpenStructHash.convert YAML.load(data)
582
773
  end
583
774
 
775
+ ##
776
+ # Looks up and displays ri data according to the options given.
777
+
584
778
  def run
585
- if(@list_doc_dirs)
586
- puts @doc_dirs.join("\n")
779
+ if @list_doc_dirs then
780
+ puts @doc_dirs
781
+ elsif @interactive then
782
+ interactive
587
783
  elsif @names.empty? then
588
784
  @display.list_known_classes class_cache.keys.sort
589
785
  else
590
786
  @names.each do |name|
591
- if class_cache.key? name then
592
- method_map = display_class name
593
- if(@interactive)
594
- method_name = @display.get_class_method_choice(method_map)
595
-
596
- if(method_name != nil)
597
- method = lookup_method "#{name}#{method_name}", name
598
- display_method method
599
- end
600
- end
601
- elsif name =~ /::|\#|\./ then
602
- klass, = parse_name name
603
-
604
- orig_klass = klass
605
- orig_name = name
606
-
607
- loop do
608
- method = lookup_method name, klass
609
-
610
- break method if method
611
-
612
- ancestor = lookup_ancestor klass, orig_klass
613
-
614
- break unless ancestor
615
-
616
- name = name.sub klass, ancestor
617
- klass = ancestor
618
- end
619
-
620
- raise NotFoundError, orig_name unless method
621
-
622
- display_method method
623
- else
624
- methods = select_methods(/#{name}/)
625
-
626
- if methods.size == 0
627
- raise NotFoundError, name
628
- elsif methods.size == 1
629
- display_method methods[0]
630
- else
631
- if(@interactive)
632
- @display.display_method_list_choice methods
633
- else
634
- @display.display_method_list methods
635
- end
636
- end
637
- end
787
+ display_name name
638
788
  end
639
789
  end
640
790
  rescue NotFoundError => e
641
791
  abort e.message
642
792
  end
643
793
 
794
+ ##
795
+ # Selects methods matching +pattern+ from all modules
796
+
644
797
  def select_methods(pattern)
645
798
  methods = []
646
799
  class_cache.keys.sort.each do |klass|
@@ -656,14 +809,20 @@ Options may also be set in the 'RI' environment variable.
656
809
  methods
657
810
  end
658
811
 
812
+ ##
813
+ # Writes +cache+ to +path+
814
+
659
815
  def write_cache(cache, path)
660
- if(@use_cache)
816
+ if @use_cache then
661
817
  File.open path, "wb" do |cache_file|
662
818
  Marshal.dump cache, cache_file
663
819
  end
664
820
  end
665
821
 
822
+ cache
823
+ rescue Errno::EISDIR # HACK toplevel, replace with main
666
824
  cache
667
825
  end
668
826
 
669
827
  end
828
+