rdoc 8.0.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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -3
  3. data/RI.md +75 -75
  4. data/exe/rdoc +2 -2
  5. data/lib/rdoc/code_object/alias.rb +71 -69
  6. data/lib/rdoc/code_object/any_method.rb +305 -303
  7. data/lib/rdoc/code_object/attr.rb +150 -148
  8. data/lib/rdoc/code_object/class_module.rb +798 -792
  9. data/lib/rdoc/code_object/constant.rb +175 -173
  10. data/lib/rdoc/code_object/context/section.rb +142 -138
  11. data/lib/rdoc/code_object/context.rb +926 -958
  12. data/lib/rdoc/code_object/extend.rb +7 -5
  13. data/lib/rdoc/code_object/include.rb +7 -5
  14. data/lib/rdoc/code_object/method_attr.rb +326 -319
  15. data/lib/rdoc/code_object/mixin.rb +97 -95
  16. data/lib/rdoc/code_object/normal_class.rb +77 -78
  17. data/lib/rdoc/code_object/normal_module.rb +61 -59
  18. data/lib/rdoc/code_object/require.rb +23 -39
  19. data/lib/rdoc/code_object/single_class.rb +21 -19
  20. data/lib/rdoc/code_object/top_level.rb +212 -219
  21. data/lib/rdoc/code_object.rb +305 -303
  22. data/lib/rdoc/comment.rb +275 -273
  23. data/lib/rdoc/cross_reference.rb +192 -190
  24. data/lib/rdoc/encoding.rb +105 -103
  25. data/lib/rdoc/erb_partial.rb +13 -11
  26. data/lib/rdoc/erbio.rb +29 -27
  27. data/lib/rdoc/generator/aliki.rb +161 -153
  28. data/lib/rdoc/generator/darkfish.rb +645 -635
  29. data/lib/rdoc/generator/json_index.rb +233 -229
  30. data/lib/rdoc/generator/markup.rb +164 -146
  31. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  32. data/lib/rdoc/generator/pot/po.rb +52 -51
  33. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  34. data/lib/rdoc/generator/pot.rb +85 -81
  35. data/lib/rdoc/generator/ri.rb +23 -19
  36. data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
  37. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  38. data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
  39. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  40. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  41. data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
  42. data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  44. data/lib/rdoc/generator.rb +48 -46
  45. data/lib/rdoc/i18n/locale.rb +99 -95
  46. data/lib/rdoc/i18n/text.rb +109 -105
  47. data/lib/rdoc/i18n.rb +7 -5
  48. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  49. data/lib/rdoc/markdown.kpeg +15 -11
  50. data/lib/rdoc/markdown.rb +40 -47
  51. data/lib/rdoc/markup/block_quote.rb +12 -8
  52. data/lib/rdoc/markup/document.rb +127 -123
  53. data/lib/rdoc/markup/formatter.rb +219 -215
  54. data/lib/rdoc/markup/include.rb +33 -29
  55. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  56. data/lib/rdoc/markup/inline_parser.rb +281 -277
  57. data/lib/rdoc/markup/list.rb +80 -88
  58. data/lib/rdoc/markup/list_item.rb +73 -85
  59. data/lib/rdoc/markup/paragraph.rb +23 -19
  60. data/lib/rdoc/markup/parser.rb +501 -497
  61. data/lib/rdoc/markup/pre_process.rb +283 -279
  62. data/lib/rdoc/markup/raw.rb +2 -2
  63. data/lib/rdoc/markup/rule.rb +16 -12
  64. data/lib/rdoc/markup/to_ansi.rb +143 -139
  65. data/lib/rdoc/markup/to_bs.rb +72 -68
  66. data/lib/rdoc/markup/to_html.rb +594 -565
  67. data/lib/rdoc/markup/to_html_crossref.rb +234 -230
  68. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  69. data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
  70. data/lib/rdoc/markup/to_label.rb +63 -59
  71. data/lib/rdoc/markup/to_markdown.rb +212 -208
  72. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  73. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  74. data/lib/rdoc/markup/to_test.rb +60 -56
  75. data/lib/rdoc/markup/to_tt_only.rb +84 -80
  76. data/lib/rdoc/markup/verbatim.rb +62 -58
  77. data/lib/rdoc/markup.rb +198 -196
  78. data/lib/rdoc/options.rb +1063 -1061
  79. data/lib/rdoc/parser/c.rb +1039 -1037
  80. data/lib/rdoc/parser/changelog.rb +319 -315
  81. data/lib/rdoc/parser/markdown.rb +17 -13
  82. data/lib/rdoc/parser/rbs.rb +239 -235
  83. data/lib/rdoc/parser/rd.rb +17 -13
  84. data/lib/rdoc/parser/ruby.rb +1245 -1124
  85. data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
  86. data/lib/rdoc/parser/simple.rb +31 -27
  87. data/lib/rdoc/parser/text.rb +12 -8
  88. data/lib/rdoc/parser.rb +228 -220
  89. data/lib/rdoc/rbs_helper.rb +1 -1
  90. data/lib/rdoc/rd/inline.rb +57 -53
  91. data/lib/rdoc/rd.rb +90 -88
  92. data/lib/rdoc/rdoc.rb +500 -491
  93. data/lib/rdoc/ri/driver.rb +1140 -1135
  94. data/lib/rdoc/ri/formatter.rb +7 -3
  95. data/lib/rdoc/ri/paths.rb +140 -136
  96. data/lib/rdoc/ri/servlet.rb +354 -350
  97. data/lib/rdoc/ri/store.rb +4 -2
  98. data/lib/rdoc/ri/task.rb +55 -51
  99. data/lib/rdoc/ri.rb +14 -12
  100. data/lib/rdoc/rubygems_hook.rb +183 -181
  101. data/lib/rdoc/server.rb +349 -347
  102. data/lib/rdoc/stats/normal.rb +46 -42
  103. data/lib/rdoc/stats/quiet.rb +39 -35
  104. data/lib/rdoc/stats/verbose.rb +35 -31
  105. data/lib/rdoc/stats.rb +365 -363
  106. data/lib/rdoc/store.rb +888 -902
  107. data/lib/rdoc/task.rb +260 -256
  108. data/lib/rdoc/text.rb +135 -133
  109. data/lib/rdoc/token_stream.rb +101 -93
  110. data/lib/rdoc/tom_doc.rb +203 -201
  111. data/lib/rdoc/version.rb +1 -1
  112. metadata +4 -5
  113. data/lib/rdoc/markdown/literals.kpeg +0 -21
  114. data/lib/rdoc/markdown/literals.rb +0 -454
data/lib/rdoc/parser.rb CHANGED
@@ -1,288 +1,296 @@
1
1
  # -*- coding: us-ascii -*-
2
2
  # frozen_string_literal: true
3
3
 
4
- ##
5
- # A parser is simple a class that subclasses RDoc::Parser and implements #scan
6
- # to fill in an RDoc::TopLevel with parsed data.
7
- #
8
- # The initialize method takes an RDoc::TopLevel to fill with parsed content,
9
- # the name of the file to be parsed, the content of the file, an RDoc::Options
10
- # object and an RDoc::Stats object to inform the user of parsed items. The
11
- # scan method is then called to parse the file and must return the
12
- # RDoc::TopLevel object. By calling super these items will be set for you.
13
- #
14
- # In order to be used by RDoc the parser needs to register the file extensions
15
- # it can parse. Use ::parse_files_matching to register extensions.
16
- #
17
- # require 'rdoc'
18
- #
19
- # class RDoc::Parser::Xyz < RDoc::Parser
20
- # parse_files_matching /\.xyz$/
21
- #
22
- # def initialize top_level, file_name, content, options, stats
23
- # super
24
- #
25
- # # extra initialization if needed
26
- # end
27
- #
28
- # def scan
29
- # # parse file and fill in @top_level
30
- # end
31
- # end
32
-
33
- class RDoc::Parser
34
-
35
- @parsers = []
36
-
37
- class << self
4
+ module RDoc
5
+ ##
6
+ # A parser is simple a class that subclasses RDoc::Parser and implements #scan
7
+ # to fill in an RDoc::TopLevel with parsed data.
8
+ #
9
+ # The initialize method takes an RDoc::TopLevel to fill with parsed content,
10
+ # the name of the file to be parsed, the content of the file, an RDoc::Options
11
+ # object and an RDoc::Stats object to inform the user of parsed items. The
12
+ # scan method is then called to parse the file and must return the
13
+ # RDoc::TopLevel object. By calling super these items will be set for you.
14
+ #
15
+ # In order to be used by RDoc the parser needs to register the file extensions
16
+ # it can parse. Use ::parse_files_matching to register extensions.
17
+ #
18
+ # require 'rdoc'
19
+ #
20
+ # class RDoc::Parser::Xyz < RDoc::Parser
21
+ # parse_files_matching /\.xyz$/
22
+ #
23
+ # def initialize top_level, file_name, content, options, stats
24
+ # super
25
+ #
26
+ # # extra initialization if needed
27
+ # end
28
+ #
29
+ # def scan
30
+ # # parse file and fill in @top_level
31
+ # end
32
+ # end
38
33
 
39
- ##
40
- # An Array of arrays that maps file extension (or name) regular
41
- # expressions to parser classes that will parse matching filenames.
42
- #
43
- # Use parse_files_matching to register a parser's file extensions.
34
+ class Parser
44
35
 
45
- attr_reader :parsers
36
+ @parsers = []
46
37
 
47
- end
38
+ class << self
48
39
 
49
- ##
50
- # The name of the file being parsed
40
+ ##
41
+ # An Array of arrays that maps file extension (or name) regular
42
+ # expressions to parser classes that will parse matching filenames.
43
+ #
44
+ # Use parse_files_matching to register a parser's file extensions.
51
45
 
52
- attr_reader :file_name
46
+ attr_reader :parsers
53
47
 
54
- ##
55
- # Alias an extension to another extension. After this call, files ending
56
- # "new_ext" will be parsed using the same parser as "old_ext"
48
+ end
57
49
 
58
- def self.alias_extension(old_ext, new_ext)
59
- old_ext = old_ext.sub(/^\.(.*)/, '\1')
60
- new_ext = new_ext.sub(/^\.(.*)/, '\1')
50
+ ##
51
+ # The name of the file being parsed
61
52
 
62
- parser = can_parse_by_name "xxx.#{old_ext}"
63
- return false unless parser
53
+ attr_reader :file_name
64
54
 
65
- RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser]
55
+ ##
56
+ # Alias an extension to another extension. After this call, files ending
57
+ # "new_ext" will be parsed using the same parser as "old_ext"
66
58
 
67
- true
68
- end
59
+ def self.alias_extension(old_ext, new_ext)
60
+ old_ext = old_ext.sub(/^\.(.*)/, '\1')
61
+ new_ext = new_ext.sub(/^\.(.*)/, '\1')
69
62
 
70
- ##
71
- # Determines if the file is a "binary" file which basically means it has
72
- # content that an RDoc parser shouldn't try to consume.
63
+ parser = can_parse_by_name "xxx.#{old_ext}"
64
+ return false unless parser
73
65
 
74
- def self.binary?(file)
75
- return false if file =~ /\.(rdoc|txt)$/
66
+ Parser.parsers.unshift [/\.#{new_ext}$/, parser]
76
67
 
77
- s = File.read(file, 1024) or return false
68
+ true
69
+ end
78
70
 
79
- return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
71
+ ##
72
+ # Determines if the file is a "binary" file which basically means it has
73
+ # content that an RDoc parser shouldn't try to consume.
80
74
 
81
- mode = 'r:utf-8' # default source encoding has been changed to utf-8
82
- s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
83
- encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
84
- mode = "rb:#{encoding}" if encoding
85
- s = File.open(file, mode) {|f| f.gets(nil, 1024)}
75
+ def self.binary?(file)
76
+ return false if file =~ /\.(rdoc|txt)$/
86
77
 
87
- not s.valid_encoding?
88
- end
78
+ s = File.read(file, 1024) or return false
89
79
 
90
- ##
91
- # Checks if +file+ is a zip file in disguise. Signatures from
92
- # http://www.garykessler.net/library/file_sigs.html
80
+ return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
93
81
 
94
- def self.zip?(file)
95
- zip_signature = File.read file, 4
82
+ mode = 'r:utf-8' # default source encoding has been changed to utf-8
83
+ s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
84
+ encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
85
+ mode = "rb:#{encoding}" if encoding
86
+ s = File.open(file, mode) {|f| f.gets(nil, 1024)}
96
87
 
97
- zip_signature == "PK\x03\x04" or
98
- zip_signature == "PK\x05\x06" or
99
- zip_signature == "PK\x07\x08"
100
- rescue
101
- false
102
- end
88
+ not s.valid_encoding?
89
+ end
103
90
 
104
- ##
105
- # Return a parser that can handle a particular extension
91
+ ##
92
+ # Checks if +file+ is a zip file in disguise. Signatures from
93
+ # http://www.garykessler.net/library/file_sigs.html
106
94
 
107
- def self.can_parse(file_name)
108
- parser = can_parse_by_name file_name
95
+ def self.zip?(file)
96
+ zip_signature = File.read file, 4
109
97
 
110
- # HACK Selenium hides a jar file using a .txt extension
111
- return if parser == RDoc::Parser::Simple and zip? file_name
98
+ zip_signature == "PK\x03\x04" or
99
+ zip_signature == "PK\x05\x06" or
100
+ zip_signature == "PK\x07\x08"
101
+ rescue
102
+ false
103
+ end
112
104
 
113
- parser
114
- end
105
+ ##
106
+ # Return a parser that can handle a particular extension
115
107
 
116
- ##
117
- # Returns a parser that can handle the extension for +file_name+. This does
118
- # not depend upon the file being readable.
108
+ def self.can_parse(file_name)
109
+ parser = can_parse_by_name file_name
119
110
 
120
- def self.can_parse_by_name(file_name)
121
- _, parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }
111
+ # HACK Selenium hides a jar file using a .txt extension
112
+ return if parser == Parser::Simple and zip? file_name
122
113
 
123
- # The default parser must not parse binary files
124
- ext_name = File.extname file_name
125
- return parser if ext_name.empty?
114
+ parser
115
+ end
126
116
 
127
- if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then
128
- case mode = check_modeline(file_name)
129
- when nil, 'rdoc' then # continue
130
- else
131
- RDoc::Parser.parsers.find { |_, p| return p if mode.casecmp?(p.name[/\w+\z/]) }
132
- return nil
117
+ ##
118
+ # Returns a parser that can handle the extension for +file_name+. This does
119
+ # not depend upon the file being readable.
120
+
121
+ def self.can_parse_by_name(file_name)
122
+ _, parser = Parser.parsers.find { |regexp,| regexp =~ file_name }
123
+
124
+ # The default parser must not parse binary files
125
+ ext_name = File.extname file_name
126
+ return parser if ext_name.empty?
127
+
128
+ if parser == Parser::Simple and ext_name !~ /txt|rdoc/
129
+ case mode = check_modeline(file_name)
130
+ when nil, 'rdoc' # continue
131
+ else
132
+ Parser.parsers.find { |_, p| return p if mode.casecmp?(p.name[/\w+\z/]) }
133
+ return nil
134
+ end
133
135
  end
134
- end
135
136
 
136
- parser
137
- rescue Errno::EACCES
138
- end
137
+ parser
138
+ rescue Errno::EACCES
139
+ end
139
140
 
140
- ##
141
- # Returns the file type from the modeline in +file_name+
141
+ ##
142
+ # Returns the file type from the modeline in +file_name+
142
143
 
143
- def self.check_modeline(file_name)
144
- line = File.open file_name do |io|
145
- io.gets
146
- end
144
+ def self.check_modeline(file_name)
145
+ line = File.open file_name do |io|
146
+ io.gets
147
+ end
147
148
 
148
- /-\*-\s*(.*?\S)\s*-\*-/ =~ line
149
+ /-\*-\s*(.*?\S)\s*-\*-/ =~ line
149
150
 
150
- return nil unless type = $1
151
+ return nil unless type = $1
151
152
 
152
- if /;/ =~ type then
153
- return nil unless /(?:\s|\A)mode:\s*([^\s;]+)/i =~ type
154
- type = $1
155
- end
153
+ if /;/ =~ type
154
+ return nil unless /(?:\s|\A)mode:\s*([^\s;]+)/i =~ type
155
+ type = $1
156
+ end
156
157
 
157
- return nil if /coding:/i =~ type
158
+ return nil if /coding:/i =~ type
158
159
 
159
- type.downcase
160
- rescue ArgumentError
161
- rescue Encoding::InvalidByteSequenceError # invalid byte sequence
160
+ type.downcase
161
+ rescue ArgumentError
162
+ rescue ::Encoding::InvalidByteSequenceError # invalid byte sequence
162
163
 
163
- end
164
+ end
164
165
 
165
- ##
166
- # Finds and instantiates the correct parser for the given +file_name+ and
167
- # +content+.
166
+ ##
167
+ # Finds and instantiates the correct parser for the given +file_name+ and
168
+ # +content+.
168
169
 
169
- def self.for(top_level, content, options, stats)
170
- file_name = top_level.absolute_name
171
- return if binary? file_name
170
+ def self.for(top_level, content, options, stats)
171
+ file_name = top_level.absolute_name
172
+ return if binary? file_name
172
173
 
173
- parser = use_markup content
174
+ parser = use_markup content
174
175
 
175
- unless parser then
176
- parse_name = file_name
176
+ unless parser
177
+ parse_name = file_name
177
178
 
178
- # If no extension, look for shebang
179
- if file_name !~ /\.\w+$/ && content =~ %r{\A#!(.+)} then
180
- shebang = $1
181
- case shebang
182
- when %r{env\s+ruby}, %r{/ruby}
183
- parse_name = 'dummy.rb'
179
+ # If no extension, look for shebang
180
+ if file_name !~ /\.\w+$/ && content =~ %r{\A#!(.+)}
181
+ shebang = $1
182
+ case shebang
183
+ when %r{env\s+ruby}, %r{/ruby}
184
+ parse_name = 'dummy.rb'
185
+ end
184
186
  end
187
+
188
+ parser = can_parse parse_name
185
189
  end
186
190
 
187
- parser = can_parse parse_name
188
- end
191
+ return unless parser
189
192
 
190
- return unless parser
193
+ content = remove_modeline content
191
194
 
192
- content = remove_modeline content
195
+ parser.new top_level, content, options, stats
196
+ rescue SystemCallError
197
+ nil
198
+ end
193
199
 
194
- parser.new top_level, content, options, stats
195
- rescue SystemCallError
196
- nil
197
- end
200
+ ##
201
+ # Record which file types this parser can understand.
202
+ #
203
+ # It is ok to call this multiple times.
198
204
 
199
- ##
200
- # Record which file types this parser can understand.
201
- #
202
- # It is ok to call this multiple times.
205
+ def self.parse_files_matching(regexp)
206
+ Parser.parsers.unshift [regexp, self]
207
+ end
203
208
 
204
- def self.parse_files_matching(regexp)
205
- RDoc::Parser.parsers.unshift [regexp, self]
206
- end
209
+ ##
210
+ # Removes an emacs-style modeline from the first line of the document
207
211
 
208
- ##
209
- # Removes an emacs-style modeline from the first line of the document
212
+ def self.remove_modeline(content)
213
+ content.sub(/\A.*-\*-\s*(.*?\S)\s*-\*-.*\r?\n/, '')
214
+ end
210
215
 
211
- def self.remove_modeline(content)
212
- content.sub(/\A.*-\*-\s*(.*?\S)\s*-\*-.*\r?\n/, '')
213
- end
216
+ ##
217
+ # If there is a <tt>markup: parser_name</tt> comment at the front of the
218
+ # file, use it to determine the parser. For example:
219
+ #
220
+ # # markup: rdoc
221
+ # # Class comment can go here
222
+ #
223
+ # class C
224
+ # end
225
+ #
226
+ # The comment should appear as the first line of the +content+.
227
+ #
228
+ # If the content contains a shebang or editor modeline the comment may
229
+ # appear on the second or third line.
230
+ #
231
+ # Any comment style may be used to hide the markup comment.
232
+ #
233
+ # The +tomdoc+ and +markdown+ markups name comment formats rather than
234
+ # parsers, so no parser is selected for them and RDoc::Parser.for picks one
235
+ # from the file name instead.
214
236
 
215
- ##
216
- # If there is a <tt>markup: parser_name</tt> comment at the front of the
217
- # file, use it to determine the parser. For example:
218
- #
219
- # # markup: rdoc
220
- # # Class comment can go here
221
- #
222
- # class C
223
- # end
224
- #
225
- # The comment should appear as the first line of the +content+.
226
- #
227
- # If the content contains a shebang or editor modeline the comment may
228
- # appear on the second or third line.
229
- #
230
- # Any comment style may be used to hide the markup comment.
237
+ def self.use_markup(content)
238
+ markup = content.lines.first(3).grep(/markup:\s+(\w+)/) { $1 }.first
231
239
 
232
- def self.use_markup(content)
233
- markup = content.lines.first(3).grep(/markup:\s+(\w+)/) { $1 }.first
240
+ return unless markup
234
241
 
235
- return unless markup
242
+ # tomdoc and markdown name a comment format, not a parser. Skipping them
243
+ # keeps the search below from matching RDoc::Parser::Markdown for a file
244
+ # that is not markdown.
245
+ return if %w[tomdoc markdown].include? markup
236
246
 
237
- # TODO Ruby should be returned only when the filename is correct
238
- return RDoc::Parser::Ruby if %w[tomdoc markdown].include? markup
247
+ markup = Regexp.escape markup
239
248
 
240
- markup = Regexp.escape markup
249
+ _, selected = Parser.parsers.find do |_, parser|
250
+ /^#{markup}$/i =~ parser.name.sub(/.*:/, '')
251
+ end
241
252
 
242
- _, selected = RDoc::Parser.parsers.find do |_, parser|
243
- /^#{markup}$/i =~ parser.name.sub(/.*:/, '')
253
+ selected
244
254
  end
245
255
 
246
- selected
247
- end
248
-
249
- ##
250
- # Creates a new Parser storing +top_level+, +file_name+, +content+,
251
- # +options+ and +stats+ in instance variables. In +@preprocess+ an
252
- # RDoc::Markup::PreProcess object is created which allows processing of
253
- # directives.
254
-
255
- def initialize(top_level, content, options, stats)
256
- @top_level = top_level
257
- @top_level.parser = self.class
258
- @store = @top_level.store
259
-
260
- @file_name = top_level.absolute_name
261
- @content = content
262
- @options = options
263
- @stats = stats
264
-
265
- @preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
266
- @preprocess.options = @options
267
- end
256
+ ##
257
+ # Creates a new Parser storing +top_level+, +file_name+, +content+,
258
+ # +options+ and +stats+ in instance variables. In +@preprocess+ an
259
+ # RDoc::Markup::PreProcess object is created which allows processing of
260
+ # directives.
261
+
262
+ def initialize(top_level, content, options, stats)
263
+ @top_level = top_level
264
+ @top_level.parser = self.class
265
+ @store = @top_level.store
266
+
267
+ @file_name = top_level.absolute_name
268
+ @content = content
269
+ @options = options
270
+ @stats = stats
271
+
272
+ @preprocess = Markup::PreProcess.new @file_name, @options.rdoc_include
273
+ @preprocess.options = @options
274
+ end
268
275
 
269
- autoload :Text, "#{__dir__}/parser/text"
276
+ autoload :Text, "#{__dir__}/parser/text"
270
277
 
271
- ##
272
- # Normalizes tabs in +body+
273
-
274
- def handle_tab_width(body)
275
- if /\t/ =~ body
276
- tab_width = @options.tab_width
277
- body.split(/\n/).map do |line|
278
- 1 while line.gsub!(/\t+/) do
279
- b, e = $~.offset(0)
280
- ' ' * (tab_width * (e-b) - b % tab_width)
281
- end
282
- line
283
- end.join "\n"
284
- else
285
- body
278
+ ##
279
+ # Normalizes tabs in +body+
280
+
281
+ def handle_tab_width(body)
282
+ if /\t/ =~ body
283
+ tab_width = @options.tab_width
284
+ body.split(/\n/).map do |line|
285
+ 1 while line.gsub!(/\t+/) do
286
+ b, e = $~.offset(0)
287
+ ' ' * (tab_width * (e-b) - b % tab_width)
288
+ end
289
+ line
290
+ end.join "\n"
291
+ else
292
+ body
293
+ end
286
294
  end
287
295
  end
288
296
  end
@@ -122,7 +122,7 @@ module RDoc
122
122
  start_in_escaped = prefix.length
123
123
  end_in_escaped = start_in_escaped + escaped_name.length
124
124
 
125
- href = ERB::Util.html_escape(::RDoc::Markup::Formatter.gen_relative_url(from_path, target_path))
125
+ href = ERB::Util.html_escape(Markup::Formatter.gen_relative_url(from_path, target_path))
126
126
  result[start_in_escaped...end_in_escaped] =
127
127
  "<a href=\"#{href}\" class=\"rbs-type\">#{escaped_name}</a>"
128
128
  end
@@ -1,71 +1,75 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Inline keeps track of markup and labels to create proper links.
2
+ module RDoc
3
+ class RD
4
+ ##
5
+ # Inline keeps track of markup and labels to create proper links.
4
6
 
5
- class RDoc::RD::Inline
7
+ class Inline
6
8
 
7
- ##
8
- # The text of the reference
9
+ ##
10
+ # The text of the reference
9
11
 
10
- attr_reader :reference
12
+ attr_reader :reference
11
13
 
12
- ##
13
- # The markup of this reference in RDoc format
14
+ ##
15
+ # The markup of this reference in RDoc format
14
16
 
15
- attr_reader :rdoc
17
+ attr_reader :rdoc
16
18
 
17
- ##
18
- # Creates a new Inline for +rdoc+ and +reference+.
19
- #
20
- # +rdoc+ may be another Inline or a String. If +reference+ is not given it
21
- # will use the text from +rdoc+.
19
+ ##
20
+ # Creates a new Inline for +rdoc+ and +reference+.
21
+ #
22
+ # +rdoc+ may be another Inline or a String. If +reference+ is not given it
23
+ # will use the text from +rdoc+.
22
24
 
23
- def self.new(rdoc, reference = rdoc)
24
- if self === rdoc and reference.equal? rdoc then
25
- rdoc
26
- else
27
- super
28
- end
29
- end
25
+ def self.new(rdoc, reference = rdoc)
26
+ if self === rdoc and reference.equal? rdoc
27
+ rdoc
28
+ else
29
+ super
30
+ end
31
+ end
30
32
 
31
- ##
32
- # Initializes the Inline with +rdoc+ and +inline+
33
+ ##
34
+ # Initializes the Inline with +rdoc+ and +inline+
33
35
 
34
- def initialize(rdoc, reference) # :not-new:
35
- @reference = reference.equal?(rdoc) ? reference.dup : reference
36
+ def initialize(rdoc, reference) # :not-new:
37
+ @reference = reference.equal?(rdoc) ? reference.dup : reference
36
38
 
37
- # unpack
38
- @reference = @reference.reference if self.class === @reference
39
- @rdoc = rdoc
40
- end
39
+ # unpack
40
+ @reference = @reference.reference if self.class === @reference
41
+ @rdoc = rdoc
42
+ end
41
43
 
42
- def ==(other) # :nodoc:
43
- self.class === other and
44
- @reference == other.reference and @rdoc == other.rdoc
45
- end
44
+ def ==(other) # :nodoc:
45
+ self.class === other and
46
+ @reference == other.reference and @rdoc == other.rdoc
47
+ end
46
48
 
47
- ##
48
- # Appends +more+ to this inline. +more+ may be a String or another Inline.
49
-
50
- def append(more)
51
- case more
52
- when String then
53
- @reference += more
54
- @rdoc += more
55
- when RDoc::RD::Inline then
56
- @reference += more.reference
57
- @rdoc += more.rdoc
58
- else
59
- raise "unknown thingy #{more}"
60
- end
49
+ ##
50
+ # Appends +more+ to this inline. +more+ may be a String or another Inline.
61
51
 
62
- self
63
- end
52
+ def append(more)
53
+ case more
54
+ when String
55
+ @reference += more
56
+ @rdoc += more
57
+ when RD::Inline
58
+ @reference += more.reference
59
+ @rdoc += more.rdoc
60
+ else
61
+ raise "unknown thingy #{more}"
62
+ end
64
63
 
65
- def inspect # :nodoc:
66
- "(inline: #{self})"
67
- end
64
+ self
65
+ end
66
+
67
+ def inspect # :nodoc:
68
+ "(inline: #{self})"
69
+ end
68
70
 
69
- alias to_s rdoc # :nodoc:
71
+ alias to_s rdoc # :nodoc:
70
72
 
73
+ end
74
+ end
71
75
  end