rdoc 4.0.0.preview2 → 4.0.0.preview2.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.

Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +4 -1
  5. data/History.rdoc +26 -1
  6. data/Manifest.txt +2 -0
  7. data/Rakefile +1 -1
  8. data/lib/rdoc.rb +1 -1
  9. data/lib/rdoc/class_module.rb +13 -2
  10. data/lib/rdoc/context.rb +7 -5
  11. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +7 -1
  12. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +1 -1
  13. data/lib/rdoc/markdown/entities.rb +3 -0
  14. data/lib/rdoc/markup/document.rb +8 -8
  15. data/lib/rdoc/markup/formatter.rb +6 -1
  16. data/lib/rdoc/markup/heading.rb +2 -1
  17. data/lib/rdoc/markup/to_joined_paragraph.rb +5 -2
  18. data/lib/rdoc/markup/to_table_of_contents.rb +27 -1
  19. data/lib/rdoc/options.rb +36 -1
  20. data/lib/rdoc/parser.rb +30 -1
  21. data/lib/rdoc/parser/c.rb +56 -14
  22. data/lib/rdoc/parser/changelog.rb +186 -0
  23. data/lib/rdoc/parser/ruby.rb +53 -11
  24. data/lib/rdoc/rdoc.rb +9 -0
  25. data/lib/rdoc/ri/driver.rb +5 -1
  26. data/lib/rdoc/ruby_lex.rb +1 -1
  27. data/lib/rdoc/rubygems_hook.rb +16 -10
  28. data/lib/rdoc/servlet.rb +111 -6
  29. data/lib/rdoc/store.rb +110 -19
  30. data/test/test_rdoc_class_module.rb +32 -0
  31. data/test/test_rdoc_context.rb +25 -0
  32. data/test/test_rdoc_markup_document.rb +19 -0
  33. data/test/test_rdoc_markup_to_table_of_contents.rb +31 -0
  34. data/test/test_rdoc_options.rb +38 -0
  35. data/test/test_rdoc_parser.rb +56 -0
  36. data/test/test_rdoc_parser_c.rb +129 -6
  37. data/test/test_rdoc_parser_changelog.rb +294 -0
  38. data/test/test_rdoc_parser_ruby.rb +145 -8
  39. data/test/test_rdoc_rdoc.rb +25 -5
  40. data/test/test_rdoc_ri_driver.rb +27 -0
  41. data/test/test_rdoc_ruby_lex.rb +10 -0
  42. data/test/test_rdoc_rubygems_hook.rb +49 -18
  43. data/test/test_rdoc_store.rb +148 -37
  44. metadata +26 -23
  45. metadata.gz.sig +0 -0
@@ -122,6 +122,11 @@ class RDoc::Parser::C < RDoc::Parser
122
122
 
123
123
  include RDoc::Text
124
124
 
125
+ ##
126
+ # Maps C variable names to names of ruby classes or modules
127
+
128
+ attr_reader :classes
129
+
125
130
  ##
126
131
  # C file the parser is parsing
127
132
 
@@ -150,16 +155,23 @@ class RDoc::Parser::C < RDoc::Parser
150
155
  attr_reader :singleton_classes
151
156
 
152
157
  ##
153
- # Prepare to parse a C file
158
+ # The TopLevel items in the parsed file belong to
159
+
160
+ attr_reader :top_level
161
+
162
+ ##
163
+ # Prepares for parsing a C file. See RDoc::Parser#initialize for details on
164
+ # the arguments.
154
165
 
155
- def initialize(top_level, file_name, content, options, stats)
166
+ def initialize top_level, file_name, content, options, stats
156
167
  super
157
168
 
158
169
  @known_classes = RDoc::KNOWN_CLASSES.dup
159
- @content = handle_tab_width handle_ifdefs_in(@content)
160
- @classes = {}
161
- @singleton_classes = {}
162
- @file_dir = File.dirname(@file_name)
170
+ @content = handle_tab_width handle_ifdefs_in @content
171
+ @file_dir = File.dirname @file_name
172
+
173
+ @classes = load_variable_map :c_class_variables
174
+ @singleton_classes = load_variable_map :c_singleton_class_variables
163
175
 
164
176
  # missing variable => [handle_class_module arguments]
165
177
  @missing_dependencies = {}
@@ -386,13 +398,12 @@ class RDoc::Parser::C < RDoc::Parser
386
398
 
387
399
  def do_includes
388
400
  @content.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
389
- if cls = @classes[c]
390
- m = @known_classes[m] || m
401
+ next unless cls = @classes[c]
402
+ m = @known_classes[m] || m
391
403
 
392
- comment = RDoc::Comment.new '', @top_level
393
- incl = cls.add_include RDoc::Include.new(m, comment)
394
- incl.record_location @top_level
395
- end
404
+ comment = RDoc::Comment.new '', @top_level
405
+ incl = cls.add_include RDoc::Include.new(m, comment)
406
+ incl.record_location @top_level
396
407
  end
397
408
  end
398
409
 
@@ -446,6 +457,10 @@ class RDoc::Parser::C < RDoc::Parser
446
457
  end
447
458
  end
448
459
 
460
+ ##
461
+ # Creates classes and module that were missing were defined due to the file
462
+ # order being different than the declaration order.
463
+
449
464
  def do_missing
450
465
  return if @missing_dependencies.empty?
451
466
 
@@ -797,7 +812,7 @@ class RDoc::Parser::C < RDoc::Parser
797
812
  parent_name = @known_classes[parent] || parent
798
813
 
799
814
  if in_module then
800
- enclosure = @classes[in_module] || @store.c_enclosure_classes[in_module]
815
+ enclosure = @classes[in_module] || @store.find_c_enclosure(in_module)
801
816
 
802
817
  if enclosure.nil? and enclosure = @known_classes[in_module] then
803
818
  enc_type = /^rb_m/ =~ in_module ? :module : :class
@@ -844,8 +859,8 @@ class RDoc::Parser::C < RDoc::Parser
844
859
  end
845
860
 
846
861
  @classes[var_name] = cm
847
- @store.c_enclosure_classes[var_name] = cm
848
862
  @known_classes[var_name] = cm.full_name
863
+ @store.add_c_enclosure var_name, cm
849
864
  end
850
865
 
851
866
  ##
@@ -1000,6 +1015,30 @@ class RDoc::Parser::C < RDoc::Parser
1000
1015
  end
1001
1016
  end
1002
1017
 
1018
+ ##
1019
+ # Loads the variable map with the given +name+ from the RDoc::Store, if
1020
+ # present.
1021
+
1022
+ def load_variable_map map_name
1023
+ return {} unless files = @store.cache[map_name]
1024
+ return {} unless name_map = files[@file_name]
1025
+
1026
+ class_map = {}
1027
+
1028
+ name_map.each do |variable, name|
1029
+ next unless mod = @store.find_class_or_module(name)
1030
+
1031
+ class_map[variable] = if map_name == :c_class_variables then
1032
+ mod
1033
+ else
1034
+ name
1035
+ end
1036
+ @known_classes[variable] = name
1037
+ end
1038
+
1039
+ class_map
1040
+ end
1041
+
1003
1042
  ##
1004
1043
  # Look for directives in a normal comment block:
1005
1044
  #
@@ -1132,6 +1171,9 @@ class RDoc::Parser::C < RDoc::Parser
1132
1171
  do_includes
1133
1172
  do_aliases
1134
1173
  do_attrs
1174
+
1175
+ @store.add_c_variables self
1176
+
1135
1177
  @top_level
1136
1178
  end
1137
1179
 
@@ -0,0 +1,186 @@
1
+ require 'time'
2
+
3
+ ##
4
+ # A ChangeLog file parser.
5
+ #
6
+ # This parser converts a ChangeLog into an RDoc::Markup::Document. When
7
+ # viewed as HTML a ChangeLog page will have an entry for each day's entries in
8
+ # the sidebar table of contents.
9
+ #
10
+ # This parser is meant to parse the MRI ChangeLog, but can be used to parse any
11
+ # {GNU style Change
12
+ # Log}[http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html].
13
+
14
+ class RDoc::Parser::ChangeLog < RDoc::Parser
15
+
16
+ include RDoc::Parser::Text
17
+
18
+ parse_files_matching(/(\/|\\|\A)ChangeLog[^\/\\]*\z/)
19
+
20
+ ##
21
+ # Attaches the +continuation+ of the previous line to the +entry_body+.
22
+ #
23
+ # Continued function listings are joined together as a single entry.
24
+ # Continued descriptions are joined to make a single paragraph.
25
+
26
+ def continue_entry_body entry_body, continuation
27
+ return unless last = entry_body.last
28
+
29
+ if last =~ /\)\s*\z/ and continuation =~ /\A\(/ then
30
+ last.sub!(/\)\s*\z/, ',')
31
+ continuation.sub!(/\A\(/, '')
32
+ end
33
+
34
+ if last =~ /\s\z/ then
35
+ last << continuation
36
+ else
37
+ last << ' ' << continuation
38
+ end
39
+ end
40
+
41
+ ##
42
+ # Creates an RDoc::Markup::Document given the +groups+ of ChangeLog entries.
43
+
44
+ def create_document groups
45
+ doc = RDoc::Markup::Document.new
46
+ doc.omit_headings_below = 2
47
+ doc.file = @top_level
48
+
49
+ doc << RDoc::Markup::Heading.new(1, File.basename(@file_name))
50
+ doc << RDoc::Markup::BlankLine.new
51
+
52
+ groups.sort_by do |day,| day end.reverse_each do |day, entries|
53
+ doc << RDoc::Markup::Heading.new(2, day.dup)
54
+ doc << RDoc::Markup::BlankLine.new
55
+
56
+ doc.concat create_entries entries
57
+ end
58
+
59
+ doc
60
+ end
61
+
62
+ ##
63
+ # Returns a list of ChangeLog entries an RDoc::Markup nodes for the given
64
+ # +entries+.
65
+
66
+ def create_entries entries
67
+ out = []
68
+
69
+ entries.each do |entry, items|
70
+ out << RDoc::Markup::Heading.new(3, entry)
71
+ out << RDoc::Markup::BlankLine.new
72
+
73
+ out << create_items(items)
74
+ end
75
+
76
+ out
77
+ end
78
+
79
+ ##
80
+ # Returns an RDoc::Markup::List containing the given +items+ in the
81
+ # ChangeLog
82
+
83
+ def create_items items
84
+ list = RDoc::Markup::List.new :NOTE
85
+
86
+ items.each do |item|
87
+ item =~ /\A(.*?(?:\([^)]+\))?):\s*/
88
+
89
+ title = $1
90
+ body = $'
91
+
92
+ paragraph = RDoc::Markup::Paragraph.new body
93
+ list_item = RDoc::Markup::ListItem.new title, paragraph
94
+ list << list_item
95
+ end
96
+
97
+ list
98
+ end
99
+
100
+ ##
101
+ # Groups +entries+ by date.
102
+
103
+ def group_entries entries
104
+ entries.group_by do |title, _|
105
+ Time.parse(title).strftime "%Y-%m-%d"
106
+ end
107
+ end
108
+
109
+ ##
110
+ # Parses the entries in the ChangeLog.
111
+ #
112
+ # Returns an Array of each ChangeLog entry in order of parsing.
113
+ #
114
+ # A ChangeLog entry is an Array containing the ChangeLog title (date and
115
+ # committer) and an Array of ChangeLog items (file and function changed with
116
+ # description).
117
+ #
118
+ # An example result would be:
119
+ #
120
+ # [ 'Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
121
+ # [ 'README.EXT: Converted to RDoc format',
122
+ # 'README.EXT.ja: ditto']]
123
+
124
+ def parse_entries
125
+ entries = []
126
+ entry_name = nil
127
+ entry_body = []
128
+
129
+ @content.each_line do |line|
130
+ case line
131
+ when /^\s*$/ then
132
+ next
133
+ when /^\w.*/ then
134
+ entries << [entry_name, entry_body] if entry_name
135
+
136
+ entry_name = $&
137
+
138
+ begin
139
+ time = Time.parse entry_name
140
+ # HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
141
+ entry_name = nil unless entry_name =~ /#{time.year}/
142
+ rescue ArgumentError
143
+ entry_name = nil
144
+ end
145
+
146
+ entry_body = []
147
+ when /^(\t| {8})?\*\s*(.*)/ then # "\t* file.c (func): ..."
148
+ entry_body << $2
149
+ when /^(\t| {8})?\s*(\(.*)/ then # "\t(func): ..."
150
+ entry = $2
151
+
152
+ if entry_body.last =~ /:/ then
153
+ entry_body << entry
154
+ else
155
+ continue_entry_body entry_body, entry
156
+ end
157
+ when /^(\t| {8})?\s*(.*)/ then
158
+ continue_entry_body entry_body, $2
159
+ end
160
+ end
161
+
162
+ entries << [entry_name, entry_body] if entry_name
163
+
164
+ entries.reject! do |(entry,_)|
165
+ entry == nil
166
+ end
167
+
168
+ entries
169
+ end
170
+
171
+ ##
172
+ # Converts the ChangeLog into an RDoc::Markup::Document
173
+
174
+ def scan
175
+ entries = parse_entries
176
+ grouped_entries = group_entries entries
177
+
178
+ doc = create_document grouped_entries
179
+
180
+ @top_level.comment = doc
181
+
182
+ @top_level
183
+ end
184
+
185
+ end
186
+
@@ -240,7 +240,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
240
240
  # with :: separated named) and return the ultimate name, the associated
241
241
  # container, and the given name (with the ::).
242
242
 
243
- def get_class_or_module container
243
+ def get_class_or_module container, ignore_constants = false
244
244
  skip_tkspace
245
245
  name_t = get_tk
246
246
  given_name = ''
@@ -259,9 +259,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
259
259
  while TkCOLON2 === peek_tk do
260
260
  prev_container = container
261
261
  container = container.find_module_named name_t.name
262
- container ||= prev_container.add_module RDoc::NormalModule, name_t.name
262
+ container ||=
263
+ if ignore_constants then
264
+ RDoc::Context.new
265
+ else
266
+ c = prev_container.add_module RDoc::NormalModule, name_t.name
267
+ c.ignore unless prev_container.document_children
268
+ c
269
+ end
263
270
 
264
- container.ignore unless prev_container.document_children
271
+ container.record_location @top_level
265
272
 
266
273
  get_tk
267
274
  skip_tkspace false
@@ -663,9 +670,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
663
670
  end
664
671
 
665
672
  ##
666
- # Parses a constant in +context+ with +comment+
673
+ # Parses a constant in +context+ with +comment+. If +ignore_constants+ is
674
+ # true, no found constants will be added to RDoc.
667
675
 
668
- def parse_constant container, tk, comment
676
+ def parse_constant container, tk, comment, ignore_constants = false
669
677
  offset = tk.seek
670
678
  line_no = tk.line_no
671
679
 
@@ -676,6 +684,17 @@ class RDoc::Parser::Ruby < RDoc::Parser
676
684
 
677
685
  eq_tk = get_tk
678
686
 
687
+ if TkCOLON2 === eq_tk then
688
+ unget_tk eq_tk
689
+ unget_tk tk
690
+
691
+ container, name_t, = get_class_or_module container, ignore_constants
692
+
693
+ name = name_t.name
694
+
695
+ eq_tk = get_tk
696
+ end
697
+
679
698
  unless TkASSIGN === eq_tk then
680
699
  unget_tk eq_tk
681
700
  return false
@@ -1281,16 +1300,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
1281
1300
  #
1282
1301
  # and add this as the block_params for the method
1283
1302
 
1284
- def parse_method_parameters(method)
1303
+ def parse_method_parameters method
1285
1304
  res = parse_method_or_yield_parameters method
1286
1305
 
1287
1306
  res = "(#{res})" unless res =~ /\A\(/
1288
1307
  method.params = res unless method.params
1289
1308
 
1290
- if method.block_params.nil? then
1291
- skip_tkspace false
1292
- read_documentation_modifiers method, RDoc::METHOD_MODIFIERS
1293
- end
1309
+ return if method.block_params
1310
+
1311
+ skip_tkspace false
1312
+ read_documentation_modifiers method, RDoc::METHOD_MODIFIERS
1294
1313
  end
1295
1314
 
1296
1315
  ##
@@ -1334,6 +1353,26 @@ class RDoc::Parser::Ruby < RDoc::Parser
1334
1353
  end
1335
1354
  end
1336
1355
 
1356
+ ##
1357
+ # Parses a rescue
1358
+
1359
+ def parse_rescue
1360
+ skip_tkspace false
1361
+
1362
+ while tk = get_tk
1363
+ case tk
1364
+ when TkNL, TkSEMICOLON then
1365
+ break
1366
+ when TkCOMMA then
1367
+ skip_tkspace false
1368
+
1369
+ get_tk if TkNL === peek_tk
1370
+ end
1371
+
1372
+ skip_tkspace false
1373
+ end
1374
+ end
1375
+
1337
1376
  ##
1338
1377
  # The core of the ruby parser.
1339
1378
 
@@ -1407,7 +1446,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1407
1446
  parse_method container, single, tk, comment
1408
1447
 
1409
1448
  when TkCONSTANT then
1410
- unless parse_constant container, tk, comment then
1449
+ unless parse_constant container, tk, comment, current_method then
1411
1450
  try_parse_comment = true
1412
1451
  end
1413
1452
 
@@ -1441,6 +1480,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
1441
1480
  when TkSUPER then
1442
1481
  current_method.calls_super = true if current_method
1443
1482
 
1483
+ when TkRESCUE then
1484
+ parse_rescue
1485
+
1444
1486
  when TkIDENTIFIER then
1445
1487
  if nest == 1 and current_method.nil? then
1446
1488
  case tk.name
@@ -349,6 +349,12 @@ option)
349
349
  filename_path = Pathname(filename).expand_path
350
350
  relative_path = filename_path.relative_path_from @options.root
351
351
 
352
+ if @options.page_dir and
353
+ relative_path.to_s.start_with? @options.page_dir.to_s then
354
+ relative_path =
355
+ relative_path.relative_path_from @options.page_dir
356
+ end
357
+
352
358
  top_level = @store.add_file filename, relative_path.to_s
353
359
 
354
360
  parser = RDoc::Parser.for top_level, filename, content, @options, @stats
@@ -470,9 +476,12 @@ The internal error was:
470
476
  @store.dry_run = @options.dry_run
471
477
  @store.main = @options.main_page
472
478
  @store.title = @options.title
479
+ @store.path = @options.op_dir
473
480
 
474
481
  @start_time = Time.now
475
482
 
483
+ @store.load_cache
484
+
476
485
  file_info = parse_files @options.files
477
486
 
478
487
  @options.default_title = "RDoc Documentation"