rdoc 3.6.1 → 3.7

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 (66) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +45 -0
  3. data/Manifest.txt +4 -0
  4. data/lib/rdoc.rb +3 -2
  5. data/lib/rdoc/any_method.rb +12 -7
  6. data/lib/rdoc/attr.rb +16 -1
  7. data/lib/rdoc/class_module.rb +156 -42
  8. data/lib/rdoc/code_object.rb +8 -1
  9. data/lib/rdoc/context.rb +75 -29
  10. data/lib/rdoc/generator/markup.rb +3 -1
  11. data/lib/rdoc/generator/ri.rb +3 -2
  12. data/lib/rdoc/generator/template/darkfish/rdoc.css +4 -0
  13. data/lib/rdoc/known_classes.rb +2 -2
  14. data/lib/rdoc/markup.rb +63 -18
  15. data/lib/rdoc/markup/document.rb +43 -4
  16. data/lib/rdoc/markup/formatter.rb +13 -3
  17. data/lib/rdoc/markup/formatter_test_case.rb +13 -3
  18. data/lib/rdoc/markup/indented_paragraph.rb +33 -0
  19. data/lib/rdoc/markup/inline.rb +8 -1
  20. data/lib/rdoc/markup/parser.rb +1 -0
  21. data/lib/rdoc/markup/pre_process.rb +7 -0
  22. data/lib/rdoc/markup/to_ansi.rb +4 -4
  23. data/lib/rdoc/markup/to_bs.rb +1 -1
  24. data/lib/rdoc/markup/to_html.rb +2 -2
  25. data/lib/rdoc/markup/to_html_crossref.rb +3 -2
  26. data/lib/rdoc/markup/to_rdoc.rb +10 -1
  27. data/lib/rdoc/markup/to_test.rb +1 -1
  28. data/lib/rdoc/markup/to_tt_only.rb +1 -1
  29. data/lib/rdoc/parser.rb +1 -1
  30. data/lib/rdoc/parser/c.rb +69 -26
  31. data/lib/rdoc/parser/ruby.rb +19 -9
  32. data/lib/rdoc/rdoc.rb +14 -3
  33. data/lib/rdoc/ri/driver.rb +137 -103
  34. data/lib/rdoc/ri/store.rb +111 -26
  35. data/lib/rdoc/ruby_lex.rb +1 -1
  36. data/lib/rdoc/rubygems_hook.rb +220 -0
  37. data/lib/rdoc/text.rb +1 -1
  38. data/lib/rdoc/top_level.rb +31 -0
  39. data/test/test_rdoc_any_method.rb +68 -0
  40. data/test/test_rdoc_attr.rb +62 -0
  41. data/test/test_rdoc_class_module.rb +459 -29
  42. data/test/test_rdoc_code_object.rb +17 -0
  43. data/test/test_rdoc_context.rb +70 -0
  44. data/test/test_rdoc_context_section.rb +1 -1
  45. data/test/test_rdoc_generator_ri.rb +14 -3
  46. data/test/test_rdoc_markup.rb +55 -1
  47. data/test/test_rdoc_markup_document.rb +83 -0
  48. data/test/test_rdoc_markup_indented_paragraph.rb +40 -0
  49. data/test/test_rdoc_markup_paragraph.rb +12 -0
  50. data/test/test_rdoc_markup_pre_process.rb +13 -2
  51. data/test/test_rdoc_markup_to_ansi.rb +4 -0
  52. data/test/test_rdoc_markup_to_bs.rb +4 -0
  53. data/test/test_rdoc_markup_to_html.rb +7 -3
  54. data/test/test_rdoc_markup_to_rdoc.rb +14 -0
  55. data/test/test_rdoc_markup_to_tt_only.rb +4 -0
  56. data/test/test_rdoc_parser_c.rb +302 -2
  57. data/test/test_rdoc_parser_ruby.rb +48 -1
  58. data/test/test_rdoc_rdoc.rb +41 -10
  59. data/test/test_rdoc_ri_driver.rb +40 -7
  60. data/test/test_rdoc_ri_store.rb +111 -23
  61. data/test/test_rdoc_rubygems_hook.rb +201 -0
  62. data/test/test_rdoc_stats.rb +12 -12
  63. data/test/test_rdoc_text.rb +17 -0
  64. data/test/test_rdoc_top_level.rb +35 -0
  65. metadata +18 -14
  66. metadata.gz.sig +0 -0
@@ -16,15 +16,25 @@ class RDoc::Markup::Formatter
16
16
  ##
17
17
  # Creates a new Formatter
18
18
 
19
- def initialize
20
- @markup = RDoc::Markup.new
21
- @am = @markup.attribute_manager
19
+ def initialize markup = nil
20
+ @markup = markup || RDoc::Markup.new
21
+ @am = @markup.attribute_manager
22
+
22
23
  @attr_tags = []
23
24
 
24
25
  @in_tt = 0
25
26
  @tt_bit = RDoc::Markup::Attribute.bitmap_for :TT
26
27
  end
27
28
 
29
+ ##
30
+ # Adds +document+ to the output
31
+
32
+ def accept_document document
33
+ document.parts.each do |item|
34
+ item.accept self
35
+ end
36
+ end
37
+
28
38
  ##
29
39
  # Add a new set of tags for an attribute. We allow separate start and end
30
40
  # tags for flexibility
@@ -90,7 +90,7 @@ class RDoc::Markup::FormatterTestCase < MiniTest::Unit::TestCase
90
90
 
91
91
  ##
92
92
  # Calls start_accepting which needs to verify startup state
93
-
93
+
94
94
  def test_start_accepting
95
95
  @to.start_accepting
96
96
 
@@ -100,7 +100,7 @@ class RDoc::Markup::FormatterTestCase < MiniTest::Unit::TestCase
100
100
  ##
101
101
  # Calls end_accepting on your test case which needs to call
102
102
  # <tt>@to.end_accepting</tt> and verify document generation
103
-
103
+
104
104
  def test_end_accepting
105
105
  @to.start_accepting
106
106
  @to.res << 'hi'
@@ -119,6 +119,16 @@ class RDoc::Markup::FormatterTestCase < MiniTest::Unit::TestCase
119
119
  accept_blank_line
120
120
  end
121
121
 
122
+ ##
123
+ # Test case that calls <tt>@to.accept_document</tt>
124
+
125
+ def test_accept_document
126
+ @to.start_accepting
127
+ @to.accept_document @RM::Document.new @RM::Paragraph.new 'hello'
128
+
129
+ accept_document
130
+ end
131
+
122
132
  ##
123
133
  # Calls accept_heading with a level 5 RDoc::Markup::Heading
124
134
 
@@ -196,7 +206,7 @@ class RDoc::Markup::FormatterTestCase < MiniTest::Unit::TestCase
196
206
  @to.start_accepting
197
207
 
198
208
  @to.accept_heading @RM::Heading.new(1, '\\Hello')
199
-
209
+
200
210
  accept_heading_suppressed_crossref
201
211
  end
202
212
 
@@ -0,0 +1,33 @@
1
+ ##
2
+ # An Indented Paragraph of text
3
+
4
+ class RDoc::Markup::IndentedParagraph < RDoc::Markup::Raw
5
+
6
+ ##
7
+ # The indent in number of spaces
8
+
9
+ attr_reader :indent
10
+
11
+ ##
12
+ # Creates a new IndentedParagraph containing +parts+ indented with +indent+
13
+ # spaces
14
+
15
+ def initialize indent, *parts
16
+ @indent = indent
17
+
18
+ super(*parts)
19
+ end
20
+
21
+ def == other # :nodoc:
22
+ super and indent == other.indent
23
+ end
24
+
25
+ ##
26
+ # Calls #accept_indented_paragraph on +visitor+
27
+
28
+ def accept visitor
29
+ visitor.accept_indented_paragraph self
30
+ end
31
+
32
+ end
33
+
@@ -60,7 +60,14 @@ class RDoc::Markup
60
60
 
61
61
  class AttrChanger
62
62
  def to_s # :nodoc:
63
- "Attr: +#{Attribute.as_string turn_on}/-#{Attribute.as_string turn_on}"
63
+ "Attr: +#{Attribute.as_string turn_on}/-#{Attribute.as_string turn_off}"
64
+ end
65
+
66
+ def inspect # :nodoc:
67
+ "+%s/-%s" % [
68
+ Attribute.as_string(turn_on),
69
+ Attribute.as_string(turn_off),
70
+ ]
64
71
  end
65
72
  end
66
73
 
@@ -478,6 +478,7 @@ require 'rdoc/markup/list'
478
478
  require 'rdoc/markup/list_item'
479
479
  require 'rdoc/markup/raw'
480
480
  require 'rdoc/markup/paragraph'
481
+ require 'rdoc/markup/indented_paragraph'
481
482
  require 'rdoc/markup/rule'
482
483
  require 'rdoc/markup/verbatim'
483
484
 
@@ -74,6 +74,13 @@ class RDoc::Markup::PreProcess
74
74
  filename = param.split[0]
75
75
  encoding = if defined?(Encoding) then text.encoding else nil end
76
76
  include_file filename, prefix, encoding
77
+ when 'category' then
78
+ if RDoc::Context === code_object then
79
+ section = code_object.add_section param, ''
80
+ code_object.temporary_section = section
81
+ end
82
+
83
+ '' # ignore category if we're not on an RDoc::Context
77
84
  else
78
85
  result = yield directive, param if block_given?
79
86
 
@@ -8,13 +8,13 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
8
8
  ##
9
9
  # Creates a new ToAnsi visitor that is ready to output vibrant ANSI color!
10
10
 
11
- def initialize
11
+ def initialize markup = nil
12
12
  super
13
13
 
14
14
  @headings.clear
15
- @headings[1] = ["\e[1;32m", "\e[m"]
16
- @headings[2] = ["\e[4;32m", "\e[m"]
17
- @headings[3] = ["\e[32m", "\e[m"]
15
+ @headings[1] = ["\e[1;32m", "\e[m"] # bold
16
+ @headings[2] = ["\e[4;32m", "\e[m"] # underline
17
+ @headings[3] = ["\e[32m", "\e[m"] # just green
18
18
  end
19
19
 
20
20
  ##
@@ -11,7 +11,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
11
11
  ##
12
12
  # Returns a new ToBs that is ready for hot backspace action!
13
13
 
14
- def initialize
14
+ def initialize markup = nil
15
15
  super
16
16
 
17
17
  @in_b = false
@@ -17,7 +17,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
17
17
 
18
18
  LIST_TYPE_TO_HTML = {
19
19
  :BULLET => ['<ul>', '</ul>'],
20
- :LABEL => ['<dl>', '</dl>'],
20
+ :LABEL => ['<dl class="rdoc-list">', '</dl>'],
21
21
  :LALPHA => ['<ol style="display: lower-alpha">', '</ol>'],
22
22
  :NOTE => ['<table class="rdoc-list">', '</table>'],
23
23
  :NUMBER => ['<ol>', '</ol>'],
@@ -62,7 +62,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
62
62
  ##
63
63
  # Creates a new formatter that will output HTML
64
64
 
65
- def initialize
65
+ def initialize markup = nil
66
66
  super
67
67
 
68
68
  @th = nil
@@ -104,9 +104,10 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
104
104
  # references are removed unless +show_hash+ is true. Only method names
105
105
  # preceded by '#' or '::' are hyperlinked, unless +hyperlink_all+ is true.
106
106
 
107
- def initialize(from_path, context, show_hash, hyperlink_all = false)
107
+ def initialize(from_path, context, show_hash, hyperlink_all = false,
108
+ markup = nil)
108
109
  raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
109
- super()
110
+ super markup
110
111
 
111
112
  crossref_re = hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
112
113
 
@@ -44,7 +44,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
44
44
  ##
45
45
  # Creates a new formatter that will output (mostly) \RDoc markup
46
46
 
47
- def initialize
47
+ def initialize markup = nil
48
48
  super
49
49
 
50
50
  @markup.add_special(/\\\S/, :SUPPRESSED_CROSSREF)
@@ -171,6 +171,15 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
171
171
  wrap attributes(paragraph.text)
172
172
  end
173
173
 
174
+ ##
175
+ # Adds +paragraph+ to the output
176
+
177
+ def accept_indented_paragraph paragraph
178
+ @indent += paragraph.indent
179
+ wrap attributes(paragraph.text)
180
+ @indent -= paragraph.indent
181
+ end
182
+
174
183
  ##
175
184
  # Adds +raw+ to the output
176
185
 
@@ -21,7 +21,7 @@ class RDoc::Markup::ToTest < RDoc::Markup::Formatter
21
21
  end
22
22
 
23
23
  def accept_paragraph(paragraph)
24
- @res << paragraph.text
24
+ @res << convert_flow(@am.flow(paragraph.text))
25
25
  end
26
26
 
27
27
  def accept_raw raw
@@ -20,7 +20,7 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
20
20
  ##
21
21
  # Creates a new tt-only formatter.
22
22
 
23
- def initialize
23
+ def initialize markup = nil
24
24
  super
25
25
 
26
26
  add_tag :TT, nil, nil
@@ -185,7 +185,7 @@ class RDoc::Parser
185
185
  end
186
186
 
187
187
  ##
188
- # Creates a new Parser storing +top_level+, +file_name+, +content+,
188
+ # Creates a new Parser storing +top_level+, +file_name+, +content+,
189
189
  # +options+ and +stats+ in instance variables.
190
190
  #
191
191
  # Usually invoked by +super+
@@ -1,4 +1,4 @@
1
- require 'rdoc/parser'
1
+
2
2
  require 'rdoc/parser/ruby'
3
3
  require 'rdoc/known_classes'
4
4
 
@@ -64,8 +64,17 @@ require 'rdoc/known_classes'
64
64
  # [Document-variable: +name+]
65
65
  # Documentation for the named +rb_define_variable+
66
66
  #
67
- # [Document-method: +name+]
68
- # Documentation for the named method.
67
+ # [Document-method: +method_name+]
68
+ # Documentation for the named method. Use this when the method name is
69
+ # unambiguous.
70
+ #
71
+ # [Document-method: <tt>ClassName::method_name<tt>]
72
+ # Documentation for a singleton method in the given class. Use this when
73
+ # the method name alone is ambiguous.
74
+ #
75
+ # [Document-method: <tt>ClassName#method_name<tt>]
76
+ # Documentation for a instance method in the given class. Use this when the
77
+ # method name alone is ambiguous.
69
78
  #
70
79
  # [Document-attr: +name+]
71
80
  # Documentation for the named attribute.
@@ -113,6 +122,17 @@ class RDoc::Parser::C < RDoc::Parser
113
122
 
114
123
  attr_accessor :content
115
124
 
125
+
126
+ ##
127
+ # Maps C variable names to names of ruby classes (andsingleton classes)
128
+
129
+ attr_reader :known_classes
130
+
131
+ ##
132
+ # Maps C variable names to names of ruby singleton classes
133
+
134
+ attr_reader :singleton_classes
135
+
116
136
  ##
117
137
  # Resets cross-file state. Call when parsing different projects that need
118
138
  # separate documentation.
@@ -132,8 +152,8 @@ class RDoc::Parser::C < RDoc::Parser
132
152
 
133
153
  @known_classes = RDoc::KNOWN_CLASSES.dup
134
154
  @content = handle_tab_width handle_ifdefs_in(@content)
135
- @classes = Hash.new
136
- @singleton_classes = Hash.new
155
+ @classes = {}
156
+ @singleton_classes = {}
137
157
  @file_dir = File.dirname(@file_name)
138
158
  end
139
159
 
@@ -146,17 +166,25 @@ class RDoc::Parser::C < RDoc::Parser
146
166
  \s*"(.+?)",
147
167
  \s*"(.+?)"
148
168
  \s*\)/xm) do |var_name, new_name, old_name|
149
- class_name = @known_classes[var_name] || var_name
150
- class_obj = find_class var_name, class_name
169
+ class_name = @known_classes[var_name]
170
+
171
+ unless class_name then
172
+ warn "Enclosing class/module %p for alias %s %s not known" % [
173
+ var_name, new_name, old_name]
174
+ next
175
+ end
176
+
177
+ class_obj = find_class var_name, class_name
151
178
 
152
179
  al = RDoc::Alias.new '', old_name, new_name, ''
153
- al.singleton = @singleton_classes.key?(var_name)
180
+ al.singleton = @singleton_classes.key? var_name
154
181
 
155
182
  comment = find_alias_comment var_name, new_name, old_name
156
183
  comment = strip_stars comment
157
184
  al.comment = comment
158
185
 
159
186
  al.record_location @top_level
187
+
160
188
  class_obj.add_alias al
161
189
  @stats.add_alias al
162
190
  end
@@ -262,6 +290,18 @@ class RDoc::Parser::C < RDoc::Parser
262
290
  var_name = "rb_cObject" if !var_name or var_name == "rb_mKernel"
263
291
  handle_constants type, var_name, const_name, definition
264
292
  end
293
+
294
+ @content.scan(%r%
295
+ \Wrb_curses_define_const
296
+ \s*\(
297
+ \s*
298
+ (\w+)
299
+ \s*
300
+ \)
301
+ \s*;%xm) do |consts|
302
+ const = consts.first
303
+ handle_constants 'const', 'mCurses', const, "UINT2NUM(#{const})"
304
+ end
265
305
  end
266
306
 
267
307
  ##
@@ -271,7 +311,8 @@ class RDoc::Parser::C < RDoc::Parser
271
311
  @content.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
272
312
  if cls = @classes[c]
273
313
  m = @known_classes[m] || m
274
- cls.add_include RDoc::Include.new(m, "")
314
+ incl = cls.add_include RDoc::Include.new(m, "")
315
+ incl.record_location @top_level
275
316
  end
276
317
  end
277
318
  end
@@ -293,7 +334,7 @@ class RDoc::Parser::C < RDoc::Parser
293
334
  \s*"([^"]+)",
294
335
  \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
295
336
  \s*(-?\w+)\s*\)
296
- (?:;\s*/[*/]\s+in\s+(\w+?\.[cy]))?
337
+ (?:;\s*/[*/]\s+in\s+(\w+?\.(?:cpp|c|y)))?
297
338
  %xm) do |type, var_name, meth_name, function, param_count, source_file|
298
339
 
299
340
  # Ignore top-object and weird struct.c dynamic stuff
@@ -401,7 +442,7 @@ class RDoc::Parser::C < RDoc::Parser
401
442
  # distinct (for example Kernel.hash and Kernel.object_id share the same
402
443
  # implementation
403
444
 
404
- override_comment = find_override_comment class_name, meth_obj.name
445
+ override_comment = find_override_comment class_name, meth_obj
405
446
  comment = override_comment if override_comment
406
447
 
407
448
  find_modifiers comment, meth_obj if comment
@@ -444,7 +485,7 @@ class RDoc::Parser::C < RDoc::Parser
444
485
  warn "No definition for #{meth_name}" if @options.verbosity > 1
445
486
  false
446
487
  else # No body, but might still have an override comment
447
- comment = find_override_comment class_name, meth_obj.name
488
+ comment = find_override_comment class_name, meth_obj
448
489
 
449
490
  if comment then
450
491
  find_modifiers comment, meth_obj
@@ -524,21 +565,26 @@ class RDoc::Parser::C < RDoc::Parser
524
565
 
525
566
  comment = look_for_directives_in class_mod, comment
526
567
 
527
- class_mod.comment = comment
568
+ class_mod.add_comment comment, @top_level
528
569
  end
529
570
 
530
571
  ##
531
572
  # Finds a comment matching +type+ and +const_name+ either above the
532
573
  # comment or in the matching Document- section.
533
574
 
534
- def find_const_comment(type, const_name)
575
+ def find_const_comment(type, const_name, class_name = nil)
535
576
  if @content =~ %r%((?>^\s*/\*.*?\*/\s+))
536
577
  rb_define_#{type}\((?:\s*(\w+),)?\s*
537
578
  "#{const_name}"\s*,
538
579
  .*?\)\s*;%xmi then
539
580
  $1
581
+ elsif class_name and
582
+ @content =~ %r%Document-(?:const|global|variable):\s
583
+ #{class_name}::#{const_name}
584
+ \s*?\n((?>.*?\*/))%xm then
585
+ $1
540
586
  elsif @content =~ %r%Document-(?:const|global|variable):\s#{const_name}
541
- \s*?\n((?>.*?\*/))%xm
587
+ \s*?\n((?>.*?\*/))%xm then
542
588
  $1
543
589
  else
544
590
  ''
@@ -607,12 +653,13 @@ class RDoc::Parser::C < RDoc::Parser
607
653
  end
608
654
 
609
655
  ##
610
- # Finds a <tt>Document-method</tt> override for +meth_name+ in +class_name+
656
+ # Finds a <tt>Document-method</tt> override for +meth_obj+ on +class_name+
611
657
 
612
- def find_override_comment(class_name, meth_name)
613
- name = Regexp.escape(meth_name)
658
+ def find_override_comment class_name, meth_obj
659
+ name = Regexp.escape meth_obj.name
660
+ prefix = Regexp.escape meth_obj.name_prefix
614
661
 
615
- if @content =~ %r%Document-method:\s+#{class_name}(?:\.|::|#)#{name}\s*?\n((?>.*?\*/))%m then
662
+ if @content =~ %r%Document-method:\s+#{class_name}#{prefix}#{name}\s*?\n((?>.*?\*/))%m then
616
663
  $1
617
664
  elsif @content =~ %r%Document-method:\s#{name}\s*?\n((?>.*?\*/))%m then
618
665
  $1
@@ -726,7 +773,7 @@ class RDoc::Parser::C < RDoc::Parser
726
773
  return
727
774
  end
728
775
 
729
- comment = find_const_comment type, const_name
776
+ comment = find_const_comment type, const_name, class_name
730
777
  comment = strip_stars comment
731
778
  comment = normalize_comment comment
732
779
 
@@ -781,13 +828,8 @@ class RDoc::Parser::C < RDoc::Parser
781
828
 
782
829
  def handle_method(type, var_name, meth_name, function, param_count,
783
830
  source_file = nil)
784
- singleton = false
785
831
  class_name = @known_classes[var_name]
786
-
787
- unless class_name then
788
- class_name = @singleton_classes[var_name]
789
- singleton = true if class_name
790
- end
832
+ singleton = @singleton_classes.key? var_name
791
833
 
792
834
  return unless class_name
793
835
 
@@ -845,6 +887,7 @@ class RDoc::Parser::C < RDoc::Parser
845
887
  def handle_singleton sclass_var, class_var
846
888
  class_name = @known_classes[class_var]
847
889
 
890
+ @known_classes[sclass_var] = class_name
848
891
  @singleton_classes[sclass_var] = class_name
849
892
  end
850
893