rdoc 2.0.0 → 2.1.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 (52) hide show
  1. data.tar.gz.sig +1 -0
  2. data/History.txt +30 -0
  3. data/Manifest.txt +18 -6
  4. data/Rakefile +52 -0
  5. data/lib/rdoc.rb +69 -69
  6. data/lib/rdoc/code_objects.rb +331 -112
  7. data/lib/rdoc/generator.rb +172 -144
  8. data/lib/rdoc/generator/html.rb +45 -18
  9. data/lib/rdoc/generator/html/frameless.rb +795 -0
  10. data/lib/rdoc/generator/html/hefss.rb +11 -11
  11. data/lib/rdoc/generator/html/html.rb +81 -87
  12. data/lib/rdoc/generator/html/kilmer.rb +10 -10
  13. data/lib/rdoc/generator/html/one_page_html.rb +9 -9
  14. data/lib/rdoc/generator/ri.rb +5 -8
  15. data/lib/rdoc/generator/texinfo.rb +84 -0
  16. data/lib/rdoc/generator/texinfo/class.texinfo.erb +44 -0
  17. data/lib/rdoc/generator/texinfo/file.texinfo.erb +6 -0
  18. data/lib/rdoc/generator/texinfo/method.texinfo.erb +6 -0
  19. data/lib/rdoc/generator/texinfo/texinfo.erb +28 -0
  20. data/lib/rdoc/known_classes.rb +69 -0
  21. data/lib/rdoc/markup.rb +3 -3
  22. data/lib/rdoc/markup/attribute_manager.rb +0 -9
  23. data/lib/rdoc/markup/fragments.rb +1 -1
  24. data/lib/rdoc/markup/preprocess.rb +10 -6
  25. data/lib/rdoc/markup/to_html.rb +55 -8
  26. data/lib/rdoc/markup/to_html_crossref.rb +21 -5
  27. data/lib/rdoc/markup/to_texinfo.rb +69 -0
  28. data/lib/rdoc/options.rb +37 -14
  29. data/lib/rdoc/parser.rb +109 -0
  30. data/lib/rdoc/parser/c.rb +656 -0
  31. data/lib/rdoc/parser/f95.rb +1835 -0
  32. data/lib/rdoc/{parsers/parse_rb.rb → parser/ruby.rb} +1436 -1191
  33. data/lib/rdoc/parser/simple.rb +38 -0
  34. data/lib/rdoc/rdoc.rb +48 -32
  35. data/lib/rdoc/ri.rb +5 -1
  36. data/lib/rdoc/ri/descriptions.rb +8 -5
  37. data/lib/rdoc/ri/driver.rb +148 -49
  38. data/lib/rdoc/stats.rb +94 -4
  39. data/test/test_rdoc_info_formatting.rb +175 -0
  40. data/test/test_rdoc_info_sections.rb +136 -0
  41. data/test/test_rdoc_markup_to_html.rb +30 -0
  42. data/test/test_rdoc_markup_to_html_crossref.rb +18 -0
  43. data/test/{test_rdoc_c_parser.rb → test_rdoc_parser_c.rb} +8 -11
  44. data/test/test_rdoc_parser_ruby.rb +539 -0
  45. data/test/test_rdoc_ri_default_display.rb +17 -16
  46. data/test/test_rdoc_ri_driver.rb +92 -0
  47. metadata +54 -12
  48. metadata.gz.sig +0 -0
  49. data/lib/rdoc/parsers/parse_c.rb +0 -775
  50. data/lib/rdoc/parsers/parse_f95.rb +0 -1841
  51. data/lib/rdoc/parsers/parse_simple.rb +0 -40
  52. data/lib/rdoc/parsers/parserfactory.rb +0 -99
@@ -0,0 +1 @@
1
+ U�����5j�_Bf~M�]�h煆�_����-G}�tk��C�{�6)��6XGÆ���|�����KE��~þ{>�va���RV����B,�0JA��K w|ީ7�4�}�P��
@@ -1,3 +1,33 @@
1
+ === 2.1.0 / ??
2
+
3
+ * 3 Major Enhancements:
4
+ * RDoc now knows about meta-programmed methods, see RDoc::Parser::Ruby
5
+ * Reorganized parsers under RDoc::Parser base class
6
+ * ri now walks the ancestors of a class looking for a method e.g. ri
7
+ File#read displays documentation for IO#read (may require regeneration of
8
+ ri data)
9
+ * 5 Minor Enhancements:
10
+ * Allow links to files
11
+ * Default options now taken from RDOCOPT environment variable
12
+ * Class method documentation can be found at toplevel now (def X.foo)
13
+ * Allow HTML templates distributed as gems to be loaded with the -T option,
14
+ just like the standard templates in rdoc/generator/html (so an HTML
15
+ template lib/new_template.rb in a gem can be used with rdoc -T new_template)
16
+ * `rdoc -v` prints out files, classes, modules and methods as it goes
17
+ * 11 Bug Fixes:
18
+ * `ri Foo.bar` now looks for class methods also
19
+ * Sections work in the default template again
20
+ * Doesn't warn about :foo:: list item being an unrecognized directive
21
+ * RDoc no longer converts characters inside tt tags
22
+ * Fixed "unitialized constant RDoc::Markup::ToHtml::HTML"
23
+ * Fixed generation of relative links
24
+ * Fixed various diagram generation issues
25
+ * Fixed templates broken by switch to erb
26
+ * Fixed issue with <!-- --> style comments
27
+ * Lowercase words are no longer rdoc'd as methods without leading #, as
28
+ described in the documentation
29
+ * RDoc now correctly sets superclasses if they were originally unknown
30
+
1
31
  === 2.0.0 / 2008-04-10
2
32
 
3
33
  * 3 Major Enhancements:
@@ -12,14 +12,21 @@ lib/rdoc/generator.rb
12
12
  lib/rdoc/generator/chm.rb
13
13
  lib/rdoc/generator/chm/chm.rb
14
14
  lib/rdoc/generator/html.rb
15
+ lib/rdoc/generator/html/frameless.rb
15
16
  lib/rdoc/generator/html/hefss.rb
16
17
  lib/rdoc/generator/html/html.rb
17
18
  lib/rdoc/generator/html/kilmer.rb
18
19
  lib/rdoc/generator/html/one_page_html.rb
19
20
  lib/rdoc/generator/ri.rb
21
+ lib/rdoc/generator/texinfo.rb
22
+ lib/rdoc/generator/texinfo/class.texinfo.erb
23
+ lib/rdoc/generator/texinfo/file.texinfo.erb
24
+ lib/rdoc/generator/texinfo/method.texinfo.erb
25
+ lib/rdoc/generator/texinfo/texinfo.erb
20
26
  lib/rdoc/generator/xml.rb
21
27
  lib/rdoc/generator/xml/rdf.rb
22
28
  lib/rdoc/generator/xml/xml.rb
29
+ lib/rdoc/known_classes.rb
23
30
  lib/rdoc/markup.rb
24
31
  lib/rdoc/markup/attribute_manager.rb
25
32
  lib/rdoc/markup/formatter.rb
@@ -32,12 +39,13 @@ lib/rdoc/markup/to_html.rb
32
39
  lib/rdoc/markup/to_html_crossref.rb
33
40
  lib/rdoc/markup/to_latex.rb
34
41
  lib/rdoc/markup/to_test.rb
42
+ lib/rdoc/markup/to_texinfo.rb
35
43
  lib/rdoc/options.rb
36
- lib/rdoc/parsers/parse_c.rb
37
- lib/rdoc/parsers/parse_f95.rb
38
- lib/rdoc/parsers/parse_rb.rb
39
- lib/rdoc/parsers/parse_simple.rb
40
- lib/rdoc/parsers/parserfactory.rb
44
+ lib/rdoc/parser.rb
45
+ lib/rdoc/parser/c.rb
46
+ lib/rdoc/parser/f95.rb
47
+ lib/rdoc/parser/ruby.rb
48
+ lib/rdoc/parser/simple.rb
41
49
  lib/rdoc/rdoc.rb
42
50
  lib/rdoc/ri.rb
43
51
  lib/rdoc/ri/cache.rb
@@ -52,10 +60,14 @@ lib/rdoc/ri/writer.rb
52
60
  lib/rdoc/stats.rb
53
61
  lib/rdoc/template.rb
54
62
  lib/rdoc/tokenstream.rb
55
- test/test_rdoc_c_parser.rb
63
+ test/test_rdoc_info_formatting.rb
64
+ test/test_rdoc_info_sections.rb
56
65
  test/test_rdoc_markup.rb
57
66
  test/test_rdoc_markup_attribute_manager.rb
67
+ test/test_rdoc_parser_c.rb
68
+ test/test_rdoc_parser_ruby.rb
58
69
  test/test_rdoc_ri_attribute_formatter.rb
59
70
  test/test_rdoc_ri_default_display.rb
71
+ test/test_rdoc_ri_driver.rb
60
72
  test/test_rdoc_ri_formatter.rb
61
73
  test/test_rdoc_ri_overstrike_formatter.rb
data/Rakefile CHANGED
@@ -6,5 +6,57 @@ require 'rdoc'
6
6
  Hoe.new "rdoc", RDoc::VERSION do |rdoc|
7
7
  rdoc.developer 'Eric Hodel', 'drbrain@segment7.net'
8
8
  rdoc.developer 'Dave Thomas', ''
9
+ rdoc.developer 'Phil Hagelberg', 'technomancy@gmail.com'
10
+ end
11
+
12
+ # These tasks expect to have the following directory structure:
13
+ #
14
+ # git/git.rubini.us/code # Rubinius git HEAD checkout
15
+ # svn/ruby/trunk # ruby subversion HEAD checkout
16
+ # svn/rdoc/trunk # RDoc subversion HEAD checkout
17
+ #
18
+ # If you don't have this directory structure, set RUBY_PATH and/or
19
+ # RUBINIUS_PATH.
20
+
21
+ diff_options = "-urpN --exclude '*svn*' --exclude '*swp' --exclude '*rbc'"
22
+ rsync_options = "-avP --exclude '*svn*' --exclude '*swp' --exclude '*rbc' --exclude '*.rej' --exclude '*.orig'"
23
+
24
+ rubinius_dir = ENV['RUBINIUS_PATH'] || '../../../git/git.rubini.us/code'
25
+ ruby_dir = ENV['RUBY_PATH'] || '../../ruby/trunk'
26
+
27
+ desc "Updates Ruby HEAD with the currently checked-out copy of RDoc."
28
+ task :update_ruby do
29
+ sh "rsync #{rsync_options} bin/rdoc #{ruby_dir}/bin/rdoc"
30
+ sh "rsync #{rsync_options} bin/ri #{ruby_dir}/bin/ri"
31
+ sh "rsync #{rsync_options} lib/ #{ruby_dir}/lib"
32
+ sh "rsync #{rsync_options} test/ #{ruby_dir}/test/rdoc"
33
+ end
34
+
35
+ desc "Diffs Ruby HEAD with the currently checked-out copy of RDoc."
36
+ task :diff_ruby do
37
+ options = "-urpN --exclude '*svn*' --exclude '*swp' --exclude '*rbc'"
38
+
39
+ sh "diff #{diff_options} bin/rdoc #{ruby_dir}/bin/rdoc; true"
40
+ sh "diff #{diff_options} bin/ri #{ruby_dir}/bin/ri; true"
41
+ sh "diff #{diff_options} lib/rdoc.rb #{ruby_dir}/lib/rdoc.rb; true"
42
+ sh "diff #{diff_options} lib/rdoc #{ruby_dir}/lib/rdoc; true"
43
+ sh "diff #{diff_options} test #{ruby_dir}/test/rdoc; true"
44
+ end
45
+
46
+ desc "Updates Rubinius HEAD with the currently checked-out copy of RDoc."
47
+ task :update_rubinius do
48
+ sh "rsync #{rsync_options} bin/rdoc #{rubinius_dir}/lib/bin/rdoc.rb"
49
+ sh "rsync #{rsync_options} bin/ri #{rubinius_dir}/lib/bin/ri.rb"
50
+ sh "rsync #{rsync_options} lib/ #{rubinius_dir}/lib"
51
+ sh "rsync #{rsync_options} test/ #{rubinius_dir}/test/rdoc"
52
+ end
53
+
54
+ desc "Diffs Rubinius HEAD with the currently checked-out copy of RDoc."
55
+ task :diff_rubinius do
56
+ sh "diff #{diff_options} bin/rdoc #{rubinius_dir}/lib/bin/rdoc.rb; true"
57
+ sh "diff #{diff_options} bin/ri #{rubinius_dir}/lib/bin/ri.rb; true"
58
+ sh "diff #{diff_options} lib/rdoc.rb #{rubinius_dir}/lib/rdoc.rb; true"
59
+ sh "diff #{diff_options} lib/rdoc #{rubinius_dir}/lib/rdoc; true"
60
+ sh "diff #{diff_options} test #{rubinius_dir}/test/rdoc; true"
9
61
  end
10
62
 
@@ -1,8 +1,8 @@
1
1
  $DEBUG_RDOC = nil
2
2
 
3
3
  ##
4
- # = RDOC - Ruby Documentation System
5
- #
4
+ # RDoc - Ruby Documentation System
5
+ #
6
6
  # This package contains RDoc and RDoc::Markup. RDoc is an application that
7
7
  # produces documentation for one or more Ruby source files. We work similarly
8
8
  # to JavaDoc, parsing the source, and extracting the definition for classes,
@@ -12,76 +12,76 @@ $DEBUG_RDOC = nil
12
12
  # RDoc::Markup is a library that converts plain text into various output
13
13
  # formats. The markup library is used to interpret the comment blocks that
14
14
  # RDoc uses to document methods, classes, and so on.
15
- #
15
+ #
16
16
  # == Roadmap
17
- #
17
+ #
18
18
  # * If you want to use RDoc to create documentation for your Ruby source files,
19
19
  # read on.
20
- # * If you want to include extensions written in C, see RDoc::C_Parser
20
+ # * If you want to include extensions written in C, see RDoc::Parser::C
21
21
  # * For information on the various markups available in comment blocks, see
22
22
  # RDoc::Markup.
23
- # * If you want to drive RDoc programatically, see RDoc::RDoc.
23
+ # * If you want to drive RDoc programmatically, see RDoc::RDoc.
24
24
  # * If you want to use the library to format text blocks into HTML, have a look
25
25
  # at RDoc::Markup.
26
26
  # * If you want to try writing your own HTML output template, see
27
27
  # RDoc::Generator::HTML
28
- #
28
+ #
29
29
  # == Summary
30
- #
30
+ #
31
31
  # Once installed, you can create documentation using the 'rdoc' command
32
32
  # (the command is 'rdoc.bat' under Windows)
33
- #
33
+ #
34
34
  # % rdoc [options] [names...]
35
- #
35
+ #
36
36
  # Type "rdoc --help" for an up-to-date option summary.
37
- #
37
+ #
38
38
  # A typical use might be to generate documentation for a package of Ruby
39
- # source (such as rdoc itself).
40
- #
39
+ # source (such as rdoc itself).
40
+ #
41
41
  # % rdoc
42
- #
42
+ #
43
43
  # This command generates documentation for all the Ruby and C source
44
44
  # files in and below the current directory. These will be stored in a
45
45
  # documentation tree starting in the subdirectory 'doc'.
46
- #
46
+ #
47
47
  # You can make this slightly more useful for your readers by having the
48
48
  # index page contain the documentation for the primary file. In our
49
49
  # case, we could type
50
- #
50
+ #
51
51
  # % rdoc --main rdoc.rb
52
- #
52
+ #
53
53
  # You'll find information on the various formatting tricks you can use
54
54
  # in comment blocks in the documentation this generates.
55
- #
55
+ #
56
56
  # RDoc uses file extensions to determine how to process each file. File names
57
57
  # ending +.rb+ and <tt>.rbw</tt> are assumed to be Ruby source. Files
58
58
  # ending +.c+ are parsed as C files. All other files are assumed to
59
59
  # contain just Markup-style markup (with or without leading '#' comment
60
60
  # markers). If directory names are passed to RDoc, they are scanned
61
61
  # recursively for C and Ruby source files only.
62
- #
62
+ #
63
63
  # = Markup
64
- #
64
+ #
65
65
  # For information on how to make lists, hyperlinks, etc. with RDoc, see
66
66
  # RDoc::Markup.
67
- #
67
+ #
68
68
  # Comment blocks can be written fairly naturally, either using '#' on
69
69
  # successive lines of the comment, or by including the comment in
70
70
  # an =begin/=end block. If you use the latter form, the =begin line must be
71
71
  # flagged with an RDoc tag:
72
- #
72
+ #
73
73
  # =begin rdoc
74
74
  # Documentation to be processed by RDoc.
75
75
  #
76
76
  # ...
77
77
  # =end
78
- #
78
+ #
79
79
  # RDoc stops processing comments if it finds a comment line containing
80
80
  # a <tt>--</tt>. This can be used to separate external from internal
81
81
  # comments, or to stop a comment being associated with a method, class, or
82
82
  # module. Commenting can be turned back on with a line that starts with a
83
83
  # <tt>++</tt>.
84
- #
84
+ #
85
85
  # ##
86
86
  # # Extract the age and calculate the date-of-birth.
87
87
  # #--
@@ -92,40 +92,40 @@ $DEBUG_RDOC = nil
92
92
  # def get_dob(person)
93
93
  # # ...
94
94
  # end
95
- #
95
+ #
96
96
  # Names of classes, source files, and any method names containing an
97
97
  # underscore or preceded by a hash character are automatically hyperlinked
98
- # from comment text to their description.
99
- #
98
+ # from comment text to their description.
99
+ #
100
100
  # Method parameter lists are extracted and displayed with the method
101
101
  # description. If a method calls +yield+, then the parameters passed to yield
102
102
  # will also be displayed:
103
- #
103
+ #
104
104
  # def fred
105
105
  # ...
106
106
  # yield line, address
107
- #
107
+ #
108
108
  # This will get documented as:
109
- #
109
+ #
110
110
  # fred() { |line, address| ... }
111
- #
111
+ #
112
112
  # You can override this using a comment containing ':yields: ...' immediately
113
113
  # after the method definition
114
- #
114
+ #
115
115
  # def fred # :yields: index, position
116
116
  # # ...
117
117
  #
118
118
  # yield line, address
119
- #
119
+ #
120
120
  # which will get documented as
121
- #
121
+ #
122
122
  # fred() { |index, position| ... }
123
- #
123
+ #
124
124
  # +:yields:+ is an example of a documentation directive. These appear
125
125
  # immediately after the start of the document element they are modifying.
126
- #
126
+ #
127
127
  # == Directives
128
- #
128
+ #
129
129
  # [+:nodoc:+ / +:nodoc:+ all]
130
130
  # Don't include this element in the documentation. For classes
131
131
  # and modules, the methods, aliases, constants, and attributes
@@ -143,27 +143,27 @@ $DEBUG_RDOC = nil
143
143
  # class Output
144
144
  # end
145
145
  # end
146
- #
147
- # In the above code, only class +MyModule::Input+ will be documented.
148
- # :nodoc: is global across all files the class or module appears in, so use
149
- # :stopdoc:/:startdoc: to only omit documentation for a particular set of
150
- # methods, etc.
151
- #
146
+ #
147
+ # In the above code, only class +MyModule::Input+ will be documented.The
148
+ # The :nodoc: directive is global across all files the class or module
149
+ # appears in, so use :stopdoc:/:startdoc: to only omit documentation for a
150
+ # particular set of methods, etc.
151
+ #
152
152
  # [+:doc:+]
153
153
  # Force a method or attribute to be documented even if it wouldn't otherwise
154
154
  # be. Useful if, for example, you want to include documentation of a
155
155
  # particular private method.
156
- #
156
+ #
157
157
  # [+:notnew:+]
158
158
  # Only applicable to the +initialize+ instance method. Normally RDoc
159
- # assumes that the documentation and parameters for #initialize are
159
+ # assumes that the documentation and parameters for #initialize are
160
160
  # actually for the ::new method, and so fakes out a ::new for the class.
161
161
  # The :notnew: modifier stops this. Remember that #initialize is protected,
162
162
  # so you won't see the documentation unless you use the -a command line
163
163
  # option.
164
- #
164
+ #
165
165
  # Comment blocks can contain other directives:
166
- #
166
+ #
167
167
  # [<tt>:section: title</tt>]
168
168
  # Starts a new section in the output. The title following +:section:+ is
169
169
  # used as the section heading, and the remainder of the comment containing
@@ -178,66 +178,66 @@ $DEBUG_RDOC = nil
178
178
  # # This is the section that I wrote.
179
179
  # # See it glisten in the noon-day sun.
180
180
  # # ----------------------------------------
181
- #
181
+ #
182
182
  # [+:call-seq:+]
183
183
  # Lines up to the next blank line in the comment are treated as the method's
184
184
  # calling sequence, overriding the default parsing of method parameters and
185
185
  # yield arguments.
186
- #
186
+ #
187
187
  # [+:include:+ _filename_]
188
188
  # \Include the contents of the named file at this point. The file will be
189
189
  # searched for in the directories listed by the +--include+ option, or in
190
190
  # the current directory by default. The contents of the file will be
191
- # shifted to have the same indentation as the ':' at the start of the
192
- # :include: directive.
193
- #
191
+ # shifted to have the same indentation as the ':' at the start of
192
+ # the :include: directive.
193
+ #
194
194
  # [+:title:+ _text_]
195
195
  # Sets the title for the document. Equivalent to the <tt>--title</tt>
196
196
  # command line parameter. (The command line parameter overrides any :title:
197
197
  # directive in the source).
198
- #
198
+ #
199
199
  # [+:enddoc:+]
200
200
  # Document nothing further at the current level.
201
- #
201
+ #
202
202
  # [+:main:+ _name_]
203
203
  # Equivalent to the <tt>--main</tt> command line parameter.
204
- #
204
+ #
205
205
  # [+:stopdoc:+ / +:startdoc:+]
206
206
  # Stop and start adding new documentation elements to the current container.
207
207
  # For example, if a class has a number of constants that you don't want to
208
208
  # document, put a +:stopdoc:+ before the first, and a +:startdoc:+ after the
209
- # last. If you don't specifiy a +:startdoc:+ by the end of the container,
209
+ # last. If you don't specify a +:startdoc:+ by the end of the container,
210
210
  # disables documentation for the entire class or module.
211
- #
211
+ #
212
212
  # = Other stuff
213
- #
213
+ #
214
214
  # RDoc is currently being maintained by Eric Hodel <drbrain@segment7.net>
215
215
  #
216
216
  # Dave Thomas <dave@pragmaticprogrammer.com> is the original author of RDoc.
217
- #
217
+ #
218
218
  # == Credits
219
- #
219
+ #
220
220
  # * The Ruby parser in rdoc/parse.rb is based heavily on the outstanding
221
221
  # work of Keiju ISHITSUKA of Nippon Rational Inc, who produced the Ruby
222
222
  # parser for irb and the rtags package.
223
- #
223
+ #
224
224
  # * Code to diagram classes and modules was written by Sergey A Yanovitsky
225
225
  # (Jah) of Enticla.
226
- #
226
+ #
227
227
  # * Charset patch from MoonWolf.
228
- #
228
+ #
229
229
  # * Rich Kilmer wrote the kilmer.rb output template.
230
- #
230
+ #
231
231
  # * Dan Brickley led the design of the RDF format.
232
- #
232
+ #
233
233
  # == License
234
- #
234
+ #
235
235
  # RDoc is Copyright (c) 2001-2003 Dave Thomas, The Pragmatic Programmers. It
236
236
  # is free software, and may be redistributed under the terms specified
237
237
  # in the README file of the Ruby distribution.
238
- #
238
+ #
239
239
  # == Warranty
240
- #
240
+ #
241
241
  # This software is provided "as is" and without any express or implied
242
242
  # warranties, including, without limitation, the implied warranties of
243
243
  # merchantibility and fitness for a particular purpose.
@@ -254,7 +254,7 @@ module RDoc
254
254
  ##
255
255
  # RDoc version you are using
256
256
 
257
- VERSION = "2.0.0"
257
+ VERSION = "2.1.0"
258
258
 
259
259
  ##
260
260
  # Name of the dotfile that contains the description of files to be processed
@@ -6,8 +6,8 @@ require 'rdoc/tokenstream'
6
6
  module RDoc
7
7
 
8
8
  ##
9
- # We contain the common stuff for contexts (which are containers)
10
- # and other elements (methods, attributes and so on)
9
+ # We contain the common stuff for contexts (which are containers) and other
10
+ # elements (methods, attributes and so on)
11
11
 
12
12
  class CodeObject
13
13
 
@@ -31,6 +31,13 @@ module RDoc
31
31
 
32
32
  attr_reader :document_self
33
33
 
34
+ def initialize
35
+ @document_self = true
36
+ @document_children = true
37
+ @force_documentation = false
38
+ @done_documenting = false
39
+ end
40
+
34
41
  def document_self=(val)
35
42
  @document_self = val
36
43
  if !val
@@ -64,6 +71,14 @@ module RDoc
64
71
  # Do we _force_ documentation, even is we wouldn't normally show the entity
65
72
  attr_accessor :force_documentation
66
73
 
74
+ def parent_file_name
75
+ @parent ? @parent.file_base_name : '(unknown)'
76
+ end
77
+
78
+ def parent_name
79
+ @parent ? @parent.name : '(unknown)'
80
+ end
81
+
67
82
  # Default callbacks to nothing, but this is overridden for classes
68
83
  # and modules
69
84
  def remove_classes_and_modules
@@ -72,13 +87,6 @@ module RDoc
72
87
  def remove_methods_etc
73
88
  end
74
89
 
75
- def initialize
76
- @document_self = true
77
- @document_children = true
78
- @force_documentation = false
79
- @done_documenting = false
80
- end
81
-
82
90
  # Access the code object's comment
83
91
  attr_reader :comment
84
92
 
@@ -106,15 +114,24 @@ module RDoc
106
114
 
107
115
  end
108
116
 
109
- # A Context is something that can hold modules, classes, methods,
110
- # attributes, aliases, requires, and includes. Classes, modules, and
111
- # files are all Contexts.
117
+ ##
118
+ # A Context is something that can hold modules, classes, methods,
119
+ # attributes, aliases, requires, and includes. Classes, modules, and files
120
+ # are all Contexts.
112
121
 
113
122
  class Context < CodeObject
114
- attr_reader :name, :method_list, :attributes, :aliases, :constants
115
- attr_reader :requires, :includes, :in_files, :visibility
116
123
 
117
- attr_reader :sections
124
+ attr_reader :aliases
125
+ attr_reader :attributes
126
+ attr_reader :constants
127
+ attr_reader :current_section
128
+ attr_reader :in_files
129
+ attr_reader :includes
130
+ attr_reader :method_list
131
+ attr_reader :name
132
+ attr_reader :requires
133
+ attr_reader :sections
134
+ attr_reader :visibility
118
135
 
119
136
  class Section
120
137
  attr_reader :title, :comment, :sequence
@@ -129,12 +146,22 @@ module RDoc
129
146
  set_comment(comment)
130
147
  end
131
148
 
132
- private
149
+ def ==(other)
150
+ self.class === other and @sequence == other.sequence
151
+ end
152
+
153
+ def inspect
154
+ "#<%s:0x%x %s %p>" % [
155
+ self.class, object_id,
156
+ @sequence, title
157
+ ]
158
+ end
133
159
 
134
- # Set the comment for this section from the original comment block
135
- # If the first line contains :section:, strip it and use the rest. Otherwise
136
- # remove lines up to the line containing :section:, and look for
137
- # those lines again at the end and remove them. This lets us write
160
+ ##
161
+ # Set the comment for this section from the original comment block If
162
+ # the first line contains :section:, strip it and use the rest.
163
+ # Otherwise remove lines up to the line containing :section:, and look
164
+ # for those lines again at the end and remove them. This lets us write
138
165
  #
139
166
  # # ---------------------
140
167
  # # :SECTION: The title
@@ -144,9 +171,10 @@ module RDoc
144
171
  def set_comment(comment)
145
172
  return unless comment
146
173
 
147
- if comment =~ /^.*?:section:.*$/
174
+ if comment =~ /^#[ \t]*:section:.*\n/
148
175
  start = $`
149
176
  rest = $'
177
+
150
178
  if start.empty?
151
179
  @comment = rest
152
180
  else
@@ -157,13 +185,13 @@ module RDoc
157
185
  end
158
186
  @comment = nil if @comment.empty?
159
187
  end
160
- end
161
188
 
189
+ end
162
190
 
163
191
  def initialize
164
- super()
192
+ super
165
193
 
166
- @in_files = []
194
+ @in_files = []
167
195
 
168
196
  @name ||= "unknown"
169
197
  @comment ||= ""
@@ -177,29 +205,37 @@ module RDoc
177
205
  initialize_classes_and_modules
178
206
  end
179
207
 
208
+ ##
180
209
  # map the class hash to an array externally
210
+
181
211
  def classes
182
212
  @classes.values
183
213
  end
184
214
 
215
+ ##
185
216
  # map the module hash to an array externally
217
+
186
218
  def modules
187
219
  @modules.values
188
220
  end
189
221
 
222
+ ##
190
223
  # Change the default visibility for new methods
224
+
191
225
  def ongoing_visibility=(vis)
192
226
  @visibility = vis
193
227
  end
194
228
 
195
- # Given an array +methods+ of method names, set the
196
- # visibility of the corresponding AnyMethod object
229
+ ##
230
+ # Yields Method and Attr entries matching the list of names in +methods+.
231
+ # Attributes are only returned when +singleton+ is false.
197
232
 
198
- def set_visibility_for(methods, vis, singleton=false)
233
+ def methods_matching(methods, singleton = false)
199
234
  count = 0
235
+
200
236
  @method_list.each do |m|
201
- if methods.include?(m.name) && m.singleton == singleton
202
- m.visibility = vis
237
+ if methods.include? m.name and m.singleton == singleton then
238
+ yield m
203
239
  count += 1
204
240
  end
205
241
  end
@@ -209,14 +245,23 @@ module RDoc
209
245
  # perhaps we need to look at attributes
210
246
 
211
247
  @attributes.each do |a|
212
- if methods.include?(a.name)
213
- a.visibility = vis
214
- count += 1
215
- end
248
+ yield a if methods.include? a.name
216
249
  end
217
250
  end
218
251
 
252
+ ##
253
+ # Given an array +methods+ of method names, set the visibility of the
254
+ # corresponding AnyMethod object
255
+
256
+ def set_visibility_for(methods, vis, singleton = false)
257
+ methods_matching methods, singleton do |m|
258
+ m.visibility = vis
259
+ end
260
+ end
261
+
262
+ ##
219
263
  # Record the file that we happen to find it in
264
+
220
265
  def record_location(toplevel)
221
266
  @in_files << toplevel unless @in_files.include?(toplevel)
222
267
  end
@@ -227,7 +272,7 @@ module RDoc
227
272
  end
228
273
 
229
274
  def add_class(class_type, name, superclass)
230
- add_class_or_module(@classes, class_type, name, superclass)
275
+ add_class_or_module @classes, class_type, name, superclass
231
276
  end
232
277
 
233
278
  def add_module(class_type, name)
@@ -235,7 +280,6 @@ module RDoc
235
280
  end
236
281
 
237
282
  def add_method(a_method)
238
- puts "Adding #@visibility method #{a_method.name} to #@name" if $DEBUG_RDOC
239
283
  a_method.visibility = @visibility
240
284
  add_to(@method_list, a_method)
241
285
  end
@@ -246,7 +290,8 @@ module RDoc
246
290
 
247
291
  def add_alias(an_alias)
248
292
  meth = find_instance_method_named(an_alias.old_name)
249
- if meth
293
+
294
+ if meth then
250
295
  new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
251
296
  new_meth.is_alias_for = meth
252
297
  new_meth.singleton = meth.singleton
@@ -257,6 +302,8 @@ module RDoc
257
302
  else
258
303
  add_to(@aliases, an_alias)
259
304
  end
305
+
306
+ an_alias
260
307
  end
261
308
 
262
309
  def add_include(an_include)
@@ -269,20 +316,21 @@ module RDoc
269
316
 
270
317
  # Requires always get added to the top-level (file) context
271
318
  def add_require(a_require)
272
- if self.kind_of? TopLevel
273
- add_to(@requires, a_require)
319
+ if TopLevel === self then
320
+ add_to @requires, a_require
274
321
  else
275
- parent.add_require(a_require)
322
+ parent.add_require a_require
276
323
  end
277
324
  end
278
325
 
279
326
  def add_class_or_module(collection, class_type, name, superclass=nil)
280
327
  cls = collection[name]
281
- if cls
328
+
329
+ if cls then
330
+ cls.superclass = superclass unless cls.module?
282
331
  puts "Reusing class/module #{name}" if $DEBUG_RDOC
283
332
  else
284
333
  cls = class_type.new(name, superclass)
285
- puts "Adding class/module #{name} to #@name" if $DEBUG_RDOC
286
334
  # collection[name] = cls if @document_self && !@done_documenting
287
335
  collection[name] = cls if !@done_documenting
288
336
  cls.parent = self
@@ -292,7 +340,7 @@ module RDoc
292
340
  end
293
341
 
294
342
  def add_to(array, thing)
295
- array << thing if @document_self && !@done_documenting
343
+ array << thing if @document_self and not @done_documenting
296
344
  thing.parent = self
297
345
  thing.section = @current_section
298
346
  end
@@ -371,26 +419,30 @@ module RDoc
371
419
  name <=> other.name
372
420
  end
373
421
 
374
- # Look up the given symbol. If method is non-nil, then
375
- # we assume the symbol references a module that
376
- # contains that method
377
- def find_symbol(symbol, method=nil)
422
+ ##
423
+ # Look up +symbol+. If +method+ is non-nil, then we assume the symbol
424
+ # references a module that contains that method.
425
+
426
+ def find_symbol(symbol, method = nil)
378
427
  result = nil
428
+
379
429
  case symbol
380
- when /^::(.*)/
430
+ when /^::(.*)/ then
381
431
  result = toplevel.find_symbol($1)
382
- when /::/
432
+ when /::/ then
383
433
  modules = symbol.split(/::/)
384
- unless modules.empty?
434
+
435
+ unless modules.empty? then
385
436
  module_name = modules.shift
386
437
  result = find_module_named(module_name)
387
- if result
438
+ if result then
388
439
  modules.each do |name|
389
440
  result = result.find_module_named(name)
390
441
  break unless result
391
442
  end
392
443
  end
393
444
  end
445
+
394
446
  else
395
447
  # if a method is specified, then we're definitely looking for
396
448
  # a module, otherwise it could be any symbol
@@ -408,22 +460,21 @@ module RDoc
408
460
  end
409
461
  end
410
462
  end
411
- if result && method
412
- if !result.respond_to?(:find_local_symbol)
413
- #p result.name
414
- #p method
415
- fail
416
- end
463
+
464
+ if result and method then
465
+ fail unless result.respond_to? :find_local_symbol
417
466
  result = result.find_local_symbol(method)
418
467
  end
468
+
419
469
  result
420
470
  end
421
-
471
+
422
472
  def find_local_symbol(symbol)
423
473
  res = find_method_named(symbol) ||
424
474
  find_constant_named(symbol) ||
425
475
  find_attribute_named(symbol) ||
426
- find_module_named(symbol)
476
+ find_module_named(symbol) ||
477
+ find_file_named(symbol)
427
478
  end
428
479
 
429
480
  # Handle sections
@@ -454,7 +505,14 @@ module RDoc
454
505
  def find_attribute_named(name)
455
506
  @attributes.find {|m| m.name == name}
456
507
  end
457
-
508
+
509
+ ##
510
+ # Find a named file, or return nil
511
+
512
+ def find_file_named(name)
513
+ toplevel.class.find_file_named(name)
514
+ end
515
+
458
516
  end
459
517
 
460
518
  ##
@@ -465,22 +523,29 @@ module RDoc
465
523
  attr_accessor :file_relative_name
466
524
  attr_accessor :file_absolute_name
467
525
  attr_accessor :diagram
468
-
526
+
469
527
  @@all_classes = {}
470
528
  @@all_modules = {}
529
+ @@all_files = {}
471
530
 
472
531
  def self.reset
473
532
  @@all_classes = {}
474
533
  @@all_modules = {}
534
+ @@all_files = {}
475
535
  end
476
536
 
477
537
  def initialize(file_name)
478
538
  super()
479
539
  @name = "TopLevel"
480
- @file_relative_name = file_name
481
- @file_absolute_name = file_name
482
- @file_stat = File.stat(file_name)
483
- @diagram = nil
540
+ @file_relative_name = file_name
541
+ @file_absolute_name = file_name
542
+ @file_stat = File.stat(file_name)
543
+ @diagram = nil
544
+ @@all_files[file_name] = self
545
+ end
546
+
547
+ def file_base_name
548
+ File.basename @file_absolute_name
484
549
  end
485
550
 
486
551
  def full_name
@@ -496,10 +561,11 @@ module RDoc
496
561
  def add_class_or_module(collection, class_type, name, superclass)
497
562
  cls = collection[name]
498
563
 
499
- if cls
500
- puts "Reusing class/module #{name}" if $DEBUG_RDOC
564
+ if cls then
565
+ cls.superclass = superclass unless cls.module?
566
+ puts "Reusing class/module #{cls.full_name}" if $DEBUG_RDOC
501
567
  else
502
- if class_type == NormalModule
568
+ if class_type == NormalModule then
503
569
  all = @@all_modules
504
570
  else
505
571
  all = @@all_classes
@@ -507,13 +573,11 @@ module RDoc
507
573
 
508
574
  cls = all[name]
509
575
 
510
- if !cls
511
- cls = class_type.new(name, superclass)
576
+ unless cls then
577
+ cls = class_type.new name, superclass
512
578
  all[name] = cls unless @done_documenting
513
579
  end
514
580
 
515
- puts "Adding class/module #{name} to #{@name}" if $DEBUG_RDOC
516
-
517
581
  collection[name] = cls unless @done_documenting
518
582
 
519
583
  cls.parent = self
@@ -534,6 +598,10 @@ module RDoc
534
598
  nil
535
599
  end
536
600
 
601
+ def self.find_file_named(name)
602
+ @@all_files[name]
603
+ end
604
+
537
605
  def find_local_symbol(symbol)
538
606
  find_class_or_module_named(symbol) || super
539
607
  end
@@ -551,14 +619,23 @@ module RDoc
551
619
  find_class_or_module_named(name) || find_enclosing_module_named(name)
552
620
  end
553
621
 
622
+ def inspect
623
+ "#<%s:0x%x %p modules: %p classes: %p>" % [
624
+ self.class, object_id,
625
+ file_base_name,
626
+ @modules.map { |n,m| m },
627
+ @classes.map { |n,c| c }
628
+ ]
629
+ end
630
+
554
631
  end
555
632
 
556
- # ClassModule is the base class for objects representing either a
557
- # class or a module.
633
+ ##
634
+ # ClassModule is the base class for objects representing either a class or a
635
+ # module.
558
636
 
559
637
  class ClassModule < Context
560
638
 
561
- attr_reader :superclass
562
639
  attr_accessor :diagram
563
640
 
564
641
  def initialize(name, superclass = nil)
@@ -569,7 +646,15 @@ module RDoc
569
646
  super()
570
647
  end
571
648
 
649
+ def find_class_named(name)
650
+ return self if full_name == name
651
+ @classes.each_value {|c| return c if c.find_class_named(name) }
652
+ nil
653
+ end
654
+
655
+ ##
572
656
  # Return the fully qualified name of this class or module
657
+
573
658
  def full_name
574
659
  if @parent && @parent.full_name
575
660
  @parent.full_name + "::" + @name
@@ -583,49 +668,106 @@ module RDoc
583
668
  File.join(prefix, *path) + ".html"
584
669
  end
585
670
 
586
- # Return +true+ if this object represents a module
587
- def is_module?
671
+ ##
672
+ # Does this object represent a module?
673
+
674
+ def module?
588
675
  false
589
676
  end
590
677
 
591
- # to_s is simply for debugging
592
- def to_s
593
- res = self.class.name + ": " + @name
594
- res << @comment.to_s
595
- res << super
596
- res
678
+ ##
679
+ # Get the superclass of this class. Attempts to retrieve the superclass'
680
+ # real name by following module nesting.
681
+
682
+ def superclass
683
+ raise NoMethodError, "#{full_name} is a module" if module?
684
+
685
+ scope = self
686
+
687
+ begin
688
+ superclass = scope.classes.find { |c| c.name == @superclass }
689
+
690
+ return superclass.full_name if superclass
691
+ scope = scope.parent
692
+ end until scope.nil? or TopLevel === scope
693
+
694
+ @superclass
597
695
  end
598
696
 
599
- def find_class_named(name)
600
- return self if full_name == name
601
- @classes.each_value {|c| return c if c.find_class_named(name) }
602
- nil
697
+ ##
698
+ # Set the superclass of this class
699
+
700
+ def superclass=(superclass)
701
+ raise NoMethodError, "#{full_name} is a module" if module?
702
+
703
+ if @superclass.nil? or @superclass == 'Object' then
704
+ @superclass = superclass
705
+ end
706
+ end
707
+
708
+ def to_s
709
+ "#{self.class}: #{@name} #{@comment} #{super}"
603
710
  end
711
+
604
712
  end
605
713
 
714
+ ##
606
715
  # Anonymous classes
716
+
607
717
  class AnonClass < ClassModule
608
718
  end
609
719
 
720
+ ##
610
721
  # Normal classes
722
+
611
723
  class NormalClass < ClassModule
724
+
725
+ def inspect
726
+ superclass = @superclass ? " < #{@superclass}" : nil
727
+ "<%s:0x%x class %s%s includes: %p attributes: %p methods: %p aliases: %p>" % [
728
+ self.class, object_id,
729
+ @name, superclass, @includes, @attributes, @method_list, @aliases
730
+ ]
731
+ end
732
+
612
733
  end
613
734
 
735
+ ##
614
736
  # Singleton classes
737
+
615
738
  class SingleClass < ClassModule
616
739
  end
617
740
 
741
+ ##
618
742
  # Module
743
+
619
744
  class NormalModule < ClassModule
620
- def is_module?
745
+
746
+ def comment=(comment)
747
+ return if comment.empty?
748
+ comment = @comment << "# ---\n" << comment unless @comment.empty?
749
+
750
+ super
751
+ end
752
+
753
+ def inspect
754
+ "#<%s:0x%x module %s includes: %p attributes: %p methods: %p aliases: %p>" % [
755
+ self.class, object_id,
756
+ @name, @includes, @attributes, @method_list, @aliases
757
+ ]
758
+ end
759
+
760
+ def module?
621
761
  true
622
762
  end
763
+
623
764
  end
624
765
 
625
766
  ##
626
767
  # AnyMethod is the base class for objects representing methods
627
768
 
628
769
  class AnyMethod < CodeObject
770
+
629
771
  attr_accessor :name
630
772
  attr_accessor :visibility
631
773
  attr_accessor :block_params
@@ -663,44 +805,71 @@ module RDoc
663
805
  @name <=> other.name
664
806
  end
665
807
 
666
- def to_s
667
- res = self.class.name + ": " + @name + " (" + @text + ")\n"
668
- res << @comment.to_s
669
- res
808
+ def add_alias(method)
809
+ @aliases << method
810
+ end
811
+
812
+ def inspect
813
+ alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
814
+ "#<%s:0x%x %s%s%s (%s)%s>" % [
815
+ self.class, object_id,
816
+ parent_name,
817
+ singleton ? '::' : '#',
818
+ name,
819
+ visibility,
820
+ alias_for,
821
+ ]
670
822
  end
671
823
 
672
824
  def param_seq
673
- p = params.gsub(/\s*\#.*/, '')
674
- p = p.tr("\n", " ").squeeze(" ")
675
- p = "(" + p + ")" unless p[0] == ?(
825
+ params = params.gsub(/\s*\#.*/, '')
826
+ params = params.tr("\n", " ").squeeze(" ")
827
+ params = "(#{params})" unless p[0] == ?(
676
828
 
677
- if (block = block_params)
678
- # If this method has explicit block parameters, remove any
679
- # explicit &block
680
- $stderr.puts p
681
- p.sub!(/,?\s*&\w+/)
682
- $stderr.puts p
829
+ if block = block_params then # yes, =
830
+ # If this method has explicit block parameters, remove any explicit
831
+ # &block
832
+ params.sub!(/,?\s*&\w+/)
683
833
 
684
834
  block.gsub!(/\s*\#.*/, '')
685
835
  block = block.tr("\n", " ").squeeze(" ")
686
836
  if block[0] == ?(
687
837
  block.sub!(/^\(/, '').sub!(/\)/, '')
688
838
  end
689
- p << " {|#{block}| ...}"
839
+ params << " { |#{block}| ... }"
690
840
  end
691
- p
841
+
842
+ params
692
843
  end
693
844
 
694
- def add_alias(method)
695
- @aliases << method
845
+ def to_s
846
+ res = self.class.name + ": " + @name + " (" + @text + ")\n"
847
+ res << @comment.to_s
848
+ res
696
849
  end
850
+
851
+ end
852
+
853
+ ##
854
+ # GhostMethod represents a method referenced only by a comment
855
+
856
+ class GhostMethod < AnyMethod
857
+ end
858
+
859
+ ##
860
+ # MetaMethod represents a meta-programmed method
861
+
862
+ class MetaMethod < AnyMethod
697
863
  end
698
864
 
699
- # Represent an alias, which is an old_name/ new_name pair associated
700
- # with a particular context
865
+ ##
866
+ # Represent an alias, which is an old_name/ new_name pair associated with a
867
+ # particular context
868
+
701
869
  class Alias < CodeObject
870
+
702
871
  attr_accessor :text, :old_name, :new_name, :comment
703
-
872
+
704
873
  def initialize(text, old_name, new_name, comment)
705
874
  super()
706
875
  @text = text
@@ -709,12 +878,22 @@ $stderr.puts p
709
878
  self.comment = comment
710
879
  end
711
880
 
881
+ def inspect
882
+ "#<%s:0x%x %s.alias_method %s, %s>" % [
883
+ self.class, object_id,
884
+ parent.name, @old_name, @new_name,
885
+ ]
886
+ end
887
+
712
888
  def to_s
713
889
  "alias: #{self.old_name} -> #{self.new_name}\n#{self.comment}"
714
890
  end
891
+
715
892
  end
716
893
 
894
+ ##
717
895
  # Represent a constant
896
+
718
897
  class Constant < CodeObject
719
898
  attr_accessor :name, :value
720
899
 
@@ -726,7 +905,9 @@ $stderr.puts p
726
905
  end
727
906
  end
728
907
 
908
+ ##
729
909
  # Represent attributes
910
+
730
911
  class Attr < CodeObject
731
912
  attr_accessor :text, :name, :rw, :visibility
732
913
 
@@ -739,16 +920,33 @@ $stderr.puts p
739
920
  self.comment = comment
740
921
  end
741
922
 
923
+ def <=>(other)
924
+ self.name <=> other.name
925
+ end
926
+
927
+ def inspect
928
+ attr = case rw
929
+ when 'RW' then :attr_accessor
930
+ when 'R' then :attr_reader
931
+ when 'W' then :attr_writer
932
+ else
933
+ " (#{rw})"
934
+ end
935
+
936
+ "#<%s:0x%x %s.%s :%s>" % [
937
+ self.class, object_id,
938
+ parent_name, attr, @name,
939
+ ]
940
+ end
941
+
742
942
  def to_s
743
943
  "attr: #{self.name} #{self.rw}\n#{self.comment}"
744
944
  end
745
945
 
746
- def <=>(other)
747
- self.name <=> other.name
748
- end
749
946
  end
750
947
 
751
- # a required file
948
+ ##
949
+ # A required file
752
950
 
753
951
  class Require < CodeObject
754
952
  attr_accessor :name
@@ -759,16 +957,37 @@ $stderr.puts p
759
957
  self.comment = comment
760
958
  end
761
959
 
960
+ def inspect
961
+ "#<%s:0x%x require '%s' in %s>" % [
962
+ self.class,
963
+ object_id,
964
+ @name,
965
+ parent_file_name,
966
+ ]
967
+ end
968
+
762
969
  end
763
970
 
764
- # an included module
971
+ ##
972
+ # An included module
973
+
765
974
  class Include < CodeObject
975
+
766
976
  attr_accessor :name
767
977
 
768
978
  def initialize(name, comment)
769
979
  super()
770
980
  @name = name
771
981
  self.comment = comment
982
+
983
+ end
984
+
985
+ def inspect
986
+ "#<%s:0x%x %s.include %s>" % [
987
+ self.class,
988
+ object_id,
989
+ parent_name, @name,
990
+ ]
772
991
  end
773
992
 
774
993
  end