gitlab-rdoc 6.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +220 -0
  3. data/CVE-2013-0256.rdoc +49 -0
  4. data/ExampleMarkdown.md +37 -0
  5. data/ExampleRDoc.rdoc +208 -0
  6. data/Gemfile +12 -0
  7. data/History.rdoc +1666 -0
  8. data/LEGAL.rdoc +50 -0
  9. data/LICENSE.rdoc +57 -0
  10. data/README.rdoc +133 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +101 -0
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/exe/rdoc +44 -0
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +112 -0
  19. data/lib/rdoc/anon_class.rb +11 -0
  20. data/lib/rdoc/any_method.rb +361 -0
  21. data/lib/rdoc/attr.rb +176 -0
  22. data/lib/rdoc/class_module.rb +802 -0
  23. data/lib/rdoc/code_object.rb +421 -0
  24. data/lib/rdoc/code_objects.rb +6 -0
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +187 -0
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +1266 -0
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +136 -0
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +42 -0
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +790 -0
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +160 -0
  37. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  38. data/lib/rdoc/generator/pot/po.rb +84 -0
  39. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  40. data/lib/rdoc/generator/pot.rb +98 -0
  41. data/lib/rdoc/generator/ri.rb +31 -0
  42. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  44. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  58. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  59. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  72. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  73. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  74. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  75. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  76. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  77. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  78. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  79. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  80. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  81. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  82. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  83. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  84. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  85. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  86. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  87. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  88. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  89. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  90. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  91. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  92. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
  93. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
  94. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  95. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  96. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  97. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  98. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  99. data/lib/rdoc/generator/template/json_index/.document +1 -0
  100. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  101. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  102. data/lib/rdoc/generator.rb +51 -0
  103. data/lib/rdoc/ghost_method.rb +7 -0
  104. data/lib/rdoc/i18n/locale.rb +102 -0
  105. data/lib/rdoc/i18n/text.rb +126 -0
  106. data/lib/rdoc/i18n.rb +10 -0
  107. data/lib/rdoc/include.rb +10 -0
  108. data/lib/rdoc/known_classes.rb +73 -0
  109. data/lib/rdoc/markdown/entities.rb +2132 -0
  110. data/lib/rdoc/markdown/literals.kpeg +23 -0
  111. data/lib/rdoc/markdown/literals.rb +417 -0
  112. data/lib/rdoc/markdown.kpeg +1237 -0
  113. data/lib/rdoc/markdown.rb +16685 -0
  114. data/lib/rdoc/markup/attr_changer.rb +23 -0
  115. data/lib/rdoc/markup/attr_span.rb +36 -0
  116. data/lib/rdoc/markup/attribute_manager.rb +409 -0
  117. data/lib/rdoc/markup/attributes.rb +71 -0
  118. data/lib/rdoc/markup/blank_line.rb +28 -0
  119. data/lib/rdoc/markup/block_quote.rb +15 -0
  120. data/lib/rdoc/markup/document.rb +165 -0
  121. data/lib/rdoc/markup/formatter.rb +266 -0
  122. data/lib/rdoc/markup/hard_break.rb +32 -0
  123. data/lib/rdoc/markup/heading.rb +79 -0
  124. data/lib/rdoc/markup/include.rb +43 -0
  125. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  126. data/lib/rdoc/markup/list.rb +102 -0
  127. data/lib/rdoc/markup/list_item.rb +100 -0
  128. data/lib/rdoc/markup/paragraph.rb +29 -0
  129. data/lib/rdoc/markup/parser.rb +575 -0
  130. data/lib/rdoc/markup/pre_process.rb +296 -0
  131. data/lib/rdoc/markup/raw.rb +70 -0
  132. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  133. data/lib/rdoc/markup/rule.rb +21 -0
  134. data/lib/rdoc/markup/table.rb +47 -0
  135. data/lib/rdoc/markup/to_ansi.rb +94 -0
  136. data/lib/rdoc/markup/to_bs.rb +77 -0
  137. data/lib/rdoc/markup/to_html.rb +444 -0
  138. data/lib/rdoc/markup/to_html_crossref.rb +176 -0
  139. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  140. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  141. data/lib/rdoc/markup/to_label.rb +75 -0
  142. data/lib/rdoc/markup/to_markdown.rb +192 -0
  143. data/lib/rdoc/markup/to_rdoc.rb +362 -0
  144. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  145. data/lib/rdoc/markup/to_test.rb +70 -0
  146. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  147. data/lib/rdoc/markup/verbatim.rb +84 -0
  148. data/lib/rdoc/markup.rb +867 -0
  149. data/lib/rdoc/meta_method.rb +7 -0
  150. data/lib/rdoc/method_attr.rb +419 -0
  151. data/lib/rdoc/mixin.rb +121 -0
  152. data/lib/rdoc/normal_class.rb +93 -0
  153. data/lib/rdoc/normal_module.rb +74 -0
  154. data/lib/rdoc/options.rb +1285 -0
  155. data/lib/rdoc/parser/c.rb +1225 -0
  156. data/lib/rdoc/parser/changelog.rb +335 -0
  157. data/lib/rdoc/parser/markdown.rb +24 -0
  158. data/lib/rdoc/parser/rd.rb +23 -0
  159. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  160. data/lib/rdoc/parser/ruby.rb +2327 -0
  161. data/lib/rdoc/parser/ruby_tools.rb +167 -0
  162. data/lib/rdoc/parser/simple.rb +61 -0
  163. data/lib/rdoc/parser/text.rb +12 -0
  164. data/lib/rdoc/parser.rb +277 -0
  165. data/lib/rdoc/rd/block_parser.rb +1056 -0
  166. data/lib/rdoc/rd/block_parser.ry +639 -0
  167. data/lib/rdoc/rd/inline.rb +72 -0
  168. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  169. data/lib/rdoc/rd/inline_parser.ry +593 -0
  170. data/lib/rdoc/rd.rb +100 -0
  171. data/lib/rdoc/rdoc.rb +579 -0
  172. data/lib/rdoc/require.rb +52 -0
  173. data/lib/rdoc/ri/driver.rb +1572 -0
  174. data/lib/rdoc/ri/formatter.rb +6 -0
  175. data/lib/rdoc/ri/paths.rb +171 -0
  176. data/lib/rdoc/ri/store.rb +7 -0
  177. data/lib/rdoc/ri/task.rb +71 -0
  178. data/lib/rdoc/ri.rb +21 -0
  179. data/lib/rdoc/rubygems_hook.rb +246 -0
  180. data/lib/rdoc/servlet.rb +451 -0
  181. data/lib/rdoc/single_class.rb +26 -0
  182. data/lib/rdoc/stats/normal.rb +58 -0
  183. data/lib/rdoc/stats/quiet.rb +60 -0
  184. data/lib/rdoc/stats/verbose.rb +46 -0
  185. data/lib/rdoc/stats.rb +462 -0
  186. data/lib/rdoc/store.rb +979 -0
  187. data/lib/rdoc/task.rb +329 -0
  188. data/lib/rdoc/text.rb +304 -0
  189. data/lib/rdoc/token_stream.rb +119 -0
  190. data/lib/rdoc/tom_doc.rb +263 -0
  191. data/lib/rdoc/top_level.rb +289 -0
  192. data/lib/rdoc/version.rb +8 -0
  193. data/lib/rdoc.rb +201 -0
  194. data/man/ri.1 +247 -0
  195. data/rdoc.gemspec +249 -0
  196. metadata +279 -0
data/lib/rdoc/task.rb ADDED
@@ -0,0 +1,329 @@
1
+ # frozen_string_literal: true
2
+ #--
3
+ # Copyright (c) 2003, 2004 Jim Weirich, 2009 Eric Hodel
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #++
24
+
25
+ begin
26
+ gem 'rdoc'
27
+ rescue Gem::LoadError
28
+ end unless defined?(RDoc)
29
+
30
+ begin
31
+ gem 'rake'
32
+ rescue Gem::LoadError
33
+ end unless defined?(Rake)
34
+
35
+ require 'rdoc'
36
+ require 'rake'
37
+ require 'rake/tasklib'
38
+
39
+ ##
40
+ # RDoc::Task creates the following rake tasks to generate and clean up RDoc
41
+ # output:
42
+ #
43
+ # [rdoc]
44
+ # Main task for this RDoc task.
45
+ #
46
+ # [clobber_rdoc]
47
+ # Delete all the rdoc files. This target is automatically added to the main
48
+ # clobber target.
49
+ #
50
+ # [rerdoc]
51
+ # Rebuild the rdoc files from scratch, even if they are not out of date.
52
+ #
53
+ # Simple Example:
54
+ #
55
+ # require 'rdoc/task'
56
+ #
57
+ # RDoc::Task.new do |rdoc|
58
+ # rdoc.main = "README.rdoc"
59
+ # rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
60
+ # end
61
+ #
62
+ # The +rdoc+ object passed to the block is an RDoc::Task object. See the
63
+ # attributes list for the RDoc::Task class for available customization options.
64
+ #
65
+ # == Specifying different task names
66
+ #
67
+ # You may wish to give the task a different name, such as if you are
68
+ # generating two sets of documentation. For instance, if you want to have a
69
+ # development set of documentation including private methods:
70
+ #
71
+ # require 'rdoc/task'
72
+ #
73
+ # RDoc::Task.new :rdoc_dev do |rdoc|
74
+ # rdoc.main = "README.doc"
75
+ # rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
76
+ # rdoc.options << "--all"
77
+ # end
78
+ #
79
+ # The tasks would then be named :<em>rdoc_dev</em>,
80
+ # :clobber_<em>rdoc_dev</em>, and :re<em>rdoc_dev</em>.
81
+ #
82
+ # If you wish to have completely different task names, then pass a Hash as
83
+ # first argument. With the <tt>:rdoc</tt>, <tt>:clobber_rdoc</tt> and
84
+ # <tt>:rerdoc</tt> options, you can customize the task names to your liking.
85
+ #
86
+ # For example:
87
+ #
88
+ # require 'rdoc/task'
89
+ #
90
+ # RDoc::Task.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean",
91
+ # :rerdoc => "rdoc:force")
92
+ #
93
+ # This will create the tasks <tt>:rdoc</tt>, <tt>:rdoc:clean</tt> and
94
+ # <tt>:rdoc:force</tt>.
95
+
96
+ class RDoc::Task < Rake::TaskLib
97
+
98
+ ##
99
+ # Name of the main, top level task. (default is :rdoc)
100
+
101
+ attr_accessor :name
102
+
103
+ ##
104
+ # Comment markup format. rdoc, rd and tomdoc are supported. (default is
105
+ # 'rdoc')
106
+
107
+ attr_accessor :markup
108
+
109
+ ##
110
+ # Name of directory to receive the html output files. (default is "html")
111
+
112
+ attr_accessor :rdoc_dir
113
+
114
+ ##
115
+ # Title of RDoc documentation. (defaults to rdoc's default)
116
+
117
+ attr_accessor :title
118
+
119
+ ##
120
+ # Name of file to be used as the main, top level file of the RDoc. (default
121
+ # is none)
122
+
123
+ attr_accessor :main
124
+
125
+ ##
126
+ # Name of template to be used by rdoc. (defaults to rdoc's default)
127
+
128
+ attr_accessor :template
129
+
130
+ ##
131
+ # Name of format generator (<tt>--format</tt>) used by rdoc. (defaults to
132
+ # rdoc's default)
133
+
134
+ attr_accessor :generator
135
+
136
+ ##
137
+ # List of files to be included in the rdoc generation. (default is [])
138
+
139
+ attr_accessor :rdoc_files
140
+
141
+ ##
142
+ # Additional list of options to be passed rdoc. (default is [])
143
+
144
+ attr_accessor :options
145
+
146
+ ##
147
+ # Whether to run the rdoc process as an external shell (default is false)
148
+
149
+ attr_accessor :external
150
+
151
+ ##
152
+ # Create an RDoc task with the given name. See the RDoc::Task class overview
153
+ # for documentation.
154
+
155
+ def initialize name = :rdoc # :yield: self
156
+ defaults
157
+
158
+ check_names name
159
+
160
+ @name = name
161
+
162
+ yield self if block_given?
163
+
164
+ define
165
+ end
166
+
167
+ ##
168
+ # Ensures that +names+ only includes names for the :rdoc, :clobber_rdoc and
169
+ # :rerdoc. If other names are given an ArgumentError is raised.
170
+
171
+ def check_names names
172
+ return unless Hash === names
173
+
174
+ invalid_options =
175
+ names.keys.map { |k| k.to_sym } - [:rdoc, :clobber_rdoc, :rerdoc]
176
+
177
+ unless invalid_options.empty? then
178
+ raise ArgumentError, "invalid options: #{invalid_options.join ', '}"
179
+ end
180
+ end
181
+
182
+ ##
183
+ # Task description for the clobber rdoc task or its renamed equivalent
184
+
185
+ def clobber_task_description
186
+ "Remove RDoc HTML files"
187
+ end
188
+
189
+ ##
190
+ # Sets default task values
191
+
192
+ def defaults
193
+ @name = :rdoc
194
+ @rdoc_files = Rake::FileList.new
195
+ @rdoc_dir = 'html'
196
+ @main = nil
197
+ @title = nil
198
+ @template = nil
199
+ @generator = nil
200
+ @options = []
201
+ end
202
+
203
+ ##
204
+ # All source is inline now. This method is deprecated
205
+
206
+ def inline_source # :nodoc:
207
+ warn "RDoc::Task#inline_source is deprecated"
208
+ true
209
+ end
210
+
211
+ ##
212
+ # All source is inline now. This method is deprecated
213
+
214
+ def inline_source=(value) # :nodoc:
215
+ warn "RDoc::Task#inline_source is deprecated"
216
+ end
217
+
218
+ ##
219
+ # Create the tasks defined by this task lib.
220
+
221
+ def define
222
+ desc rdoc_task_description
223
+ task rdoc_task_name
224
+
225
+ desc rerdoc_task_description
226
+ task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
227
+
228
+ desc clobber_task_description
229
+ task clobber_task_name do
230
+ rm_r @rdoc_dir rescue nil
231
+ end
232
+
233
+ task :clobber => [clobber_task_name]
234
+
235
+ directory @rdoc_dir
236
+
237
+ rdoc_target_deps = [
238
+ @rdoc_files,
239
+ Rake.application.rakefile
240
+ ].flatten.compact
241
+
242
+ task rdoc_task_name => [rdoc_target]
243
+ file rdoc_target => rdoc_target_deps do
244
+ @before_running_rdoc.call if @before_running_rdoc
245
+ args = option_list + @rdoc_files
246
+
247
+ $stderr.puts "rdoc #{args.join ' '}" if Rake.application.options.trace
248
+ RDoc::RDoc.new.document args
249
+ end
250
+
251
+ self
252
+ end
253
+
254
+ ##
255
+ # List of options that will be supplied to RDoc
256
+
257
+ def option_list
258
+ result = @options.dup
259
+ result << "-o" << @rdoc_dir
260
+ result << "--main" << main if main
261
+ result << "--markup" << markup if markup
262
+ result << "--title" << title if title
263
+ result << "-T" << template if template
264
+ result << '-f' << generator if generator
265
+ result
266
+ end
267
+
268
+ ##
269
+ # The block passed to this method will be called just before running the
270
+ # RDoc generator. It is allowed to modify RDoc::Task attributes inside the
271
+ # block.
272
+
273
+ def before_running_rdoc(&block)
274
+ @before_running_rdoc = block
275
+ end
276
+
277
+ ##
278
+ # Task description for the rdoc task or its renamed equivalent
279
+
280
+ def rdoc_task_description
281
+ 'Build RDoc HTML files'
282
+ end
283
+
284
+ ##
285
+ # Task description for the rerdoc task or its renamed description
286
+
287
+ def rerdoc_task_description
288
+ "Rebuild RDoc HTML files"
289
+ end
290
+
291
+ private
292
+
293
+ def rdoc_target
294
+ "#{rdoc_dir}/created.rid"
295
+ end
296
+
297
+ def rdoc_task_name
298
+ case name
299
+ when Hash then (name[:rdoc] || "rdoc").to_s
300
+ else name.to_s
301
+ end
302
+ end
303
+
304
+ def clobber_task_name
305
+ case name
306
+ when Hash then (name[:clobber_rdoc] || "clobber_rdoc").to_s
307
+ else "clobber_#{name}"
308
+ end
309
+ end
310
+
311
+ def rerdoc_task_name
312
+ case name
313
+ when Hash then (name[:rerdoc] || "rerdoc").to_s
314
+ else "re#{name}"
315
+ end
316
+ end
317
+
318
+ end
319
+
320
+ # :stopdoc:
321
+ module Rake
322
+
323
+ ##
324
+ # For backwards compatibility
325
+
326
+ RDocTask = RDoc::Task
327
+
328
+ end
329
+ # :startdoc:
data/lib/rdoc/text.rb ADDED
@@ -0,0 +1,304 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # For RDoc::Text#to_html
5
+
6
+ require 'strscan'
7
+
8
+ ##
9
+ # Methods for manipulating comment text
10
+
11
+ module RDoc::Text
12
+
13
+ attr_accessor :language
14
+
15
+ ##
16
+ # Maps markup formats to classes that can parse them. If the format is
17
+ # unknown, "rdoc" format is used.
18
+
19
+ MARKUP_FORMAT = {
20
+ 'markdown' => RDoc::Markdown,
21
+ 'rdoc' => RDoc::Markup,
22
+ 'rd' => RDoc::RD,
23
+ 'tomdoc' => RDoc::TomDoc,
24
+ }
25
+
26
+ MARKUP_FORMAT.default = RDoc::Markup
27
+
28
+ ##
29
+ # Maps an encoding to a Hash of characters properly transcoded for that
30
+ # encoding.
31
+ #
32
+ # See also encode_fallback.
33
+
34
+ TO_HTML_CHARACTERS = Hash.new do |h, encoding|
35
+ h[encoding] = {
36
+ :close_dquote => encode_fallback('”', encoding, '"'),
37
+ :close_squote => encode_fallback('’', encoding, '\''),
38
+ :copyright => encode_fallback('©', encoding, '(c)'),
39
+ :ellipsis => encode_fallback('…', encoding, '...'),
40
+ :em_dash => encode_fallback('—', encoding, '---'),
41
+ :en_dash => encode_fallback('–', encoding, '--'),
42
+ :open_dquote => encode_fallback('“', encoding, '"'),
43
+ :open_squote => encode_fallback('‘', encoding, '\''),
44
+ :trademark => encode_fallback('®', encoding, '(r)'),
45
+ }
46
+ end
47
+
48
+ ##
49
+ # Transcodes +character+ to +encoding+ with a +fallback+ character.
50
+
51
+ def self.encode_fallback character, encoding, fallback
52
+ character.encode(encoding, :fallback => { character => fallback },
53
+ :undef => :replace, :replace => fallback)
54
+ end
55
+
56
+ ##
57
+ # Expands tab characters in +text+ to eight spaces
58
+
59
+ def expand_tabs text
60
+ expanded = []
61
+
62
+ text.each_line do |line|
63
+ nil while line.gsub!(/(?:\G|\r)((?:.{8})*?)([^\t\r\n]{0,7})\t/) do
64
+ r = "#{$1}#{$2}#{' ' * (8 - $2.size)}"
65
+ r = RDoc::Encoding.change_encoding r, text.encoding
66
+ r
67
+ end
68
+
69
+ expanded << line
70
+ end
71
+
72
+ expanded.join
73
+ end
74
+
75
+ ##
76
+ # Flush +text+ left based on the shortest line
77
+
78
+ def flush_left text
79
+ indent = 9999
80
+
81
+ text.each_line do |line|
82
+ line_indent = line =~ /\S/ || 9999
83
+ indent = line_indent if indent > line_indent
84
+ end
85
+
86
+ empty = ''
87
+ empty = RDoc::Encoding.change_encoding empty, text.encoding
88
+
89
+ text.gsub(/^ {0,#{indent}}/, empty)
90
+ end
91
+
92
+ ##
93
+ # Convert a string in markup format into HTML.
94
+ #
95
+ # Requires the including class to implement #formatter
96
+
97
+ def markup text
98
+ if @store.rdoc.options
99
+ locale = @store.rdoc.options.locale
100
+ else
101
+ locale = nil
102
+ end
103
+ if locale
104
+ i18n_text = RDoc::I18n::Text.new(text)
105
+ text = i18n_text.translate(locale)
106
+ end
107
+ parse(text).accept formatter
108
+ end
109
+
110
+ ##
111
+ # Strips hashes, expands tabs then flushes +text+ to the left
112
+
113
+ def normalize_comment text
114
+ return text if text.empty?
115
+
116
+ case language
117
+ when :ruby
118
+ text = strip_hashes text
119
+ when :c
120
+ text = strip_stars text
121
+ end
122
+ text = expand_tabs text
123
+ text = flush_left text
124
+ text = strip_newlines text
125
+ text
126
+ end
127
+
128
+ ##
129
+ # Normalizes +text+ then builds a RDoc::Markup::Document from it
130
+
131
+ def parse text, format = 'rdoc'
132
+ return text if RDoc::Markup::Document === text
133
+ return text.parse if RDoc::Comment === text
134
+
135
+ text = normalize_comment text # TODO remove, should not be necessary
136
+
137
+ return RDoc::Markup::Document.new if text =~ /\A\n*\z/
138
+
139
+ MARKUP_FORMAT[format].parse text
140
+ end
141
+
142
+ ##
143
+ # The first +limit+ characters of +text+ as HTML
144
+
145
+ def snippet text, limit = 100
146
+ document = parse text
147
+
148
+ RDoc::Markup::ToHtmlSnippet.new(options, limit).convert document
149
+ end
150
+
151
+ ##
152
+ # Strips leading # characters from +text+
153
+
154
+ def strip_hashes text
155
+ return text if text =~ /^(?>\s*)[^\#]/
156
+
157
+ empty = ''
158
+ empty = RDoc::Encoding.change_encoding empty, text.encoding
159
+
160
+ text.gsub(/^\s*(#+)/) { $1.tr '#', ' ' }.gsub(/^\s+$/, empty)
161
+ end
162
+
163
+ ##
164
+ # Strips leading and trailing \n characters from +text+
165
+
166
+ def strip_newlines text
167
+ text.gsub(/\A\n*(.*?)\n*\z/m) do $1 end # block preserves String encoding
168
+ end
169
+
170
+ ##
171
+ # Strips /* */ style comments
172
+
173
+ def strip_stars text
174
+ return text unless text =~ %r%/\*.*\*/%m
175
+
176
+ encoding = text.encoding
177
+
178
+ text = text.gsub %r%Document-method:\s+[\w:.#=!?|^&<>~+\-/*\%@`\[\]]+%, ''
179
+
180
+ space = ' '
181
+ space = RDoc::Encoding.change_encoding space, encoding if encoding
182
+
183
+ text.sub! %r%/\*+% do space * $&.length end
184
+ text.sub! %r%\*+/% do space * $&.length end
185
+ text.gsub! %r%^[ \t]*\*%m do space * $&.length end
186
+
187
+ empty = ''
188
+ empty = RDoc::Encoding.change_encoding empty, encoding if encoding
189
+ text.gsub(/^\s+$/, empty)
190
+ end
191
+
192
+ ##
193
+ # Converts ampersand, dashes, ellipsis, quotes, copyright and registered
194
+ # trademark symbols in +text+ to properly encoded characters.
195
+
196
+ def to_html text
197
+ html = (''.encode text.encoding).dup
198
+
199
+ encoded = RDoc::Text::TO_HTML_CHARACTERS[text.encoding]
200
+
201
+ s = StringScanner.new text
202
+ insquotes = false
203
+ indquotes = false
204
+ after_word = nil
205
+
206
+ until s.eos? do
207
+ case
208
+ when s.scan(/<(tt|code)>.*?<\/\1>/) then # skip contents of tt
209
+ html << s.matched.gsub('\\\\', '\\')
210
+ when s.scan(/<(tt|code)>.*?/) then
211
+ warn "mismatched <#{s[1]}> tag" # TODO signal file/line
212
+ html << s.matched
213
+ when s.scan(/<[^>]+\/?s*>/) then # skip HTML tags
214
+ html << s.matched
215
+ when s.scan(/\\(\S)/) then # unhandled suppressed crossref
216
+ html << s[1]
217
+ after_word = nil
218
+ when s.scan(/\.\.\.(\.?)/) then
219
+ html << s[1] << encoded[:ellipsis]
220
+ after_word = nil
221
+ when s.scan(/\(c\)/) then
222
+ html << encoded[:copyright]
223
+ after_word = nil
224
+ when s.scan(/\(r\)/) then
225
+ html << encoded[:trademark]
226
+ after_word = nil
227
+ when s.scan(/---/) then
228
+ html << encoded[:em_dash]
229
+ after_word = nil
230
+ when s.scan(/--/) then
231
+ html << encoded[:en_dash]
232
+ after_word = nil
233
+ when s.scan(/&quot;|"/) then
234
+ html << encoded[indquotes ? :close_dquote : :open_dquote]
235
+ indquotes = !indquotes
236
+ after_word = nil
237
+ when s.scan(/``/) then # backtick double quote
238
+ html << encoded[:open_dquote]
239
+ after_word = nil
240
+ when s.scan(/''/) then # tick double quote
241
+ html << encoded[:close_dquote]
242
+ after_word = nil
243
+ when s.scan(/'/) then # single quote
244
+ if insquotes
245
+ html << encoded[:close_squote]
246
+ insquotes = false
247
+ elsif after_word
248
+ # Mary's dog, my parents' house: do not start paired quotes
249
+ html << encoded[:close_squote]
250
+ else
251
+ html << encoded[:open_squote]
252
+ insquotes = true
253
+ end
254
+
255
+ after_word = nil
256
+ else # advance to the next potentially significant character
257
+ match = s.scan(/.+?(?=[<\\.("'`&-])/) #"
258
+
259
+ if match then
260
+ html << match
261
+ after_word = match =~ /\w$/
262
+ else
263
+ html << s.rest
264
+ break
265
+ end
266
+ end
267
+ end
268
+
269
+ html
270
+ end
271
+
272
+ ##
273
+ # Wraps +txt+ to +line_len+
274
+
275
+ def wrap(txt, line_len = 76)
276
+ res = []
277
+ sp = 0
278
+ ep = txt.length
279
+
280
+ while sp < ep
281
+ # scan back for a space
282
+ p = sp + line_len - 1
283
+ if p >= ep
284
+ p = ep
285
+ else
286
+ while p > sp and txt[p] != ?\s
287
+ p -= 1
288
+ end
289
+ if p <= sp
290
+ p = sp + line_len
291
+ while p < ep and txt[p] != ?\s
292
+ p += 1
293
+ end
294
+ end
295
+ end
296
+ res << txt[sp...p] << "\n"
297
+ sp = p
298
+ sp += 1 while sp < ep and txt[sp] == ?\s
299
+ end
300
+
301
+ res.join.strip
302
+ end
303
+
304
+ end