rdoc 3.1 → 6.3.3

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.

Files changed (247) 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 +129 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +84 -81
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/{bin → exe}/rdoc +11 -2
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +1 -2
  19. data/lib/rdoc/anon_class.rb +3 -2
  20. data/lib/rdoc/any_method.rb +234 -40
  21. data/lib/rdoc/attr.rb +79 -11
  22. data/lib/rdoc/class_module.rb +443 -71
  23. data/lib/rdoc/code_object.rb +216 -20
  24. data/lib/rdoc/code_objects.rb +4 -21
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +110 -9
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +392 -172
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +83 -28
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +8 -3
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +507 -84
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +27 -74
  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 +8 -62
  42. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  43. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  57. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  58. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  59. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  60. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/index.rhtml +18 -60
  72. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -83
  73. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  74. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  75. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  76. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  77. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  78. data/lib/rdoc/generator/template/json_index/.document +1 -0
  79. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  80. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  81. data/lib/rdoc/generator.rb +24 -13
  82. data/lib/rdoc/ghost_method.rb +1 -2
  83. data/lib/rdoc/i18n/locale.rb +102 -0
  84. data/lib/rdoc/i18n/text.rb +126 -0
  85. data/lib/rdoc/i18n.rb +10 -0
  86. data/lib/rdoc/include.rb +5 -95
  87. data/lib/rdoc/known_classes.rb +5 -2
  88. data/lib/rdoc/markdown/entities.rb +2132 -0
  89. data/lib/rdoc/markdown/literals.kpeg +23 -0
  90. data/lib/rdoc/markdown/literals.rb +416 -0
  91. data/lib/rdoc/markdown.kpeg +1237 -0
  92. data/lib/rdoc/markdown.rb +16684 -0
  93. data/lib/rdoc/markup/attr_changer.rb +23 -0
  94. data/lib/rdoc/markup/attr_span.rb +36 -0
  95. data/lib/rdoc/markup/attribute_manager.rb +135 -62
  96. data/lib/rdoc/markup/attributes.rb +71 -0
  97. data/lib/rdoc/markup/blank_line.rb +1 -0
  98. data/lib/rdoc/markup/block_quote.rb +15 -0
  99. data/lib/rdoc/markup/document.rb +96 -9
  100. data/lib/rdoc/markup/formatter.rb +138 -25
  101. data/lib/rdoc/markup/hard_break.rb +32 -0
  102. data/lib/rdoc/markup/heading.rb +61 -2
  103. data/lib/rdoc/markup/include.rb +43 -0
  104. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  105. data/lib/rdoc/markup/list.rb +25 -4
  106. data/lib/rdoc/markup/list_item.rb +18 -4
  107. data/lib/rdoc/markup/paragraph.rb +15 -0
  108. data/lib/rdoc/markup/parser.rb +180 -88
  109. data/lib/rdoc/markup/pre_process.rb +183 -38
  110. data/lib/rdoc/markup/raw.rb +6 -5
  111. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  112. data/lib/rdoc/markup/rule.rb +1 -0
  113. data/lib/rdoc/markup/table.rb +47 -0
  114. data/lib/rdoc/markup/to_ansi.rb +17 -7
  115. data/lib/rdoc/markup/to_bs.rb +5 -8
  116. data/lib/rdoc/markup/to_html.rb +238 -137
  117. data/lib/rdoc/markup/to_html_crossref.rb +125 -152
  118. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  119. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  120. data/lib/rdoc/markup/to_label.rb +75 -0
  121. data/lib/rdoc/markup/to_markdown.rb +192 -0
  122. data/lib/rdoc/markup/to_rdoc.rb +85 -15
  123. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  124. data/lib/rdoc/markup/to_test.rb +2 -4
  125. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  126. data/lib/rdoc/markup/verbatim.rb +39 -0
  127. data/lib/rdoc/markup.rb +388 -110
  128. data/lib/rdoc/meta_method.rb +1 -2
  129. data/lib/rdoc/method_attr.rb +87 -21
  130. data/lib/rdoc/mixin.rb +121 -0
  131. data/lib/rdoc/normal_class.rb +39 -10
  132. data/lib/rdoc/normal_module.rb +22 -7
  133. data/lib/rdoc/options.rb +613 -73
  134. data/lib/rdoc/parser/c.rb +621 -287
  135. data/lib/rdoc/parser/changelog.rb +335 -0
  136. data/lib/rdoc/parser/markdown.rb +24 -0
  137. data/lib/rdoc/parser/rd.rb +23 -0
  138. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  139. data/lib/rdoc/parser/ruby.rb +1368 -762
  140. data/lib/rdoc/parser/ruby_tools.rb +42 -35
  141. data/lib/rdoc/parser/simple.rb +23 -11
  142. data/lib/rdoc/parser/text.rb +12 -0
  143. data/lib/rdoc/parser.rb +162 -89
  144. data/lib/rdoc/rd/block_parser.rb +1056 -0
  145. data/lib/rdoc/rd/block_parser.ry +639 -0
  146. data/lib/rdoc/rd/inline.rb +72 -0
  147. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  148. data/lib/rdoc/rd/inline_parser.ry +593 -0
  149. data/lib/rdoc/rd.rb +100 -0
  150. data/lib/rdoc/rdoc.rb +208 -115
  151. data/lib/rdoc/require.rb +1 -2
  152. data/lib/rdoc/ri/driver.rb +734 -239
  153. data/lib/rdoc/ri/formatter.rb +1 -0
  154. data/lib/rdoc/ri/paths.rb +91 -48
  155. data/lib/rdoc/ri/store.rb +3 -261
  156. data/lib/rdoc/ri/task.rb +71 -0
  157. data/lib/rdoc/ri.rb +5 -2
  158. data/lib/rdoc/rubygems_hook.rb +246 -0
  159. data/lib/rdoc/servlet.rb +451 -0
  160. data/lib/rdoc/single_class.rb +14 -2
  161. data/lib/rdoc/stats/normal.rb +19 -12
  162. data/lib/rdoc/stats/quiet.rb +1 -0
  163. data/lib/rdoc/stats/verbose.rb +1 -0
  164. data/lib/rdoc/stats.rb +262 -104
  165. data/lib/rdoc/store.rb +979 -0
  166. data/lib/rdoc/task.rb +84 -44
  167. data/lib/rdoc/text.rb +117 -72
  168. data/lib/rdoc/token_stream.rb +73 -4
  169. data/lib/rdoc/tom_doc.rb +263 -0
  170. data/lib/rdoc/top_level.rb +111 -261
  171. data/lib/rdoc/version.rb +8 -0
  172. data/lib/rdoc.rb +127 -64
  173. data/man/ri.1 +247 -0
  174. data/rdoc.gemspec +249 -0
  175. metadata +171 -291
  176. data/.autotest +0 -16
  177. data/.document +0 -5
  178. data/History.txt +0 -594
  179. data/LICENSE.txt +0 -57
  180. data/Manifest.txt +0 -158
  181. data/README.txt +0 -45
  182. data/RI.txt +0 -58
  183. data/bin/ri +0 -5
  184. data/lib/rdoc/gauntlet.rb +0 -52
  185. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -296
  186. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  187. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -32
  188. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  189. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
  190. data/lib/rdoc/generator/template/darkfish/rdoc.css +0 -706
  191. data/lib/rdoc/markup/formatter_test_case.rb +0 -689
  192. data/lib/rdoc/markup/inline.rb +0 -137
  193. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -116
  194. data/lib/rdoc/ruby_lex.rb +0 -1291
  195. data/lib/rdoc/ruby_token.rb +0 -416
  196. data/test/README +0 -1
  197. data/test/binary.dat +0 -0
  198. data/test/hidden.zip.txt +0 -1
  199. data/test/test.ja.rdoc +0 -10
  200. data/test/test.ja.txt +0 -8
  201. data/test/test.txt +0 -1
  202. data/test/test_attribute_manager.rb +0 -120
  203. data/test/test_rdoc_alias.rb +0 -13
  204. data/test/test_rdoc_any_method.rb +0 -126
  205. data/test/test_rdoc_attr.rb +0 -61
  206. data/test/test_rdoc_class_module.rb +0 -233
  207. data/test/test_rdoc_code_object.rb +0 -165
  208. data/test/test_rdoc_constant.rb +0 -15
  209. data/test/test_rdoc_context.rb +0 -370
  210. data/test/test_rdoc_encoding.rb +0 -166
  211. data/test/test_rdoc_generator_darkfish.rb +0 -119
  212. data/test/test_rdoc_generator_ri.rb +0 -76
  213. data/test/test_rdoc_include.rb +0 -96
  214. data/test/test_rdoc_markup.rb +0 -37
  215. data/test/test_rdoc_markup_attribute_manager.rb +0 -240
  216. data/test/test_rdoc_markup_document.rb +0 -51
  217. data/test/test_rdoc_markup_paragraph.rb +0 -9
  218. data/test/test_rdoc_markup_parser.rb +0 -1395
  219. data/test/test_rdoc_markup_pre_process.rb +0 -185
  220. data/test/test_rdoc_markup_raw.rb +0 -27
  221. data/test/test_rdoc_markup_to_ansi.rb +0 -328
  222. data/test/test_rdoc_markup_to_bs.rb +0 -341
  223. data/test/test_rdoc_markup_to_html.rb +0 -335
  224. data/test/test_rdoc_markup_to_html_crossref.rb +0 -169
  225. data/test/test_rdoc_markup_to_rdoc.rb +0 -327
  226. data/test/test_rdoc_method_attr.rb +0 -122
  227. data/test/test_rdoc_normal_class.rb +0 -17
  228. data/test/test_rdoc_normal_module.rb +0 -31
  229. data/test/test_rdoc_options.rb +0 -342
  230. data/test/test_rdoc_parser.rb +0 -83
  231. data/test/test_rdoc_parser_c.rb +0 -912
  232. data/test/test_rdoc_parser_ruby.rb +0 -1754
  233. data/test/test_rdoc_parser_simple.rb +0 -99
  234. data/test/test_rdoc_rdoc.rb +0 -164
  235. data/test/test_rdoc_require.rb +0 -25
  236. data/test/test_rdoc_ri_driver.rb +0 -846
  237. data/test/test_rdoc_ri_paths.rb +0 -43
  238. data/test/test_rdoc_ri_store.rb +0 -352
  239. data/test/test_rdoc_ruby_lex.rb +0 -23
  240. data/test/test_rdoc_stats.rb +0 -38
  241. data/test/test_rdoc_task.rb +0 -92
  242. data/test/test_rdoc_text.rb +0 -251
  243. data/test/test_rdoc_top_level.rb +0 -120
  244. data/test/xref_data.rb +0 -62
  245. data/test/xref_test_case.rb +0 -61
  246. data.tar.gz.sig +0 -3
  247. metadata.gz.sig +0 -0
data/lib/rdoc/rdoc.rb CHANGED
@@ -1,57 +1,39 @@
1
+ # frozen_string_literal: true
1
2
  require 'rdoc'
2
3
 
3
- require 'rdoc/encoding'
4
- require 'rdoc/parser'
5
-
6
- # Simple must come first
7
- require 'rdoc/parser/simple'
8
- require 'rdoc/parser/ruby'
9
- require 'rdoc/parser/c'
10
-
11
- require 'rdoc/stats'
12
- require 'rdoc/options'
13
-
14
4
  require 'find'
15
5
  require 'fileutils'
6
+ require 'pathname'
16
7
  require 'time'
17
8
 
18
9
  ##
19
- # Encapsulate the production of rdoc documentation. Basically you can use this
20
- # as you would invoke rdoc from the command line:
21
- #
22
- # rdoc = RDoc::RDoc.new
23
- # rdoc.document(args)
10
+ # This is the driver for generating RDoc output. It handles file parsing and
11
+ # generation of output.
24
12
  #
25
- # Where +args+ is an array of strings, each corresponding to an argument you'd
26
- # give rdoc on the command line. See <tt>rdoc --help<tt> for details.
13
+ # To use this class to generate RDoc output via the API, the recommended way
14
+ # is:
27
15
  #
28
- # = Plugins
29
- #
30
- # When you <tt>require 'rdoc/rdoc'</tt> RDoc looks for 'rdoc/discover' files
31
- # in your installed gems. This can be used to load alternate generators or
32
- # add additional preprocessor directives.
33
- #
34
- # You will want to wrap your plugin loading in an RDoc version check.
35
- # Something like:
16
+ # rdoc = RDoc::RDoc.new
17
+ # options = rdoc.load_options # returns an RDoc::Options instance
18
+ # # set extra options
19
+ # rdoc.document options
36
20
  #
37
- # begin
38
- # gem 'rdoc', '~> 3'
39
- # require 'path/to/my/awesome/rdoc/plugin'
40
- # rescue Gem::LoadError
41
- # end
21
+ # You can also generate output like the +rdoc+ executable:
42
22
  #
43
- # The most obvious plugin type is a new output generator. See RDoc::Generator
44
- # for details.
23
+ # rdoc = RDoc::RDoc.new
24
+ # rdoc.document argv
45
25
  #
46
- # You can also hook into RDoc::Markup to add new directives (:nodoc: is a
47
- # directive). See RDoc::Markup::PreProcess::register for details.
26
+ # Where +argv+ is an array of strings, each corresponding to an argument you'd
27
+ # give rdoc on the command line. See <tt>rdoc --help</tt> for details.
48
28
 
49
29
  class RDoc::RDoc
50
30
 
31
+ @current = nil
32
+
51
33
  ##
52
- # File pattern to exclude
34
+ # This is the list of supported output generators
53
35
 
54
- attr_accessor :exclude
36
+ GENERATORS = {}
55
37
 
56
38
  ##
57
39
  # Generator instance used for creating output
@@ -74,9 +56,9 @@ class RDoc::RDoc
74
56
  attr_reader :stats
75
57
 
76
58
  ##
77
- # This is the list of supported output generators
59
+ # The current documentation store
78
60
 
79
- GENERATORS = {}
61
+ attr_reader :store
80
62
 
81
63
  ##
82
64
  # Add +klass+ that can generate output after parsing
@@ -96,7 +78,7 @@ class RDoc::RDoc
96
78
  ##
97
79
  # Sets the active RDoc::RDoc instance
98
80
 
99
- def self.current=(rdoc)
81
+ def self.current= rdoc
100
82
  @current = rdoc
101
83
  end
102
84
 
@@ -106,12 +88,12 @@ class RDoc::RDoc
106
88
 
107
89
  def initialize
108
90
  @current = nil
109
- @exclude = nil
110
91
  @generator = nil
111
92
  @last_modified = {}
112
93
  @old_siginfo = nil
113
94
  @options = nil
114
95
  @stats = nil
96
+ @store = nil
115
97
  end
116
98
 
117
99
  ##
@@ -128,20 +110,32 @@ class RDoc::RDoc
128
110
  def gather_files files
129
111
  files = ["."] if files.empty?
130
112
 
131
- file_list = normalized_file_list files, true, @exclude
113
+ file_list = normalized_file_list files, true, @options.exclude
132
114
 
133
- file_list = file_list.uniq
115
+ file_list = remove_unparseable(file_list)
134
116
 
135
- file_list = remove_unparseable file_list
117
+ if file_list.count {|name, mtime|
118
+ file_list[name] = @last_modified[name] unless mtime
119
+ mtime
120
+ } > 0
121
+ @last_modified.replace file_list
122
+ file_list.keys.sort
123
+ else
124
+ []
125
+ end
136
126
  end
137
127
 
138
128
  ##
139
129
  # Turns RDoc from stdin into HTML
140
130
 
141
131
  def handle_pipe
142
- @html = RDoc::Markup::ToHtml.new
132
+ @html = RDoc::Markup::ToHtml.new @options
133
+
134
+ parser = RDoc::Text::MARKUP_FORMAT[@options.markup]
143
135
 
144
- out = @html.convert $stdin.read
136
+ document = parser.parse $stdin.read
137
+
138
+ out = @html.convert document
145
139
 
146
140
  $stdout.write out
147
141
  end
@@ -157,6 +151,34 @@ class RDoc::RDoc
157
151
  end
158
152
  end
159
153
 
154
+ ##
155
+ # Loads options from .rdoc_options if the file exists, otherwise creates a
156
+ # new RDoc::Options instance.
157
+
158
+ def load_options
159
+ options_file = File.expand_path '.rdoc_options'
160
+ return RDoc::Options.new unless File.exist? options_file
161
+
162
+ RDoc.load_yaml
163
+
164
+ begin
165
+ options = YAML.load_file '.rdoc_options'
166
+ rescue Psych::SyntaxError
167
+ end
168
+
169
+ return RDoc::Options.new if options == false # Allow empty file.
170
+
171
+ raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
172
+ RDoc::Options === options or Hash === options
173
+
174
+ if Hash === options
175
+ # Override the default values with the contents of YAML file.
176
+ options = RDoc::Options.new options
177
+ end
178
+
179
+ options
180
+ end
181
+
160
182
  ##
161
183
  # Create an output dir if it doesn't exist. If it does exist, but doesn't
162
184
  # contain the flag file <tt>created.rid</tt> then we refuse to use it, as
@@ -173,7 +195,7 @@ class RDoc::RDoc
173
195
  error "#{dir} exists and is not a directory" unless File.directory? dir
174
196
 
175
197
  begin
176
- open flag_file do |io|
198
+ File.open flag_file do |io|
177
199
  unless force then
178
200
  Time.parse io.gets
179
201
 
@@ -197,18 +219,31 @@ option)
197
219
  end unless @options.force_output
198
220
  else
199
221
  FileUtils.mkdir_p dir
222
+ FileUtils.touch flag_file
200
223
  end
201
224
 
202
225
  last
203
226
  end
204
227
 
228
+ ##
229
+ # Sets the current documentation tree to +store+ and sets the store's rdoc
230
+ # driver to this instance.
231
+
232
+ def store= store
233
+ @store = store
234
+ @store.rdoc = self
235
+ end
236
+
205
237
  ##
206
238
  # Update the flag file in an output directory.
207
239
 
208
240
  def update_output_dir(op_dir, time, last = {})
209
- return if @options.dry_run
241
+ return if @options.dry_run or not @options.update_output_dir
242
+ unless ENV['SOURCE_DATE_EPOCH'].nil?
243
+ time = Time.at(ENV['SOURCE_DATE_EPOCH'].to_i).gmtime
244
+ end
210
245
 
211
- open output_flag_file(op_dir), "w" do |f|
246
+ File.open output_flag_file(op_dir), "w" do |f|
212
247
  f.puts time.rfc2822
213
248
  last.each do |n, t|
214
249
  f.puts "#{n}\t#{t.rfc2822}"
@@ -232,11 +267,11 @@ option)
232
267
  # read and strip comments
233
268
  patterns = File.read(filename).gsub(/#.*/, '')
234
269
 
235
- result = []
270
+ result = {}
236
271
 
237
- patterns.split.each do |patt|
272
+ patterns.split(' ').each do |patt|
238
273
  candidates = Dir.glob(File.join(in_dir, patt))
239
- result.concat normalized_file_list(candidates)
274
+ result.update normalized_file_list(candidates, false, @options.exclude)
240
275
  end
241
276
 
242
277
  result
@@ -256,37 +291,41 @@ option)
256
291
 
257
292
  def normalized_file_list(relative_files, force_doc = false,
258
293
  exclude_pattern = nil)
259
- file_list = []
294
+ file_list = {}
260
295
 
261
296
  relative_files.each do |rel_file_name|
297
+ rel_file_name = rel_file_name.sub(/^\.\//, '')
298
+ next if rel_file_name.end_with? 'created.rid'
262
299
  next if exclude_pattern && exclude_pattern =~ rel_file_name
263
300
  stat = File.stat rel_file_name rescue next
264
301
 
265
302
  case type = stat.ftype
266
303
  when "file" then
267
- next if last_modified = @last_modified[rel_file_name] and
268
- stat.mtime.to_i <= last_modified.to_i
304
+ mtime = (stat.mtime unless (last_modified = @last_modified[rel_file_name] and
305
+ stat.mtime.to_i <= last_modified.to_i))
269
306
 
270
307
  if force_doc or RDoc::Parser.can_parse(rel_file_name) then
271
- file_list << rel_file_name.sub(/^\.\//, '')
272
- @last_modified[rel_file_name] = stat.mtime
308
+ file_list[rel_file_name] = mtime
273
309
  end
274
310
  when "directory" then
275
311
  next if rel_file_name == "CVS" || rel_file_name == ".svn"
276
312
 
313
+ created_rid = File.join rel_file_name, "created.rid"
314
+ next if File.file? created_rid
315
+
277
316
  dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
278
317
 
279
318
  if File.file? dot_doc then
280
- file_list << parse_dot_doc_file(rel_file_name, dot_doc)
319
+ file_list.update(parse_dot_doc_file(rel_file_name, dot_doc))
281
320
  else
282
- file_list << list_files_in_directory(rel_file_name)
321
+ file_list.update(list_files_in_directory(rel_file_name))
283
322
  end
284
323
  else
285
- raise RDoc::Error, "I can't deal with a #{type} #{rel_file_name}"
324
+ warn "rdoc can't parse the #{type} #{rel_file_name}"
286
325
  end
287
326
  end
288
327
 
289
- file_list.flatten
328
+ file_list
290
329
  end
291
330
 
292
331
  ##
@@ -305,14 +344,31 @@ option)
305
344
  # Parses +filename+ and returns an RDoc::TopLevel
306
345
 
307
346
  def parse_file filename
347
+ encoding = @options.encoding
348
+ filename = filename.encode encoding
349
+
308
350
  @stats.add_file filename
309
- encoding = @options.encoding if defined?(Encoding)
351
+
352
+ return if RDoc::Parser.binary? filename
310
353
 
311
354
  content = RDoc::Encoding.read_file filename, encoding
312
355
 
313
356
  return unless content
314
357
 
315
- top_level = RDoc::TopLevel.new filename
358
+ filename_path = Pathname(filename).expand_path
359
+ begin
360
+ relative_path = filename_path.relative_path_from @options.root
361
+ rescue ArgumentError
362
+ relative_path = filename_path
363
+ end
364
+
365
+ if @options.page_dir and
366
+ relative_path.to_s.start_with? @options.page_dir.to_s then
367
+ relative_path =
368
+ relative_path.relative_path_from @options.page_dir
369
+ end
370
+
371
+ top_level = @store.add_file filename, relative_name: relative_path.to_s
316
372
 
317
373
  parser = RDoc::Parser.for top_level, filename, content, @options, @stats
318
374
 
@@ -327,6 +383,14 @@ option)
327
383
 
328
384
  top_level
329
385
 
386
+ rescue Errno::EACCES => e
387
+ $stderr.puts <<-EOF
388
+ Unable to read #{filename}, #{e.message}
389
+
390
+ Please check the permissions for this file. Perhaps you do not have access to
391
+ it or perhaps the original author's permissions are to restrictive. If the
392
+ this is not your library please report a bug to the author.
393
+ EOF
330
394
  rescue => e
331
395
  $stderr.puts <<-EOF
332
396
  Before reporting this, could you check that the file you're documenting
@@ -353,12 +417,11 @@ The internal error was:
353
417
 
354
418
  def parse_files files
355
419
  file_list = gather_files files
420
+ @stats = RDoc::Stats.new @store, file_list.length, @options.verbosity
356
421
 
357
422
  return [] if file_list.empty?
358
423
 
359
- file_info = []
360
-
361
- @stats = RDoc::Stats.new file_list.size, @options.verbosity
424
+ original_options = @options.dup
362
425
  @stats.begin_adding
363
426
 
364
427
  file_info = file_list.map do |filename|
@@ -367,89 +430,120 @@ The internal error was:
367
430
  end.compact
368
431
 
369
432
  @stats.done_adding
433
+ @options = original_options
370
434
 
371
435
  file_info
372
436
  end
373
437
 
374
438
  ##
375
- # Removes file extensions known to be unparseable from +files+
439
+ # Removes file extensions known to be unparseable from +files+ and TAGS
440
+ # files for emacs and vim.
376
441
 
377
442
  def remove_unparseable files
378
- files.reject do |file|
379
- file =~ /\.(?:class|eps|erb|scpt\.txt|ttf|yml)$/i
443
+ files.reject do |file, *|
444
+ file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
445
+ (file =~ /tags$/i and
446
+ File.open(file, 'rb') { |io|
447
+ io.read(100) =~ /\A(\f\n[^,]+,\d+$|!_TAG_)/
448
+ })
380
449
  end
381
450
  end
382
451
 
383
452
  ##
384
- # Format up one or more files according to the given arguments.
453
+ # Generates documentation or a coverage report depending upon the settings
454
+ # in +options+.
455
+ #
456
+ # +options+ can be either an RDoc::Options instance or an array of strings
457
+ # equivalent to the strings that would be passed on the command line like
458
+ # <tt>%w[-q -o doc -t My\ Doc\ Title]</tt>. #document will automatically
459
+ # call RDoc::Options#finish if an options instance was given.
460
+ #
461
+ # For a list of options, see either RDoc::Options or <tt>rdoc --help</tt>.
385
462
  #
386
- # For simplicity, +argv+ is an array of strings, equivalent to the strings
387
- # that would be passed on the command line. (This isn't a coincidence, as
388
- # we _do_ pass in ARGV when running interactively). For a list of options,
389
- # see <tt>rdoc --help</tt>. By default, output will be stored in a directory
390
- # called +doc+ below the current directory, so make sure you're somewhere
391
- # writable before invoking.
463
+ # By default, output will be stored in a directory called "doc" below the
464
+ # current directory, so make sure you're somewhere writable before invoking.
392
465
 
393
- def document(argv)
394
- RDoc::TopLevel.reset
395
- RDoc::Parser::C.reset
466
+ def document options
467
+ self.store = RDoc::Store.new
396
468
 
397
- @options = RDoc::Options.new
398
- @options.parse argv
469
+ if RDoc::Options === options then
470
+ @options = options
471
+ @options.finish
472
+ else
473
+ @options = load_options
474
+ @options.parse options
475
+ end
399
476
 
400
477
  if @options.pipe then
401
478
  handle_pipe
402
479
  exit
403
480
  end
404
481
 
405
- @exclude = @options.exclude
406
-
407
482
  unless @options.coverage_report then
408
483
  @last_modified = setup_output_dir @options.op_dir, @options.force_update
409
484
  end
410
485
 
411
- start_time = Time.now
486
+ @store.encoding = @options.encoding
487
+ @store.dry_run = @options.dry_run
488
+ @store.main = @options.main_page
489
+ @store.title = @options.title
490
+ @store.path = @options.op_dir
491
+
492
+ @start_time = Time.now
493
+
494
+ @store.load_cache
412
495
 
413
496
  file_info = parse_files @options.files
414
497
 
415
498
  @options.default_title = "RDoc Documentation"
416
499
 
417
- RDoc::TopLevel.complete @options.visibility
500
+ @store.complete @options.visibility
501
+
502
+ @stats.coverage_level = @options.coverage_report
418
503
 
419
504
  if @options.coverage_report then
420
505
  puts
421
- puts @stats.report
422
- elsif file_info.empty?
506
+
507
+ puts @stats.report.accept RDoc::Markup::ToRdoc.new
508
+ elsif file_info.empty? then
423
509
  $stderr.puts "\nNo newer files." unless @options.quiet
424
510
  else
425
511
  gen_klass = @options.generator
426
512
 
427
- @generator = gen_klass.new @options
428
-
429
- Dir.chdir @options.op_dir do
430
- begin
431
- self.class.current = self
432
-
433
- unless @options.quiet then
434
- $stderr.puts "\nGenerating #{gen_klass.name.sub(/^.*::/, '')} format into #{Dir.pwd}..."
435
- end
513
+ @generator = gen_klass.new @store, @options
436
514
 
437
- @generator.generate file_info
438
- update_output_dir ".", start_time, @last_modified
439
- ensure
440
- self.class.current = nil
441
- end
442
- end
515
+ generate
443
516
  end
444
517
 
445
- unless @options.quiet or not @stats then
518
+ if @stats and (@options.coverage_report or not @options.quiet) then
446
519
  puts
447
- puts @stats.summary
520
+ puts @stats.summary.accept RDoc::Markup::ToRdoc.new
448
521
  end
449
522
 
450
523
  exit @stats.fully_documented? if @options.coverage_report
451
524
  end
452
525
 
526
+ ##
527
+ # Generates documentation for +file_info+ (from #parse_files) into the
528
+ # output dir using the generator selected
529
+ # by the RDoc options
530
+
531
+ def generate
532
+ if @options.dry_run then
533
+ # do nothing
534
+ @generator.generate
535
+ else
536
+ Dir.chdir @options.op_dir do
537
+ unless @options.quiet then
538
+ $stderr.puts "\nGenerating #{@generator.class.name.sub(/^.*::/, '')} format into #{Dir.pwd}..."
539
+ end
540
+
541
+ @generator.generate
542
+ update_output_dir '.', @start_time, @last_modified
543
+ end
544
+ end
545
+ end
546
+
453
547
  ##
454
548
  # Removes a siginfo handler and replaces the previous
455
549
 
@@ -466,21 +560,20 @@ end
466
560
  begin
467
561
  require 'rubygems'
468
562
 
469
- if Gem.respond_to? :find_files then
470
- rdoc_extensions = Gem.find_files 'rdoc/discover'
563
+ rdoc_extensions = Gem.find_files 'rdoc/discover'
471
564
 
472
- rdoc_extensions.each do |extension|
473
- begin
474
- load extension
475
- rescue => e
476
- warn "error loading #{extension.inspect}: #{e.message} (#{e.class})"
477
- end
565
+ rdoc_extensions.each do |extension|
566
+ begin
567
+ load extension
568
+ rescue => e
569
+ warn "error loading #{extension.inspect}: #{e.message} (#{e.class})"
570
+ warn "\t#{e.backtrace.join "\n\t"}" if $DEBUG
478
571
  end
479
572
  end
480
573
  rescue LoadError
481
574
  end
482
575
 
483
576
  # require built-in generators after discovery in case they've been replaced
484
- require 'rdoc/generator/darkfish'
485
- require 'rdoc/generator/ri'
486
-
577
+ require_relative 'generator/darkfish'
578
+ require_relative 'generator/ri'
579
+ require_relative 'generator/pot'
data/lib/rdoc/require.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'rdoc/code_object'
2
-
1
+ # frozen_string_literal: true
3
2
  ##
4
3
  # A file loaded by \#require
5
4