rdoc 4.0.0 → 4.0.1

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.

@@ -12,7 +12,7 @@
12
12
  Alphanumeric = /[0-9A-Za-z\200-\377]/
13
13
  AlphanumericAscii = /[A-Za-z0-9]/
14
14
  BOM = "\357\273\277"
15
- Newline = "\n" | "\r" "\n"?
15
+ Newline = /\n|\r\n?/
16
16
  NonAlphanumeric = /[\000-\057\072-\100\133-\140\173-\177]/
17
- Spacechar = " " | "\t"
17
+ Spacechar = / |\t/
18
18
 
@@ -381,39 +381,9 @@ class RDoc::Markdown::Literals
381
381
  return _tmp
382
382
  end
383
383
 
384
- # Newline = ("\n" | "
384
+ # Newline = /\n|\r\n?/
385
385
  def _Newline
386
-
387
- _save = self.pos
388
- while true # choice
389
- _tmp = match_string("\n")
390
- break if _tmp
391
- self.pos = _save
392
-
393
- _save1 = self.pos
394
- while true # sequence
395
- _tmp = match_string("\r")
396
- unless _tmp
397
- self.pos = _save1
398
- break
399
- end
400
- _save2 = self.pos
401
- _tmp = match_string("\n")
402
- unless _tmp
403
- _tmp = true
404
- self.pos = _save2
405
- end
406
- unless _tmp
407
- self.pos = _save1
408
- end
409
- break
410
- end # end sequence
411
-
412
- break if _tmp
413
- self.pos = _save
414
- break
415
- end # end choice
416
-
386
+ _tmp = scan(/\A(?-mix:\n|\r\n?)/)
417
387
  set_failed_rule :_Newline unless _tmp
418
388
  return _tmp
419
389
  end
@@ -425,20 +395,9 @@ class RDoc::Markdown::Literals
425
395
  return _tmp
426
396
  end
427
397
 
428
- # Spacechar = (" " | "\t")
398
+ # Spacechar = / |\t/
429
399
  def _Spacechar
430
-
431
- _save = self.pos
432
- while true # choice
433
- _tmp = match_string(" ")
434
- break if _tmp
435
- self.pos = _save
436
- _tmp = match_string("\t")
437
- break if _tmp
438
- self.pos = _save
439
- break
440
- end # end choice
441
-
400
+ _tmp = scan(/\A(?-mix: |\t)/)
442
401
  set_failed_rule :_Spacechar unless _tmp
443
402
  return _tmp
444
403
  end
@@ -447,8 +406,8 @@ class RDoc::Markdown::Literals
447
406
  Rules[:_Alphanumeric] = rule_info("Alphanumeric", "/[0-9A-Za-z\\200-\\377]/")
448
407
  Rules[:_AlphanumericAscii] = rule_info("AlphanumericAscii", "/[A-Za-z0-9]/")
449
408
  Rules[:_BOM] = rule_info("BOM", "\"\"")
450
- Rules[:_Newline] = rule_info("Newline", "(\"\\n\" | \"
409
+ Rules[:_Newline] = rule_info("Newline", "/\\n|\\r\\n?/")
451
410
  Rules[:_NonAlphanumeric] = rule_info("NonAlphanumeric", "/[\\000-\\057\\072-\\100\\133-\\140\\173-\\177]/")
452
- Rules[:_Spacechar] = rule_info("Spacechar", "(\" \" | \"\\t\")")
411
+ Rules[:_Spacechar] = rule_info("Spacechar", "/ |\\t/")
453
412
  # :startdoc:
454
413
  end
@@ -59,7 +59,7 @@
59
59
  #
60
60
  # require 'rdoc'
61
61
  #
62
- # h = RDoc::Markup::ToHtml.new
62
+ # h = RDoc::Markup::ToHtml.new(RDoc::Options.new)
63
63
  #
64
64
  # puts h.convert(input_string)
65
65
  #
@@ -176,6 +176,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
176
176
  def accept_paragraph paragraph
177
177
  @res << "\n<p>"
178
178
  text = paragraph.text @hard_break
179
+ text = text.gsub(/\r?\n/, ' ')
179
180
  @res << wrap(to_html(text))
180
181
  @res << "</p>\n"
181
182
  end
@@ -186,19 +187,26 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
186
187
  def accept_verbatim verbatim
187
188
  text = verbatim.text.rstrip
188
189
 
189
- @res << if verbatim.ruby? or parseable? text then
190
- begin
191
- tokens = RDoc::RubyLex.tokenize text, @options
190
+ klass = nil
192
191
 
193
- html = RDoc::TokenStream.to_html tokens
192
+ content = if verbatim.ruby? or parseable? text then
193
+ begin
194
+ tokens = RDoc::RubyLex.tokenize text, @options
195
+ klass = ' class="ruby"'
194
196
 
195
- "\n<pre class=\"ruby\">#{html}</pre>\n"
196
- rescue RDoc::RubyLex::Error
197
- "\n<pre>#{CGI.escapeHTML text}</pre>\n"
197
+ RDoc::TokenStream.to_html tokens
198
+ rescue RDoc::RubyLex::Error
199
+ CGI.escapeHTML text
200
+ end
201
+ else
202
+ CGI.escapeHTML text
198
203
  end
199
- else
200
- "\n<pre>#{CGI.escapeHTML text}</pre>\n"
201
- end
204
+
205
+ if @options.pipe then
206
+ @res << "\n<pre><code>#{CGI.escapeHTML text}</code></pre>\n"
207
+ else
208
+ @res << "\n<pre#{klass}>#{content}</pre>\n"
209
+ end
202
210
  end
203
211
 
204
212
  ##
@@ -52,6 +52,18 @@ require 'pathname'
52
52
  # end
53
53
  # end
54
54
  #
55
+ # Of course, RDoc::Options does not respond to +spell_dictionary+ by default
56
+ # so you will need to add it:
57
+ #
58
+ # class RDoc::Options
59
+ #
60
+ # ##
61
+ # # The spell dictionary used by the spell-checking plugin.
62
+ #
63
+ # attr_accessor :spell_dictionary
64
+ #
65
+ # end
66
+ #
55
67
  # == Option Validators
56
68
  #
57
69
  # OptionParser validators will validate and cast user input values. In
@@ -916,7 +928,7 @@ Usage: #{opt.program_name} [options] [names...]
916
928
  check_generator
917
929
 
918
930
  @generator_name = "ri"
919
- @op_dir = RDoc::RI::Paths::SITEDIR
931
+ @op_dir = RDoc::RI::Paths.site_dir
920
932
  setup_generator
921
933
  end
922
934
 
@@ -991,7 +1003,7 @@ Usage: #{opt.program_name} [options] [names...]
991
1003
 
992
1004
  begin
993
1005
  opts.parse! argv
994
- rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
1006
+ rescue OptionParser::ParseError => e
995
1007
  if DEPRECATED[e.args.first] then
996
1008
  deprecated << e.args.first
997
1009
  elsif %w[--format --ri -r --ri-site -R].include? e.args.first then
@@ -1017,18 +1029,22 @@ Usage: #{opt.program_name} [options] [names...]
1017
1029
  deprecated.each do |opt|
1018
1030
  $stderr.puts 'option ' << opt << ' is deprecated: ' << DEPRECATED[opt]
1019
1031
  end
1032
+ end
1020
1033
 
1021
- unless invalid.empty? then
1022
- invalid = "invalid options: #{invalid.join ', '}"
1034
+ unless invalid.empty? then
1035
+ invalid = "invalid options: #{invalid.join ', '}"
1023
1036
 
1024
- if ignore_invalid then
1037
+ if ignore_invalid then
1038
+ unless quiet then
1025
1039
  $stderr.puts invalid
1026
1040
  $stderr.puts '(invalid options are ignored)'
1027
- else
1041
+ end
1042
+ else
1043
+ unless quiet then
1028
1044
  $stderr.puts opts
1029
- $stderr.puts invalid
1030
- exit 1
1031
1045
  end
1046
+ $stderr.puts invalid
1047
+ exit 1
1032
1048
  end
1033
1049
  end
1034
1050
 
@@ -218,6 +218,8 @@ class RDoc::Parser
218
218
 
219
219
  return unless parser
220
220
 
221
+ content = remove_modeline content
222
+
221
223
  parser.new top_level, file_name, content, options, stats
222
224
  rescue SystemCallError
223
225
  nil
@@ -232,6 +234,13 @@ class RDoc::Parser
232
234
  RDoc::Parser.parsers.unshift [regexp, self]
233
235
  end
234
236
 
237
+ ##
238
+ # Removes an emacs-style modeline from the first line of the document
239
+
240
+ def self.remove_modeline content
241
+ content.sub(/\A.*-\*-\s*(.*?\S)\s*-\*-.*\r?\n/, '')
242
+ end
243
+
235
244
  ##
236
245
  # If there is a <tt>markup: parser_name</tt> comment at the front of the
237
246
  # file, use it to determine the parser. For example:
@@ -173,6 +173,9 @@ class RDoc::Parser::C < RDoc::Parser
173
173
  @classes = load_variable_map :c_class_variables
174
174
  @singleton_classes = load_variable_map :c_singleton_class_variables
175
175
 
176
+ # class_variable => { function => [method, ...] }
177
+ @methods = Hash.new { |h, f| h[f] = Hash.new { |i, m| i[m] = [] } }
178
+
176
179
  # missing variable => [handle_class_module arguments]
177
180
  @missing_dependencies = {}
178
181
 
@@ -206,6 +209,41 @@ class RDoc::Parser::C < RDoc::Parser
206
209
  end
207
210
  end
208
211
 
212
+ ##
213
+ # Removes duplicate call-seq entries for methods using the same
214
+ # implementation.
215
+
216
+ def deduplicate_call_seq
217
+ @methods.each do |var_name, functions|
218
+ class_name = @known_classes[var_name]
219
+ class_obj = find_class var_name, class_name
220
+
221
+ functions.each_value do |method_names|
222
+ next if method_names.length == 1
223
+
224
+ method_names.each do |method_name|
225
+ deduplicate_method_name class_obj, method_name
226
+ end
227
+ end
228
+ end
229
+ end
230
+
231
+ def deduplicate_method_name class_obj, method_name
232
+ return unless
233
+ method = class_obj.method_list.find { |m| m.name == method_name }
234
+ return unless call_seq = method.call_seq
235
+
236
+ method_name = method_name[0, 1] unless method_name =~ /\A\w/
237
+
238
+ entries = call_seq.split "\n"
239
+
240
+ matching = entries.select do |entry|
241
+ entry =~ /^\w*\.?#{Regexp.escape method_name}/
242
+ end
243
+
244
+ method.call_seq = matching.join "\n"
245
+ end
246
+
209
247
  ##
210
248
  # Scans #content for rb_define_alias
211
249
 
@@ -422,7 +460,7 @@ class RDoc::Parser::C < RDoc::Parser
422
460
  )
423
461
  \s*\(\s*([\w\.]+),
424
462
  \s*"([^"]+)",
425
- \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
463
+ \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\(|\(METHOD\))?(\w+)\)?,
426
464
  \s*(-?\w+)\s*\)
427
465
  (?:;\s*/[*/]\s+in\s+(\w+?\.(?:cpp|c|y)))?
428
466
  %xm) do |type, var_name, meth_name, function, param_count, source_file|
@@ -938,6 +976,8 @@ class RDoc::Parser::C < RDoc::Parser
938
976
  class_name = @known_classes[var_name]
939
977
  singleton = @singleton_classes.key? var_name
940
978
 
979
+ @methods[var_name][function] << meth_name
980
+
941
981
  return unless class_name
942
982
 
943
983
  class_obj = find_class var_name, class_name
@@ -1172,6 +1212,8 @@ class RDoc::Parser::C < RDoc::Parser
1172
1212
  do_aliases
1173
1213
  do_attrs
1174
1214
 
1215
+ deduplicate_call_seq
1216
+
1175
1217
  @store.add_c_variables self
1176
1218
 
1177
1219
  @top_level
@@ -342,6 +342,8 @@ option)
342
342
 
343
343
  @stats.add_file filename
344
344
 
345
+ return if RDoc::Parser.binary? filename
346
+
345
347
  content = RDoc::Encoding.read_file filename, encoding
346
348
 
347
349
  return unless content
@@ -1412,7 +1412,9 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
1412
1412
 
1413
1413
  server = WEBrick::HTTPServer.new :Port => @server
1414
1414
 
1415
- server.mount '/', RDoc::Servlet
1415
+ extra_doc_dirs = @stores.map {|s| s.type == :extra ? s.path : nil}.compact
1416
+
1417
+ server.mount '/', RDoc::Servlet, nil, extra_doc_dirs
1416
1418
 
1417
1419
  trap 'INT' do server.shutdown end
1418
1420
  trap 'TERM' do server.shutdown end
@@ -1028,6 +1028,8 @@ class RDoc::RubyLex
1028
1028
  end
1029
1029
 
1030
1030
  if output_heredoc then
1031
+ raise Error, "Missing terminating #{quoted} for string" unless l
1032
+
1031
1033
  doc << l.chomp
1032
1034
  else
1033
1035
  doc << '"'
@@ -12,6 +12,7 @@ require 'rdoc'
12
12
  class RDoc::RubygemsHook
13
13
 
14
14
  include Gem::UserInteraction
15
+ extend Gem::UserInteraction
15
16
 
16
17
  @rdoc_version = nil
17
18
  @specs = []
@@ -45,7 +46,8 @@ class RDoc::RubygemsHook
45
46
  # +specs+
46
47
 
47
48
  def self.generation_hook installer, specs
48
- types = installer.document
49
+ start = Time.now
50
+ types = installer.document
49
51
 
50
52
  generate_rdoc = types.include? 'rdoc'
51
53
  generate_ri = types.include? 'ri'
@@ -53,6 +55,13 @@ class RDoc::RubygemsHook
53
55
  specs.each do |spec|
54
56
  new(spec, generate_rdoc, generate_ri).generate
55
57
  end
58
+
59
+ return unless generate_rdoc or generate_ri
60
+
61
+ duration = (Time.now - start).to_i
62
+ names = specs.map(&:name).join ', '
63
+
64
+ say "Done installing documentation for #{names} after #{duration} seconds"
56
65
  end
57
66
 
58
67
  ##
@@ -53,14 +53,17 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
53
53
  #
54
54
  # Use +mount_path+ when mounting the servlet somewhere other than /.
55
55
  #
56
+ # Use +extra_doc_dirs+ for additional documentation directories.
57
+ #
56
58
  # +server+ is provided automatically by WEBrick when mounting. +stores+ and
57
59
  # +cache+ are provided automatically by the servlet.
58
60
 
59
- def initialize server, stores, cache, mount_path = nil
61
+ def initialize server, stores, cache, mount_path = nil, extra_doc_dirs = []
60
62
  super server
61
63
 
62
64
  @cache = cache
63
65
  @mount_path = mount_path
66
+ @extra_doc_dirs = extra_doc_dirs
64
67
  @stores = stores
65
68
 
66
69
  @options = RDoc::Options.new
@@ -270,6 +273,7 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
270
273
  # and the filesystem to the RDoc::Store for the documentation.
271
274
 
272
275
  def installed_docs
276
+ extra_counter = 0
273
277
  ri_paths.map do |path, type|
274
278
  store = RDoc::Store.new path, type
275
279
  exists = File.exist? store.cache_path
@@ -284,6 +288,11 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
284
288
  ['Site Documentation', 'site/', exists, type, path]
285
289
  when :home then
286
290
  ['Home Documentation', 'home/', exists, type, path]
291
+ when :extra then
292
+ extra_counter += 1
293
+ store.load_cache if exists
294
+ title = store.title || "Extra Documentation"
295
+ [title, "extra-#{extra_counter}/", exists, type, path]
287
296
  end
288
297
  end
289
298
  end
@@ -300,7 +309,7 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
300
309
  # Enumerates the ri paths. See RDoc::RI::Paths#each
301
310
 
302
311
  def ri_paths &block
303
- RDoc::RI::Paths.each true, true, true, :all, &block
312
+ RDoc::RI::Paths.each true, true, true, :all, *@extra_doc_dirs, &block #TODO: pass extra_dirs
304
313
  end
305
314
 
306
315
  ##
@@ -344,6 +353,8 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
344
353
  when :home then
345
354
  path = 'home'
346
355
  comment = 'Documentation from your home directory'
356
+ when :extra
357
+ comment = name
347
358
  end
348
359
 
349
360
  info << [name, '', path, '', comment]
@@ -397,6 +408,10 @@ version. If you're viewing Ruby's documentation, include the version of ruby.
397
408
  RDoc::Store.new RDoc::RI::Paths.system_dir, :system
398
409
  when 'site' then
399
410
  RDoc::Store.new RDoc::RI::Paths.site_dir, :site
411
+ when /^extra-(\d+)$/ then
412
+ index = $1.to_i - 1
413
+ ri_dir = installed_docs[index][4]
414
+ RDoc::Store.new ri_dir, :extra
400
415
  else
401
416
  ri_dir, type = ri_paths.find do |dir, dir_type|
402
417
  next unless dir_type == :gem
@@ -140,7 +140,7 @@ module RDoc::Text
140
140
  def snippet text, limit = 100
141
141
  document = parse text
142
142
 
143
- RDoc::Markup::ToHtmlSnippet.new(limit).convert document
143
+ RDoc::Markup::ToHtmlSnippet.new(options, limit).convert document
144
144
  end
145
145
 
146
146
  ##
@@ -165,6 +165,7 @@ class TestRDocClassModule < XrefTestCase
165
165
  ns = tl.add_module RDoc::NormalModule, 'Namespace'
166
166
 
167
167
  cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super'
168
+ cm.document_self = true
168
169
  cm.record_location tl
169
170
 
170
171
  a1 = RDoc::Attr.new nil, 'a1', 'RW', ''
@@ -236,6 +237,58 @@ class TestRDocClassModule < XrefTestCase
236
237
  assert_equal tl, loaded.method_list.first.file
237
238
  end
238
239
 
240
+ def test_marshal_dump_visibilty
241
+ @store.path = Dir.tmpdir
242
+ tl = @store.add_file 'file.rb'
243
+
244
+ ns = tl.add_module RDoc::NormalModule, 'Namespace'
245
+
246
+ cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super'
247
+ cm.record_location tl
248
+
249
+ a1 = RDoc::Attr.new nil, 'a1', 'RW', ''
250
+ a1.record_location tl
251
+ a1.document_self = false
252
+
253
+ m1 = RDoc::AnyMethod.new nil, 'm1'
254
+ m1.record_location tl
255
+ m1.document_self = false
256
+
257
+ c1 = RDoc::Constant.new 'C1', nil, ''
258
+ c1.record_location tl
259
+ c1.document_self = false
260
+
261
+ i1 = RDoc::Include.new 'I1', ''
262
+ i1.record_location tl
263
+ i1.document_self = false
264
+
265
+ e1 = RDoc::Extend.new 'E1', ''
266
+ e1.record_location tl
267
+ e1.document_self = false
268
+
269
+ section_comment = RDoc::Comment.new('section comment')
270
+ section_comment.location = tl
271
+
272
+ assert_equal 1, cm.sections.length, 'sanity, default section only'
273
+
274
+ cm.add_attribute a1
275
+ cm.add_method m1
276
+ cm.add_constant c1
277
+ cm.add_include i1
278
+ cm.add_extend e1
279
+ cm.add_comment 'this is a comment', tl
280
+
281
+ loaded = Marshal.load Marshal.dump cm
282
+ loaded.store = @store
283
+
284
+ assert_equal cm, loaded
285
+
286
+ assert_empty loaded.attributes
287
+ assert_empty loaded.constants
288
+ assert_empty loaded.includes
289
+ assert_empty loaded.extends
290
+ assert_empty loaded.method_list
291
+ end
239
292
  def test_marshal_load_version_0
240
293
  tl = @store.add_file 'file.rb'
241
294
  ns = tl.add_module RDoc::NormalModule, 'Namespace'