rdoc 3.8 → 3.9

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.

@@ -106,6 +106,8 @@ class RDoc::Parser
106
106
  # Applies +directive+'s +value+ to +code_object+, if appropriate
107
107
 
108
108
  def self.process_directive code_object, directive, value
109
+ warn "RDoc::Parser::process_directive is deprecated and wil be removed in RDoc 4. Use RDoc::Markup::PreProcess#handle_directive instead" if $-w
110
+
109
111
  case directive
110
112
  when 'nodoc' then
111
113
  code_object.document_self = nil # notify nodoc
@@ -196,6 +198,9 @@ class RDoc::Parser
196
198
  @content = content
197
199
  @options = options
198
200
  @stats = stats
201
+
202
+ @preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
203
+ @preprocess.options = @options
199
204
  end
200
205
 
201
206
  end
@@ -645,9 +645,7 @@ class RDoc::Parser::C < RDoc::Parser
645
645
  meth_obj.call_seq = $1.strip
646
646
  end
647
647
 
648
- if comment.sub!(/\s*:(nodoc|doc|yields?|args?):\s*(.*)/, '') then
649
- RDoc::Parser.process_directive meth_obj, $1, $2
650
- end
648
+ look_for_directives_in meth_obj, comment
651
649
  end
652
650
 
653
651
  ##
@@ -913,12 +911,10 @@ class RDoc::Parser::C < RDoc::Parser
913
911
  # * :title: My Awesome Project
914
912
  # */
915
913
  #
916
- # This routine modifies its parameter
917
-
918
- def look_for_directives_in(context, comment)
919
- preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
914
+ # This method modifies the +comment+
920
915
 
921
- preprocess.handle comment, context do |directive, param|
916
+ def look_for_directives_in context, comment
917
+ @preprocess.handle comment, context do |directive, param|
922
918
  case directive
923
919
  when 'main' then
924
920
  @options.main_page = param
@@ -405,17 +405,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
405
405
  #
406
406
  # This routine modifies its +comment+ parameter.
407
407
 
408
- def look_for_directives_in(context, comment)
409
- preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
410
-
411
- preprocess.handle comment, context do |directive, param|
408
+ def look_for_directives_in context, comment
409
+ @preprocess.handle comment, context do |directive, param|
412
410
  case directive
413
- when 'enddoc' then
414
- context.done_documenting = true
415
- ''
416
- when 'main' then
417
- @options.main_page = param if @options.respond_to? :main_page
418
- ''
419
411
  when 'method', 'singleton-method',
420
412
  'attr', 'attr_accessor', 'attr_reader', 'attr_writer' then
421
413
  false # handled elsewhere
@@ -423,16 +415,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
423
415
  context.set_current_section param, comment
424
416
  comment.replace ''
425
417
  break
426
- when 'startdoc' then
427
- context.start_doc
428
- context.force_documentation = true
429
- ''
430
- when 'stopdoc' then
431
- context.stop_doc
432
- ''
433
- when 'title' then
434
- @options.default_title = param if @options.respond_to? :default_title=
435
- ''
436
418
  end
437
419
  end
438
420
 
@@ -629,6 +611,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
629
611
 
630
612
  cls_type = single == SINGLE ? RDoc::SingleClass : RDoc::NormalClass
631
613
  cls = declaration_context.add_class cls_type, given_name, superclass
614
+ cls.ignore unless container.document_children
632
615
 
633
616
  read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
634
617
  cls.record_location @top_level
@@ -679,7 +662,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
679
662
  ##
680
663
  # Parses a constant in +context+ with +comment+
681
664
 
682
- def parse_constant(container, tk, comment)
665
+ def parse_constant container, tk, comment
683
666
  offset = tk.seek
684
667
  line_no = tk.line_no
685
668
 
@@ -718,7 +701,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
718
701
  when TkRPAREN, TkRBRACE, TkRBRACK, TkEND then
719
702
  nest -= 1
720
703
  when TkCOMMENT then
721
- if nest <= 0 && @scanner.lex_state == EXPR_END
704
+ if nest <= 0 &&
705
+ (@scanner.lex_state == EXPR_END || !@scanner.continue) then
722
706
  unget_tk tk
723
707
  break
724
708
  end
@@ -733,7 +717,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
733
717
  end
734
718
 
735
719
  container.add_module_alias mod, name, @top_level if mod
736
- get_tk # TkNL
737
720
  break
738
721
  end
739
722
  when TkNL then
@@ -1327,11 +1310,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1327
1310
  keep_comment = true
1328
1311
 
1329
1312
  when TkCLASS then
1330
- if container.document_children then
1331
- parse_class container, single, tk, comment
1332
- else
1333
- nest += 1
1334
- end
1313
+ parse_class container, single, tk, comment
1335
1314
 
1336
1315
  when TkMODULE then
1337
1316
  if container.document_children then
@@ -1516,11 +1495,13 @@ class RDoc::Parser::Ruby < RDoc::Parser
1516
1495
  ##
1517
1496
  # Parses statements in the top-level +container+
1518
1497
 
1519
- def parse_top_level_statements(container)
1498
+ def parse_top_level_statements container
1520
1499
  comment = collect_first_comment
1521
- look_for_directives_in(container, comment)
1500
+ look_for_directives_in container, comment
1501
+
1522
1502
  # HACK move if to RDoc::Context#comment=
1523
1503
  container.comment = comment if container.document_self unless comment.empty?
1504
+
1524
1505
  parse_statements container, NORMAL, nil, comment
1525
1506
  end
1526
1507
 
@@ -1643,16 +1624,17 @@ class RDoc::Parser::Ruby < RDoc::Parser
1643
1624
  # Handles the directive for +context+ if the directive is listed in +allow+.
1644
1625
  # This method is called for directives following a definition.
1645
1626
 
1646
- def read_documentation_modifiers(context, allow)
1627
+ def read_documentation_modifiers context, allow
1647
1628
  directive, value = read_directive allow
1648
1629
 
1649
1630
  return unless directive
1650
1631
 
1651
- case directive
1652
- when 'notnew', 'not_new', 'not-new' then
1653
- context.dont_rename_initialize = true
1654
- else
1655
- RDoc::Parser.process_directive context, directive, value
1632
+ @preprocess.handle_directive '', directive, value, context do |dir, param|
1633
+ if %w[notnew not_new not-new].include? dir then
1634
+ context.dont_rename_initialize = true
1635
+
1636
+ true
1637
+ end
1656
1638
  end
1657
1639
  end
1658
1640
 
@@ -153,6 +153,8 @@ module RDoc::Parser::RubyTools
153
153
  @token_listeners.each do |obj|
154
154
  obj.pop_token
155
155
  end if @token_listeners
156
+
157
+ nil
156
158
  end
157
159
 
158
160
  end
@@ -387,6 +387,8 @@ Options may also be set in the 'RI' environment variable.
387
387
  klass.superclass unless klass.module?
388
388
  end.compact.shift || 'Object'
389
389
 
390
+ superclass = superclass.full_name unless String === superclass
391
+
390
392
  "#{name} < #{superclass}"
391
393
  end
392
394
 
@@ -451,7 +453,7 @@ Options may also be set in the 'RI' environment variable.
451
453
  # Adds a list of +methods+ to +out+ with a heading of +name+
452
454
 
453
455
  def add_method_list out, methods, name
454
- return unless methods
456
+ return if methods.empty?
455
457
 
456
458
  out << RDoc::Markup::Heading.new(1, "#{name}:")
457
459
  out << RDoc::Markup::BlankLine.new
@@ -518,11 +520,13 @@ Options may also be set in the 'RI' environment variable.
518
520
 
519
521
  found.each do |store, klass|
520
522
  comment = klass.comment
521
- class_methods = store.class_methods[klass.full_name]
522
- instance_methods = store.instance_methods[klass.full_name]
523
- attributes = store.attributes[klass.full_name]
523
+ # TODO the store's cache should always return an empty Array
524
+ class_methods = store.class_methods[klass.full_name] || []
525
+ instance_methods = store.instance_methods[klass.full_name] || []
526
+ attributes = store.attributes[klass.full_name] || []
524
527
 
525
- if comment.empty? and !(instance_methods or class_methods) then
528
+ if comment.empty? and
529
+ instance_methods.empty? and class_methods.empty? then
526
530
  also_in << store
527
531
  next
528
532
  end
@@ -531,7 +535,17 @@ Options may also be set in the 'RI' environment variable.
531
535
 
532
536
  unless comment.empty? then
533
537
  out << RDoc::Markup::Rule.new(1)
534
- out << comment
538
+
539
+ if comment.merged? then
540
+ parts = comment.parts
541
+ parts = parts.zip [RDoc::Markup::BlankLine.new] * parts.length
542
+ parts.flatten!
543
+ parts.pop
544
+
545
+ out.push(*parts)
546
+ else
547
+ out << comment
548
+ end
535
549
  end
536
550
 
537
551
  if class_methods or instance_methods or not klass.constants.empty? then
@@ -554,13 +568,12 @@ Options may also be set in the 'RI' environment variable.
554
568
  end)
555
569
 
556
570
  out << list
571
+ out << RDoc::Markup::BlankLine.new
557
572
  end
558
573
 
559
574
  add_method_list out, class_methods, 'Class methods'
560
575
  add_method_list out, instance_methods, 'Instance methods'
561
576
  add_method_list out, attributes, 'Attributes'
562
-
563
- out << RDoc::Markup::BlankLine.new
564
577
  end
565
578
 
566
579
  add_also_in out, also_in
@@ -1090,11 +1103,11 @@ Options may also be set in the 'RI' environment variable.
1090
1103
  # NOTE: Given Foo::Bar, Bar is considered a class even though it may be a
1091
1104
  # method
1092
1105
 
1093
- def parse_name(name)
1106
+ def parse_name name
1094
1107
  parts = name.split(/(::|#|\.)/)
1095
1108
 
1096
1109
  if parts.length == 1 then
1097
- if parts.first =~ /^[a-z]/ then
1110
+ if parts.first =~ /^[a-z]|^([%&*+\/<>^`|~-]|\+@|-@|<<|<=>?|===?|=>|=~|>>|\[\]=?|~@)$/ then
1098
1111
  type = '.'
1099
1112
  meth = parts.pop
1100
1113
  else
@@ -67,6 +67,30 @@ class TestRDocCodeObject < XrefTestCase
67
67
  assert_equal Encoding::UTF_8, @co.comment.encoding
68
68
  end
69
69
 
70
+ def test_display_eh_document_self
71
+ assert @co.display?
72
+
73
+ @co.document_self = false
74
+
75
+ refute @co.display?
76
+ end
77
+
78
+ def test_display_eh_ignore
79
+ assert @co.display?
80
+
81
+ @co.ignore
82
+
83
+ refute @co.display?
84
+
85
+ @co.stop_doc
86
+
87
+ refute @co.display?
88
+
89
+ @co.done_documenting = false
90
+
91
+ refute @co.display?
92
+ end
93
+
70
94
  def test_document_children_equals
71
95
  @co.document_children = false
72
96
  refute @co.document_children
@@ -156,6 +180,22 @@ class TestRDocCodeObject < XrefTestCase
156
180
  assert_nil @co.instance_variable_get(:@full_name)
157
181
  end
158
182
 
183
+ def test_ignore
184
+ @co.ignore
185
+
186
+ refute @co.document_self
187
+ refute @co.document_children
188
+ assert @co.ignored?
189
+ end
190
+
191
+ def test_ignore_eh
192
+ refute @co.ignored?
193
+
194
+ @co.ignore
195
+
196
+ assert @co.ignored?
197
+ end
198
+
159
199
  def test_line
160
200
  @c1_m.line = 5
161
201
 
@@ -202,10 +242,16 @@ class TestRDocCodeObject < XrefTestCase
202
242
  end
203
243
 
204
244
  def test_record_location
205
- c = RDoc::CodeObject.new
206
- c.record_location @xref_data
245
+ @co.record_location @xref_data
207
246
 
208
- assert_equal 'xref_data.rb', c.file.relative_name
247
+ assert_equal 'xref_data.rb', @co.file.relative_name
248
+ end
249
+
250
+ def test_record_location_ignored
251
+ @co.ignore
252
+ @co.record_location @xref_data
253
+
254
+ refute @co.ignored?
209
255
  end
210
256
 
211
257
  def test_start_doc
@@ -218,6 +264,16 @@ class TestRDocCodeObject < XrefTestCase
218
264
  assert @co.document_children
219
265
  end
220
266
 
267
+ def test_start_doc_ignored
268
+ @co.ignore
269
+
270
+ @co.start_doc
271
+
272
+ assert @co.document_self
273
+ assert @co.document_children
274
+ refute @co.ignored?
275
+ end
276
+
221
277
  def test_stop_doc
222
278
  @co.document_self = true
223
279
  @co.document_children = true
@@ -0,0 +1,154 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require File.expand_path '../xref_test_case', __FILE__
4
+
5
+ class TestRDocCrossReference < XrefTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @xref = RDoc::CrossReference.new @c1
11
+ end
12
+
13
+ def assert_ref expected, name
14
+ assert_equal expected, @xref.resolve(name, 'fail')
15
+ end
16
+
17
+ def refute_ref name
18
+ assert_equal name, @xref.resolve(name, name)
19
+ end
20
+
21
+ def test_resolve_C2
22
+ @xref = RDoc::CrossReference.new @c2
23
+
24
+ refute_ref '#m'
25
+
26
+ assert_ref @c1__m, 'C1::m'
27
+ assert_ref @c2_c3, 'C2::C3'
28
+ assert_ref @c2_c3_m, 'C2::C3#m'
29
+ assert_ref @c2_c3_h1, 'C3::H1'
30
+ assert_ref @c4, 'C4'
31
+
32
+ assert_ref @c3_h2, 'C3::H2'
33
+ refute_ref 'H1'
34
+ end
35
+
36
+ def test_resolve_C2_C3
37
+ @xref = RDoc::CrossReference.new @c2_c3
38
+
39
+ assert_ref @c2_c3_m, '#m'
40
+
41
+ assert_ref @c2_c3, 'C3'
42
+ assert_ref @c2_c3_m, 'C3#m'
43
+
44
+ assert_ref @c2_c3_h1, 'H1'
45
+ assert_ref @c2_c3_h1, 'C3::H1'
46
+
47
+ assert_ref @c4, 'C4'
48
+
49
+ assert_ref @c3_h2, 'C3::H2'
50
+ end
51
+
52
+ def test_resolve_C3
53
+ @xref = RDoc::CrossReference.new @c3
54
+
55
+ assert_ref @c3, 'C3'
56
+
57
+ refute_ref '#m'
58
+ refute_ref 'C3#m'
59
+
60
+ assert_ref @c3_h1, 'H1'
61
+
62
+ assert_ref @c3_h1, 'C3::H1'
63
+ assert_ref @c3_h2, 'C3::H2'
64
+
65
+ assert_ref @c4, 'C4'
66
+ end
67
+
68
+ def test_resolve_C4
69
+ @xref = RDoc::CrossReference.new @c4
70
+
71
+ # C4 ref inside a C4 containing a C4 should resolve to the contained class
72
+ assert_ref @c4_c4, 'C4'
73
+ end
74
+
75
+ def test_resolve_C4_C4
76
+ @xref = RDoc::CrossReference.new @c4_c4
77
+
78
+ # A C4 reference inside a C4 class contained within a C4 class should
79
+ # resolve to the inner C4 class.
80
+ assert_ref @c4_c4, 'C4'
81
+ end
82
+
83
+ def test_resolve_class
84
+ assert_ref @c1, 'C1'
85
+ refute_ref 'H1'
86
+
87
+ assert_ref @c2, 'C2'
88
+ assert_ref @c2_c3, 'C2::C3'
89
+ assert_ref @c2_c3_h1, 'C2::C3::H1'
90
+
91
+ assert_ref @c3, '::C3'
92
+ assert_ref @c3_h1, '::C3::H1'
93
+
94
+ assert_ref @c4_c4, 'C4::C4'
95
+ end
96
+
97
+ def test_resolve_file
98
+ assert_ref @xref_data, 'xref_data.rb'
99
+ end
100
+
101
+ def test_resolve_method
102
+ assert_ref @c1__m, 'm'
103
+ assert_ref @c1_m, '#m'
104
+ assert_ref @c1__m, '::m'
105
+
106
+ assert_ref @c1_m, 'C1#m'
107
+ assert_ref @c1__m, 'C1.m'
108
+ assert_ref @c1__m, 'C1::m'
109
+
110
+ assert_ref @c1_m, 'C1#m'
111
+ assert_ref @c1_m, 'C1#m()'
112
+ assert_ref @c1_m, 'C1#m(*)'
113
+
114
+ assert_ref @c1__m, 'C1.m'
115
+ assert_ref @c1__m, 'C1.m()'
116
+ assert_ref @c1__m, 'C1.m(*)'
117
+
118
+ assert_ref @c1__m, 'C1::m'
119
+ assert_ref @c1__m, 'C1::m()'
120
+ assert_ref @c1__m, 'C1::m(*)'
121
+
122
+ assert_ref @c2_c3_m, 'C2::C3#m'
123
+
124
+ assert_ref @c2_c3_m, 'C2::C3.m'
125
+
126
+ # TODO stop escaping - HTML5 allows anything but space
127
+ assert_ref @c2_c3_h1_meh, 'C2::C3::H1#m?'
128
+
129
+ assert_ref @c2_c3_m, '::C2::C3#m'
130
+ assert_ref @c2_c3_m, '::C2::C3#m()'
131
+ assert_ref @c2_c3_m, '::C2::C3#m(*)'
132
+ end
133
+
134
+ def test_resolve_no_ref
135
+ assert_equal '', @xref.resolve('', '')
136
+
137
+ assert_equal "bogus", @xref.resolve("bogus", "bogus")
138
+ assert_equal "\\bogus", @xref.resolve("\\bogus", "\\bogus")
139
+ assert_equal "\\\\bogus", @xref.resolve("\\\\bogus", "\\\\bogus")
140
+
141
+ assert_equal "\\#n", @xref.resolve("\\#n", "fail")
142
+ assert_equal "\\#n()", @xref.resolve("\\#n()", "fail")
143
+ assert_equal "\\#n(*)", @xref.resolve("\\#n(*)", "fail")
144
+
145
+ assert_equal "C1", @xref.resolve("\\C1", "fail")
146
+ assert_equal "::C3", @xref.resolve("\\::C3", "fail")
147
+
148
+ assert_equal "succeed", @xref.resolve("::C3::H1#n", "succeed")
149
+ assert_equal "succeed", @xref.resolve("::C3::H1#n(*)", "succeed")
150
+ assert_equal "\\::C3::H1#n", @xref.resolve("\\::C3::H1#n", "fail")
151
+ end
152
+
153
+ end
154
+