rdoc 4.1.2 → 4.2.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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/.autotest +3 -1
  3. data/History.rdoc +70 -3
  4. data/LEGAL.rdoc +11 -0
  5. data/Manifest.txt +6 -2
  6. data/Rakefile +8 -1
  7. data/lib/rdoc.rb +3 -1
  8. data/lib/rdoc/context.rb +2 -0
  9. data/lib/rdoc/encoding.rb +3 -1
  10. data/lib/rdoc/generator.rb +1 -0
  11. data/lib/rdoc/generator/darkfish.rb +3 -2
  12. data/lib/rdoc/generator/json_index.rb +44 -0
  13. data/lib/rdoc/generator/pot.rb +97 -0
  14. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
  15. data/lib/rdoc/generator/template/darkfish/_head.rhtml +9 -12
  16. data/lib/rdoc/generator/template/darkfish/{fonts.css → css/fonts.css} +0 -0
  17. data/lib/rdoc/generator/template/darkfish/{rdoc.css → css/rdoc.css} +11 -1
  18. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +32 -11
  19. data/lib/rdoc/markdown.kpeg +6 -1
  20. data/lib/rdoc/markdown.rb +174 -2
  21. data/lib/rdoc/markup.rb +2 -2
  22. data/lib/rdoc/markup/attribute_manager.rb +1 -1
  23. data/lib/rdoc/markup/to_html.rb +5 -4
  24. data/lib/rdoc/markup/to_label.rb +1 -1
  25. data/lib/rdoc/method_attr.rb +11 -3
  26. data/lib/rdoc/options.rb +55 -3
  27. data/lib/rdoc/parser.rb +1 -1
  28. data/lib/rdoc/parser/c.rb +5 -6
  29. data/lib/rdoc/parser/changelog.rb +7 -3
  30. data/lib/rdoc/parser/ruby.rb +8 -12
  31. data/lib/rdoc/rd/block_parser.rb +1 -1
  32. data/lib/rdoc/rd/inline_parser.rb +1 -1
  33. data/lib/rdoc/rdoc.rb +5 -3
  34. data/lib/rdoc/ruby_lex.rb +3 -3
  35. data/lib/rdoc/ruby_token.rb +7 -7
  36. data/lib/rdoc/single_class.rb +4 -0
  37. data/lib/rdoc/stats.rb +4 -0
  38. data/lib/rdoc/stats/normal.rb +22 -11
  39. data/lib/rdoc/task.rb +1 -1
  40. data/lib/rdoc/test_case.rb +1 -1
  41. data/lib/rdoc/text.rb +9 -0
  42. data/lib/rdoc/token_stream.rb +1 -1
  43. data/test/test_rdoc_context.rb +2 -0
  44. data/test/test_rdoc_encoding.rb +23 -0
  45. data/test/test_rdoc_generator_darkfish.rb +2 -2
  46. data/test/test_rdoc_generator_json_index.rb +55 -0
  47. data/test/test_rdoc_generator_markup.rb +1 -1
  48. data/test/test_rdoc_generator_pot.rb +91 -0
  49. data/test/test_rdoc_generator_pot_po.rb +51 -0
  50. data/test/test_rdoc_generator_pot_po_entry.rb +139 -0
  51. data/test/test_rdoc_i18n_locale.rb +73 -0
  52. data/test/test_rdoc_i18n_text.rb +123 -0
  53. data/test/test_rdoc_markup_attribute_manager.rb +6 -0
  54. data/test/test_rdoc_markup_heading.rb +4 -4
  55. data/test/test_rdoc_markup_pre_process.rb +1 -1
  56. data/test/test_rdoc_markup_to_html.rb +46 -26
  57. data/test/test_rdoc_markup_to_html_snippet.rb +8 -7
  58. data/test/test_rdoc_markup_to_label.rb +4 -4
  59. data/test/test_rdoc_method_attr.rb +31 -1
  60. data/test/test_rdoc_normal_class.rb +4 -4
  61. data/test/test_rdoc_options.rb +19 -0
  62. data/test/test_rdoc_parser.rb +16 -1
  63. data/test/test_rdoc_parser_c.rb +31 -1
  64. data/test/test_rdoc_parser_changelog.rb +1 -1
  65. data/test/test_rdoc_parser_markdown.rb +1 -1
  66. data/test/test_rdoc_parser_rd.rb +1 -1
  67. data/test/test_rdoc_parser_ruby.rb +22 -25
  68. data/test/test_rdoc_parser_simple.rb +1 -1
  69. data/test/test_rdoc_rd_block_parser.rb +3 -1
  70. data/test/test_rdoc_rdoc.rb +24 -3
  71. data/test/test_rdoc_ruby_lex.rb +11 -0
  72. data/test/test_rdoc_rubygems_hook.rb +0 -3
  73. data/test/test_rdoc_single_class.rb +13 -5
  74. data/test/test_rdoc_stats.rb +55 -0
  75. data/test/test_rdoc_task.rb +1 -0
  76. metadata +18 -7
@@ -83,7 +83,7 @@ class RDoc::Parser
83
83
  mode = "r"
84
84
  s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
85
85
  encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
86
- mode = "r:#{encoding}" if encoding
86
+ mode = "rb:#{encoding}" if encoding
87
87
  s = File.open(file, mode) {|f| f.gets(nil, 1024)}
88
88
 
89
89
  not s.valid_encoding?
@@ -611,7 +611,7 @@ class RDoc::Parser::C < RDoc::Parser
611
611
  def find_body class_name, meth_name, meth_obj, file_content, quiet = false
612
612
  case file_content
613
613
  when %r%((?>/\*.*?\*/\s*)?)
614
- ((?:(?:static|SWIGINTERN)\s+)?
614
+ ((?:(?:\w+)\s+)?
615
615
  (?:intern\s+)?VALUE\s+#{meth_name}
616
616
  \s*(\([^)]*\))([^;]|$))%xm then
617
617
  comment = RDoc::Comment.new $1, @top_level
@@ -745,11 +745,11 @@ class RDoc::Parser::C < RDoc::Parser
745
745
  elsif @content =~ %r%Document-(?:class|module):\s+#{class_name}\s*?
746
746
  (?:<\s+[:,\w]+)?\n((?>.*?\*/))%xm then
747
747
  comment = "/*\n#{$1}"
748
- elsif @content =~ %r%.*((?>/\*.*?\*/\s+))
749
- ([\w\.\s]+\s* = \s+)?rb_define_(class|module).*?"(#{class_name})"%xm then
748
+ elsif @content =~ %r%((?>/\*.*?\*/\s+))
749
+ ([\w\.\s]+\s* = \s+)?rb_define_(class|module)[\t (]*?"(#{class_name})"%xm then
750
750
  comment = $1
751
- elsif @content =~ %r%.*((?>/\*.*?\*/\s+))
752
- ([\w\.\s]+\s* = \s+)?rb_define_(class|module)_under.*?"(#{class_name.split('::').last})"%xm then
751
+ elsif @content =~ %r%((?>/\*.*?\*/\s+))
752
+ ([\w\. \t]+ = \s+)?rb_define_(class|module)_under[\t\w, (]*?"(#{class_name.split('::').last})"%xm then
753
753
  comment = $1
754
754
  else
755
755
  comment = ''
@@ -1186,7 +1186,6 @@ class RDoc::Parser::C < RDoc::Parser
1186
1186
 
1187
1187
  if hash then
1188
1188
  args << "p#{position} = {}"
1189
- position += 1
1190
1189
  end
1191
1190
 
1192
1191
  args << '&block' if block
@@ -145,10 +145,14 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
145
145
  # HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
146
146
  entry_name = nil unless entry_name =~ /#{time.year}/
147
147
  rescue NoMethodError
148
- time, = entry_name.split ' ', 2
149
- time = Time.parse time
148
+ # HACK Ruby 2.1.2 and earlier raises NoMethodError if time part is absent
149
+ entry_name.split ' ', 2
150
150
  rescue ArgumentError
151
- entry_name = nil
151
+ if /out of range/ =~ $!.message
152
+ Time.parse(entry_name.split(' ', 2)[0]) rescue entry_name = nil
153
+ else
154
+ entry_name = nil
155
+ end
152
156
  end
153
157
 
154
158
  entry_body = []
@@ -187,15 +187,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
187
187
  end
188
188
 
189
189
  ##
190
- # Extracts the visibility information for the visibility token +tk+.
190
+ # Extracts the visibility information for the visibility token +tk+
191
+ # and +single+ class type identifier.
191
192
  #
192
193
  # Returns the visibility type (a string), the visibility (a symbol) and
193
194
  # +singleton+ if the methods following should be converted to singleton
194
195
  # methods.
195
196
 
196
- def get_visibility_information tk # :nodoc:
197
+ def get_visibility_information tk, single # :nodoc:
197
198
  vis_type = tk.name
198
- singleton = false
199
+ singleton = single == SINGLE
199
200
 
200
201
  vis =
201
202
  case vis_type
@@ -845,7 +846,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
845
846
  # true, no found constants will be added to RDoc.
846
847
 
847
848
  def parse_constant container, tk, comment, ignore_constants = false
848
- prev_container = container
849
849
  offset = tk.seek
850
850
  line_no = tk.line_no
851
851
 
@@ -868,8 +868,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
868
868
  end
869
869
 
870
870
  unless TkASSIGN === eq_tk then
871
- suppress_parents container, prev_container
872
-
873
871
  unget_tk eq_tk
874
872
  return false
875
873
  end
@@ -893,7 +891,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
893
891
  read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
894
892
 
895
893
  @stats.add_constant con
896
- con = container.add_constant con
894
+ container.add_constant con
897
895
 
898
896
  true
899
897
  end
@@ -1309,7 +1307,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1309
1307
  return unless name
1310
1308
 
1311
1309
  meth = RDoc::AnyMethod.new get_tkread, name
1312
- meth.singleton = singleton
1310
+ meth.singleton = single == SINGLE ? true : singleton
1313
1311
 
1314
1312
  record_location meth
1315
1313
  meth.offset = offset
@@ -1879,9 +1877,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1879
1877
  # Determines the visibility in +container+ from +tk+
1880
1878
 
1881
1879
  def parse_visibility(container, single, tk)
1882
- singleton = (single == SINGLE)
1883
-
1884
- vis_type, vis, singleton = get_visibility_information tk
1880
+ vis_type, vis, singleton = get_visibility_information tk, single
1885
1881
 
1886
1882
  skip_tkspace_comment false
1887
1883
 
@@ -2082,7 +2078,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
2082
2078
 
2083
2079
  def skip_for_variable
2084
2080
  skip_tkspace false
2085
- tk = get_tk
2081
+ get_tk
2086
2082
  skip_tkspace false
2087
2083
  tk = get_tk
2088
2084
  unget_tk(tk) unless TkIN === tk
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.11
3
+ # This file is automatically generated by Racc 1.4.12
4
4
  # from Racc grammer file "".
5
5
  #
6
6
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.11
3
+ # This file is automatically generated by Racc 1.4.12
4
4
  # from Racc grammer file "".
5
5
  #
6
6
 
@@ -305,6 +305,9 @@ option)
305
305
  when "directory" then
306
306
  next if rel_file_name == "CVS" || rel_file_name == ".svn"
307
307
 
308
+ created_rid = File.join rel_file_name, "created.rid"
309
+ next if File.file? created_rid
310
+
308
311
  dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
309
312
 
310
313
  if File.file? dot_doc then
@@ -336,7 +339,7 @@ option)
336
339
  # Parses +filename+ and returns an RDoc::TopLevel
337
340
 
338
341
  def parse_file filename
339
- if defined?(Encoding) then
342
+ if Object.const_defined? :Encoding then
340
343
  encoding = @options.encoding
341
344
  filename = filename.encode encoding
342
345
  end
@@ -411,8 +414,6 @@ The internal error was:
411
414
 
412
415
  return [] if file_list.empty?
413
416
 
414
- file_info = []
415
-
416
417
  @stats.begin_adding
417
418
 
418
419
  file_info = file_list.map do |filename|
@@ -565,4 +566,5 @@ end
565
566
  # require built-in generators after discovery in case they've been replaced
566
567
  require 'rdoc/generator/darkfish'
567
568
  require 'rdoc/generator/ri'
569
+ require 'rdoc/generator/pot'
568
570
 
@@ -434,7 +434,7 @@ class RDoc::RubyLex
434
434
  |op, io|
435
435
  @ltype = "="
436
436
  res = ''
437
- nil until (ch = getc) == "\n"
437
+ nil until getc == "\n"
438
438
 
439
439
  until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do
440
440
  (ch = getc)
@@ -1184,9 +1184,9 @@ class RDoc::RubyLex
1184
1184
  str = if ltype == quoted and %w[" ' /].include? ltype then
1185
1185
  ltype.dup
1186
1186
  elsif RUBY_VERSION > '1.9' then
1187
- "%#{type or PERCENT_LTYPE.key ltype}#{PERCENT_PAREN_REV[quoted]}"
1187
+ "%#{type or PERCENT_LTYPE.key ltype}#{PERCENT_PAREN_REV[quoted]||quoted}"
1188
1188
  else
1189
- "%#{type or PERCENT_LTYPE.index ltype}#{PERCENT_PAREN_REV[quoted]}"
1189
+ "%#{type or PERCENT_LTYPE.index ltype}#{PERCENT_PAREN_REV[quoted]||quoted}"
1190
1190
  end
1191
1191
 
1192
1192
  subtype = nil
@@ -38,9 +38,9 @@ module RDoc::RubyToken
38
38
  @text = text
39
39
  end
40
40
 
41
- attr :seek
42
- attr :line_no
43
- attr :char_no
41
+ attr_reader :seek
42
+ attr_reader :line_no
43
+ attr_reader :char_no
44
44
 
45
45
  attr_accessor :text
46
46
 
@@ -73,7 +73,7 @@ module RDoc::RubyToken
73
73
  @node = node
74
74
  end
75
75
 
76
- attr :node
76
+ attr_reader:node
77
77
 
78
78
  def ==(other)
79
79
  self.class == other.class and
@@ -101,7 +101,7 @@ module RDoc::RubyToken
101
101
  super(seek, line_no, char_no)
102
102
  @name = name
103
103
  end
104
- attr :name
104
+ attr_reader:name
105
105
 
106
106
  def ==(other)
107
107
  self.class == other.class and
@@ -192,7 +192,7 @@ module RDoc::RubyToken
192
192
  @text = nil
193
193
  end
194
194
 
195
- attr :op
195
+ attr_reader:op
196
196
 
197
197
  def ==(other)
198
198
  self.class == other.class and
@@ -217,7 +217,7 @@ module RDoc::RubyToken
217
217
  super(seek, line_no, char_no)
218
218
  @name = name
219
219
  end
220
- attr :name
220
+ attr_reader:name
221
221
 
222
222
  def ==(other)
223
223
  self.class == other.class and
@@ -10,6 +10,10 @@ class RDoc::SingleClass < RDoc::ClassModule
10
10
  superclass ? super + [superclass] : super
11
11
  end
12
12
 
13
+ def aref_prefix # :nodoc:
14
+ 'sclass'
15
+ end
16
+
13
17
  ##
14
18
  # The definition of this singleton class, <tt>class << MyClassName</tt>
15
19
 
@@ -4,6 +4,8 @@
4
4
 
5
5
  class RDoc::Stats
6
6
 
7
+ include RDoc::Text
8
+
7
9
  ##
8
10
  # Output level for the coverage report
9
11
 
@@ -438,6 +440,8 @@ class RDoc::Stats
438
440
 
439
441
  params = method.param_list
440
442
 
443
+ params = params.map { |param| param.gsub(/^\*\*?/, '') }
444
+
441
445
  return 0, [] if params.empty?
442
446
 
443
447
  document = parse method.comment
@@ -1,3 +1,8 @@
1
+ begin
2
+ require 'io/console/size'
3
+ rescue LoadError
4
+ end
5
+
1
6
  ##
2
7
  # Stats printer that prints just the files being documented with a progress
3
8
  # bar
@@ -5,15 +10,14 @@
5
10
  class RDoc::Stats::Normal < RDoc::Stats::Quiet
6
11
 
7
12
  def begin_adding # :nodoc:
8
- puts "Parsing sources..." if $stdout.tty?
13
+ puts "Parsing sources..."
14
+ @last_width = 0
9
15
  end
10
16
 
11
17
  ##
12
18
  # Prints a file with a progress bar
13
19
 
14
20
  def print_file files_so_far, filename
15
- return unless $stdout.tty?
16
-
17
21
  progress_bar = sprintf("%3d%% [%2d/%2d] ",
18
22
  100 * files_so_far / @num_files,
19
23
  files_so_far,
@@ -21,7 +25,11 @@ class RDoc::Stats::Normal < RDoc::Stats::Quiet
21
25
 
22
26
  # Print a progress bar, but make sure it fits on a single line. Filename
23
27
  # will be truncated if necessary.
24
- terminal_width = (ENV['COLUMNS'] || 80).to_i
28
+ terminal_width = if defined?(IO) && IO.respond_to?(:console_size)
29
+ IO.console_size[1].to_i.nonzero? || 80
30
+ else
31
+ 80
32
+ end
25
33
  max_filename_size = terminal_width - progress_bar.size
26
34
 
27
35
  if filename.size > max_filename_size then
@@ -30,18 +38,21 @@ class RDoc::Stats::Normal < RDoc::Stats::Quiet
30
38
  filename[0..2] = "..."
31
39
  end
32
40
 
33
- # Pad the line with whitespaces so that leftover output from the
34
- # previous line doesn't show up.
35
41
  line = "#{progress_bar}#{filename}"
36
- padding = terminal_width - line.size
37
- line << (" " * padding) if padding > 0
38
-
39
- $stdout.print("#{line}\r")
42
+ if $stdout.tty?
43
+ # Clean the line with whitespaces so that leftover output from the
44
+ # previous line doesn't show up.
45
+ $stdout.print("\r" << (" " * @last_width) << ("\b" * @last_width) << "\r") if @last_width && @last_width > 0
46
+ @last_width = line.size
47
+ $stdout.print("#{line}\r")
48
+ else
49
+ $stdout.puts(line)
50
+ end
40
51
  $stdout.flush
41
52
  end
42
53
 
43
54
  def done_adding # :nodoc:
44
- puts if $stdout.tty?
55
+ puts
45
56
  end
46
57
 
47
58
  end
@@ -291,7 +291,7 @@ class RDoc::Task < Rake::TaskLib
291
291
  private
292
292
 
293
293
  def rdoc_target
294
- "#{rdoc_dir}/index.html"
294
+ "#{rdoc_dir}/created.rid"
295
295
  end
296
296
 
297
297
  def rdoc_task_name
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  begin
4
4
  gem 'minitest', '~> 4.0' unless defined?(Test::Unit)
5
- rescue NoMethodError
5
+ rescue NoMethodError, Gem::LoadError
6
6
  # for ruby tests
7
7
  end
8
8
 
@@ -103,6 +103,15 @@ module RDoc::Text
103
103
  # Requires the including class to implement #formatter
104
104
 
105
105
  def markup text
106
+ if @store.rdoc.options
107
+ locale = @store.rdoc.options.locale
108
+ else
109
+ locale = nil
110
+ end
111
+ if locale
112
+ i18n_text = RDoc::I18n::Text.new(text)
113
+ text = i18n_text.translate(locale)
114
+ end
106
115
  parse(text).accept formatter
107
116
  end
108
117
 
@@ -88,7 +88,7 @@ module RDoc::TokenStream
88
88
  # Returns a string representation of the token stream
89
89
 
90
90
  def tokens_to_s
91
- token_stream.map { |token| token.text }.join ''
91
+ token_stream.compact.map { |token| token.text }.join ''
92
92
  end
93
93
 
94
94
  end
@@ -621,6 +621,8 @@ class TestRDocContext < XrefTestCase
621
621
 
622
622
  assert_equal 1, @c2_c3.<=>(@c2)
623
623
  assert_equal(-1, @c2_c3.<=>(@c3))
624
+
625
+ assert_nil @c2.<=>(Gem.loaded_specs.values.first)
624
626
  end
625
627
 
626
628
  def test_methods_by_type
@@ -10,6 +10,12 @@ class TestRDocEncoding < RDoc::TestCase
10
10
  @tempfile = Tempfile.new 'test_rdoc_encoding'
11
11
  end
12
12
 
13
+ def teardown
14
+ @tempfile.close!
15
+
16
+ super
17
+ end
18
+
13
19
  def test_class_read_file
14
20
  @tempfile.write "hi everybody"
15
21
  @tempfile.flush
@@ -125,6 +131,23 @@ class TestRDocEncoding < RDoc::TestCase
125
131
  assert_equal "hi everybody", content, bug3360
126
132
  end
127
133
 
134
+ def test_class_read_file_encoding_iso_2022_jp
135
+ skip "Encoding not implemented" unless Object.const_defined? :Encoding
136
+
137
+ input = "# coding: ISO-2022-JP\n:\e$B%3%^%s%I\e(B:"
138
+
139
+ @tempfile.write input
140
+ @tempfile.flush
141
+
142
+ contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8
143
+
144
+ expected = ":\xe3\x82\xb3\xe3\x83\x9e\xe3\x83\xb3\xe3\x83\x89:"
145
+ expected.force_encoding Encoding::UTF_8
146
+
147
+ assert_equal expected, contents
148
+ assert_equal Encoding::UTF_8, contents.encoding
149
+ end
150
+
128
151
  def test_class_set_encoding
129
152
  s = "# coding: UTF-8\n"
130
153
  RDoc::Encoding.set_encoding s
@@ -76,8 +76,8 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
76
76
  assert_file 'table_of_contents.html'
77
77
  assert_file 'js/search_index.js'
78
78
 
79
- assert_hard_link 'rdoc.css'
80
- assert_hard_link 'fonts.css'
79
+ assert_hard_link 'css/rdoc.css'
80
+ assert_hard_link 'css/fonts.css'
81
81
 
82
82
  assert_hard_link 'fonts/SourceCodePro-Bold.ttf'
83
83
  assert_hard_link 'fonts/SourceCodePro-Regular.ttf'