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
@@ -20,6 +20,11 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
20
20
  def initialize
21
21
  super
22
22
 
23
+ # @in_tt - tt nested levels count
24
+ # @tt_bit - cache
25
+ @in_tt = 0
26
+ @tt_bit = RDoc::Markup::Attribute.bitmap_for :TT
27
+
23
28
  # external hyperlinks
24
29
  @markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
25
30
 
@@ -29,6 +34,27 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
29
34
  init_tags
30
35
  end
31
36
 
37
+ ##
38
+ # Converts a target url to one that is relative to a given path
39
+
40
+ def self.gen_relative_url(path, target)
41
+ from = File.dirname path
42
+ to, to_file = File.split target
43
+
44
+ from = from.split "/"
45
+ to = to.split "/"
46
+
47
+ while from.size > 0 and to.size > 0 and from[0] == to[0] do
48
+ from.shift
49
+ to.shift
50
+ end
51
+
52
+ from.fill ".."
53
+ from.concat to
54
+ from << to_file
55
+ File.join(*from)
56
+ end
57
+
32
58
  ##
33
59
  # Generate a hyperlink for url, labeled with text. Handle the
34
60
  # special cases for img: and link: described under handle_special_HYPEDLINK
@@ -47,7 +73,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
47
73
  url = if path[0, 1] == '#' then # is this meaningful?
48
74
  path
49
75
  else
50
- HTML.gen_url @from_path, path
76
+ self.class.gen_relative_url @from_path, path
51
77
  end
52
78
  end
53
79
 
@@ -86,6 +112,20 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
86
112
  gen_url url, label
87
113
  end
88
114
 
115
+ ##
116
+ # are we currently inside <tt> tags?
117
+
118
+ def in_tt?
119
+ @in_tt > 0
120
+ end
121
+
122
+ ##
123
+ # is +tag+ a <tt> tag?
124
+
125
+ def tt?(tag)
126
+ tag.bit == @tt_bit
127
+ end
128
+
89
129
  ##
90
130
  # Set up the standard mapping of attributes to HTML tags
91
131
 
@@ -215,6 +255,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
215
255
  @attr_tags.each do |tag|
216
256
  if attr_mask & tag.bit != 0
217
257
  res << annotate(tag.on)
258
+ @in_tt += 1 if tt?(tag)
218
259
  end
219
260
  end
220
261
  end
@@ -225,6 +266,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
225
266
 
226
267
  @attr_tags.reverse_each do |tag|
227
268
  if attr_mask & tag.bit != 0
269
+ @in_tt -= 1 if tt?(tag)
228
270
  res << annotate(tag.off)
229
271
  end
230
272
  end
@@ -250,27 +292,33 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
250
292
  res
251
293
  end
252
294
 
295
+ def convert_string(item)
296
+ in_tt? ? convert_string_simple(item) : convert_string_fancy(item)
297
+ end
298
+
299
+ def convert_string_simple(item)
300
+ CGI.escapeHTML item
301
+ end
302
+
253
303
  ##
254
304
  # some of these patterns are taken from SmartyPants...
255
305
 
256
- def convert_string(item)
257
- CGI.escapeHTML(item).
258
-
306
+ def convert_string_fancy(item)
259
307
  # convert -- to em-dash, (-- to en-dash)
260
- gsub(/---?/, '&#8212;'). #gsub(/--/, '&#8211;').
308
+ item.gsub(/---?/, '&#8212;'). #gsub(/--/, '&#8211;').
261
309
 
262
310
  # convert ... to elipsis (and make sure .... becomes .<elipsis>)
263
311
  gsub(/\.\.\.\./, '.&#8230;').gsub(/\.\.\./, '&#8230;').
264
312
 
265
313
  # convert single closing quote
266
- gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1&#8217;').
314
+ gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1&#8217;'). # }
267
315
  gsub(%r{\'(?=\W|s\b)}, '&#8217;').
268
316
 
269
317
  # convert single opening quote
270
318
  gsub(/'/, '&#8216;').
271
319
 
272
320
  # convert double closing quote
273
- gsub(%r{([^ \t\r\n\[\{\(])\'(?=\W)}, '\1&#8221;').
321
+ gsub(%r{([^ \t\r\n\[\{\(])\'(?=\W)}, '\1&#8221;'). # }
274
322
 
275
323
  # convert double opening quote
276
324
  gsub(/'/, '&#8220;').
@@ -280,7 +328,6 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
280
328
 
281
329
  # convert and registered trademark
282
330
  gsub(/\(r\)/, '&#174;')
283
-
284
331
  end
285
332
 
286
333
  def convert_special(special)
@@ -14,6 +14,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
14
14
  # correct relative paths for any hyperlinks that we find
15
15
 
16
16
  def initialize(from_path, context, show_hash)
17
+ raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
17
18
  super()
18
19
 
19
20
  # class names, variable names, or instance variables
@@ -47,28 +48,43 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
47
48
  def handle_special_CROSSREF(special)
48
49
  name = special.text
49
50
 
51
+ return name if name =~ /\A[a-z]*\z/
52
+
50
53
  return @seen[name] if @seen.include? name
51
54
 
52
- if name[0,1] == '#' then
55
+ if name[0, 1] == '#' then
53
56
  lookup = name[1..-1]
54
57
  name = lookup unless @show_hash
55
58
  else
56
59
  lookup = name
57
60
  end
58
61
 
62
+
59
63
  # Find class, module, or method in class or module.
60
- if /([A-Z]\w*)[.\#](\w+[!?=]?)/ =~ lookup then
64
+ #
65
+ # Do not, however, use an if/elsif/else chain to do so. Instead, test
66
+ # each possible pattern until one matches. The reason for this is that a
67
+ # string like "YAML.txt" could be the txt() class method of class YAML (in
68
+ # which case it would match the first pattern, which splits the string
69
+ # into container and method components and looks up both) or a filename
70
+ # (in which case it would match the last pattern, which just checks
71
+ # whether the string as a whole is a known symbol).
72
+
73
+ if /([A-Z][\w:]*)[.\#](\w+[!?=]?)/ =~ lookup then
61
74
  container = $1
62
75
  method = $2
63
76
  ref = @context.find_symbol container, method
64
- elsif /([A-Za-z]\w*)[.\#](\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?)/ =~ lookup then
77
+ end
78
+
79
+ if !ref and
80
+ /([A-Za-z][\w:]*)[.\#](\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?)/ =~ lookup then
65
81
  container = $1
66
82
  method = $2
67
83
  ref = @context.find_symbol container, method
68
- else
69
- ref = @context.find_symbol lookup
70
84
  end
71
85
 
86
+ ref = @context.find_symbol lookup unless ref
87
+
72
88
  out = if lookup =~ /^\\/ then
73
89
  $'
74
90
  elsif ref and ref.document_self then
@@ -0,0 +1,69 @@
1
+ require 'rdoc/markup/formatter'
2
+ require 'rdoc/markup/fragments'
3
+ require 'rdoc/markup/inline'
4
+
5
+ require 'rdoc/markup'
6
+ require 'rdoc/markup/formatter'
7
+
8
+ ##
9
+ # Convert SimpleMarkup to basic TexInfo format
10
+ #
11
+ # TODO: WTF is AttributeManager for?
12
+ #
13
+ class RDoc::Markup::ToTexInfo < RDoc::Markup::Formatter
14
+
15
+ def start_accepting
16
+ @text = []
17
+ end
18
+
19
+ def end_accepting
20
+ @text.join("\n")
21
+ end
22
+
23
+ def accept_paragraph(attributes, text)
24
+ @text << format(text)
25
+ end
26
+
27
+ def accept_verbatim(attributes, text)
28
+ @text << "@verb{|#{format(text)}|}"
29
+ end
30
+
31
+ def accept_heading(attributes, text)
32
+ heading = ['@majorheading', '@chapheading'][text.head_level - 1] || '@heading'
33
+ @text << "#{heading}{#{format(text)}}"
34
+ end
35
+
36
+ def accept_list_start(attributes, text)
37
+ @text << '@itemize @bullet'
38
+ end
39
+
40
+ def accept_list_end(attributes, text)
41
+ @text << '@end itemize'
42
+ end
43
+
44
+ def accept_list_item(attributes, text)
45
+ @text << "@item\n#{format(text)}"
46
+ end
47
+
48
+ def accept_blank_line(attributes, text)
49
+ @text << "\n"
50
+ end
51
+
52
+ def accept_rule(attributes, text)
53
+ @text << '-----'
54
+ end
55
+
56
+ def format(text)
57
+ text.txt.
58
+ gsub(/@/, "@@").
59
+ gsub(/\{/, "@{").
60
+ gsub(/\}/, "@}").
61
+ # gsub(/,/, "@,"). # technically only required in cross-refs
62
+ gsub(/\+([\w]+)\+/, "@code{\\1}").
63
+ gsub(/\<tt\>([^<]+)\<\/tt\>/, "@code{\\1}").
64
+ gsub(/\*([\w]+)\*/, "@strong{\\1}").
65
+ gsub(/\<b\>([^<]+)\<\/b\>/, "@strong{\\1}").
66
+ gsub(/_([\w]+)_/, "@emph{\\1}").
67
+ gsub(/\<em\>([^<]+)\<\/em\>/, "@emph{\\1}")
68
+ end
69
+ end
@@ -39,7 +39,7 @@ class RDoc::Options
39
39
  ##
40
40
  # Pattern for additional attr_... style methods
41
41
 
42
- attr_reader :extra_accessors
42
+ attr_accessor :extra_accessors
43
43
 
44
44
  ##
45
45
  # Should we draw fileboxes in diagrams
@@ -61,6 +61,11 @@ class RDoc::Options
61
61
 
62
62
  attr_accessor :generator
63
63
 
64
+ ##
65
+ # Formatter to mark up text with
66
+
67
+ attr_accessor :formatter
68
+
64
69
  ##
65
70
  # image format for diagrams
66
71
 
@@ -95,18 +100,13 @@ class RDoc::Options
95
100
  ##
96
101
  # The name to use for the output
97
102
 
98
- attr_reader :op_name
103
+ attr_accessor :op_name
99
104
 
100
105
  ##
101
106
  # Are we promiscuous about showing module contents across multiple files
102
107
 
103
108
  attr_reader :promiscuous
104
109
 
105
- ##
106
- # Don't display progress as we process the files
107
-
108
- attr_reader :quiet
109
-
110
110
  ##
111
111
  # Array of directories to search for files to satisfy an :include:
112
112
 
@@ -144,19 +144,23 @@ class RDoc::Options
144
144
 
145
145
  attr_reader :title
146
146
 
147
+ ##
148
+ # Verbosity, zero means quiet
149
+
150
+ attr_accessor :verbosity
151
+
147
152
  ##
148
153
  # URL of web cvs frontend
149
154
 
150
155
  attr_reader :webcvs
151
156
 
152
- def initialize(generators) # :nodoc:
157
+ def initialize(generators = {}) # :nodoc:
153
158
  @op_dir = "doc"
154
159
  @op_name = nil
155
160
  @show_all = false
156
161
  @main_page = nil
157
162
  @merge = false
158
163
  @exclude = []
159
- @quiet = false
160
164
  @generators = generators
161
165
  @generator_name = 'html'
162
166
  @generator = @generators[@generator_name]
@@ -175,7 +179,7 @@ class RDoc::Options
175
179
  @extra_accessor_flags = {}
176
180
  @promiscuous = false
177
181
  @force_update = false
178
- @title = "RDoc Documentation"
182
+ @verbosity = 1
179
183
 
180
184
  @css = nil
181
185
  @webcvs = nil
@@ -420,9 +424,15 @@ Usage: #{opt.program_name} [options] [names...]
420
424
 
421
425
  opt.on("--quiet", "-q",
422
426
  "Don't show progress as we parse.") do |value|
423
- @quiet = value
427
+ @verbosity = 0
428
+ end
429
+
430
+ opt.on("--verbose", "-v",
431
+ "Display extra progress as we parse.") do |value|
432
+ @verbosity = 2
424
433
  end
425
434
 
435
+
426
436
  opt.separator nil
427
437
 
428
438
  opt.on("--ri", "-r",
@@ -513,6 +523,8 @@ Usage: #{opt.program_name} [options] [names...]
513
523
  end
514
524
  end
515
525
 
526
+ argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']
527
+
516
528
  opts.parse! argv
517
529
 
518
530
  @files = argv.dup
@@ -553,6 +565,17 @@ Usage: #{opt.program_name} [options] [names...]
553
565
  @title ||= string
554
566
  end
555
567
 
568
+ ##
569
+ # Don't display progress as we process the files
570
+
571
+ def quiet
572
+ @verbosity.zero?
573
+ end
574
+
575
+ def quiet=(bool)
576
+ @verbosity = bool ? 0 : 1
577
+ end
578
+
556
579
  private
557
580
 
558
581
  ##
@@ -571,7 +594,7 @@ Usage: #{opt.program_name} [options] [names...]
571
594
  end
572
595
  end
573
596
 
574
- # Check that the right version of 'dot' is available. Unfortuately this
597
+ # Check that the right version of 'dot' is available. Unfortunately this
575
598
  # doesn't work correctly under Windows NT, so we'll bypass the test under
576
599
  # Windows.
577
600
 
@@ -607,8 +630,8 @@ Usage: #{opt.program_name} [options] [names...]
607
630
 
608
631
  def check_files
609
632
  @files.each do |f|
610
- stat = File.stat f rescue abort("File not found: #{f}")
611
- abort("File '#{f}' not readable") unless stat.readable?
633
+ stat = File.stat f
634
+ raise RDoc::Error, "file '#{f}' not readable" unless stat.readable?
612
635
  end
613
636
  end
614
637
 
@@ -0,0 +1,109 @@
1
+ require 'rdoc'
2
+ require 'rdoc/code_objects'
3
+ require 'rdoc/markup/preprocess'
4
+ require 'rdoc/stats'
5
+
6
+ ##
7
+ # A parser is simple a class that implements
8
+ #
9
+ # #initialize(file_name, body, options)
10
+ #
11
+ # and
12
+ #
13
+ # #scan
14
+ #
15
+ # The initialize method takes a file name to be used, the body of the file,
16
+ # and an RDoc::Options object. The scan method is then called to return an
17
+ # appropriately parsed TopLevel code object.
18
+ #
19
+ # The ParseFactory is used to redirect to the correct parser given a
20
+ # filename extension. This magic works because individual parsers have to
21
+ # register themselves with us as they are loaded in. The do this using the
22
+ # following incantation
23
+ #
24
+ # require "rdoc/parser"
25
+ #
26
+ # class RDoc::Parser::Xyz < RDoc::Parser
27
+ # parse_files_matching /\.xyz$/ # <<<<
28
+ #
29
+ # def initialize(file_name, body, options)
30
+ # ...
31
+ # end
32
+ #
33
+ # def scan
34
+ # ...
35
+ # end
36
+ # end
37
+ #
38
+ # Just to make life interesting, if we suspect a plain text file, we also
39
+ # look for a shebang line just in case it's a potential shell script
40
+
41
+ class RDoc::Parser
42
+
43
+ @parsers = []
44
+
45
+ class << self
46
+ attr_reader :parsers
47
+ end
48
+
49
+ ##
50
+ # Alias an extension to another extension. After this call, files ending
51
+ # "new_ext" will be parsed using the same parser as "old_ext"
52
+
53
+ def self.alias_extension(old_ext, new_ext)
54
+ old_ext = old_ext.sub(/^\.(.*)/, '\1')
55
+ new_ext = new_ext.sub(/^\.(.*)/, '\1')
56
+
57
+ parser = can_parse "xxx.#{old_ext}"
58
+ return false unless parser
59
+
60
+ RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser]
61
+
62
+ true
63
+ end
64
+
65
+ ##
66
+ # Return a parser that can handle a particular extension
67
+
68
+ def self.can_parse(file_name)
69
+ RDoc::Parser.parsers.find { |regexp, parser| regexp =~ file_name }.last
70
+ end
71
+
72
+ ##
73
+ # Find the correct parser for a particular file name. Return a SimpleParser
74
+ # for ones that we don't know
75
+
76
+ def self.for(top_level, file_name, body, options, stats)
77
+ # If no extension, look for shebang
78
+ if file_name !~ /\.\w+$/ && body =~ %r{\A#!(.+)} then
79
+ shebang = $1
80
+ case shebang
81
+ when %r{env\s+ruby}, %r{/ruby}
82
+ file_name = "dummy.rb"
83
+ end
84
+ end
85
+
86
+ parser = can_parse file_name
87
+
88
+ parser.new top_level, file_name, body, options, stats
89
+ end
90
+
91
+ ##
92
+ # Record which file types this parser can understand.
93
+
94
+ def self.parse_files_matching(regexp)
95
+ RDoc::Parser.parsers.unshift [regexp, self]
96
+ end
97
+
98
+ def initialize(top_level, file_name, content, options, stats)
99
+ @top_level = top_level
100
+ @file_name = file_name
101
+ @content = content
102
+ @options = options
103
+ @stats = stats
104
+ end
105
+
106
+ end
107
+
108
+ require 'rdoc/parser/simple'
109
+