rdoc 6.17.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +193 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/LICENSE.rdoc +4 -0
  5. data/README.md +132 -8
  6. data/RI.md +75 -75
  7. data/doc/markup_reference/markdown.md +659 -0
  8. data/doc/markup_reference/rdoc.rdoc +1169 -0
  9. data/exe/rdoc +2 -2
  10. data/lib/rdoc/code_object/alias.rb +70 -74
  11. data/lib/rdoc/code_object/any_method.rb +308 -293
  12. data/lib/rdoc/code_object/attr.rb +150 -142
  13. data/lib/rdoc/code_object/class_module.rb +802 -715
  14. data/lib/rdoc/code_object/constant.rb +181 -144
  15. data/lib/rdoc/code_object/context/section.rb +140 -130
  16. data/lib/rdoc/code_object/context.rb +925 -941
  17. data/lib/rdoc/code_object/extend.rb +7 -5
  18. data/lib/rdoc/code_object/include.rb +7 -5
  19. data/lib/rdoc/code_object/method_attr.rb +328 -315
  20. data/lib/rdoc/code_object/mixin.rb +97 -92
  21. data/lib/rdoc/code_object/normal_class.rb +77 -78
  22. data/lib/rdoc/code_object/normal_module.rb +61 -59
  23. data/lib/rdoc/code_object/require.rb +23 -39
  24. data/lib/rdoc/code_object/single_class.rb +21 -19
  25. data/lib/rdoc/code_object/top_level.rb +215 -202
  26. data/lib/rdoc/code_object.rb +305 -305
  27. data/lib/rdoc/comment.rb +274 -337
  28. data/lib/rdoc/cross_reference.rb +195 -206
  29. data/lib/rdoc/encoding.rb +105 -103
  30. data/lib/rdoc/erb_partial.rb +13 -11
  31. data/lib/rdoc/erbio.rb +29 -27
  32. data/lib/rdoc/generator/aliki.rb +196 -30
  33. data/lib/rdoc/generator/darkfish.rb +647 -629
  34. data/lib/rdoc/generator/json_index.rb +233 -229
  35. data/lib/rdoc/generator/markup.rb +165 -122
  36. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  37. data/lib/rdoc/generator/pot/po.rb +52 -51
  38. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  39. data/lib/rdoc/generator/pot.rb +85 -81
  40. data/lib/rdoc/generator/ri.rb +23 -19
  41. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  42. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  43. data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
  44. data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
  45. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  46. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  47. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  48. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  49. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
  50. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  51. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  52. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  53. data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
  54. data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
  55. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
  57. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  58. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  59. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  60. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  61. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  62. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  63. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  64. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  65. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  66. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  67. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  68. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  69. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
  70. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  71. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  72. data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
  73. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
  74. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  75. data/lib/rdoc/generator.rb +48 -46
  76. data/lib/rdoc/i18n/locale.rb +99 -95
  77. data/lib/rdoc/i18n/text.rb +109 -105
  78. data/lib/rdoc/i18n.rb +7 -5
  79. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  80. data/lib/rdoc/markdown.kpeg +52 -33
  81. data/lib/rdoc/markdown.rb +365 -177
  82. data/lib/rdoc/markup/blank_line.rb +25 -23
  83. data/lib/rdoc/markup/block_quote.rb +12 -8
  84. data/lib/rdoc/markup/document.rb +127 -123
  85. data/lib/rdoc/markup/element.rb +21 -0
  86. data/lib/rdoc/markup/formatter.rb +220 -203
  87. data/lib/rdoc/markup/hard_break.rb +30 -27
  88. data/lib/rdoc/markup/heading.rb +163 -77
  89. data/lib/rdoc/markup/include.rb +33 -29
  90. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  91. data/lib/rdoc/markup/inline_parser.rb +316 -0
  92. data/lib/rdoc/markup/list.rb +80 -88
  93. data/lib/rdoc/markup/list_item.rb +73 -85
  94. data/lib/rdoc/markup/paragraph.rb +23 -19
  95. data/lib/rdoc/markup/parser.rb +501 -497
  96. data/lib/rdoc/markup/pre_process.rb +284 -305
  97. data/lib/rdoc/markup/raw.rb +52 -55
  98. data/lib/rdoc/markup/rule.rb +16 -12
  99. data/lib/rdoc/markup/table.rb +48 -40
  100. data/lib/rdoc/markup/to_ansi.rb +143 -92
  101. data/lib/rdoc/markup/to_bs.rb +86 -102
  102. data/lib/rdoc/markup/to_html.rb +608 -506
  103. data/lib/rdoc/markup/to_html_crossref.rb +219 -210
  104. data/lib/rdoc/markup/to_html_snippet.rb +210 -205
  105. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  106. data/lib/rdoc/markup/to_label.rb +64 -51
  107. data/lib/rdoc/markup/to_markdown.rb +212 -184
  108. data/lib/rdoc/markup/to_rdoc.rb +341 -277
  109. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  110. data/lib/rdoc/markup/to_test.rb +62 -50
  111. data/lib/rdoc/markup/to_tt_only.rb +83 -92
  112. data/lib/rdoc/markup/verbatim.rb +62 -58
  113. data/lib/rdoc/markup.rb +196 -215
  114. data/lib/rdoc/options.rb +1063 -1076
  115. data/lib/rdoc/parser/c.rb +1039 -1036
  116. data/lib/rdoc/parser/changelog.rb +320 -287
  117. data/lib/rdoc/parser/markdown.rb +17 -13
  118. data/lib/rdoc/parser/rbs.rb +279 -0
  119. data/lib/rdoc/parser/rd.rb +17 -13
  120. data/lib/rdoc/parser/ruby.rb +1231 -2222
  121. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  122. data/lib/rdoc/parser/simple.rb +31 -27
  123. data/lib/rdoc/parser/text.rb +12 -8
  124. data/lib/rdoc/parser.rb +230 -221
  125. data/lib/rdoc/rbs_helper.rb +186 -0
  126. data/lib/rdoc/rd/inline.rb +57 -53
  127. data/lib/rdoc/rd.rb +90 -88
  128. data/lib/rdoc/rdoc.rb +547 -366
  129. data/lib/rdoc/ri/driver.rb +1141 -1130
  130. data/lib/rdoc/ri/formatter.rb +7 -3
  131. data/lib/rdoc/ri/paths.rb +140 -136
  132. data/lib/rdoc/ri/servlet.rb +456 -0
  133. data/lib/rdoc/ri/store.rb +4 -2
  134. data/lib/rdoc/ri/task.rb +55 -51
  135. data/lib/rdoc/ri.rb +14 -11
  136. data/lib/rdoc/rubygems_hook.rb +194 -192
  137. data/lib/rdoc/server.rb +462 -0
  138. data/lib/rdoc/stats/normal.rb +46 -42
  139. data/lib/rdoc/stats/quiet.rb +39 -35
  140. data/lib/rdoc/stats/verbose.rb +35 -31
  141. data/lib/rdoc/stats.rb +363 -338
  142. data/lib/rdoc/store.rb +919 -725
  143. data/lib/rdoc/task.rb +260 -255
  144. data/lib/rdoc/text.rb +164 -240
  145. data/lib/rdoc/token_stream.rb +88 -106
  146. data/lib/rdoc/tom_doc.rb +203 -201
  147. data/lib/rdoc/version.rb +1 -1
  148. data/lib/rdoc.rb +35 -7
  149. data/lib/rubygems_plugin.rb +2 -11
  150. data/rdoc-logo.svg +43 -0
  151. data/rdoc.gemspec +9 -7
  152. metadata +46 -32
  153. data/CONTRIBUTING.rdoc +0 -219
  154. data/ExampleMarkdown.md +0 -39
  155. data/ExampleRDoc.rdoc +0 -210
  156. data/lib/rdoc/code_object/anon_class.rb +0 -10
  157. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  158. data/lib/rdoc/code_object/meta_method.rb +0 -6
  159. data/lib/rdoc/markdown/literals.kpeg +0 -21
  160. data/lib/rdoc/markdown/literals.rb +0 -454
  161. data/lib/rdoc/markup/attr_changer.rb +0 -22
  162. data/lib/rdoc/markup/attr_span.rb +0 -35
  163. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  164. data/lib/rdoc/markup/attributes.rb +0 -70
  165. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  166. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  167. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  168. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  169. data/lib/rdoc/servlet.rb +0 -452
@@ -1,228 +1,217 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'markup/attribute_manager' # for PROTECT_ATTR
4
-
5
- ##
6
- # RDoc::CrossReference is a reusable way to create cross references for names.
7
-
8
- class RDoc::CrossReference
9
-
10
- ##
11
- # Regular expression to match class references
12
- #
13
- # 1. There can be a '\\' in front of text to suppress the cross-reference
14
- # 2. There can be a '::' in front of class names to reference from the
15
- # top-level namespace.
16
- # 3. The method can be followed by parenthesis (not recommended)
17
-
18
- CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'
19
-
20
- ##
21
- # Regular expression to match a single method argument.
22
-
23
- METHOD_ARG_REGEXP_STR = '[\w.+*/=<>-]+'
24
-
25
- ##
26
- # Regular expression to match method arguments.
27
-
28
- METHOD_ARGS_REGEXP_STR = /(?:\((?:#{METHOD_ARG_REGEXP_STR}(?:,\s*#{METHOD_ARG_REGEXP_STR})*)?\))?/.source
29
-
30
- ##
31
- # Regular expression to match method references.
32
- #
33
- # See CLASS_REGEXP_STR
34
-
35
- METHOD_REGEXP_STR = /(
36
- (?!\d)[\w#{RDoc::Markup::AttributeManager::PROTECT_ATTR}]+[!?=]?|
37
- %|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[\/%\`|&^~]
38
- )#{METHOD_ARGS_REGEXP_STR}/.source.delete("\n ").freeze
39
-
40
- ##
41
- # Regular expressions matching text that should potentially have
42
- # cross-reference links generated are passed to add_regexp_handling. Note
43
- # that these expressions are meant to pick up text for which cross-references
44
- # have been suppressed, since the suppression characters are removed by the
45
- # code that is triggered.
46
-
47
- CROSSREF_REGEXP = /(?:^|[\s()])
48
- (
49
- (?:
50
- # A::B::C.meth
51
- #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
52
-
53
- # A::B::C
54
- # The stuff after CLASS_REGEXP_STR is a
55
- # nasty hack. CLASS_REGEXP_STR unfortunately matches
56
- # words like dog and cat (these are legal "class"
57
- # names in Fortran 95). When a word is flagged as a
58
- # potential cross-reference, limitations in the markup
59
- # engine suppress other processing, such as typesetting.
60
- # This is particularly noticeable for contractions.
61
- # In order that words like "can't" not
62
- # be flagged as potential cross-references, only
63
- # flag potential class cross-references if the character
64
- # after the cross-reference is a space, sentence
65
- # punctuation, tag start character, or attribute
66
- # marker.
67
- | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
68
-
69
- # Stand-alone method (preceded by a #)
70
- | \\?\##{METHOD_REGEXP_STR}
71
-
72
- # Stand-alone method (preceded by ::)
73
- | ::#{METHOD_REGEXP_STR}
74
-
75
- # Things that look like filenames
76
- # The key thing is that there must be at least
77
- # one special character (period, slash, or
78
- # underscore).
79
- | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
80
-
81
- # Things that have markup suppressed
82
- # Don't process things like '\<' in \<tt>, though.
83
- # TODO: including < is a hack, not very satisfying.
84
- | \\[^\s<]
85
- )
86
-
87
- # labels for headings
88
- (?:@[\w+%-]+(?:\.[\w|%-]+)?)?
89
- )/x
90
-
91
- ##
92
- # Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
93
-
94
- ALL_CROSSREF_REGEXP = /
95
- (?:^|[\s()])
96
- (
97
- (?:
98
- # A::B::C.meth
99
- #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
100
-
101
- # A::B::C
102
- | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
103
-
104
- # Stand-alone method
105
- | \\?#{METHOD_REGEXP_STR}
106
-
107
- # Things that look like filenames
108
- | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
109
-
110
- # Things that have markup suppressed
111
- | \\[^\s<]
112
- )
113
-
114
- # labels for headings
115
- (?:@[\w+%-]+)?
116
- )/x
117
-
118
- ##
119
- # Hash of references that have been looked-up to their replacements
120
-
121
- attr_accessor :seen
122
-
123
- ##
124
- # Allows cross-references to be created based on the given +context+
125
- # (RDoc::Context).
126
-
127
- def initialize(context)
128
- @context = context
129
- @store = context.store
130
-
131
- @seen = {}
132
- end
133
-
3
+ module RDoc
134
4
  ##
135
- # Returns a method reference to +name+.
136
-
137
- def resolve_method(name)
138
- ref = nil
5
+ # RDoc::CrossReference is a reusable way to create cross references for names.
6
+
7
+ class CrossReference
8
+
9
+ ##
10
+ # Regular expression to match class references
11
+ #
12
+ # 1. There can be a '\\' in front of text to suppress the cross-reference
13
+ # 2. There can be a '::' in front of class names to reference from the
14
+ # top-level namespace.
15
+ # 3. The method can be followed by parenthesis (not recommended)
16
+
17
+ CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'
18
+
19
+ ##
20
+ # Regular expression to match a single method argument.
21
+
22
+ METHOD_ARG_REGEXP_STR = '[\w.+*/=<>-]+'
23
+
24
+ ##
25
+ # Regular expression to match method arguments.
26
+
27
+ METHOD_ARGS_REGEXP_STR = /(?:\((?:#{METHOD_ARG_REGEXP_STR}(?:,\s*#{METHOD_ARG_REGEXP_STR})*)?\))?/.source
28
+
29
+ ##
30
+ # Regular expression to match method references.
31
+ #
32
+ # See CLASS_REGEXP_STR
33
+
34
+ METHOD_REGEXP_STR = /(
35
+ (?!\d)[\w]+[!?=]?|
36
+ %|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[\/%\`|&^~]
37
+ )#{METHOD_ARGS_REGEXP_STR}/.source.delete("\n ").freeze
38
+
39
+ ##
40
+ # Regular expressions matching text that should potentially have
41
+ # cross-reference links generated are passed to add_regexp_handling. Note
42
+ # that these expressions are meant to pick up text for which cross-references
43
+ # have been suppressed, since the suppression characters are removed by the
44
+ # code that is triggered.
45
+
46
+ CROSSREF_REGEXP = /(?:^|[\s()])
47
+ (
48
+ (?:
49
+ # A::B::C.meth
50
+ #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
51
+
52
+ # A::B::C
53
+ # The stuff after CLASS_REGEXP_STR is a
54
+ # nasty hack. CLASS_REGEXP_STR unfortunately matches
55
+ # words like dog and cat (these are legal "class"
56
+ # names in Fortran 95). When a word is flagged as a
57
+ # potential cross-reference, limitations in the markup
58
+ # engine suppress other processing, such as typesetting.
59
+ # This is particularly noticeable for contractions.
60
+ # In order that words like "can't" not
61
+ # be flagged as potential cross-references, only
62
+ # flag potential class cross-references if the character
63
+ # after the cross-reference is a space, sentence
64
+ # punctuation, tag start character, or attribute
65
+ # marker.
66
+ | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
67
+
68
+ # Stand-alone method (preceded by a #)
69
+ | \\?\##{METHOD_REGEXP_STR}
70
+
71
+ # Stand-alone method (preceded by ::)
72
+ | ::#{METHOD_REGEXP_STR}
73
+
74
+ # Things that look like filenames
75
+ # The key thing is that there must be at least
76
+ # one special character (period, slash, or
77
+ # underscore).
78
+ | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
79
+
80
+ # Things that have markup suppressed
81
+ # Don't process things like '\<' in \<tt>, though.
82
+ # TODO: including < is a hack, not very satisfying.
83
+ | \\[^\s<]
84
+ )
85
+
86
+ # labels for headings
87
+ (?:@[\w+%-]+(?:\.[\w|%-]+)?)?
88
+ )/x
89
+
90
+ ##
91
+ # Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
92
+
93
+ ALL_CROSSREF_REGEXP = /
94
+ (?:^|[\s()])
95
+ (
96
+ (?:
97
+ # A::B::C.meth
98
+ #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
99
+
100
+ # A::B::C
101
+ | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
102
+
103
+ # Stand-alone method
104
+ | \\?#{METHOD_REGEXP_STR}
105
+
106
+ # Things that look like filenames
107
+ | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
108
+
109
+ # Things that have markup suppressed
110
+ | \\[^\s<]
111
+ )
112
+
113
+ # labels for headings
114
+ (?:@[\w+%-]+)?
115
+ )/x
116
+
117
+ ##
118
+ # Hash of references that have been looked-up to their replacements
119
+
120
+ attr_accessor :seen
121
+
122
+ ##
123
+ # Allows cross-references to be created based on the given +context+
124
+ # (RDoc::Context).
125
+
126
+ def initialize(context)
127
+ @context = context
128
+ @store = context.store
129
+
130
+ @seen = {}
131
+ end
139
132
 
140
- if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
141
- type = $2
142
- if '.' == type # will find either #method or ::method
143
- method = $3
144
- else
145
- method = "#{type}#{$3}"
146
- end
147
- container = @context.find_symbol_module($1)
148
- elsif /^([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
149
- type = $1
150
- if '.' == type
151
- method = $2
152
- else
153
- method = "#{type}#{$2}"
154
- end
155
- container = @context
156
- else
133
+ ##
134
+ # Returns a method, attribute or constant reference to +name+
135
+ # if it exists in the containing context object. It returns
136
+ # nil otherwise.
137
+ #
138
+ # For example, this method would decompose name = 'A::CONSTANT' into a
139
+ # container object A and a symbol 'CONSTANT', and it would try to find
140
+ # 'CONSTANT' in A.
141
+
142
+ def resolve_local_symbol(name)
143
+ ref = nil
157
144
  type = nil
158
145
  container = nil
159
- end
160
146
 
161
- if container then
162
- unless RDoc::TopLevel === container then
163
- if '.' == type then
164
- if 'new' == method then # AnyClassName.new will be class method
165
- ref = container.find_local_symbol method
166
- ref = container.find_ancestor_local_symbol method unless ref
147
+ case name
148
+ when /#{CLASS_REGEXP_STR}::([A-Z]\w*)\z/o
149
+ symbol = $2
150
+ container = @context.find_symbol_module($1)
151
+ when /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o
152
+ type = $2
153
+ if '.' == type # will find either #method or ::method
154
+ symbol = $3
155
+ else
156
+ symbol = "#{type}#{$3}"
157
+ end
158
+ container = @context.find_symbol_module($1)
159
+ when /^([.#]|::)#{METHOD_REGEXP_STR}/o
160
+ type = $1
161
+ if '.' == type
162
+ symbol = $2
163
+ else
164
+ symbol = "#{type}#{$2}"
165
+ end
166
+ container = @context
167
+ end
168
+
169
+ if container
170
+ unless TopLevel === container
171
+ if '.' == type
172
+ if 'new' == symbol # AnyClassName.new will be class method
173
+ ref = container.find_local_symbol symbol
174
+ ref = container.find_ancestor_local_symbol symbol unless ref
175
+ else
176
+ ref = container.find_local_symbol "::#{symbol}"
177
+ ref = container.find_ancestor_local_symbol "::#{symbol}" unless ref
178
+ ref = container.find_local_symbol "##{symbol}" unless ref
179
+ ref = container.find_ancestor_local_symbol "##{symbol}" unless ref
180
+ end
167
181
  else
168
- ref = container.find_local_symbol "::#{method}"
169
- ref = container.find_ancestor_local_symbol "::#{method}" unless ref
170
- ref = container.find_local_symbol "##{method}" unless ref
171
- ref = container.find_ancestor_local_symbol "##{method}" unless ref
182
+ ref = container.find_local_symbol symbol
183
+ ref = container.find_ancestor_local_symbol symbol unless ref
172
184
  end
173
- else
174
- ref = container.find_local_symbol method
175
- ref = container.find_ancestor_local_symbol method unless ref
176
185
  end
177
186
  end
187
+
188
+ ref
178
189
  end
179
190
 
180
- ref
181
- end
191
+ ##
192
+ # Returns a reference to +name+.
193
+ #
194
+ # If the reference is found and +name+ is not documented +nil+ will be
195
+ # returned. If +name+ is not found +nil+ is returned.
182
196
 
183
- ##
184
- # Returns a reference to +name+.
185
- #
186
- # If the reference is found and +name+ is not documented +text+ will be
187
- # returned. If +name+ is escaped +name+ is returned. If +name+ is not
188
- # found +text+ is returned.
189
-
190
- def resolve(name, text)
191
- return @seen[name] if @seen.include? name
192
-
193
- ref = case name
194
- when /^\\(#{CLASS_REGEXP_STR})$/o then
195
- @context.find_symbol $1
196
- else
197
- @context.find_symbol name
198
- end
197
+ def resolve(name)
198
+ return @seen[name] if @seen.include? name
199
199
 
200
- ref = resolve_method name unless ref
200
+ ref = @context.find_symbol name
201
201
 
202
- # Try a page name
203
- ref = @store.page name if not ref and name =~ /^[\w.\/]+$/
202
+ ref = resolve_local_symbol name unless ref
204
203
 
205
- ref = nil if RDoc::Alias === ref # external alias, can't link to it
204
+ # Try a page name
205
+ ref = @store.page name if not ref and name =~ /^[\w.\/]+$/
206
206
 
207
- out = if name == '\\' then
208
- name
209
- elsif name =~ /^\\/ then
210
- # we remove the \ only in front of what we know:
211
- # other backslashes are treated later, only outside of <tt>
212
- ref ? $' : name
213
- elsif ref then
214
- if ref.display? then
215
- ref
216
- else
217
- text
218
- end
219
- else
220
- text
221
- end
207
+ ref = nil if Alias === ref # external alias, can't link to it
222
208
 
223
- @seen[name] = out
209
+ ref = nil unless ref&.display?
224
210
 
225
- out
226
- end
211
+ @seen[name] = ref
227
212
 
213
+ ref
214
+ end
215
+
216
+ end
228
217
  end
data/lib/rdoc/encoding.rb CHANGED
@@ -1,120 +1,122 @@
1
1
  # coding: US-ASCII
2
2
  # frozen_string_literal: true
3
3
 
4
- ##
5
- # This class is a wrapper around File IO and Encoding that helps RDoc load
6
- # files and convert them to the correct encoding.
7
-
8
- module RDoc::Encoding
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
-
4
+ module RDoc
22
5
  ##
23
- # Reads the contents of +filename+ and handles any encoding directives in
24
- # the file.
25
- #
26
- # The content will be converted to the +encoding+. If the file cannot be
27
- # converted a warning will be printed and nil will be returned.
28
- #
29
- # If +force_transcode+ is true the document will be transcoded and any
30
- # unknown character in the target encoding will be replaced with '?'
31
-
32
- def self.read_file(filename, encoding, force_transcode = false)
33
- content = File.open filename, "rb" do |f| f.read end
34
- content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/
35
-
36
- utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
37
-
38
- enc = RDoc::Encoding.detect_encoding content
39
- content = RDoc::Encoding.change_encoding content, enc if enc
40
-
41
- begin
42
- encoding ||= Encoding.default_external
43
- orig_encoding = content.encoding
44
-
45
- if not orig_encoding.ascii_compatible? then
46
- content = content.encode encoding
47
- elsif utf8 then
48
- content = RDoc::Encoding.change_encoding content, Encoding::UTF_8
49
- content = content.encode encoding
50
- else
51
- # assume the content is in our output encoding
52
- content = RDoc::Encoding.change_encoding content, encoding
53
- end
54
-
55
- unless content.valid_encoding? then
56
- # revert and try to transcode
57
- content = RDoc::Encoding.change_encoding content, orig_encoding
58
- content = content.encode encoding
6
+ # This class is a wrapper around File IO and Encoding that helps RDoc load
7
+ # files and convert them to the correct encoding.
8
+
9
+ module Encoding
10
+
11
+ HEADER_REGEXP = /\A
12
+ (?:
13
+ \#!.*\n
14
+ |
15
+ ^\#\s+frozen[-_]string[-_]literal[=:].+\n
16
+ |
17
+ ^\#\s*(?:-\*-\s*(?:[^;\n]*;\s*)*)?(?:en)?coding[=:]\s*(?<name>[^:\s;]+).*\n
18
+ |
19
+ <\?xml[^?]*encoding=(?<quote>["'])(?<name>.*?)\k<quote>.*\n
20
+ )+
21
+ /xi # :nodoc:
22
+
23
+ ##
24
+ # Reads the contents of +filename+ and handles any encoding directives in
25
+ # the file.
26
+ #
27
+ # The content will be converted to the +encoding+. If the file cannot be
28
+ # converted a warning will be printed and nil will be returned.
29
+ #
30
+ # If +force_transcode+ is true the document will be transcoded and any
31
+ # unknown character in the target encoding will be replaced with '?'
32
+
33
+ def self.read_file(filename, encoding, force_transcode = false)
34
+ content = File.open filename, "rb" do |f| f.read end
35
+ content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/
36
+
37
+ utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
38
+
39
+ enc = Encoding.detect_encoding content
40
+ content = Encoding.change_encoding content, enc if enc
41
+
42
+ begin
43
+ encoding ||= ::Encoding.default_external
44
+ orig_encoding = content.encoding
45
+
46
+ if not orig_encoding.ascii_compatible?
47
+ content = content.encode encoding
48
+ elsif utf8
49
+ content = Encoding.change_encoding content, ::Encoding::UTF_8
50
+ content = content.encode encoding
51
+ else
52
+ # assume the content is in our output encoding
53
+ content = Encoding.change_encoding content, encoding
54
+ end
55
+
56
+ unless content.valid_encoding?
57
+ # revert and try to transcode
58
+ content = Encoding.change_encoding content, orig_encoding
59
+ content = content.encode encoding
60
+ end
61
+
62
+ unless content.valid_encoding?
63
+ warn "unable to convert #{filename} to #{encoding}, skipping"
64
+ content = nil
65
+ end
66
+ rescue ::Encoding::InvalidByteSequenceError,
67
+ ::Encoding::UndefinedConversionError => e
68
+ if force_transcode
69
+ content = Encoding.change_encoding content, orig_encoding
70
+ content = content.encode(encoding,
71
+ :invalid => :replace,
72
+ :undef => :replace,
73
+ :replace => '?')
74
+ return content
75
+ else
76
+ warn "unable to convert #{e.message} for #{filename}, skipping"
77
+ return nil
78
+ end
59
79
  end
60
80
 
61
- unless content.valid_encoding? then
62
- warn "unable to convert #{filename} to #{encoding}, skipping"
63
- content = nil
64
- end
65
- rescue Encoding::InvalidByteSequenceError,
66
- Encoding::UndefinedConversionError => e
67
- if force_transcode then
68
- content = RDoc::Encoding.change_encoding content, orig_encoding
69
- content = content.encode(encoding,
70
- :invalid => :replace,
71
- :undef => :replace,
72
- :replace => '?')
73
- return content
74
- else
75
- warn "unable to convert #{e.message} for #{filename}, skipping"
76
- return nil
77
- end
81
+ content
82
+ rescue ArgumentError => e
83
+ raise unless e.message =~ /unknown encoding name - (.*)/
84
+ warn "unknown encoding name \"#{$1}\" for #{filename}, skipping"
85
+ nil
86
+ rescue Errno::EISDIR, Errno::ENOENT
87
+ nil
78
88
  end
79
89
 
80
- content
81
- rescue ArgumentError => e
82
- raise unless e.message =~ /unknown encoding name - (.*)/
83
- warn "unknown encoding name \"#{$1}\" for #{filename}, skipping"
84
- nil
85
- rescue Errno::EISDIR, Errno::ENOENT
86
- nil
87
- end
90
+ ##
91
+ # Detects the encoding of +string+ based on the magic comment
88
92
 
89
- ##
90
- # Detects the encoding of +string+ based on the magic comment
93
+ def self.detect_encoding(string)
94
+ result = HEADER_REGEXP.match string
95
+ name = result && result[:name]
91
96
 
92
- def self.detect_encoding(string)
93
- result = HEADER_REGEXP.match string
94
- name = result && result[:name]
95
-
96
- name ? Encoding.find(name) : nil
97
- end
97
+ name ? ::Encoding.find(name) : nil
98
+ end
98
99
 
99
- ##
100
- # Removes magic comments and shebang
100
+ ##
101
+ # Removes magic comments and shebang
101
102
 
102
- def self.remove_magic_comment(string)
103
- string.sub HEADER_REGEXP do |s|
104
- s.gsub(/[^\n]/, '')
103
+ def self.remove_magic_comment(string)
104
+ string.sub HEADER_REGEXP do |s|
105
+ s.gsub(/[^\n]/, '')
106
+ end
105
107
  end
106
- end
107
108
 
108
- ##
109
- # Changes encoding based on +encoding+ without converting and returns new
110
- # string
111
-
112
- def self.change_encoding(text, encoding)
113
- if text.kind_of? RDoc::Comment
114
- text.encode! encoding
115
- else
116
- String.new text, encoding: encoding
109
+ ##
110
+ # Changes encoding based on +encoding+ without converting and returns new
111
+ # string
112
+
113
+ def self.change_encoding(text, encoding)
114
+ if text.kind_of? Comment
115
+ text.encode! encoding
116
+ else
117
+ String.new text, encoding: encoding
118
+ end
117
119
  end
118
- end
119
120
 
121
+ end
120
122
  end
@@ -1,18 +1,20 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Allows an ERB template to be rendered in the context (binding) of an
4
- # existing ERB template evaluation.
2
+ module RDoc
3
+ ##
4
+ # Allows an ERB template to be rendered in the context (binding) of an
5
+ # existing ERB template evaluation.
5
6
 
6
- class RDoc::ERBPartial < ERB
7
+ class ERBPartial < ERB
7
8
 
8
- ##
9
- # Overrides +compiler+ startup to set the +eoutvar+ to an empty string only
10
- # if it isn't already set.
9
+ ##
10
+ # Overrides +compiler+ startup to set the +eoutvar+ to an empty string only
11
+ # if it isn't already set.
11
12
 
12
- def set_eoutvar(compiler, eoutvar = '_erbout')
13
- super
13
+ def set_eoutvar(compiler, eoutvar = '_erbout')
14
+ super
14
15
 
15
- compiler.pre_cmd = ["#{eoutvar} ||= +''"]
16
- end
16
+ compiler.pre_cmd = ["#{eoutvar} ||= +''"]
17
+ end
17
18
 
19
+ end
18
20
  end