rdoc 6.3.4.1 → 8.0.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 (205) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +195 -0
  3. data/History.rdoc +65 -63
  4. data/LEGAL.rdoc +7 -1
  5. data/LICENSE.rdoc +6 -0
  6. data/README.md +236 -0
  7. data/RI.md +842 -0
  8. data/TODO.rdoc +8 -7
  9. data/doc/markup_reference/markdown.md +659 -0
  10. data/doc/markup_reference/rdoc.rdoc +1169 -0
  11. data/exe/rdoc +0 -1
  12. data/lib/rdoc/{alias.rb → code_object/alias.rb} +4 -18
  13. data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +50 -24
  14. data/lib/rdoc/{attr.rb → code_object/attr.rb} +16 -14
  15. data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +225 -58
  16. data/lib/rdoc/{constant.rb → code_object/constant.rb} +44 -10
  17. data/lib/rdoc/code_object/context/section.rb +182 -0
  18. data/lib/rdoc/{context.rb → code_object/context.rb} +78 -106
  19. data/lib/rdoc/{extend.rb → code_object/extend.rb} +0 -1
  20. data/lib/rdoc/{include.rb → code_object/include.rb} +0 -1
  21. data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +46 -48
  22. data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +6 -4
  23. data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +2 -3
  24. data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +2 -3
  25. data/lib/rdoc/{require.rb → code_object/require.rb} +1 -2
  26. data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +5 -1
  27. data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +60 -63
  28. data/lib/rdoc/code_object.rb +11 -39
  29. data/lib/rdoc/code_objects.rb +1 -2
  30. data/lib/rdoc/comment.rb +202 -99
  31. data/lib/rdoc/cross_reference.rb +75 -62
  32. data/lib/rdoc/encoding.rb +8 -24
  33. data/lib/rdoc/erb_partial.rb +1 -2
  34. data/lib/rdoc/erbio.rb +3 -8
  35. data/lib/rdoc/generator/aliki.rb +200 -0
  36. data/lib/rdoc/generator/darkfish.rb +156 -122
  37. data/lib/rdoc/generator/json_index.rb +8 -24
  38. data/lib/rdoc/generator/markup.rb +70 -34
  39. data/lib/rdoc/generator/pot/message_extractor.rb +7 -7
  40. data/lib/rdoc/generator/pot/po.rb +1 -1
  41. data/lib/rdoc/generator/pot/po_entry.rb +8 -8
  42. data/lib/rdoc/generator/pot.rb +1 -5
  43. data/lib/rdoc/generator/ri.rb +1 -2
  44. data/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
  45. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
  46. data/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
  47. data/lib/rdoc/generator/template/aliki/_head.rhtml +163 -0
  48. data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
  49. data/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
  50. data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
  51. data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
  52. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +27 -0
  53. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +27 -0
  54. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
  55. data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
  56. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
  57. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
  58. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
  59. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
  60. data/lib/rdoc/generator/template/aliki/class.rhtml +230 -0
  61. data/lib/rdoc/generator/template/aliki/css/rdoc.css +2181 -0
  62. data/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
  63. data/lib/rdoc/generator/template/aliki/js/aliki.js +513 -0
  64. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  65. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
  66. data/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
  67. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  68. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  69. data/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
  70. data/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
  71. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
  72. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
  73. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +3 -3
  74. data/lib/rdoc/generator/template/darkfish/_head.rhtml +35 -14
  75. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -5
  76. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +11 -9
  77. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +11 -9
  78. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +7 -6
  79. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +20 -11
  80. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +25 -5
  81. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +4 -9
  82. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +2 -1
  83. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  84. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +28 -7
  85. data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  86. data/lib/rdoc/generator/template/darkfish/class.rhtml +138 -90
  87. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +420 -358
  88. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  89. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  90. data/lib/rdoc/generator/template/darkfish/index.rhtml +14 -12
  91. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +59 -3
  92. data/lib/rdoc/generator/template/darkfish/js/search.js +15 -5
  93. data/lib/rdoc/generator/template/darkfish/page.rhtml +7 -6
  94. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +12 -9
  95. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +24 -21
  96. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +35 -21
  97. data/lib/rdoc/generator/template/json_index/js/navigation.js +8 -8
  98. data/lib/rdoc/generator/template/json_index/js/searcher.js +48 -6
  99. data/lib/rdoc/generator.rb +6 -5
  100. data/lib/rdoc/i18n/text.rb +3 -3
  101. data/lib/rdoc/i18n.rb +1 -1
  102. data/lib/rdoc/known_classes.rb +5 -4
  103. data/lib/rdoc/markdown/entities.rb +0 -1
  104. data/lib/rdoc/markdown/literals.kpeg +0 -2
  105. data/lib/rdoc/markdown/literals.rb +0 -1
  106. data/lib/rdoc/markdown.kpeg +140 -62
  107. data/lib/rdoc/markdown.rb +1015 -873
  108. data/lib/rdoc/markup/blank_line.rb +25 -24
  109. data/lib/rdoc/markup/block_quote.rb +1 -2
  110. data/lib/rdoc/markup/document.rb +10 -11
  111. data/lib/rdoc/markup/element.rb +21 -0
  112. data/lib/rdoc/markup/formatter.rb +134 -115
  113. data/lib/rdoc/markup/hard_break.rb +30 -28
  114. data/lib/rdoc/markup/heading.rb +163 -72
  115. data/lib/rdoc/markup/include.rb +3 -4
  116. data/lib/rdoc/markup/indented_paragraph.rb +4 -5
  117. data/lib/rdoc/markup/inline_parser.rb +312 -0
  118. data/lib/rdoc/markup/list.rb +6 -7
  119. data/lib/rdoc/markup/list_item.rb +6 -7
  120. data/lib/rdoc/markup/paragraph.rb +2 -3
  121. data/lib/rdoc/markup/parser.rb +29 -19
  122. data/lib/rdoc/markup/pre_process.rb +39 -18
  123. data/lib/rdoc/markup/raw.rb +52 -56
  124. data/lib/rdoc/markup/rule.rb +2 -3
  125. data/lib/rdoc/markup/table.rb +49 -32
  126. data/lib/rdoc/markup/to_ansi.rb +58 -8
  127. data/lib/rdoc/markup/to_bs.rb +47 -38
  128. data/lib/rdoc/markup/to_html.rb +343 -105
  129. data/lib/rdoc/markup/to_html_crossref.rb +143 -58
  130. data/lib/rdoc/markup/to_html_snippet.rb +78 -76
  131. data/lib/rdoc/markup/to_joined_paragraph.rb +3 -9
  132. data/lib/rdoc/markup/to_label.rb +34 -25
  133. data/lib/rdoc/markup/to_markdown.rb +74 -51
  134. data/lib/rdoc/markup/to_rdoc.rb +141 -82
  135. data/lib/rdoc/markup/to_table_of_contents.rb +4 -5
  136. data/lib/rdoc/markup/to_test.rb +10 -3
  137. data/lib/rdoc/markup/to_tt_only.rb +17 -31
  138. data/lib/rdoc/markup/verbatim.rb +5 -6
  139. data/lib/rdoc/markup.rb +59 -707
  140. data/lib/rdoc/options.rb +228 -101
  141. data/lib/rdoc/parser/c.rb +186 -184
  142. data/lib/rdoc/parser/changelog.rb +57 -13
  143. data/lib/rdoc/parser/markdown.rb +0 -2
  144. data/lib/rdoc/parser/rbs.rb +275 -0
  145. data/lib/rdoc/parser/rd.rb +0 -1
  146. data/lib/rdoc/parser/ruby.rb +963 -2024
  147. data/lib/rdoc/parser/ruby_colorizer.rb +253 -0
  148. data/lib/rdoc/parser/simple.rb +6 -23
  149. data/lib/rdoc/parser/text.rb +0 -1
  150. data/lib/rdoc/parser.rb +35 -14
  151. data/lib/rdoc/rbs_helper.rb +186 -0
  152. data/lib/rdoc/rd/block_parser.rb +659 -11
  153. data/lib/rdoc/rd/block_parser.ry +13 -9
  154. data/lib/rdoc/rd/inline.rb +4 -5
  155. data/lib/rdoc/rd/inline_parser.rb +646 -2
  156. data/lib/rdoc/rd.rb +4 -5
  157. data/lib/rdoc/rdoc.rb +234 -90
  158. data/lib/rdoc/ri/driver.rb +172 -172
  159. data/lib/rdoc/ri/paths.rb +3 -3
  160. data/lib/rdoc/{servlet.rb → ri/servlet.rb} +28 -27
  161. data/lib/rdoc/ri/store.rb +0 -1
  162. data/lib/rdoc/ri/task.rb +3 -3
  163. data/lib/rdoc/ri.rb +5 -5
  164. data/lib/rdoc/rubygems_hook.rb +106 -25
  165. data/lib/rdoc/server.rb +460 -0
  166. data/lib/rdoc/stats/normal.rb +1 -1
  167. data/lib/rdoc/stats/quiet.rb +1 -2
  168. data/lib/rdoc/stats/verbose.rb +3 -5
  169. data/lib/rdoc/stats.rb +158 -136
  170. data/lib/rdoc/store.rb +267 -48
  171. data/lib/rdoc/task.rb +54 -28
  172. data/lib/rdoc/text.rb +60 -120
  173. data/lib/rdoc/token_stream.rb +30 -45
  174. data/lib/rdoc/tom_doc.rb +9 -15
  175. data/lib/rdoc/version.rb +3 -1
  176. data/lib/rdoc.rb +90 -52
  177. data/lib/rubygems_plugin.rb +14 -0
  178. data/man/ri.1 +2 -0
  179. data/rdoc-logo.svg +43 -0
  180. data/rdoc.gemspec +25 -200
  181. metadata +120 -53
  182. data/CONTRIBUTING.rdoc +0 -220
  183. data/ExampleMarkdown.md +0 -37
  184. data/ExampleRDoc.rdoc +0 -208
  185. data/Gemfile +0 -12
  186. data/README.rdoc +0 -129
  187. data/RI.rdoc +0 -57
  188. data/Rakefile +0 -101
  189. data/bin/console +0 -7
  190. data/bin/setup +0 -6
  191. data/lib/rdoc/anon_class.rb +0 -11
  192. data/lib/rdoc/context/section.rb +0 -232
  193. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  194. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  195. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  196. data/lib/rdoc/generator/template/json_index/.document +0 -1
  197. data/lib/rdoc/ghost_method.rb +0 -7
  198. data/lib/rdoc/markup/attr_changer.rb +0 -23
  199. data/lib/rdoc/markup/attr_span.rb +0 -36
  200. data/lib/rdoc/markup/attribute_manager.rb +0 -409
  201. data/lib/rdoc/markup/attributes.rb +0 -71
  202. data/lib/rdoc/markup/regexp_handling.rb +0 -41
  203. data/lib/rdoc/meta_method.rb +0 -7
  204. data/lib/rdoc/parser/ripper_state_lex.rb +0 -590
  205. data/lib/rdoc/parser/ruby_tools.rb +0 -167
data/lib/rdoc/erbio.rb CHANGED
@@ -20,18 +20,14 @@ class RDoc::ERBIO < ERB
20
20
  ##
21
21
  # Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize
22
22
 
23
- def initialize str, safe_level = nil, legacy_trim_mode = nil, legacy_eoutvar = 'io', trim_mode: nil, eoutvar: 'io'
24
- if RUBY_VERSION >= '2.6'
25
- super(str, trim_mode: trim_mode, eoutvar: eoutvar)
26
- else
27
- super(str, safe_level, legacy_trim_mode, legacy_eoutvar)
28
- end
23
+ def initialize(str, trim_mode: nil, eoutvar: 'io')
24
+ super(str, trim_mode: trim_mode, eoutvar: eoutvar)
29
25
  end
30
26
 
31
27
  ##
32
28
  # Instructs +compiler+ how to write to +io_variable+
33
29
 
34
- def set_eoutvar compiler, io_variable
30
+ def set_eoutvar(compiler, io_variable)
35
31
  compiler.put_cmd = "#{io_variable}.write"
36
32
  compiler.insert_cmd = "#{io_variable}.write"
37
33
  compiler.pre_cmd = []
@@ -39,4 +35,3 @@ class RDoc::ERBIO < ERB
39
35
  end
40
36
 
41
37
  end
42
-
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+
5
+ ##
6
+ # Aliki theme for RDoc documentation
7
+ #
8
+ # Author: Stan Lo
9
+ #
10
+
11
+ class RDoc::Generator::Aliki < RDoc::Generator::Darkfish
12
+ DESCRIPTION = 'HTML generator, written by Stan Lo'
13
+
14
+ RDoc::RDoc.add_generator self
15
+
16
+ def initialize(store, options)
17
+ super
18
+ aliki_template_dir = File.expand_path(File.join(__dir__, 'template', 'aliki'))
19
+ @template_dir = Pathname.new(aliki_template_dir)
20
+ end
21
+
22
+ ##
23
+ # Generate documentation. Overrides Darkfish to use Aliki's own search index
24
+ # instead of the JsonIndex generator.
25
+
26
+ def generate
27
+ setup
28
+
29
+ write_style_sheet
30
+ generate_index
31
+ generate_class_files
32
+ generate_file_files
33
+ generate_table_of_contents
34
+ write_search_index
35
+
36
+ copy_static
37
+
38
+ rescue => e
39
+ debug_msg "%s: %s\n %s" % [
40
+ e.class.name, e.message, e.backtrace.join("\n ")
41
+ ]
42
+
43
+ raise
44
+ end
45
+
46
+ ##
47
+ # Copy only the static assets required by the Aliki theme. Unlike Darkfish we
48
+ # don't ship embedded fonts or image sprites, so limit the asset list to keep
49
+ # generated documentation lightweight.
50
+
51
+ def write_style_sheet
52
+ debug_msg "Copying Aliki static files"
53
+ options = { verbose: $DEBUG_RDOC, noop: @dry_run }
54
+
55
+ install_rdoc_static_file @template_dir + 'css/rdoc.css', "./css/rdoc.css", options
56
+
57
+ unless @options.template_stylesheets.empty?
58
+ FileUtils.cp @options.template_stylesheets, '.', **options
59
+ end
60
+
61
+ Dir[(@template_dir + 'js/**/*').to_s].each do |path|
62
+ next if File.directory?(path)
63
+ next if File.basename(path).start_with?('.')
64
+
65
+ dst = Pathname.new(path).relative_path_from(@template_dir)
66
+
67
+ install_rdoc_static_file @template_dir + path, dst, options
68
+ end
69
+ end
70
+
71
+ ##
72
+ # Build a search index array for Aliki's searcher.
73
+
74
+ def build_search_index
75
+ setup
76
+
77
+ index = []
78
+
79
+ @classes.each do |klass|
80
+ next unless klass.display?
81
+
82
+ index << build_class_module_entry(klass)
83
+
84
+ klass.constants.each do |const|
85
+ next unless const.display?
86
+
87
+ index << build_constant_entry(const, klass)
88
+ end
89
+ end
90
+
91
+ @methods.each do |method|
92
+ next unless method.display?
93
+
94
+ index << build_method_entry(method)
95
+ end
96
+
97
+ index
98
+ end
99
+
100
+ ##
101
+ # Write the search index as a JavaScript file
102
+ # Format: var search_data = { index: [...] }
103
+ #
104
+ # We still write to a .js instead of a .json because loading a JSON file triggers CORS check in browsers.
105
+ # And if we simply inspect the generated pages using file://, which is often the case due to lack of the server mode,
106
+ # the JSON file will be blocked by the browser.
107
+
108
+ def write_search_index
109
+ debug_msg "Writing Aliki search index"
110
+
111
+ index = build_search_index
112
+
113
+ FileUtils.mkdir_p 'js' unless @dry_run
114
+
115
+ search_index_path = 'js/search_data.js'
116
+ return if @dry_run
117
+
118
+ data = { index: index }
119
+ File.write search_index_path, "var search_data = #{JSON.generate(data)};"
120
+ end
121
+
122
+ ##
123
+ # Returns the type signature of +method_attr+ as HTML with linked type names.
124
+ # Returns nil if no type signature is present.
125
+
126
+ def type_signature_html(method_attr, from_path)
127
+ lines = method_attr.type_signature_lines || @store.rbs_signature_for(method_attr)
128
+ return unless lines
129
+
130
+ RDoc::RbsHelper.signature_to_html(
131
+ lines,
132
+ lookup: @store.type_name_lookup,
133
+ from_path: from_path
134
+ )
135
+ end
136
+
137
+ ##
138
+ # Resolves a URL for use in templates. Absolute URLs are returned unchanged.
139
+ # Relative URLs are prefixed with rel_prefix to ensure they resolve correctly from any page.
140
+
141
+ def resolve_url(rel_prefix, url)
142
+ uri = URI.parse(url)
143
+ if uri.absolute?
144
+ url
145
+ else
146
+ "#{rel_prefix}/#{url}"
147
+ end
148
+ rescue URI::InvalidURIError
149
+ "#{rel_prefix}/#{url}"
150
+ end
151
+
152
+ private
153
+
154
+ def build_class_module_entry(klass)
155
+ type = case klass
156
+ when RDoc::NormalClass then 'class'
157
+ when RDoc::NormalModule then 'module'
158
+ else 'class'
159
+ end
160
+
161
+ entry = {
162
+ name: klass.name,
163
+ full_name: klass.full_name,
164
+ type: type,
165
+ path: klass.path
166
+ }
167
+
168
+ snippet = klass.search_snippet
169
+ entry[:snippet] = snippet unless snippet.empty?
170
+ entry
171
+ end
172
+
173
+ def build_method_entry(method)
174
+ type = method.singleton ? 'class_method' : 'instance_method'
175
+
176
+ entry = {
177
+ name: method.name,
178
+ full_name: method.full_name,
179
+ type: type,
180
+ path: method.path
181
+ }
182
+
183
+ snippet = method.search_snippet
184
+ entry[:snippet] = snippet unless snippet.empty?
185
+ entry
186
+ end
187
+
188
+ def build_constant_entry(const, parent)
189
+ entry = {
190
+ name: const.name,
191
+ full_name: "#{parent.full_name}::#{const.name}",
192
+ type: 'constant',
193
+ path: parent.path
194
+ }
195
+
196
+ snippet = const.search_snippet
197
+ entry[:snippet] = snippet unless snippet.empty?
198
+ entry
199
+ end
200
+ end
@@ -73,17 +73,6 @@ class RDoc::Generator::Darkfish
73
73
  css/rdoc.css
74
74
  ]
75
75
 
76
- ##
77
- # Path to this file's parent directory. Used to find templates and other
78
- # resources.
79
-
80
- GENERATOR_DIR = File.join 'rdoc', 'generator'
81
-
82
- ##
83
- # Release Version
84
-
85
- VERSION = '3'
86
-
87
76
  ##
88
77
  # Description of this generator
89
78
 
@@ -156,7 +145,7 @@ class RDoc::Generator::Darkfish
156
145
  ##
157
146
  # Initialize a few instance variables before we start
158
147
 
159
- def initialize store, options
148
+ def initialize(store, options)
160
149
  @store = store
161
150
  @options = options
162
151
 
@@ -179,27 +168,11 @@ class RDoc::Generator::Darkfish
179
168
  ##
180
169
  # Output progress information if debugging is enabled
181
170
 
182
- def debug_msg *msg
171
+ def debug_msg(*msg)
183
172
  return unless $DEBUG_RDOC
184
173
  $stderr.puts(*msg)
185
174
  end
186
175
 
187
- ##
188
- # Directory where generated class HTML files live relative to the output
189
- # dir.
190
-
191
- def class_dir
192
- nil
193
- end
194
-
195
- ##
196
- # Directory where generated class HTML files live relative to the output
197
- # dir.
198
-
199
- def file_dir
200
- nil
201
- end
202
-
203
176
  ##
204
177
  # Create the directories the generated docs will live in if they don't
205
178
  # already exist.
@@ -220,8 +193,8 @@ class RDoc::Generator::Darkfish
220
193
  install_rdoc_static_file @template_dir + item, "./#{item}", options
221
194
  end
222
195
 
223
- @options.template_stylesheets.each do |stylesheet|
224
- FileUtils.cp stylesheet, '.', options
196
+ unless @options.template_stylesheets.empty?
197
+ FileUtils.cp @options.template_stylesheets, '.', **options
225
198
  end
226
199
 
227
200
  Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
@@ -291,7 +264,7 @@ class RDoc::Generator::Darkfish
291
264
  # Return a list of the documented modules sorted by salience first, then
292
265
  # by name.
293
266
 
294
- def get_sorted_module_list classes
267
+ def get_sorted_module_list(classes)
295
268
  classes.select do |klass|
296
269
  klass.display?
297
270
  end.sort
@@ -301,8 +274,6 @@ class RDoc::Generator::Darkfish
301
274
  # Generate an index page which lists all the classes which are documented.
302
275
 
303
276
  def generate_index
304
- setup
305
-
306
277
  template_file = @template_dir + 'index.rhtml'
307
278
  return unless template_file.exist?
308
279
 
@@ -316,11 +287,14 @@ class RDoc::Generator::Darkfish
316
287
  asset_rel_prefix = rel_prefix + @asset_rel_path
317
288
 
318
289
  @title = @options.title
290
+ @main_page = @files.find { |f| f.full_name == @options.main_page }
319
291
 
320
292
  render_template template_file, out_file do |io|
321
293
  here = binding
322
294
  # suppress 1.9.3 warning
323
295
  here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
296
+ # some partials rely on the presence of current variable to render
297
+ here.local_variable_set(:current, @main_page) if @main_page
324
298
  here
325
299
  end
326
300
  rescue => e
@@ -334,9 +308,9 @@ class RDoc::Generator::Darkfish
334
308
  ##
335
309
  # Generates a class file for +klass+
336
310
 
337
- def generate_class klass, template_file = nil
338
- setup
339
-
311
+ def generate_class(klass, template_file = nil)
312
+ # This is used to auto-collapse Pages section on class/module pages
313
+ @inside_class_file = true
340
314
  current = klass
341
315
 
342
316
  template_file ||= @template_dir + 'class.rhtml'
@@ -348,7 +322,9 @@ class RDoc::Generator::Darkfish
348
322
  search_index_rel_prefix += @asset_rel_path if @file_output
349
323
 
350
324
  asset_rel_prefix = rel_prefix + @asset_rel_path
351
- svninfo = get_svninfo(current)
325
+
326
+ breadcrumb = # used in templates
327
+ breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix)
352
328
 
353
329
  @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
354
330
 
@@ -357,17 +333,16 @@ class RDoc::Generator::Darkfish
357
333
  here = binding
358
334
  # suppress 1.9.3 warning
359
335
  here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
360
- here.local_variable_set(:svninfo, svninfo)
361
336
  here
362
337
  end
338
+ ensure
339
+ @inside_class_file = false
363
340
  end
364
341
 
365
342
  ##
366
343
  # Generate a documentation file for each class and module
367
344
 
368
345
  def generate_class_files
369
- setup
370
-
371
346
  template_file = @template_dir + 'class.rhtml'
372
347
  template_file = @template_dir + 'classpage.rhtml' unless
373
348
  template_file.exist?
@@ -376,7 +351,9 @@ class RDoc::Generator::Darkfish
376
351
 
377
352
  current = nil
378
353
 
379
- @classes.each do |klass|
354
+ # Document files are generated only for non-alias classes/modules
355
+ @classes.reject(&:is_alias_for).each do |klass|
356
+
380
357
  current = klass
381
358
 
382
359
  generate_class klass, template_file
@@ -393,8 +370,6 @@ class RDoc::Generator::Darkfish
393
370
  # Generate a documentation file for each file
394
371
 
395
372
  def generate_file_files
396
- setup
397
-
398
373
  page_file = @template_dir + 'page.rhtml'
399
374
  fileinfo_file = @template_dir + 'fileinfo.rhtml'
400
375
 
@@ -413,6 +388,8 @@ class RDoc::Generator::Darkfish
413
388
  @files.each do |file|
414
389
  current = file
415
390
 
391
+ next if file.text? && file.full_name == @options.main_page
392
+
416
393
  if file.text? and page_file.exist? then
417
394
  generate_page file
418
395
  next
@@ -461,9 +438,7 @@ class RDoc::Generator::Darkfish
461
438
  ##
462
439
  # Generate a page file for +file+
463
440
 
464
- def generate_page file
465
- setup
466
-
441
+ def generate_page(file)
467
442
  template_file = @template_dir + 'page.rhtml'
468
443
 
469
444
  out_file = @outputdir + file.path
@@ -490,9 +465,7 @@ class RDoc::Generator::Darkfish
490
465
  ##
491
466
  # Generates the 404 page for the RDoc servlet
492
467
 
493
- def generate_servlet_not_found message
494
- setup
495
-
468
+ def generate_servlet_not_found(message)
496
469
  template_file = @template_dir + 'servlet_not_found.rhtml'
497
470
  return unless template_file.exist?
498
471
 
@@ -523,9 +496,7 @@ class RDoc::Generator::Darkfish
523
496
  ##
524
497
  # Generates the servlet root page for the RDoc servlet
525
498
 
526
- def generate_servlet_root installed
527
- setup
528
-
499
+ def generate_servlet_root(installed)
529
500
  template_file = @template_dir + 'servlet_root.rhtml'
530
501
  return unless template_file.exist?
531
502
 
@@ -551,8 +522,6 @@ class RDoc::Generator::Darkfish
551
522
  # Generate an index page which lists all the classes which are documented.
552
523
 
553
524
  def generate_table_of_contents
554
- setup
555
-
556
525
  template_file = @template_dir + 'table_of_contents.rhtml'
557
526
  return unless template_file.exist?
558
527
 
@@ -581,7 +550,7 @@ class RDoc::Generator::Darkfish
581
550
  raise error
582
551
  end
583
552
 
584
- def install_rdoc_static_file source, destination, options # :nodoc:
553
+ def install_rdoc_static_file(source, destination, options) # :nodoc:
585
554
  return unless source.exist?
586
555
 
587
556
  begin
@@ -608,62 +577,19 @@ class RDoc::Generator::Darkfish
608
577
 
609
578
  return unless @store
610
579
 
611
- @classes = @store.all_classes_and_modules.sort
612
- @files = @store.all_files.sort
613
- @methods = @classes.map { |m| m.method_list }.flatten.sort
614
- @modsort = get_sorted_module_list @classes
580
+ refresh_store_data
615
581
  end
616
582
 
617
583
  ##
618
- # Return a string describing the amount of time in the given number of
619
- # seconds in terms a human can understand easily.
620
-
621
- def time_delta_string seconds
622
- return 'less than a minute' if seconds < 60
623
- return "#{seconds / 60} minute#{seconds / 60 == 1 ? '' : 's'}" if
624
- seconds < 3000 # 50 minutes
625
- return 'about one hour' if seconds < 5400 # 90 minutes
626
- return "#{seconds / 3600} hours" if seconds < 64800 # 18 hours
627
- return 'one day' if seconds < 86400 # 1 day
628
- return 'about one day' if seconds < 172800 # 2 days
629
- return "#{seconds / 86400} days" if seconds < 604800 # 1 week
630
- return 'about one week' if seconds < 1209600 # 2 week
631
- return "#{seconds / 604800} weeks" if seconds < 7257600 # 3 months
632
- return "#{seconds / 2419200} months" if seconds < 31536000 # 1 year
633
- return "#{seconds / 31536000} years"
634
- end
584
+ # Refreshes the generator's data from the store. Called by #setup and
585
+ # can be called again after the store has been updated (e.g. in server
586
+ # mode after re-parsing changed files).
635
587
 
636
- # %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $"
637
- SVNID_PATTERN = /
638
- \$Id:\s
639
- (\S+)\s # filename
640
- (\d+)\s # rev
641
- (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
642
- (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ)
643
- (\w+)\s # committer
644
- \$$
645
- /x
646
-
647
- ##
648
- # Try to extract Subversion information out of the first constant whose
649
- # value looks like a subversion Id tag. If no matching constant is found,
650
- # and empty hash is returned.
651
-
652
- def get_svninfo klass
653
- constants = klass.constants or return {}
654
-
655
- constants.find { |c| c.value =~ SVNID_PATTERN } or return {}
656
-
657
- filename, rev, date, time, committer = $~.captures
658
- commitdate = Time.parse "#{date} #{time}"
659
-
660
- return {
661
- :filename => filename,
662
- :rev => Integer(rev),
663
- :commitdate => commitdate,
664
- :commitdelta => time_delta_string(Time.now - commitdate),
665
- :committer => committer,
666
- }
588
+ def refresh_store_data
589
+ @classes = @store.all_classes_and_modules.sort
590
+ @files = @store.all_files.sort
591
+ @methods = @classes.flat_map { |m| m.method_list }.sort
592
+ @modsort = get_sorted_module_list @classes
667
593
  end
668
594
 
669
595
  ##
@@ -672,23 +598,20 @@ class RDoc::Generator::Darkfish
672
598
  # For backwards compatibility, if +body_file+ contains "<html" the body is
673
599
  # used directly.
674
600
 
675
- def assemble_template body_file
601
+ def assemble_template(body_file)
676
602
  body = body_file.read
677
603
  return body if body =~ /<html/
678
604
 
679
605
  head_file = @template_dir + '_head.rhtml'
680
- footer_file = @template_dir + '_footer.rhtml'
681
606
 
682
607
  <<-TEMPLATE
683
608
  <!DOCTYPE html>
684
609
 
685
- <html>
610
+ <html lang="#{@options.locale&.name || 'en'}">
686
611
  <head>
687
612
  #{head_file.read}
688
613
 
689
614
  #{body}
690
-
691
- #{footer_file.read}
692
615
  TEMPLATE
693
616
  end
694
617
 
@@ -696,7 +619,7 @@ class RDoc::Generator::Darkfish
696
619
  # Renders the ERb contained in +file_name+ relative to the template
697
620
  # directory and returns the result based on the current context.
698
621
 
699
- def render file_name
622
+ def render(file_name)
700
623
  template_file = @template_dir + file_name
701
624
 
702
625
  template = template_for template_file, false, RDoc::ERBPartial
@@ -714,7 +637,7 @@ class RDoc::Generator::Darkfish
714
637
  #
715
638
  # An io will be yielded which must be captured by binding in the caller.
716
639
 
717
- def render_template template_file, out_file = nil # :yield: io
640
+ def render_template(template_file, out_file = nil) # :yield: io
718
641
  io_output = out_file && !@dry_run && @file_output
719
642
  erb_klass = io_output ? RDoc::ERBIO : ERB
720
643
 
@@ -748,7 +671,7 @@ class RDoc::Generator::Darkfish
748
671
  # Creates the result for +template+ with +context+. If an error is raised a
749
672
  # Pathname +template_file+ will indicate the file where the error occurred.
750
673
 
751
- def template_result template, context, template_file
674
+ def template_result(template, context, template_file)
752
675
  template.filename = template_file.to_s
753
676
  template.result context
754
677
  rescue NoMethodError => e
@@ -761,7 +684,7 @@ class RDoc::Generator::Darkfish
761
684
  ##
762
685
  # Retrieves a cache template for +file+, if present, or fills the cache.
763
686
 
764
- def template_for file, page = true, klass = ERB
687
+ def template_for(file, page = true, klass = ERB)
765
688
  template = @template_cache[file]
766
689
 
767
690
  return template if template
@@ -778,13 +701,124 @@ class RDoc::Generator::Darkfish
778
701
  erbout = "_erbout_#{file_var}"
779
702
  end
780
703
 
781
- if RUBY_VERSION >= '2.6'
782
- template = klass.new template, trim_mode: '-', eoutvar: erbout
783
- else
784
- template = klass.new template, nil, '-', erbout
785
- end
704
+ template = klass.new template, trim_mode: '-', eoutvar: erbout
786
705
  @template_cache[file] = template
787
706
  template
788
707
  end
789
708
 
709
+ # :stopdoc:
710
+ ParagraphExcerptRegexpOther = %r[\b\w[^./:]++\.]
711
+ # use \p/\P{letter} instead of \w/\W in Unicode
712
+ ParagraphExcerptRegexpUnicode = %r[\b\p{letter}[^./:]++\.]
713
+ # :startdoc:
714
+
715
+ # Returns an excerpt of the comment for usage in meta description tags
716
+ def excerpt(comment)
717
+ text = case comment
718
+ when RDoc::Comment
719
+ comment.text
720
+ else
721
+ comment
722
+ end
723
+
724
+ # Match from a capital letter to the first period, discarding any links, so
725
+ # that we don't end up matching badges in the README
726
+ pattern = ParagraphExcerptRegexpUnicode
727
+ begin
728
+ first_paragraph_match = text.match(pattern)
729
+ rescue Encoding::CompatibilityError
730
+ # The doc is non-ASCII text and encoded in other than Unicode base encodings.
731
+ raise if pattern == ParagraphExcerptRegexpOther
732
+ pattern = ParagraphExcerptRegexpOther
733
+ retry
734
+ end
735
+ return text[0...150].tr_s("\n", " ").squeeze(" ") unless first_paragraph_match
736
+
737
+ extracted_text = first_paragraph_match[0]
738
+ second_paragraph = text.match(pattern, first_paragraph_match.end(0))
739
+ extracted_text << " " << second_paragraph[0] if second_paragraph
740
+
741
+ extracted_text[0...150].tr_s("\n", " ").squeeze(" ")
742
+ end
743
+
744
+ def generate_ancestor_list(ancestors, klass)
745
+ return '' if ancestors.empty?
746
+
747
+ ancestor = ancestors.shift
748
+ content = +'<ul><li>'
749
+
750
+ if ancestor.is_a?(RDoc::NormalClass)
751
+ content << "<a href=\"#{klass.aref_to ancestor.path}\">#{ancestor.full_name}</a>"
752
+ else
753
+ content << ancestor.to_s
754
+ end
755
+
756
+ # Recursively call the method for the remaining ancestors
757
+ content << generate_ancestor_list(ancestors, klass)
758
+
759
+ content << '</li></ul>'
760
+ end
761
+
762
+ def generate_class_link(klass, rel_prefix)
763
+ if klass.display?
764
+ %(<code><a href="#{rel_prefix}/#{klass.path}">#{klass.name}</a></code>)
765
+ else
766
+ %(<code>#{klass.name}</code>)
767
+ end
768
+ end
769
+
770
+ def generate_class_index_content(classes, rel_prefix)
771
+ grouped_classes = group_classes_by_namespace_for_sidebar(classes)
772
+ return '' unless top = grouped_classes[nil]
773
+
774
+ solo = top.one? { |klass| klass.display? }
775
+ traverse_classes(top, grouped_classes, rel_prefix, solo)
776
+ end
777
+
778
+ def traverse_classes(klasses, grouped_classes, rel_prefix, solo = false)
779
+ content = +'<ul class="link-list nav-list">'
780
+
781
+ klasses.each do |index_klass|
782
+ if children = grouped_classes[index_klass.full_name]
783
+ content << %(<li><details#{solo ? ' open' : ''}><summary>#{generate_class_link(index_klass, rel_prefix)}</summary>)
784
+ content << traverse_classes(children, grouped_classes, rel_prefix)
785
+ content << '</details></li>'
786
+ solo = false
787
+ elsif index_klass.display?
788
+ content << %(<li>#{generate_class_link(index_klass, rel_prefix)}</li>)
789
+ end
790
+ end
791
+
792
+ "#{content}</ul>"
793
+ end
794
+
795
+ def group_classes_by_namespace_for_sidebar(classes)
796
+ grouped_classes = classes.group_by do |klass|
797
+ klass.full_name[/\A[^:]++(?:::[^:]++(?=::))*+(?=::[^:]*+\z)/]
798
+ end.select do |_, klasses|
799
+ klasses.any?(&:display?)
800
+ end
801
+
802
+ grouped_classes.values.each(&:uniq!)
803
+ grouped_classes
804
+ end
805
+
806
+ private
807
+
808
+ def nesting_namespaces_to_class_modules(klass)
809
+ tree = {}
810
+
811
+ klass.nesting_namespaces.zip(klass.fully_qualified_nesting_namespaces) do |ns, fqns|
812
+ tree[ns] = @store.classes_hash[fqns] || @store.modules_hash[fqns]
813
+ end
814
+
815
+ tree
816
+ end
817
+
818
+ def generate_nesting_namespaces_breadcrumb(klass, rel_prefix)
819
+ nesting_namespaces_to_class_modules(klass).map do |namespace, class_module|
820
+ path = class_module ? (rel_prefix + class_module.path).to_s : ""
821
+ { name: namespace, path: path, self: klass.full_name == class_module&.full_name }
822
+ end
823
+ end
790
824
  end