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
@@ -0,0 +1,300 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+ begin
4
+ require 'zlib'
5
+ rescue LoadError
6
+ end
7
+
8
+ ##
9
+ # The JsonIndex generator is designed to complement an HTML generator and
10
+ # produces a JSON search index. This generator is derived from sdoc by
11
+ # Vladimir Kolesnikov and contains verbatim code written by him.
12
+ #
13
+ # This generator is designed to be used with a regular HTML generator:
14
+ #
15
+ # class RDoc::Generator::Darkfish
16
+ # def initialize options
17
+ # # ...
18
+ # @base_dir = Pathname.pwd.expand_path
19
+ #
20
+ # @json_index = RDoc::Generator::JsonIndex.new self, options
21
+ # end
22
+ #
23
+ # def generate
24
+ # # ...
25
+ # @json_index.generate
26
+ # end
27
+ # end
28
+ #
29
+ # == Index Format
30
+ #
31
+ # The index is output as a JSON file assigned to the global variable
32
+ # +search_data+. The structure is:
33
+ #
34
+ # var search_data = {
35
+ # "index": {
36
+ # "searchIndex":
37
+ # ["a", "b", ...],
38
+ # "longSearchIndex":
39
+ # ["a", "a::b", ...],
40
+ # "info": [
41
+ # ["A", "A", "A.html", "", ""],
42
+ # ["B", "A::B", "A::B.html", "", ""],
43
+ # ...
44
+ # ]
45
+ # }
46
+ # }
47
+ #
48
+ # The same item is described across the +searchIndex+, +longSearchIndex+ and
49
+ # +info+ fields. The +searchIndex+ field contains the item's short name, the
50
+ # +longSearchIndex+ field contains the full_name (when appropriate) and the
51
+ # +info+ field contains the item's name, full_name, path, parameters and a
52
+ # snippet of the item's comment.
53
+ #
54
+ # == LICENSE
55
+ #
56
+ # Copyright (c) 2009 Vladimir Kolesnikov
57
+ #
58
+ # Permission is hereby granted, free of charge, to any person obtaining
59
+ # a copy of this software and associated documentation files (the
60
+ # "Software"), to deal in the Software without restriction, including
61
+ # without limitation the rights to use, copy, modify, merge, publish,
62
+ # distribute, sublicense, and/or sell copies of the Software, and to
63
+ # permit persons to whom the Software is furnished to do so, subject to
64
+ # the following conditions:
65
+ #
66
+ # The above copyright notice and this permission notice shall be
67
+ # included in all copies or substantial portions of the Software.
68
+ #
69
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
70
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
72
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
73
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
74
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
75
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
76
+
77
+ class RDoc::Generator::JsonIndex
78
+
79
+ include RDoc::Text
80
+
81
+ ##
82
+ # Where the search index lives in the generated output
83
+
84
+ SEARCH_INDEX_FILE = File.join 'js', 'search_index.js'
85
+
86
+ attr_reader :index # :nodoc:
87
+
88
+ ##
89
+ # Creates a new generator. +parent_generator+ is used to determine the
90
+ # class_dir and file_dir of links in the output index.
91
+ #
92
+ # +options+ are the same options passed to the parent generator.
93
+
94
+ def initialize parent_generator, options
95
+ @parent_generator = parent_generator
96
+ @store = parent_generator.store
97
+ @options = options
98
+
99
+ @template_dir = File.expand_path '../template/json_index', __FILE__
100
+ @base_dir = @parent_generator.base_dir
101
+
102
+ @classes = nil
103
+ @files = nil
104
+ @index = nil
105
+ end
106
+
107
+ ##
108
+ # Builds the JSON index as a Hash.
109
+
110
+ def build_index
111
+ reset @store.all_files.sort, @store.all_classes_and_modules.sort
112
+
113
+ index_classes
114
+ index_methods
115
+ index_pages
116
+
117
+ { :index => @index }
118
+ end
119
+
120
+ ##
121
+ # Output progress information if debugging is enabled
122
+
123
+ def debug_msg *msg
124
+ return unless $DEBUG_RDOC
125
+ $stderr.puts(*msg)
126
+ end
127
+
128
+ ##
129
+ # Writes the JSON index to disk
130
+
131
+ def generate
132
+ debug_msg "Generating JSON index"
133
+
134
+ debug_msg " writing search index to %s" % SEARCH_INDEX_FILE
135
+ data = build_index
136
+
137
+ return if @options.dry_run
138
+
139
+ out_dir = @base_dir + @options.op_dir
140
+ index_file = out_dir + SEARCH_INDEX_FILE
141
+
142
+ FileUtils.mkdir_p index_file.dirname, :verbose => $DEBUG_RDOC
143
+
144
+ index_file.open 'w', 0644 do |io|
145
+ io.set_encoding Encoding::UTF_8
146
+ io.write 'var search_data = '
147
+
148
+ JSON.dump data, io, 0
149
+ end
150
+ unless ENV['SOURCE_DATE_EPOCH'].nil?
151
+ index_file.utime index_file.atime, Time.at(ENV['SOURCE_DATE_EPOCH'].to_i).gmtime
152
+ end
153
+
154
+ Dir.chdir @template_dir do
155
+ Dir['**/*.js'].each do |source|
156
+ dest = File.join out_dir, source
157
+
158
+ FileUtils.install source, dest, :mode => 0644, :preserve => true, :verbose => $DEBUG_RDOC
159
+ end
160
+ end
161
+ end
162
+
163
+ ##
164
+ # Compress the search_index.js file using gzip
165
+
166
+ def generate_gzipped
167
+ return if @options.dry_run or not defined?(Zlib)
168
+
169
+ debug_msg "Compressing generated JSON index"
170
+ out_dir = @base_dir + @options.op_dir
171
+
172
+ search_index_file = out_dir + SEARCH_INDEX_FILE
173
+ outfile = out_dir + "#{search_index_file}.gz"
174
+
175
+ debug_msg "Reading the JSON index file from %s" % search_index_file
176
+ search_index = search_index_file.read(mode: 'r:utf-8')
177
+
178
+ debug_msg "Writing gzipped search index to %s" % outfile
179
+
180
+ Zlib::GzipWriter.open(outfile) do |gz|
181
+ gz.mtime = File.mtime(search_index_file)
182
+ gz.orig_name = search_index_file.basename.to_s
183
+ gz.write search_index
184
+ gz.close
185
+ end
186
+
187
+ # GZip the rest of the js files
188
+ Dir.chdir @template_dir do
189
+ Dir['**/*.js'].each do |source|
190
+ dest = out_dir + source
191
+ outfile = out_dir + "#{dest}.gz"
192
+
193
+ debug_msg "Reading the original js file from %s" % dest
194
+ data = dest.read
195
+
196
+ debug_msg "Writing gzipped file to %s" % outfile
197
+
198
+ Zlib::GzipWriter.open(outfile) do |gz|
199
+ gz.mtime = File.mtime(dest)
200
+ gz.orig_name = dest.basename.to_s
201
+ gz.write data
202
+ gz.close
203
+ end
204
+ end
205
+ end
206
+ end
207
+
208
+ ##
209
+ # Adds classes and modules to the index
210
+
211
+ def index_classes
212
+ debug_msg " generating class search index"
213
+
214
+ documented = @classes.uniq.select do |klass|
215
+ klass.document_self_or_methods
216
+ end
217
+
218
+ documented.each do |klass|
219
+ debug_msg " #{klass.full_name}"
220
+ record = klass.search_record
221
+ @index[:searchIndex] << search_string(record.shift)
222
+ @index[:longSearchIndex] << search_string(record.shift)
223
+ @index[:info] << record
224
+ end
225
+ end
226
+
227
+ ##
228
+ # Adds methods to the index
229
+
230
+ def index_methods
231
+ debug_msg " generating method search index"
232
+
233
+ list = @classes.uniq.map do |klass|
234
+ klass.method_list
235
+ end.flatten.sort_by do |method|
236
+ [method.name, method.parent.full_name]
237
+ end
238
+
239
+ list.each do |method|
240
+ debug_msg " #{method.full_name}"
241
+ record = method.search_record
242
+ @index[:searchIndex] << "#{search_string record.shift}()"
243
+ @index[:longSearchIndex] << "#{search_string record.shift}()"
244
+ @index[:info] << record
245
+ end
246
+ end
247
+
248
+ ##
249
+ # Adds pages to the index
250
+
251
+ def index_pages
252
+ debug_msg " generating pages search index"
253
+
254
+ pages = @files.select do |file|
255
+ file.text?
256
+ end
257
+
258
+ pages.each do |page|
259
+ debug_msg " #{page.page_name}"
260
+ record = page.search_record
261
+ @index[:searchIndex] << search_string(record.shift)
262
+ @index[:longSearchIndex] << ''
263
+ record.shift
264
+ @index[:info] << record
265
+ end
266
+ end
267
+
268
+ ##
269
+ # The directory classes are written to
270
+
271
+ def class_dir
272
+ @parent_generator.class_dir
273
+ end
274
+
275
+ ##
276
+ # The directory files are written to
277
+
278
+ def file_dir
279
+ @parent_generator.file_dir
280
+ end
281
+
282
+ def reset files, classes # :nodoc:
283
+ @files = files
284
+ @classes = classes
285
+
286
+ @index = {
287
+ :searchIndex => [],
288
+ :longSearchIndex => [],
289
+ :info => []
290
+ }
291
+ end
292
+
293
+ ##
294
+ # Removes whitespace and downcases +string+
295
+
296
+ def search_string string
297
+ string.downcase.gsub(/\s/, '')
298
+ end
299
+
300
+ end
@@ -1,10 +1,9 @@
1
- require 'rdoc/text'
2
- require 'rdoc/code_objects'
3
- require 'rdoc/generator'
4
- require 'rdoc/markup/to_html_crossref'
5
-
1
+ # frozen_string_literal: true
6
2
  ##
7
3
  # Handle common RDoc::Markup tasks for various CodeObjects
4
+ #
5
+ # This module is loaded by generators. It allows RDoc's CodeObject tree to
6
+ # avoid loading generator code to improve startup time for +ri+.
8
7
 
9
8
  module RDoc::Generator::Markup
10
9
 
@@ -35,16 +34,18 @@ module RDoc::Generator::Markup
35
34
  def formatter
36
35
  return @formatter if defined? @formatter
37
36
 
38
- show_hash = RDoc::RDoc.current.options.show_hash
39
- hyperlink_all = RDoc::RDoc.current.options.hyperlink_all
37
+ options = @store.rdoc.options
40
38
  this = RDoc::Context === self ? self : @parent
41
- @formatter = RDoc::Markup::ToHtmlCrossref.new this.path, this, show_hash, hyperlink_all
39
+
40
+ @formatter = RDoc::Markup::ToHtmlCrossref.new options, this.path, this
41
+ @formatter.code_object = self
42
+ @formatter
42
43
  end
43
44
 
44
45
  ##
45
46
  # Build a webcvs URL starting for the given +url+ with +full_path+ appended
46
47
  # as the destination path. If +url+ contains '%s' +full_path+ will be
47
- # sprintf'd into +url+ instead.
48
+ # will replace the %s using sprintf on the +url+.
48
49
 
49
50
  def cvs_url(url, full_path)
50
51
  if /%s/ =~ url then
@@ -56,35 +57,13 @@ module RDoc::Generator::Markup
56
57
 
57
58
  end
58
59
 
59
- class RDoc::AnyMethod
60
-
61
- ##
62
- # Maps RDoc::RubyToken classes to CSS class names
63
-
64
- STYLE_MAP = {
65
- RDoc::RubyToken::TkCONSTANT => 'ruby-constant',
66
- RDoc::RubyToken::TkKW => 'ruby-keyword',
67
- RDoc::RubyToken::TkIVAR => 'ruby-ivar',
68
- RDoc::RubyToken::TkOp => 'ruby-operator',
69
- RDoc::RubyToken::TkId => 'ruby-identifier',
70
- RDoc::RubyToken::TkNode => 'ruby-node',
71
- RDoc::RubyToken::TkCOMMENT => 'ruby-comment',
72
- RDoc::RubyToken::TkREGEXP => 'ruby-regexp',
73
- RDoc::RubyToken::TkSTRING => 'ruby-string',
74
- RDoc::RubyToken::TkVal => 'ruby-value',
75
- }
60
+ class RDoc::CodeObject
76
61
 
77
62
  include RDoc::Generator::Markup
78
63
 
79
- @add_line_numbers = false
80
-
81
- class << self
82
- ##
83
- # Allows controlling whether <tt>#markup_code</tt> adds line numbers to
84
- # the source code.
64
+ end
85
65
 
86
- attr_accessor :add_line_numbers
87
- end
66
+ class RDoc::MethodAttr
88
67
 
89
68
  ##
90
69
  # Prepend +src+ with line numbers. Relies on the first line of a source
@@ -92,7 +71,8 @@ class RDoc::AnyMethod
92
71
  #
93
72
  # # File xxxxx, line dddd
94
73
  #
95
- # If it has, line numbers are added an ', line dddd' is removed.
74
+ # If it has this comment then line numbers are added to +src+ and the <tt>,
75
+ # line dddd</tt> portion of the comment is removed.
96
76
 
97
77
  def add_line_numbers(src)
98
78
  return unless src.sub!(/\A(.*)(, line (\d+))/, '\1')
@@ -116,26 +96,12 @@ class RDoc::AnyMethod
116
96
  ##
117
97
  # Turns the method's token stream into HTML.
118
98
  #
119
- # Prepends line numbers if +add_line_numbers+ is true.
99
+ # Prepends line numbers if +options.line_numbers+ is true.
120
100
 
121
101
  def markup_code
122
102
  return '' unless @token_stream
123
103
 
124
- src = ""
125
-
126
- @token_stream.each do |t|
127
- next unless t
128
-
129
- style = STYLE_MAP[t.class]
130
-
131
- text = CGI.escapeHTML t.text
132
-
133
- if style then
134
- src << "<span class=\"#{style}\">#{text}</span>"
135
- else
136
- src << text
137
- end
138
- end
104
+ src = RDoc::TokenStream.to_html @token_stream
139
105
 
140
106
  # dedent the source
141
107
  indent = src.length
@@ -150,34 +116,21 @@ class RDoc::AnyMethod
150
116
  end
151
117
  src.gsub!(/^#{' ' * indent}/, '') if indent > 0
152
118
 
153
- add_line_numbers(src) if self.class.add_line_numbers
119
+ add_line_numbers(src) if options.line_numbers
154
120
 
155
121
  src
156
122
  end
157
123
 
158
124
  end
159
125
 
160
- class RDoc::Attr
161
-
162
- include RDoc::Generator::Markup
126
+ class RDoc::ClassModule
163
127
 
164
- end
165
-
166
- class RDoc::Alias
167
-
168
- include RDoc::Generator::Markup
169
-
170
- end
171
-
172
- class RDoc::Constant
173
-
174
- include RDoc::Generator::Markup
175
-
176
- end
177
-
178
- class RDoc::Context
128
+ ##
129
+ # Handy wrapper for marking up this class or module's comment
179
130
 
180
- include RDoc::Generator::Markup
131
+ def description
132
+ markup @comment_location
133
+ end
181
134
 
182
135
  end
183
136
 
@@ -194,12 +147,12 @@ class RDoc::TopLevel
194
147
  # command line option to set.
195
148
 
196
149
  def cvs_url
197
- url = RDoc::RDoc.current.options.webcvs
150
+ url = @store.rdoc.options.webcvs
198
151
 
199
152
  if /%s/ =~ url then
200
- url % @absolute_name
153
+ url % @relative_name
201
154
  else
202
- url + @absolute_name
155
+ url + @relative_name
203
156
  end
204
157
  end
205
158
 
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Extracts message from RDoc::Store
4
+
5
+ class RDoc::Generator::POT::MessageExtractor
6
+
7
+ ##
8
+ # Creates a message extractor for +store+.
9
+
10
+ def initialize store
11
+ @store = store
12
+ @po = RDoc::Generator::POT::PO.new
13
+ end
14
+
15
+ ##
16
+ # Extracts messages from +store+, stores them into
17
+ # RDoc::Generator::POT::PO and returns it.
18
+
19
+ def extract
20
+ @store.all_classes_and_modules.each do |klass|
21
+ extract_from_klass(klass)
22
+ end
23
+ @po
24
+ end
25
+
26
+ private
27
+
28
+ def extract_from_klass klass
29
+ extract_text(klass.comment_location, klass.full_name)
30
+
31
+ klass.each_section do |section, constants, attributes|
32
+ extract_text(section.title ,"#{klass.full_name}: section title")
33
+ section.comments.each do |comment|
34
+ extract_text(comment, "#{klass.full_name}: #{section.title}")
35
+ end
36
+ end
37
+
38
+ klass.each_constant do |constant|
39
+ extract_text(constant.comment, constant.full_name)
40
+ end
41
+
42
+ klass.each_attribute do |attribute|
43
+ extract_text(attribute.comment, attribute.full_name)
44
+ end
45
+
46
+ klass.each_method do |method|
47
+ extract_text(method.comment, method.full_name)
48
+ end
49
+ end
50
+
51
+ def extract_text text, comment, location = nil
52
+ return if text.nil?
53
+
54
+ options = {
55
+ :extracted_comment => comment,
56
+ :references => [location].compact,
57
+ }
58
+ i18n_text = RDoc::I18n::Text.new(text)
59
+ i18n_text.extract_messages do |part|
60
+ @po.add(entry(part[:paragraph], options))
61
+ end
62
+ end
63
+
64
+ def entry msgid, options
65
+ RDoc::Generator::POT::POEntry.new(msgid, options)
66
+ end
67
+
68
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Generates a PO format text
4
+
5
+ class RDoc::Generator::POT::PO
6
+
7
+ ##
8
+ # Creates an object that represents PO format.
9
+
10
+ def initialize
11
+ @entries = {}
12
+ add_header
13
+ end
14
+
15
+ ##
16
+ # Adds a PO entry to the PO.
17
+
18
+ def add entry
19
+ existing_entry = @entries[entry.msgid]
20
+ if existing_entry
21
+ entry = existing_entry.merge(entry)
22
+ end
23
+ @entries[entry.msgid] = entry
24
+ end
25
+
26
+ ##
27
+ # Returns PO format text for the PO.
28
+
29
+ def to_s
30
+ po = ''
31
+ sort_entries.each do |entry|
32
+ po += "\n" unless po.empty?
33
+ po += entry.to_s
34
+ end
35
+ po
36
+ end
37
+
38
+ private
39
+
40
+ def add_header
41
+ add(header_entry)
42
+ end
43
+
44
+ def header_entry
45
+ comment = <<-COMMENT
46
+ SOME DESCRIPTIVE TITLE.
47
+ Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
48
+ This file is distributed under the same license as the PACKAGE package.
49
+ FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
50
+ COMMENT
51
+
52
+ content = <<-CONTENT
53
+ Project-Id-Version: PACKAGE VERSEION
54
+ Report-Msgid-Bugs-To:
55
+ PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE
56
+ Last-Translator: FULL NAME <EMAIL@ADDRESS>
57
+ Language-Team: LANGUAGE <LL@li.org>
58
+ Language:
59
+ MIME-Version: 1.0
60
+ Content-Type: text/plain; charset=CHARSET
61
+ Content-Transfer-Encoding: 8bit
62
+ Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;
63
+ CONTENT
64
+
65
+ options = {
66
+ :msgstr => content,
67
+ :translator_comment => comment,
68
+ :flags => ['fuzzy'],
69
+ }
70
+ RDoc::Generator::POT::POEntry.new('', options)
71
+ end
72
+
73
+ def sort_entries
74
+ headers, messages = @entries.values.partition do |entry|
75
+ entry.msgid.empty?
76
+ end
77
+ # TODO: sort by location
78
+ sorted_messages = messages.sort_by do |entry|
79
+ entry.msgid
80
+ end
81
+ headers + sorted_messages
82
+ end
83
+
84
+ end