rdoc 3.4 → 3.5
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.
- data.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/History.txt +24 -1
- data/lib/rdoc.rb +1 -1
- data/lib/rdoc/any_method.rb +7 -1
- data/lib/rdoc/code_object.rb +12 -0
- data/lib/rdoc/context.rb +11 -6
- data/lib/rdoc/generator/template/darkfish/rdoc.css +25 -1
- data/lib/rdoc/parser/c.rb +145 -44
- data/lib/rdoc/parser/ruby.rb +60 -8
- data/lib/rdoc/text.rb +7 -2
- data/test/test_rdoc_any_method.rb +6 -0
- data/test/test_rdoc_class_module.rb +3 -3
- data/test/test_rdoc_code_object.rb +12 -0
- data/test/test_rdoc_context.rb +9 -2
- data/test/test_rdoc_options.rb +1 -0
- data/test/test_rdoc_parser_c.rb +165 -17
- data/test/test_rdoc_parser_ruby.rb +179 -12
- data/test/test_rdoc_text.rb +49 -0
- data/test/test_rdoc_top_level.rb +1 -1
- metadata +20 -35
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
CHANGED
@@ -1,4 +1,27 @@
|
|
1
|
-
=== 3.
|
1
|
+
=== 3.5 / 2010-01-29
|
2
|
+
|
3
|
+
* Minor enhancements
|
4
|
+
* RDoc::Parser::C looks for rb_scan_args and fills in RDoc::AnyMethod#params
|
5
|
+
appropriately. This may provide useful information if the author did not
|
6
|
+
provide a call-seq.
|
7
|
+
* RDoc::Parser::C now records the function name for methods implemented in
|
8
|
+
C.
|
9
|
+
* RDoc now records file and byte offset information for methods.
|
10
|
+
* Bug fixes
|
11
|
+
* Locations of module aliases are now recorded.
|
12
|
+
* RDoc::Parser::C finds method bodies better now.
|
13
|
+
* Fixed further locations where output encoding was not preserved. Bug #11
|
14
|
+
by Vít Ondruch, RubyForge bug #28791 by Dzmitry Prakapenka.
|
15
|
+
* Fixed display of numeric lists on the index page and file pages. Bug #12
|
16
|
+
by tobijk.
|
17
|
+
* Skip TestRDocOptions#test_check_files on windows until a windows-specific
|
18
|
+
test can be created. RubyForge bug #28821 by Usaku Nakamura.
|
19
|
+
* Fixed line-height of headings in method and alias descriptions. RubyForge
|
20
|
+
Bug #2770 by Adam Avilla
|
21
|
+
* Relaxed RDoc::Parser::Ruby#remove_private_comments to consume more dashes
|
22
|
+
as older versions once did. Bug #7 by Claus Folke Brobak.
|
23
|
+
|
24
|
+
=== 3.4 / 2010-01-06
|
2
25
|
|
3
26
|
* Minor enhancements
|
4
27
|
* RDoc::RDoc#document may now be called with an RDoc::Options instance.
|
data/lib/rdoc.rb
CHANGED
data/lib/rdoc/any_method.rb
CHANGED
@@ -13,6 +13,11 @@ class RDoc::AnyMethod < RDoc::MethodAttr
|
|
13
13
|
|
14
14
|
attr_accessor :dont_rename_initialize
|
15
15
|
|
16
|
+
##
|
17
|
+
# The C function that implements this method (if it was defined in a C file)
|
18
|
+
|
19
|
+
attr_accessor :c_function
|
20
|
+
|
16
21
|
##
|
17
22
|
# Different ways to call this method
|
18
23
|
|
@@ -31,8 +36,9 @@ class RDoc::AnyMethod < RDoc::MethodAttr
|
|
31
36
|
def initialize text, name
|
32
37
|
super
|
33
38
|
|
39
|
+
@c_function = nil
|
34
40
|
@dont_rename_initialize = false
|
35
|
-
@token_stream
|
41
|
+
@token_stream = nil
|
36
42
|
end
|
37
43
|
|
38
44
|
##
|
data/lib/rdoc/code_object.rb
CHANGED
@@ -60,11 +60,23 @@ class RDoc::CodeObject
|
|
60
60
|
|
61
61
|
attr_reader :force_documentation
|
62
62
|
|
63
|
+
##
|
64
|
+
# Line in #file where this CodeObject was defined
|
65
|
+
|
66
|
+
attr_accessor :line
|
67
|
+
|
63
68
|
##
|
64
69
|
# Hash of arbitrary metadata for this CodeObject
|
65
70
|
|
66
71
|
attr_reader :metadata
|
67
72
|
|
73
|
+
##
|
74
|
+
# Offset in #file where this CodeObject was defined
|
75
|
+
#--
|
76
|
+
# TODO character or byte?
|
77
|
+
|
78
|
+
attr_accessor :offset
|
79
|
+
|
68
80
|
##
|
69
81
|
# Our parent CodeObject
|
70
82
|
|
data/lib/rdoc/context.rb
CHANGED
@@ -439,10 +439,13 @@ class RDoc::Context < RDoc::CodeObject
|
|
439
439
|
# HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code)
|
440
440
|
# (this is a #ifdef: should be handled by the C parser)
|
441
441
|
known = @constants_hash[constant.name]
|
442
|
-
|
443
|
-
|
442
|
+
|
443
|
+
if known then
|
444
444
|
known.comment = constant.comment if known.comment.empty?
|
445
|
-
|
445
|
+
|
446
|
+
known.value = constant.value if
|
447
|
+
known.value.nil? or known.value.strip.empty?
|
448
|
+
|
446
449
|
known.is_alias_for ||= constant.is_alias_for
|
447
450
|
else
|
448
451
|
@constants_hash[constant.name] = constant
|
@@ -494,9 +497,10 @@ class RDoc::Context < RDoc::CodeObject
|
|
494
497
|
end
|
495
498
|
|
496
499
|
##
|
497
|
-
# Adds an alias from +from+ (a class or module) to +name
|
500
|
+
# Adds an alias from +from+ (a class or module) to +name+ which was defined
|
501
|
+
# in +file+.
|
498
502
|
|
499
|
-
def add_module_alias from, name
|
503
|
+
def add_module_alias from, name, file
|
500
504
|
return from if @done_documenting
|
501
505
|
|
502
506
|
to_name = child_name(name)
|
@@ -518,7 +522,8 @@ class RDoc::Context < RDoc::CodeObject
|
|
518
522
|
# HACK: register a constant for this alias:
|
519
523
|
# constant value and comment will be updated after,
|
520
524
|
# when the Ruby parser adds the constant
|
521
|
-
const = RDoc::Constant.new
|
525
|
+
const = RDoc::Constant.new name, nil, ''
|
526
|
+
const.record_location file
|
522
527
|
const.is_alias_for = from
|
523
528
|
add_constant const
|
524
529
|
|
@@ -97,6 +97,11 @@ body.file p {
|
|
97
97
|
margin: 1em 0;
|
98
98
|
}
|
99
99
|
|
100
|
+
.indexpage ol,
|
101
|
+
.file #documentation ol {
|
102
|
+
line-height: 160%;
|
103
|
+
}
|
104
|
+
|
100
105
|
.indexpage ul,
|
101
106
|
.file #documentation ul {
|
102
107
|
line-height: 160%;
|
@@ -110,6 +115,20 @@ body.file p {
|
|
110
115
|
.indexpage li,
|
111
116
|
.file #documentation li {
|
112
117
|
padding-left: 20px;
|
118
|
+
}
|
119
|
+
|
120
|
+
.indexpage ol,
|
121
|
+
.file #documentation ol {
|
122
|
+
margin-left: 20px;
|
123
|
+
}
|
124
|
+
|
125
|
+
.indexpage ol > li,
|
126
|
+
.file #documentation ol > li {
|
127
|
+
padding-left: 0;
|
128
|
+
}
|
129
|
+
|
130
|
+
.indexpage ul > li,
|
131
|
+
.file #documentation ul > li {
|
113
132
|
background: url(images/bullet_black.png) no-repeat left 4px;
|
114
133
|
}
|
115
134
|
.indexpage li.module {
|
@@ -389,9 +408,14 @@ ul.link-list .type {
|
|
389
408
|
#documentation .method-description,
|
390
409
|
#documentation .aliases {
|
391
410
|
margin: 0 20px;
|
392
|
-
line-height: 1.2em;
|
393
411
|
color: #666;
|
394
412
|
}
|
413
|
+
|
414
|
+
#documentation .method-description p,
|
415
|
+
#documentation .aliases p {
|
416
|
+
line-height: 1.2em;
|
417
|
+
}
|
418
|
+
|
395
419
|
#documentation .aliases {
|
396
420
|
padding-top: 4px;
|
397
421
|
font-style: italic;
|
data/lib/rdoc/parser/c.rb
CHANGED
@@ -285,7 +285,7 @@ class RDoc::Parser::C < RDoc::Parser
|
|
285
285
|
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
|
286
286
|
\s*(-?\w+)\s*\)
|
287
287
|
(?:;\s*/[*/]\s+in\s+(\w+?\.[cy]))?
|
288
|
-
%xm) do |type, var_name, meth_name,
|
288
|
+
%xm) do |type, var_name, meth_name, function, param_count, source_file|
|
289
289
|
|
290
290
|
# Ignore top-object and weird struct.c dynamic stuff
|
291
291
|
next if var_name == "ruby_top_self"
|
@@ -294,7 +294,7 @@ class RDoc::Parser::C < RDoc::Parser
|
|
294
294
|
next if var_name == "argf" # it'd be nice to handle this one
|
295
295
|
|
296
296
|
var_name = "rb_cObject" if var_name == "rb_mKernel"
|
297
|
-
handle_method(type, var_name, meth_name,
|
297
|
+
handle_method(type, var_name, meth_name, function, param_count,
|
298
298
|
source_file)
|
299
299
|
end
|
300
300
|
|
@@ -303,18 +303,19 @@ class RDoc::Parser::C < RDoc::Parser
|
|
303
303
|
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
|
304
304
|
\s*(-?\w+)\s*\)
|
305
305
|
(?:;\s*/[*/]\s+in\s+(\w+?\.[cy]))?
|
306
|
-
%xm) do |meth_name,
|
307
|
-
handle_method("method", "rb_mKernel", meth_name,
|
308
|
-
|
306
|
+
%xm) do |meth_name, function, param_count, source_file|
|
307
|
+
handle_method("method", "rb_mKernel", meth_name, function, param_count,
|
308
|
+
source_file)
|
309
309
|
end
|
310
310
|
|
311
311
|
@content.scan(/define_filetest_function\s*\(
|
312
312
|
\s*"([^"]+)",
|
313
313
|
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
|
314
|
-
\s*(-?\w+)\s*\)/xm) do |meth_name,
|
314
|
+
\s*(-?\w+)\s*\)/xm) do |meth_name, function, param_count|
|
315
315
|
|
316
|
-
handle_method("method", "rb_mFileTest", meth_name,
|
317
|
-
handle_method("singleton_method", "rb_cFile", meth_name,
|
316
|
+
handle_method("method", "rb_mFileTest", meth_name, function, param_count)
|
317
|
+
handle_method("singleton_method", "rb_cFile", meth_name, function,
|
318
|
+
param_count)
|
318
319
|
end
|
319
320
|
end
|
320
321
|
|
@@ -370,21 +371,20 @@ class RDoc::Parser::C < RDoc::Parser
|
|
370
371
|
##
|
371
372
|
# Find the C code corresponding to a Ruby method
|
372
373
|
|
373
|
-
def find_body
|
374
|
-
case
|
374
|
+
def find_body class_name, meth_name, meth_obj, file_content, quiet = false
|
375
|
+
case file_content
|
375
376
|
when %r%((?>/\*.*?\*/\s*)?)
|
376
377
|
((?:(?:static|SWIGINTERN)\s+)?
|
377
378
|
(?:intern\s+)?VALUE\s+#{meth_name}
|
378
|
-
\s*(\(
|
379
|
+
\s*(\(.*?\))([^;]|$))%xm then
|
379
380
|
comment = $1
|
380
|
-
|
381
|
+
body = $2
|
382
|
+
offset = $~.offset(2).first
|
381
383
|
|
382
384
|
remove_private_comments comment if comment
|
383
385
|
|
384
|
-
#
|
385
|
-
|
386
|
-
re = Regexp.escape(body_text) + '[^(]*^\{.*?^\}'
|
387
|
-
body_text = $& if /#{re}/m =~ body
|
386
|
+
# try to find the whole body
|
387
|
+
body = $& if /#{Regexp.escape body}[^(]*?\{.*?^\}/m =~ file_content
|
388
388
|
|
389
389
|
# The comment block may have been overridden with a 'Document-method'
|
390
390
|
# block. This happens in the interpreter when multiple methods are
|
@@ -400,38 +400,53 @@ class RDoc::Parser::C < RDoc::Parser
|
|
400
400
|
#meth_obj.params = params
|
401
401
|
meth_obj.start_collecting_tokens
|
402
402
|
tk = RDoc::RubyToken::Token.new nil, 1, 1
|
403
|
-
tk.set_text
|
403
|
+
tk.set_text body
|
404
404
|
meth_obj.add_token tk
|
405
405
|
meth_obj.comment = strip_stars comment
|
406
|
-
|
406
|
+
meth_obj.offset = offset
|
407
|
+
meth_obj.line = file_content[0, offset].count("\n") + 1
|
408
|
+
|
409
|
+
body
|
410
|
+
when %r%((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+#{meth_name}\s+(\w+))%m then
|
407
411
|
comment = $1
|
408
|
-
|
409
|
-
|
412
|
+
body = $2
|
413
|
+
offset = $~.offset(2).first
|
414
|
+
|
415
|
+
find_body class_name, $3, meth_obj, file_content, true
|
410
416
|
find_modifiers comment, meth_obj
|
411
417
|
|
412
418
|
meth_obj.start_collecting_tokens
|
413
419
|
tk = RDoc::RubyToken::Token.new nil, 1, 1
|
414
|
-
tk.set_text
|
420
|
+
tk.set_text body
|
415
421
|
meth_obj.add_token tk
|
416
422
|
meth_obj.comment = strip_stars(comment) + meth_obj.comment.to_s
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
423
|
+
meth_obj.offset = offset
|
424
|
+
meth_obj.line = file_content[0, offset].count("\n") + 1
|
425
|
+
|
426
|
+
body
|
427
|
+
when %r%^\s*\#\s*define\s+#{meth_name}\s+(\w+)%m then
|
428
|
+
# with no comment we hope the aliased definition has it and use it's
|
429
|
+
# definition
|
430
|
+
|
431
|
+
body = find_body(class_name, $1, meth_obj, file_content, true)
|
432
|
+
|
433
|
+
return body if body
|
434
|
+
|
435
|
+
warn "No definition for #{meth_name}" if @options.verbosity > 1
|
436
|
+
false
|
422
437
|
else # No body, but might still have an override comment
|
423
438
|
comment = find_override_comment class_name, meth_obj.name
|
424
439
|
|
425
|
-
if comment
|
440
|
+
if comment then
|
426
441
|
find_modifiers comment, meth_obj
|
427
442
|
meth_obj.comment = strip_stars comment
|
443
|
+
|
444
|
+
''
|
428
445
|
else
|
429
446
|
warn "No definition for #{meth_name}" if @options.verbosity > 1
|
430
|
-
|
447
|
+
false
|
431
448
|
end
|
432
449
|
end
|
433
|
-
|
434
|
-
true
|
435
450
|
end
|
436
451
|
|
437
452
|
##
|
@@ -751,7 +766,7 @@ class RDoc::Parser::C < RDoc::Parser
|
|
751
766
|
# to +var_name+. +type+ is the type of method definition function used.
|
752
767
|
# +singleton_method+ and +module_function+ create a singleton method.
|
753
768
|
|
754
|
-
def handle_method(type, var_name, meth_name,
|
769
|
+
def handle_method(type, var_name, meth_name, function, param_count,
|
755
770
|
source_file = nil)
|
756
771
|
singleton = false
|
757
772
|
class_name = @known_classes[var_name]
|
@@ -773,34 +788,36 @@ class RDoc::Parser::C < RDoc::Parser
|
|
773
788
|
end
|
774
789
|
|
775
790
|
meth_obj = RDoc::AnyMethod.new '', meth_name
|
791
|
+
meth_obj.c_function = function
|
776
792
|
meth_obj.singleton =
|
777
793
|
singleton || %w[singleton_method module_function].include?(type)
|
778
794
|
|
779
795
|
p_count = Integer(param_count) rescue -1
|
780
796
|
|
781
|
-
if p_count < 0 then
|
782
|
-
meth_obj.params = "(*args)"
|
783
|
-
elsif p_count == 0
|
784
|
-
meth_obj.params = "()"
|
785
|
-
else
|
786
|
-
params = (1..p_count).map { |i| "p#{i}" }.join(', ')
|
787
|
-
meth_obj.params = "(#{params})"
|
788
|
-
end
|
789
|
-
|
790
797
|
if source_file then
|
791
798
|
file_name = File.join @file_dir, source_file
|
792
799
|
|
793
800
|
if File.exist? file_name then
|
794
|
-
|
801
|
+
file_content = (@@known_bodies[file_name] ||= File.read(file_name))
|
795
802
|
else
|
796
803
|
warn "unknown source #{source_file} for #{meth_name} in #{@file_name}"
|
797
804
|
end
|
798
805
|
else
|
799
|
-
|
806
|
+
file_content = @content
|
800
807
|
end
|
801
808
|
|
802
|
-
|
803
|
-
|
809
|
+
body = find_body class_name, function, meth_obj, file_content
|
810
|
+
|
811
|
+
if body and meth_obj.document_self then
|
812
|
+
meth_obj.params = if p_count < -1 then # -2 is Array
|
813
|
+
'(*args)'
|
814
|
+
elsif p_count == -1 then # argc, argv
|
815
|
+
rb_scan_args body
|
816
|
+
else
|
817
|
+
"(#{(1..p_count).map { |i| "p#{i}" }.join ', '})"
|
818
|
+
end
|
819
|
+
|
820
|
+
|
804
821
|
meth_obj.record_location @top_level
|
805
822
|
class_obj.add_method meth_obj
|
806
823
|
@stats.add_method meth_obj
|
@@ -861,6 +878,90 @@ class RDoc::Parser::C < RDoc::Parser
|
|
861
878
|
comment
|
862
879
|
end
|
863
880
|
|
881
|
+
##
|
882
|
+
# Extracts parameters from the +method_body+ and returns a method
|
883
|
+
# parameter string. Follows 1.9.3dev's scan-arg-spec, see README.EXT
|
884
|
+
|
885
|
+
def rb_scan_args method_body
|
886
|
+
method_body =~ /rb_scan_args\((.*?)\)/m
|
887
|
+
return '(*args)' unless $1
|
888
|
+
|
889
|
+
$1.split(/,/)[2] =~ /"(.*?)"/ # format argument
|
890
|
+
format = $1.split(//)
|
891
|
+
|
892
|
+
lead = opt = trail = 0
|
893
|
+
|
894
|
+
if format.first =~ /\d/ then
|
895
|
+
lead = $&.to_i
|
896
|
+
format.shift
|
897
|
+
if format.first =~ /\d/ then
|
898
|
+
opt = $&.to_i
|
899
|
+
format.shift
|
900
|
+
if format.first =~ /\d/ then
|
901
|
+
trail = $&.to_i
|
902
|
+
format.shift
|
903
|
+
block_arg = true
|
904
|
+
end
|
905
|
+
end
|
906
|
+
end
|
907
|
+
|
908
|
+
if format.first == '*' and not block_arg then
|
909
|
+
var = true
|
910
|
+
format.shift
|
911
|
+
if format.first =~ /\d/ then
|
912
|
+
trail = $&.to_i
|
913
|
+
format.shift
|
914
|
+
end
|
915
|
+
end
|
916
|
+
|
917
|
+
if format.first == ':' then
|
918
|
+
hash = true
|
919
|
+
format.shift
|
920
|
+
end
|
921
|
+
|
922
|
+
if format.first == '&' then
|
923
|
+
block = true
|
924
|
+
format.shift
|
925
|
+
end
|
926
|
+
|
927
|
+
# if the format string is not empty there's a bug in the C code, ignore it
|
928
|
+
|
929
|
+
args = []
|
930
|
+
position = 1
|
931
|
+
|
932
|
+
(1...(position + lead)).each do |index|
|
933
|
+
args << "p#{index}"
|
934
|
+
end
|
935
|
+
|
936
|
+
position += lead
|
937
|
+
|
938
|
+
(position...(position + opt)).each do |index|
|
939
|
+
args << "p#{index} = v#{index}"
|
940
|
+
end
|
941
|
+
|
942
|
+
position += opt
|
943
|
+
|
944
|
+
if var then
|
945
|
+
args << '*args'
|
946
|
+
position += 1
|
947
|
+
end
|
948
|
+
|
949
|
+
(position...(position + trail)).each do |index|
|
950
|
+
args << "p#{index}"
|
951
|
+
end
|
952
|
+
|
953
|
+
position += trail
|
954
|
+
|
955
|
+
if hash then
|
956
|
+
args << "p#{position} = {}"
|
957
|
+
position += 1
|
958
|
+
end
|
959
|
+
|
960
|
+
args << '&block' if block
|
961
|
+
|
962
|
+
"(#{args.join ', '})"
|
963
|
+
end
|
964
|
+
|
864
965
|
##
|
865
966
|
# Removes lines that are commented out that might otherwise get picked up
|
866
967
|
# when scanning for classes and methods
|