rdoc 2.3.0 → 2.4.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 (81) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +14 -0
  3. data/History.txt +27 -0
  4. data/Manifest.txt +29 -9
  5. data/Rakefile +2 -0
  6. data/bin/rdoc +13 -2
  7. data/lib/rdoc.rb +11 -3
  8. data/lib/rdoc/alias.rb +54 -0
  9. data/lib/rdoc/anon_class.rb +10 -0
  10. data/lib/rdoc/any_method.rb +190 -0
  11. data/lib/rdoc/attr.rb +79 -0
  12. data/lib/rdoc/cache.rb +11 -2
  13. data/lib/rdoc/class_module.rb +87 -0
  14. data/lib/rdoc/code_object.rb +152 -0
  15. data/lib/rdoc/code_objects.rb +18 -1118
  16. data/lib/rdoc/constant.rb +36 -0
  17. data/lib/rdoc/context.rb +712 -0
  18. data/lib/rdoc/diagram.rb +8 -8
  19. data/lib/rdoc/generator.rb +3 -1140
  20. data/lib/rdoc/generator/darkfish.rb +107 -133
  21. data/lib/rdoc/generator/markup.rb +194 -0
  22. data/lib/rdoc/generator/ri.rb +4 -2
  23. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +92 -113
  24. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +33 -35
  25. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -15
  26. data/lib/rdoc/ghost_method.rb +8 -0
  27. data/lib/rdoc/include.rb +39 -0
  28. data/lib/rdoc/markup/attribute_manager.rb +46 -0
  29. data/lib/rdoc/markup/formatter.rb +11 -0
  30. data/lib/rdoc/markup/fragments.rb +42 -2
  31. data/lib/rdoc/markup/inline.rb +29 -4
  32. data/lib/rdoc/markup/lines.rb +4 -0
  33. data/lib/rdoc/markup/preprocess.rb +4 -0
  34. data/lib/rdoc/markup/to_flow.rb +27 -1
  35. data/lib/rdoc/markup/to_html.rb +33 -33
  36. data/lib/rdoc/markup/to_html_crossref.rb +4 -11
  37. data/lib/rdoc/markup/to_latex.rb +31 -31
  38. data/lib/rdoc/markup/to_test.rb +3 -0
  39. data/lib/rdoc/markup/to_texinfo.rb +18 -14
  40. data/lib/rdoc/meta_method.rb +8 -0
  41. data/lib/rdoc/normal_class.rb +18 -0
  42. data/lib/rdoc/normal_module.rb +34 -0
  43. data/lib/rdoc/options.rb +26 -159
  44. data/lib/rdoc/parser/c.rb +16 -8
  45. data/lib/rdoc/parser/ruby.rb +16 -10
  46. data/lib/rdoc/parser/simple.rb +1 -1
  47. data/lib/rdoc/rdoc.rb +50 -34
  48. data/lib/rdoc/require.rb +32 -0
  49. data/lib/rdoc/ri/descriptions.rb +1 -1
  50. data/lib/rdoc/ri/driver.rb +4 -4
  51. data/lib/rdoc/ri/formatter.rb +70 -32
  52. data/lib/rdoc/single_class.rb +8 -0
  53. data/lib/rdoc/top_level.rb +232 -0
  54. data/test/test_rdoc_any_method.rb +10 -0
  55. data/test/test_rdoc_code_object.rb +80 -0
  56. data/test/test_rdoc_constant.rb +15 -0
  57. data/test/test_rdoc_context.rb +250 -0
  58. data/test/test_rdoc_include.rb +17 -0
  59. data/test/test_rdoc_markup.rb +13 -2
  60. data/test/test_rdoc_markup_to_html.rb +22 -0
  61. data/test/test_rdoc_markup_to_html_crossref.rb +50 -115
  62. data/test/test_rdoc_normal_module.rb +26 -0
  63. data/test/test_rdoc_parser_c.rb +33 -0
  64. data/test/test_rdoc_parser_ruby.rb +54 -36
  65. data/test/test_rdoc_require.rb +25 -0
  66. data/test/test_rdoc_ri_default_display.rb +2 -1
  67. data/test/test_rdoc_ri_html_formatter.rb +141 -0
  68. data/test/test_rdoc_top_level.rb +85 -0
  69. data/test/xref_data.rb +46 -0
  70. data/test/xref_test_case.rb +48 -0
  71. metadata +42 -13
  72. metadata.gz.sig +0 -0
  73. data/lib/rdoc/generator/html.rb +0 -456
  74. data/lib/rdoc/generator/html/common.rb +0 -24
  75. data/lib/rdoc/generator/html/html.rb +0 -769
  76. data/lib/rdoc/generator/html/one_page_html.rb +0 -122
  77. data/lib/rdoc/generator/xml.rb +0 -124
  78. data/lib/rdoc/generator/xml/rdf.rb +0 -113
  79. data/lib/rdoc/generator/xml/xml.rb +0 -123
  80. data/lib/rdoc/parser/f95.rb +0 -1835
  81. data/lib/rdoc/template.rb +0 -68
@@ -0,0 +1,8 @@
1
+ require 'rdoc/class_module'
2
+
3
+ ##
4
+ # A singleton class
5
+
6
+ class RDoc::SingleClass < RDoc::ClassModule
7
+ end
8
+
@@ -0,0 +1,232 @@
1
+ require 'thread'
2
+ require 'rdoc/context'
3
+
4
+ ##
5
+ # A TopLevel context is a representation of the contents of a single file
6
+
7
+ class RDoc::TopLevel < RDoc::Context
8
+
9
+ ##
10
+ # This TopLevel's File::Stat struct
11
+
12
+ attr_accessor :file_stat
13
+
14
+ ##
15
+ # Relative name of this file
16
+
17
+ attr_accessor :relative_name
18
+
19
+ ##
20
+ # Absolute name of this file
21
+
22
+ attr_accessor :absolute_name
23
+
24
+ attr_accessor :diagram
25
+
26
+ ##
27
+ # The parser that processed this file
28
+
29
+ attr_accessor :parser
30
+
31
+ ##
32
+ # Returns all classes and modules discovered by RDoc
33
+
34
+ def self.all_classes_and_modules
35
+ classes_hash.values + modules_hash.values
36
+ end
37
+
38
+ ##
39
+ # Returns all classes discovered by RDoc
40
+
41
+ def self.classes
42
+ classes_hash.values
43
+ end
44
+
45
+ ##
46
+ # Hash of all classes known to RDoc
47
+
48
+ def self.classes_hash
49
+ @all_classes
50
+ end
51
+
52
+ ##
53
+ # All TopLevels known to RDoc
54
+
55
+ def self.files
56
+ @all_files.values
57
+ end
58
+
59
+ ##
60
+ # Hash of all files known to RDoc
61
+
62
+ def self.files_hash
63
+ @all_files
64
+ end
65
+
66
+ ##
67
+ # Finds the class with +name+ in all discovered classes
68
+
69
+ def self.find_class_named(name)
70
+ @lock.synchronize do
71
+ classes_hash.values.find do |c|
72
+ c.find_class_named name
73
+ end
74
+ end
75
+ end
76
+
77
+ ##
78
+ # Finds the file with +name+ in all discovered files
79
+
80
+ def self.find_file_named(name)
81
+ @lock.synchronize do
82
+ @all_files[name]
83
+ end
84
+ end
85
+
86
+ ##
87
+ # Finds the module with +name+ in all discovered modules
88
+
89
+ def self.find_module_named(name)
90
+ @lock.synchronize do
91
+ modules_hash.values.find do |c|
92
+ c.find_module_named name
93
+ end
94
+ end
95
+ end
96
+
97
+ @lock = Mutex.new
98
+
99
+ ##
100
+ # Lock for global class, module and file stores
101
+
102
+ def self.lock
103
+ @lock
104
+ end
105
+
106
+ ##
107
+ # Returns all modules discovered by RDoc
108
+
109
+ def self.modules
110
+ modules_hash.values
111
+ end
112
+
113
+ ##
114
+ # Hash of all modules known to RDoc
115
+
116
+ def self.modules_hash
117
+ @all_modules
118
+ end
119
+
120
+ ##
121
+ # Empties RDoc of stored class, module and file information
122
+
123
+ def self.reset
124
+ @lock.synchronize do
125
+ @all_classes = {}
126
+ @all_modules = {}
127
+ @all_files = {}
128
+ end
129
+ end
130
+
131
+ reset
132
+
133
+ ##
134
+ # Creates a new TopLevel for +file_name+
135
+
136
+ def initialize(file_name)
137
+ super()
138
+ @name = nil
139
+ @relative_name = file_name
140
+ @absolute_name = file_name
141
+ @file_stat = File.stat(file_name) rescue nil # HACK for testing
142
+ @diagram = nil
143
+ @parser = nil
144
+
145
+ RDoc::TopLevel.lock.synchronize do
146
+ RDoc::TopLevel.files_hash[file_name] = self
147
+ end
148
+ end
149
+
150
+ ##
151
+ # Base name of this file
152
+
153
+ def base_name
154
+ File.basename @absolute_name
155
+ end
156
+
157
+ ##
158
+ # Find class or module named +symbol+ in all discovered classes and
159
+ # modules
160
+
161
+ def find_class_or_module_named(symbol)
162
+ RDoc::TopLevel.classes_hash.each_value do |c|
163
+ return c if c.full_name == symbol
164
+ end
165
+
166
+ RDoc::TopLevel.modules_hash.each_value do |m|
167
+ return m if m.full_name == symbol
168
+ end
169
+
170
+ nil
171
+ end
172
+
173
+ ##
174
+ # Finds a class or module named +symbol+
175
+
176
+ def find_local_symbol(symbol)
177
+ find_class_or_module_named(symbol) || super
178
+ end
179
+
180
+ ##
181
+ # Finds a module or class with +name+
182
+
183
+ def find_module_named(name)
184
+ find_class_or_module_named(name) || find_enclosing_module_named(name)
185
+ end
186
+
187
+ ##
188
+ # The name of this file
189
+
190
+ def full_name
191
+ @relative_name
192
+ end
193
+
194
+ ##
195
+ # URL for this with a +prefix+
196
+
197
+ def http_url(prefix)
198
+ path = [prefix, @relative_name.tr('.', '_')]
199
+
200
+ File.join(*path.compact) + '.html'
201
+ end
202
+
203
+ def inspect # :nodoc:
204
+ "#<%s:0x%x %p modules: %p classes: %p>" % [
205
+ self.class, object_id,
206
+ base_name,
207
+ @modules.map { |n,m| m },
208
+ @classes.map { |n,c| c }
209
+ ]
210
+ end
211
+
212
+ ##
213
+ # Date this file was last modified, if known
214
+
215
+ def last_modified
216
+ @file_stat ? file_stat.mtime.to_s : 'Unknown'
217
+ end
218
+
219
+ ##
220
+ # Base name of this file
221
+
222
+ alias name base_name
223
+
224
+ ##
225
+ # Path to this file
226
+
227
+ def path
228
+ http_url RDoc::RDoc.current.generator.file_dir
229
+ end
230
+
231
+ end
232
+
@@ -0,0 +1,10 @@
1
+ require 'test/xref_test_case'
2
+
3
+ class RDocAnyMethodTest < XrefTestCase
4
+
5
+ def test_full_name
6
+ assert_equal 'C1::m', @c1.method_list.first.full_name
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,80 @@
1
+ require 'rubygems'
2
+ require 'minitest/unit'
3
+ require 'test/xref_test_case'
4
+ require 'rdoc/code_object'
5
+
6
+ class TestRDocCodeObject < XrefTestCase
7
+
8
+ def setup
9
+ super
10
+
11
+ @co = RDoc::CodeObject.new
12
+ end
13
+
14
+ def test_initialize
15
+ assert @co.document_self, 'document_self'
16
+ assert @co.document_children, 'document_children'
17
+ refute @co.force_documentation, 'force_documentation'
18
+ refute @co.done_documenting, 'done_documenting'
19
+ assert_equal nil, @co.comment, 'comment is nil'
20
+ end
21
+
22
+ def test_comment_equals
23
+ @co.comment = ''
24
+
25
+ assert_equal nil, @co.comment
26
+
27
+ @co.comment = 'I am a comment'
28
+
29
+ assert_equal 'I am a comment', @co.comment
30
+ end
31
+
32
+ def test_document_children_equals
33
+ @co.document_children = false
34
+ refute @co.document_children
35
+
36
+ @c2.document_children = false
37
+ assert_empty @c2.classes
38
+ end
39
+
40
+ def test_document_self_equals
41
+ @co.document_self = false
42
+ refute @co.document_self
43
+
44
+ @c1.document_self = false
45
+ assert_empty @c1.method_list
46
+ end
47
+
48
+ def test_parent_file_name
49
+ assert_equal '(unknown)', @co.parent_file_name
50
+ assert_equal 'xref_data.rb', @c1.parent_file_name
51
+ end
52
+
53
+ def test_parent_name
54
+ assert_equal '(unknown)', @co.parent_name
55
+ assert_equal 'xref_data.rb', @c1.parent_name
56
+ assert_equal 'C2', @c2_c3.parent_name
57
+ end
58
+
59
+ def test_start_doc
60
+ @co.document_self = false
61
+ @co.document_children = false
62
+
63
+ @co.start_doc
64
+
65
+ assert @co.document_self
66
+ assert @co.document_children
67
+ end
68
+
69
+ def test_stop_doc
70
+ @co.document_self = true
71
+ @co.document_children = true
72
+
73
+ @co.stop_doc
74
+
75
+ refute @co.document_self
76
+ refute @co.document_children
77
+ end
78
+
79
+ end
80
+
@@ -0,0 +1,15 @@
1
+ require 'test/xref_test_case'
2
+
3
+ class TestRDocConstant < XrefTestCase
4
+
5
+ def setup
6
+ super
7
+
8
+ @const = @c1.constants.first
9
+ end
10
+
11
+ def test_path
12
+ assert_equal 'C1.html#CONST', @const.path
13
+ end
14
+
15
+ end
@@ -0,0 +1,250 @@
1
+ require 'rubygems'
2
+ require 'minitest/unit'
3
+ require 'test/xref_test_case'
4
+
5
+ class TestRDocContext < XrefTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @context = RDoc::Context.new
11
+ end
12
+
13
+ def test_initialize
14
+ assert_empty @context.in_files
15
+ assert_equal 'unknown', @context.name
16
+ assert_equal '', @context.comment
17
+ assert_equal nil, @context.parent
18
+ assert_equal :public, @context.visibility
19
+ assert_equal 1, @context.sections.length
20
+
21
+ assert_empty @context.classes_hash
22
+ assert_empty @context.modules_hash
23
+
24
+ assert_empty @context.method_list
25
+ assert_empty @context.attributes
26
+ assert_empty @context.aliases
27
+ assert_empty @context.requires
28
+ assert_empty @context.includes
29
+ assert_empty @context.constants
30
+ end
31
+
32
+ def test_add_alias
33
+ as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment'
34
+
35
+ @context.add_alias as
36
+
37
+ assert_equal [as], @context.aliases
38
+ assert_equal [as], @context.unmatched_alias_lists['old_name']
39
+ end
40
+
41
+ def test_add_alias_method
42
+ meth = RDoc::AnyMethod.new nil, 'old_name'
43
+ as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment'
44
+ as.parent = @context
45
+
46
+ @context.add_method meth
47
+ @context.add_alias as
48
+
49
+ assert_empty @context.aliases
50
+ assert_empty @context.unmatched_alias_lists
51
+ assert_equal %w[old_name new_name], @context.method_list.map { |m| m.name }
52
+ end
53
+
54
+ def test_add_class
55
+ @c1.add_class RDoc::NormalClass, 'Klass', 'Object'
56
+
57
+ assert_includes @c1.classes.map { |k| k.full_name }, 'C1::Klass'
58
+ assert_includes RDoc::TopLevel.classes.map { |k| k.full_name }, 'C1::Klass'
59
+ end
60
+
61
+ def test_add_class_upgrade
62
+ @c1.add_module RDoc::NormalModule, 'Klass'
63
+ @c1.add_class RDoc::NormalClass, 'Klass', nil
64
+
65
+ assert_includes @c1.classes.map { |k| k.full_name }, 'C1::Klass',
66
+ 'c1 classes'
67
+ refute_includes @c1.modules.map { |k| k.full_name }, 'C1::Klass',
68
+ 'c1 modules'
69
+
70
+ assert_includes RDoc::TopLevel.classes.map { |k| k.full_name }, 'C1::Klass',
71
+ 'TopLevel classes'
72
+ refute_includes RDoc::TopLevel.modules.map { |k| k.full_name }, 'C1::Klass',
73
+ 'TopLevel modules'
74
+ end
75
+
76
+ def test_add_constant
77
+ const = RDoc::Constant.new 'NAME', 'value', 'comment'
78
+ @context.add_constant const
79
+
80
+ assert_equal [const], @context.constants
81
+ end
82
+
83
+ def test_add_include
84
+ incl = RDoc::Include.new 'Name', 'comment'
85
+ @context.add_include incl
86
+
87
+ assert_equal [incl], @context.includes
88
+ end
89
+
90
+ def test_add_method
91
+ meth = RDoc::AnyMethod.new nil, 'old_name'
92
+ meth.visibility = nil
93
+
94
+ @context.add_method meth
95
+
96
+ assert_equal [meth], @context.method_list
97
+ assert_equal :public, meth.visibility
98
+ end
99
+
100
+ def test_add_method_alias
101
+ as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment'
102
+ meth = RDoc::AnyMethod.new nil, 'old_name'
103
+
104
+ @context.add_alias as
105
+ refute_empty @context.aliases
106
+
107
+ @context.add_method meth
108
+
109
+ assert_empty @context.aliases
110
+ assert_empty @context.unmatched_alias_lists
111
+ assert_equal %w[old_name new_name], @context.method_list.map { |m| m.name }
112
+ end
113
+
114
+ def test_add_module
115
+ @c1.add_module RDoc::NormalModule, 'Mod'
116
+
117
+ assert_includes @c1.modules.map { |m| m.full_name }, 'C1::Mod'
118
+ end
119
+
120
+ def test_add_module_class
121
+ k = @c1.add_class RDoc::NormalClass, 'Klass', nil
122
+ m = @c1.add_module RDoc::NormalModule, 'Klass'
123
+
124
+ assert_equal k, m, 'returns class'
125
+ assert_empty @c1.modules
126
+ end
127
+
128
+ def test_add_require
129
+ req = RDoc::Require.new 'require', 'comment'
130
+ @c1.add_require req
131
+
132
+ assert_empty @c1.requires
133
+ assert_includes @c1.top_level.requires, req
134
+ end
135
+
136
+ def test_add_to
137
+ incl = RDoc::Include.new 'Name', 'comment'
138
+ arr = []
139
+ @context.add_to arr, incl
140
+
141
+ assert_includes arr, incl
142
+ assert_equal @context, incl.parent
143
+ assert_equal @context.current_section, incl.section
144
+ end
145
+
146
+ def test_add_to_no_document_self
147
+ incl = RDoc::Include.new 'Name', 'comment'
148
+ arr = []
149
+ @context.document_self = false
150
+ @context.add_to arr, incl
151
+
152
+ refute_includes arr, incl
153
+ end
154
+
155
+ def test_add_to_done_documenting
156
+ incl = RDoc::Include.new 'Name', 'comment'
157
+ arr = []
158
+ @context.done_documenting = true
159
+ @context.add_to arr, incl
160
+
161
+ refute_includes arr, incl
162
+ end
163
+
164
+ def test_classes
165
+ assert_equal %w[C2::C3], @c2.classes.map { |k| k.full_name }
166
+ assert_equal %w[C3::H1 C3::H2], @c3.classes.map { |k| k.full_name }
167
+ end
168
+
169
+ def test_defined_in_eh
170
+ assert @c1.defined_in?(@c1.top_level)
171
+
172
+ refute @c1.defined_in?(RDoc::TopLevel.new('name.rb'))
173
+ end
174
+
175
+ def test_equals2
176
+ assert_equal @c3, @c3
177
+ refute_equal @c2, @c3
178
+ refute_equal @c2_c3, @c3
179
+ end
180
+
181
+ def test_find_attribute_named
182
+ assert_equal nil, @c1.find_attribute_named('none')
183
+ assert_equal 'R', @c1.find_attribute_named('attr').rw
184
+ assert_equal 'R', @c1.find_attribute_named('attr_reader').rw
185
+ assert_equal 'W', @c1.find_attribute_named('attr_writer').rw
186
+ assert_equal 'RW', @c1.find_attribute_named('attr_accessor').rw
187
+ end
188
+
189
+ def test_find_constant_named
190
+ assert_equal nil, @c1.find_constant_named('NONE')
191
+ assert_equal ':const', @c1.find_constant_named('CONST').value
192
+ end
193
+
194
+ def test_find_enclosing_module_named
195
+ assert_equal nil, @c2_c3.find_enclosing_module_named('NONE')
196
+ assert_equal @c1, @c2_c3.find_enclosing_module_named('C1')
197
+ assert_equal @c2, @c2_c3.find_enclosing_module_named('C2')
198
+ end
199
+
200
+ def test_find_file_named
201
+ assert_equal nil, @c1.find_file_named('nonexistent.rb')
202
+ assert_equal @xref_data, @c1.find_file_named(@file_name)
203
+ end
204
+
205
+ def test_find_instance_method_named
206
+ assert_equal nil, @c1.find_instance_method_named('none')
207
+
208
+ m = @c1.find_instance_method_named('m')
209
+ assert_instance_of RDoc::AnyMethod, m
210
+ assert_equal false, m.singleton
211
+ end
212
+
213
+ def test_find_local_symbol
214
+ assert_equal true, @c1.find_local_symbol('m').singleton
215
+ assert_equal ':const', @c1.find_local_symbol('CONST').value
216
+ assert_equal 'R', @c1.find_local_symbol('attr').rw
217
+ assert_equal @xref_data, @c1.find_local_symbol(@file_name)
218
+ assert_equal @c2_c3, @c2.find_local_symbol('C3')
219
+ end
220
+
221
+ def test_find_method_named
222
+ assert_equal true, @c1.find_method_named('m').singleton
223
+ end
224
+
225
+ def test_find_module_named
226
+ assert_equal @c2_c3, @c2.find_module_named('C3')
227
+ assert_equal @c2, @c2.find_module_named('C2')
228
+ assert_equal @c1, @c2.find_module_named('C1')
229
+
230
+ assert_equal 'C2::C3', @c2.find_module_named('C3').full_name
231
+ end
232
+
233
+ def test_find_symbol
234
+ c3 = @xref_data.find_module_named('C3')
235
+ assert_equal c3, @xref_data.find_symbol('C3')
236
+ assert_equal c3, @c2.find_symbol('::C3')
237
+ assert_equal @c2_c3, @c2.find_symbol('C3')
238
+ end
239
+
240
+ def test_spaceship
241
+ assert_equal(-1, @c2.<=>(@c3))
242
+ assert_equal 0, @c2.<=>(@c2)
243
+ assert_equal 1, @c3.<=>(@c2)
244
+
245
+ assert_equal 1, @c2_c3.<=>(@c2)
246
+ assert_equal(-1, @c2_c3.<=>(@c3))
247
+ end
248
+
249
+ end
250
+