rdoc 5.0.0 → 6.3.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.
- checksums.yaml +5 -5
- data/CONTRIBUTING.rdoc +4 -4
- data/Gemfile +9 -0
- data/History.rdoc +12 -2
- data/README.rdoc +5 -6
- data/Rakefile +35 -65
- data/lib/rdoc/alias.rb +1 -1
- data/lib/rdoc/anon_class.rb +1 -1
- data/lib/rdoc/any_method.rb +59 -15
- data/lib/rdoc/attr.rb +1 -1
- data/lib/rdoc/class_module.rb +5 -3
- data/lib/rdoc/code_object.rb +2 -9
- data/lib/rdoc/code_objects.rb +1 -1
- data/lib/rdoc/comment.rb +32 -11
- data/lib/rdoc/constant.rb +3 -3
- data/lib/rdoc/context/section.rb +1 -14
- data/lib/rdoc/context.rb +74 -21
- data/lib/rdoc/cross_reference.rb +33 -15
- data/lib/rdoc/encoding.rb +58 -30
- data/lib/rdoc/erb_partial.rb +2 -2
- data/lib/rdoc/erbio.rb +8 -4
- data/lib/rdoc/extend.rb +1 -1
- data/lib/rdoc/generator/darkfish.rb +60 -29
- data/lib/rdoc/generator/json_index.rb +7 -4
- data/lib/rdoc/generator/markup.rb +3 -13
- data/lib/rdoc/generator/pot/message_extractor.rb +1 -1
- data/lib/rdoc/generator/pot/po.rb +3 -3
- data/lib/rdoc/generator/pot/po_entry.rb +11 -11
- data/lib/rdoc/generator/pot.rb +4 -4
- data/lib/rdoc/generator/ri.rb +1 -1
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +9 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +4 -4
- data/lib/rdoc/generator/template/darkfish/class.rhtml +45 -47
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +55 -6
- data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -4
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +22 -99
- data/lib/rdoc/generator/template/darkfish/js/search.js +32 -31
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +15 -16
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +16 -16
- data/lib/rdoc/generator/template/json_index/js/navigation.js +4 -41
- data/lib/rdoc/generator/template/json_index/js/searcher.js +6 -6
- data/lib/rdoc/generator.rb +1 -1
- data/lib/rdoc/ghost_method.rb +1 -1
- data/lib/rdoc/i18n/locale.rb +2 -2
- data/lib/rdoc/i18n/text.rb +5 -5
- data/lib/rdoc/i18n.rb +3 -3
- data/lib/rdoc/include.rb +1 -1
- data/lib/rdoc/known_classes.rb +1 -1
- data/lib/rdoc/markdown/entities.rb +1 -1
- data/lib/rdoc/markdown/literals.kpeg +1 -0
- data/lib/rdoc/markdown/literals.rb +19 -7
- data/lib/rdoc/markdown.kpeg +92 -44
- data/lib/rdoc/markdown.rb +1171 -610
- data/lib/rdoc/markup/attr_changer.rb +1 -1
- data/lib/rdoc/markup/attr_span.rb +9 -3
- data/lib/rdoc/markup/attribute_manager.rb +115 -50
- data/lib/rdoc/markup/attributes.rb +7 -7
- data/lib/rdoc/markup/blank_line.rb +1 -1
- data/lib/rdoc/markup/block_quote.rb +1 -1
- data/lib/rdoc/markup/document.rb +1 -1
- data/lib/rdoc/markup/formatter.rb +25 -24
- data/lib/rdoc/markup/hard_break.rb +1 -1
- data/lib/rdoc/markup/heading.rb +4 -4
- data/lib/rdoc/markup/include.rb +1 -1
- data/lib/rdoc/markup/indented_paragraph.rb +1 -1
- data/lib/rdoc/markup/list.rb +1 -1
- data/lib/rdoc/markup/list_item.rb +1 -1
- data/lib/rdoc/markup/paragraph.rb +1 -1
- data/lib/rdoc/markup/parser.rb +79 -47
- data/lib/rdoc/markup/pre_process.rb +11 -6
- data/lib/rdoc/markup/raw.rb +1 -1
- data/lib/rdoc/markup/regexp_handling.rb +41 -0
- data/lib/rdoc/markup/rule.rb +1 -1
- data/lib/rdoc/markup/to_ansi.rb +1 -1
- data/lib/rdoc/markup/to_bs.rb +4 -4
- data/lib/rdoc/markup/to_html.rb +71 -26
- data/lib/rdoc/markup/to_html_crossref.rb +41 -26
- data/lib/rdoc/markup/to_html_snippet.rb +10 -10
- data/lib/rdoc/markup/to_joined_paragraph.rb +7 -32
- data/lib/rdoc/markup/to_label.rb +10 -10
- data/lib/rdoc/markup/to_markdown.rb +9 -9
- data/lib/rdoc/markup/to_rdoc.rb +35 -7
- data/lib/rdoc/markup/to_table_of_contents.rb +2 -1
- data/lib/rdoc/markup/to_test.rb +1 -1
- data/lib/rdoc/markup/to_tt_only.rb +3 -3
- data/lib/rdoc/markup/verbatim.rb +1 -1
- data/lib/rdoc/markup.rb +14 -17
- data/lib/rdoc/meta_method.rb +1 -1
- data/lib/rdoc/method_attr.rb +2 -2
- data/lib/rdoc/mixin.rb +1 -1
- data/lib/rdoc/normal_class.rb +3 -3
- data/lib/rdoc/normal_module.rb +1 -1
- data/lib/rdoc/options.rb +79 -21
- data/lib/rdoc/parser/c.rb +147 -194
- data/lib/rdoc/parser/changelog.rb +150 -19
- data/lib/rdoc/parser/markdown.rb +1 -1
- data/lib/rdoc/parser/rd.rb +1 -1
- data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
- data/lib/rdoc/parser/ruby.rb +634 -465
- data/lib/rdoc/parser/ruby_tools.rb +33 -34
- data/lib/rdoc/parser/simple.rb +3 -3
- data/lib/rdoc/parser/text.rb +1 -1
- data/lib/rdoc/parser.rb +12 -35
- data/lib/rdoc/rd/block_parser.rb +109 -108
- data/lib/rdoc/rd/block_parser.ry +3 -3
- data/lib/rdoc/rd/inline.rb +5 -5
- data/lib/rdoc/rd/inline_parser.rb +186 -185
- data/lib/rdoc/rd/inline_parser.ry +1 -1
- data/lib/rdoc/rd.rb +1 -1
- data/lib/rdoc/rdoc.rb +54 -41
- data/lib/rdoc/require.rb +1 -1
- data/lib/rdoc/ri/driver.rb +132 -42
- data/lib/rdoc/ri/formatter.rb +1 -1
- data/lib/rdoc/ri/paths.rb +4 -18
- data/lib/rdoc/ri/store.rb +1 -1
- data/lib/rdoc/ri/task.rb +2 -2
- data/lib/rdoc/ri.rb +1 -1
- data/lib/rdoc/rubygems_hook.rb +3 -3
- data/lib/rdoc/servlet.rb +21 -12
- data/lib/rdoc/single_class.rb +1 -1
- data/lib/rdoc/stats/normal.rb +24 -18
- data/lib/rdoc/stats/quiet.rb +1 -1
- data/lib/rdoc/stats/verbose.rb +1 -1
- data/lib/rdoc/stats.rb +1 -1
- data/lib/rdoc/store.rb +38 -27
- data/lib/rdoc/task.rb +2 -2
- data/lib/rdoc/text.rb +16 -21
- data/lib/rdoc/token_stream.rb +56 -33
- data/lib/rdoc/tom_doc.rb +17 -12
- data/lib/rdoc/top_level.rb +9 -3
- data/lib/rdoc/version.rb +8 -0
- data/lib/rdoc.rb +24 -10
- data/man/ri.1 +247 -0
- data/rdoc.gemspec +206 -15
- metadata +15 -64
- data/.document +0 -5
- data/.gitignore +0 -13
- data/.travis.yml +0 -23
- data/lib/gauntlet_rdoc.rb +0 -82
- data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
- data/lib/rdoc/markup/formatter_test_case.rb +0 -764
- data/lib/rdoc/markup/inline.rb +0 -2
- data/lib/rdoc/markup/special.rb +0 -41
- data/lib/rdoc/markup/text_formatter_test_case.rb +0 -115
- data/lib/rdoc/ruby_lex.rb +0 -1367
- data/lib/rdoc/ruby_token.rb +0 -461
- data/lib/rdoc/test_case.rb +0 -204
data/lib/rdoc/constant.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
##
|
3
3
|
# A constant
|
4
4
|
|
@@ -36,7 +36,7 @@ class RDoc::Constant < RDoc::CodeObject
|
|
36
36
|
@value = value
|
37
37
|
|
38
38
|
@is_alias_for = nil
|
39
|
-
@visibility =
|
39
|
+
@visibility = :public
|
40
40
|
|
41
41
|
self.comment = comment
|
42
42
|
end
|
@@ -136,7 +136,7 @@ class RDoc::Constant < RDoc::CodeObject
|
|
136
136
|
initialize array[1], nil, array[5]
|
137
137
|
|
138
138
|
@full_name = array[2]
|
139
|
-
@visibility = array[3]
|
139
|
+
@visibility = array[3] || :public
|
140
140
|
@is_alias_for = array[4]
|
141
141
|
# 5 handled above
|
142
142
|
# 6 handled below
|
data/lib/rdoc/context/section.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
##
|
3
3
|
# A section of documentation like:
|
4
4
|
#
|
@@ -34,8 +34,6 @@ class RDoc::Context::Section
|
|
34
34
|
|
35
35
|
attr_reader :title
|
36
36
|
|
37
|
-
@@sequence = "SEC00000"
|
38
|
-
|
39
37
|
##
|
40
38
|
# Creates a new section with +title+ and +comment+
|
41
39
|
|
@@ -43,9 +41,6 @@ class RDoc::Context::Section
|
|
43
41
|
@parent = parent
|
44
42
|
@title = title ? title.strip : title
|
45
43
|
|
46
|
-
@@sequence.succ!
|
47
|
-
@sequence = @@sequence.dup
|
48
|
-
|
49
44
|
@comments = []
|
50
45
|
|
51
46
|
add_comment comment
|
@@ -233,13 +228,5 @@ class RDoc::Context::Section
|
|
233
228
|
end
|
234
229
|
end
|
235
230
|
|
236
|
-
##
|
237
|
-
# Section sequence number (deprecated)
|
238
|
-
|
239
|
-
def sequence
|
240
|
-
warn "RDoc::Context::Section#sequence is deprecated, use #aref"
|
241
|
-
@sequence
|
242
|
-
end
|
243
|
-
|
244
231
|
end
|
245
232
|
|
data/lib/rdoc/context.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
require 'cgi'
|
3
3
|
|
4
4
|
##
|
@@ -98,6 +98,11 @@ class RDoc::Context < RDoc::CodeObject
|
|
98
98
|
|
99
99
|
attr_accessor :visibility
|
100
100
|
|
101
|
+
##
|
102
|
+
# Current visibility of this line
|
103
|
+
|
104
|
+
attr_writer :current_line_visibility
|
105
|
+
|
101
106
|
##
|
102
107
|
# Hash of registered methods. Attributes are also registered here,
|
103
108
|
# twice if they are RW.
|
@@ -148,6 +153,7 @@ class RDoc::Context < RDoc::CodeObject
|
|
148
153
|
@extends = []
|
149
154
|
@constants = []
|
150
155
|
@external_aliases = []
|
156
|
+
@current_line_visibility = nil
|
151
157
|
|
152
158
|
# This Hash maps a method name to a list of unmatched aliases (aliases of
|
153
159
|
# a method not yet encountered).
|
@@ -233,7 +239,7 @@ class RDoc::Context < RDoc::CodeObject
|
|
233
239
|
|
234
240
|
if known then
|
235
241
|
known.comment = attribute.comment if known.comment.empty?
|
236
|
-
elsif registered = @methods_hash[attribute.pretty_name
|
242
|
+
elsif registered = @methods_hash[attribute.pretty_name + '='] and
|
237
243
|
RDoc::Attr === registered then
|
238
244
|
registered.rw = 'RW'
|
239
245
|
else
|
@@ -243,7 +249,7 @@ class RDoc::Context < RDoc::CodeObject
|
|
243
249
|
end
|
244
250
|
|
245
251
|
if attribute.rw.index 'W' then
|
246
|
-
key = attribute.pretty_name
|
252
|
+
key = attribute.pretty_name + '='
|
247
253
|
known = @methods_hash[key]
|
248
254
|
|
249
255
|
if known then
|
@@ -401,6 +407,7 @@ class RDoc::Context < RDoc::CodeObject
|
|
401
407
|
mod.section = current_section # TODO declaring context? something is
|
402
408
|
# wrong here...
|
403
409
|
mod.parent = self
|
410
|
+
mod.full_name = nil
|
404
411
|
mod.store = @store
|
405
412
|
|
406
413
|
unless @done_documenting then
|
@@ -408,6 +415,10 @@ class RDoc::Context < RDoc::CodeObject
|
|
408
415
|
# this must be done AFTER adding mod to its parent, so that the full
|
409
416
|
# name is correct:
|
410
417
|
all_hash[mod.full_name] = mod
|
418
|
+
if @store.unmatched_constant_alias[mod.full_name] then
|
419
|
+
to, file = @store.unmatched_constant_alias[mod.full_name]
|
420
|
+
add_module_alias mod, mod.name, to, file
|
421
|
+
end
|
411
422
|
end
|
412
423
|
|
413
424
|
mod
|
@@ -478,7 +489,11 @@ class RDoc::Context < RDoc::CodeObject
|
|
478
489
|
end
|
479
490
|
else
|
480
491
|
@methods_hash[key] = method
|
481
|
-
|
492
|
+
if @current_line_visibility
|
493
|
+
method.visibility, @current_line_visibility = @current_line_visibility, nil
|
494
|
+
else
|
495
|
+
method.visibility = @visibility
|
496
|
+
end
|
482
497
|
add_to @method_list, method
|
483
498
|
resolve_aliases method
|
484
499
|
end
|
@@ -500,41 +515,53 @@ class RDoc::Context < RDoc::CodeObject
|
|
500
515
|
add_class_or_module mod, @modules, @store.modules_hash
|
501
516
|
end
|
502
517
|
|
518
|
+
##
|
519
|
+
# Adds a module by +RDoc::NormalModule+ instance. See also #add_module.
|
520
|
+
|
521
|
+
def add_module_by_normal_module(mod)
|
522
|
+
add_class_or_module mod, @modules, @store.modules_hash
|
523
|
+
end
|
524
|
+
|
503
525
|
##
|
504
526
|
# Adds an alias from +from+ (a class or module) to +name+ which was defined
|
505
527
|
# in +file+.
|
506
528
|
|
507
|
-
def add_module_alias from,
|
529
|
+
def add_module_alias from, from_name, to, file
|
508
530
|
return from if @done_documenting
|
509
531
|
|
510
|
-
|
532
|
+
to_full_name = child_name to.name
|
511
533
|
|
512
534
|
# if we already know this name, don't register an alias:
|
513
535
|
# see the metaprogramming in lib/active_support/basic_object.rb,
|
514
536
|
# where we already know BasicObject is a class when we find
|
515
537
|
# BasicObject = BlankSlate
|
516
|
-
return from if @store.find_class_or_module
|
538
|
+
return from if @store.find_class_or_module to_full_name
|
539
|
+
|
540
|
+
unless from
|
541
|
+
@store.unmatched_constant_alias[child_name(from_name)] = [to, file]
|
542
|
+
return to
|
543
|
+
end
|
517
544
|
|
518
|
-
|
519
|
-
|
520
|
-
|
545
|
+
new_to = from.dup
|
546
|
+
new_to.name = to.name
|
547
|
+
new_to.full_name = nil
|
521
548
|
|
522
|
-
if
|
523
|
-
@store.modules_hash[
|
524
|
-
@modules[name] =
|
549
|
+
if new_to.module? then
|
550
|
+
@store.modules_hash[to_full_name] = new_to
|
551
|
+
@modules[to.name] = new_to
|
525
552
|
else
|
526
|
-
@store.classes_hash[
|
527
|
-
@classes[name] =
|
553
|
+
@store.classes_hash[to_full_name] = new_to
|
554
|
+
@classes[to.name] = new_to
|
528
555
|
end
|
529
556
|
|
530
557
|
# Registers a constant for this alias. The constant value and comment
|
531
558
|
# will be updated later, when the Ruby parser adds the constant
|
532
|
-
const = RDoc::Constant.new name, nil,
|
559
|
+
const = RDoc::Constant.new to.name, nil, new_to.comment
|
533
560
|
const.record_location file
|
534
561
|
const.is_alias_for = from
|
535
562
|
add_constant const
|
536
563
|
|
537
|
-
|
564
|
+
new_to
|
538
565
|
end
|
539
566
|
|
540
567
|
##
|
@@ -752,7 +779,7 @@ class RDoc::Context < RDoc::CodeObject
|
|
752
779
|
attributes.default = []
|
753
780
|
|
754
781
|
sort_sections.each do |section|
|
755
|
-
yield section, constants[section].sort, attributes[section].sort
|
782
|
+
yield section, constants[section].select(&:display?).sort, attributes[section].select(&:display?).sort
|
756
783
|
end
|
757
784
|
end
|
758
785
|
|
@@ -853,7 +880,13 @@ class RDoc::Context < RDoc::CodeObject
|
|
853
880
|
# Finds a method named +name+ with singleton value +singleton+.
|
854
881
|
|
855
882
|
def find_method(name, singleton)
|
856
|
-
@method_list.find { |m|
|
883
|
+
@method_list.find { |m|
|
884
|
+
if m.singleton
|
885
|
+
m.name == name && m.singleton == singleton
|
886
|
+
else
|
887
|
+
m.name == name && !m.singleton && !singleton
|
888
|
+
end
|
889
|
+
}
|
857
890
|
end
|
858
891
|
|
859
892
|
##
|
@@ -957,13 +990,21 @@ class RDoc::Context < RDoc::CodeObject
|
|
957
990
|
@instance_attributes ||= attributes.reject { |a| a.singleton }
|
958
991
|
end
|
959
992
|
|
993
|
+
##
|
994
|
+
# Instance methods
|
995
|
+
|
996
|
+
def instance_methods
|
997
|
+
@instance_methods ||= method_list.reject { |a| a.singleton }
|
998
|
+
end
|
999
|
+
|
960
1000
|
##
|
961
1001
|
# Instance methods
|
962
1002
|
#--
|
963
|
-
# TODO
|
1003
|
+
# TODO remove this later
|
964
1004
|
|
965
1005
|
def instance_method_list
|
966
|
-
|
1006
|
+
warn '#instance_method_list is obsoleted, please use #instance_methods'
|
1007
|
+
@instance_methods ||= method_list.reject { |a| a.singleton }
|
967
1008
|
end
|
968
1009
|
|
969
1010
|
##
|
@@ -1069,6 +1110,7 @@ class RDoc::Context < RDoc::CodeObject
|
|
1069
1110
|
return if [:private, :nodoc].include? min_visibility
|
1070
1111
|
remove_invisible_in @method_list, min_visibility
|
1071
1112
|
remove_invisible_in @attributes, min_visibility
|
1113
|
+
remove_invisible_in @constants, min_visibility
|
1072
1114
|
end
|
1073
1115
|
|
1074
1116
|
##
|
@@ -1155,6 +1197,17 @@ class RDoc::Context < RDoc::CodeObject
|
|
1155
1197
|
end
|
1156
1198
|
end
|
1157
1199
|
|
1200
|
+
##
|
1201
|
+
# Given an array +names+ of constants, set the visibility of each constant to
|
1202
|
+
# +visibility+
|
1203
|
+
|
1204
|
+
def set_constant_visibility_for(names, visibility)
|
1205
|
+
names.each do |name|
|
1206
|
+
constant = @constants_hash[name] or next
|
1207
|
+
constant.visibility = visibility
|
1208
|
+
end
|
1209
|
+
end
|
1210
|
+
|
1158
1211
|
##
|
1159
1212
|
# Sorts sections alphabetically (default) or in TomDoc fashion (none,
|
1160
1213
|
# Public, Internal, Deprecated)
|
data/lib/rdoc/cross_reference.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
##
|
3
3
|
# RDoc::CrossReference is a reusable way to create cross references for names.
|
4
4
|
|
@@ -19,16 +19,16 @@ class RDoc::CrossReference
|
|
19
19
|
#
|
20
20
|
# See CLASS_REGEXP_STR
|
21
21
|
|
22
|
-
METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===|\[\]
|
22
|
+
METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===|\[\]=?|<<|>>|\+@|-@|-|\+|\*)(?:\([\w.+*/=<>-]*\))?'
|
23
23
|
|
24
24
|
##
|
25
25
|
# Regular expressions matching text that should potentially have
|
26
|
-
# cross-reference links generated are passed to
|
27
|
-
# these expressions are meant to pick up text for which cross-references
|
26
|
+
# cross-reference links generated are passed to add_regexp_handling. Note
|
27
|
+
# that these expressions are meant to pick up text for which cross-references
|
28
28
|
# have been suppressed, since the suppression characters are removed by the
|
29
29
|
# code that is triggered.
|
30
30
|
|
31
|
-
CROSSREF_REGEXP = /(
|
31
|
+
CROSSREF_REGEXP = /(?:^|[\s()])
|
32
32
|
(
|
33
33
|
(?:
|
34
34
|
# A::B::C.meth
|
@@ -76,7 +76,7 @@ class RDoc::CrossReference
|
|
76
76
|
# Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
|
77
77
|
|
78
78
|
ALL_CROSSREF_REGEXP = /
|
79
|
-
(
|
79
|
+
(?:^|[\s()])
|
80
80
|
(
|
81
81
|
(?:
|
82
82
|
# A::B::C.meth
|
@@ -127,23 +127,41 @@ class RDoc::CrossReference
|
|
127
127
|
|
128
128
|
if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
|
129
129
|
type = $2
|
130
|
-
|
131
|
-
|
130
|
+
if '.' == type # will find either #method or ::method
|
131
|
+
method = $3
|
132
|
+
else
|
133
|
+
method = "#{type}#{$3}"
|
134
|
+
end
|
132
135
|
container = @context.find_symbol_module($1)
|
133
136
|
elsif /^([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
|
134
137
|
type = $1
|
135
|
-
|
136
|
-
|
138
|
+
if '.' == type
|
139
|
+
method = $2
|
140
|
+
else
|
141
|
+
method = "#{type}#{$2}"
|
142
|
+
end
|
137
143
|
container = @context
|
138
144
|
else
|
145
|
+
type = nil
|
139
146
|
container = nil
|
140
147
|
end
|
141
148
|
|
142
149
|
if container then
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
150
|
+
unless RDoc::TopLevel === container then
|
151
|
+
if '.' == type then
|
152
|
+
if 'new' == method then # AnyClassName.new will be class method
|
153
|
+
ref = container.find_local_symbol method
|
154
|
+
ref = container.find_ancestor_local_symbol method unless ref
|
155
|
+
else
|
156
|
+
ref = container.find_local_symbol "::#{method}"
|
157
|
+
ref = container.find_ancestor_local_symbol "::#{method}" unless ref
|
158
|
+
ref = container.find_local_symbol "##{method}" unless ref
|
159
|
+
ref = container.find_ancestor_local_symbol "##{method}" unless ref
|
160
|
+
end
|
161
|
+
else
|
162
|
+
ref = container.find_local_symbol method
|
163
|
+
ref = container.find_ancestor_local_symbol method unless ref
|
164
|
+
end
|
147
165
|
end
|
148
166
|
end
|
149
167
|
|
@@ -155,7 +173,7 @@ class RDoc::CrossReference
|
|
155
173
|
end unless ref
|
156
174
|
|
157
175
|
# Try a page name
|
158
|
-
ref = @store.page name if not ref and name =~
|
176
|
+
ref = @store.page name if not ref and name =~ /^[\w.]+$/
|
159
177
|
|
160
178
|
ref = nil if RDoc::Alias === ref # external alias, can't link to it
|
161
179
|
|
data/lib/rdoc/encoding.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: US-ASCII
|
2
|
-
# frozen_string_literal:
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
##
|
5
5
|
# This class is a wrapper around File IO and Encoding that helps RDoc load
|
@@ -7,6 +7,18 @@
|
|
7
7
|
|
8
8
|
module RDoc::Encoding
|
9
9
|
|
10
|
+
HEADER_REGEXP = /^
|
11
|
+
(?:
|
12
|
+
\A\#!.*\n
|
13
|
+
|
|
14
|
+
^\#\s+frozen[-_]string[-_]literal[=:].+\n
|
15
|
+
|
|
16
|
+
^\#[^\n]+\b(?:en)?coding[=:]\s*(?<name>[^\s;]+).*\n
|
17
|
+
|
|
18
|
+
<\?xml[^?]*encoding=(?<quote>["'])(?<name>.*?)\k<quote>.*\n
|
19
|
+
)+
|
20
|
+
/xi # :nodoc:
|
21
|
+
|
10
22
|
##
|
11
23
|
# Reads the contents of +filename+ and handles any encoding directives in
|
12
24
|
# the file.
|
@@ -18,31 +30,32 @@ module RDoc::Encoding
|
|
18
30
|
# unknown character in the target encoding will be replaced with '?'
|
19
31
|
|
20
32
|
def self.read_file filename, encoding, force_transcode = false
|
21
|
-
content = open filename, "rb" do |f| f.read end
|
33
|
+
content = File.open filename, "rb" do |f| f.read end
|
22
34
|
content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/
|
23
35
|
|
24
36
|
utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
|
25
37
|
|
26
|
-
RDoc::Encoding.
|
38
|
+
enc = RDoc::Encoding.detect_encoding content
|
39
|
+
content = RDoc::Encoding.change_encoding content, enc if enc
|
27
40
|
|
28
41
|
begin
|
29
42
|
encoding ||= Encoding.default_external
|
30
43
|
orig_encoding = content.encoding
|
31
44
|
|
32
45
|
if not orig_encoding.ascii_compatible? then
|
33
|
-
content.encode
|
46
|
+
content = content.encode encoding
|
34
47
|
elsif utf8 then
|
35
|
-
content.
|
36
|
-
content.encode
|
48
|
+
content = RDoc::Encoding.change_encoding content, Encoding::UTF_8
|
49
|
+
content = content.encode encoding
|
37
50
|
else
|
38
51
|
# assume the content is in our output encoding
|
39
|
-
content.
|
52
|
+
content = RDoc::Encoding.change_encoding content, encoding
|
40
53
|
end
|
41
54
|
|
42
55
|
unless content.valid_encoding? then
|
43
56
|
# revert and try to transcode
|
44
|
-
content.
|
45
|
-
content.encode
|
57
|
+
content = RDoc::Encoding.change_encoding content, orig_encoding
|
58
|
+
content = content.encode encoding
|
46
59
|
end
|
47
60
|
|
48
61
|
unless content.valid_encoding? then
|
@@ -52,10 +65,11 @@ module RDoc::Encoding
|
|
52
65
|
rescue Encoding::InvalidByteSequenceError,
|
53
66
|
Encoding::UndefinedConversionError => e
|
54
67
|
if force_transcode then
|
55
|
-
content.
|
56
|
-
content.encode
|
57
|
-
|
58
|
-
|
68
|
+
content = RDoc::Encoding.change_encoding content, orig_encoding
|
69
|
+
content = content.encode(encoding,
|
70
|
+
:invalid => :replace,
|
71
|
+
:undef => :replace,
|
72
|
+
:replace => '?')
|
59
73
|
return content
|
60
74
|
else
|
61
75
|
warn "unable to convert #{e.message} for #{filename}, skipping"
|
@@ -77,32 +91,46 @@ module RDoc::Encoding
|
|
77
91
|
first_line = $1
|
78
92
|
|
79
93
|
if first_line =~ /\A# +frozen[-_]string[-_]literal[=:].+$/i
|
80
|
-
string.sub
|
94
|
+
string = string.sub first_line, ''
|
81
95
|
end
|
96
|
+
|
97
|
+
string
|
82
98
|
end
|
83
99
|
|
84
100
|
##
|
85
|
-
#
|
101
|
+
# Detects the encoding of +string+ based on the magic comment
|
86
102
|
|
87
|
-
def self.
|
88
|
-
|
89
|
-
|
90
|
-
string =~ /\A(?:#!.*\n)?(.*\n)/
|
103
|
+
def self.detect_encoding string
|
104
|
+
result = HEADER_REGEXP.match string
|
105
|
+
name = result && result[:name]
|
91
106
|
|
92
|
-
|
93
|
-
|
94
|
-
name = case first_line
|
95
|
-
when /^<\?xml[^?]*encoding=(["'])(.*?)\1/ then $2
|
96
|
-
when /\b(?:en)?coding[=:]\s*([^\s;]+)/i then $1
|
97
|
-
else return
|
98
|
-
end
|
107
|
+
name ? Encoding.find(name) : nil
|
108
|
+
end
|
99
109
|
|
100
|
-
|
110
|
+
##
|
111
|
+
# Removes magic comments and shebang
|
101
112
|
|
102
|
-
|
113
|
+
def self.remove_magic_comment string
|
114
|
+
string.sub HEADER_REGEXP do |s|
|
115
|
+
s.gsub(/[^\n]/, '')
|
116
|
+
end
|
117
|
+
end
|
103
118
|
|
104
|
-
|
105
|
-
|
119
|
+
##
|
120
|
+
# Changes encoding based on +encoding+ without converting and returns new
|
121
|
+
# string
|
122
|
+
|
123
|
+
def self.change_encoding text, encoding
|
124
|
+
if text.kind_of? RDoc::Comment
|
125
|
+
text.encode! encoding
|
126
|
+
else
|
127
|
+
# TODO: Remove this condition after Ruby 2.2 EOL
|
128
|
+
if RUBY_VERSION < '2.3.0'
|
129
|
+
text.force_encoding encoding
|
130
|
+
else
|
131
|
+
String.new text, encoding: encoding
|
132
|
+
end
|
133
|
+
end
|
106
134
|
end
|
107
135
|
|
108
136
|
end
|