rdoc 6.7.0 → 6.13.1

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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/ExampleMarkdown.md +2 -0
  3. data/ExampleRDoc.rdoc +2 -0
  4. data/History.rdoc +64 -62
  5. data/LICENSE.rdoc +2 -0
  6. data/README.rdoc +13 -0
  7. data/RI.md +842 -0
  8. data/TODO.rdoc +8 -7
  9. data/lib/rdoc/{alias.rb → code_object/alias.rb} +3 -10
  10. data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +7 -12
  11. data/lib/rdoc/{attr.rb → code_object/attr.rb} +4 -7
  12. data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +107 -20
  13. data/lib/rdoc/{constant.rb → code_object/constant.rb} +1 -1
  14. data/lib/rdoc/{context → code_object/context}/section.rb +10 -68
  15. data/lib/rdoc/{context.rb → code_object/context.rb} +4 -46
  16. data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +19 -27
  17. data/lib/rdoc/{require.rb → code_object/require.rb} +1 -1
  18. data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +10 -28
  19. data/lib/rdoc/code_object.rb +6 -32
  20. data/lib/rdoc/comment.rb +12 -5
  21. data/lib/rdoc/generator/darkfish.rb +121 -95
  22. data/lib/rdoc/generator/json_index.rb +1 -17
  23. data/lib/rdoc/generator/markup.rb +2 -2
  24. data/lib/rdoc/generator/pot/message_extractor.rb +3 -3
  25. data/lib/rdoc/generator/pot/po_entry.rb +1 -1
  26. data/lib/rdoc/generator/pot.rb +0 -5
  27. data/lib/rdoc/generator/template/darkfish/_head.rhtml +23 -0
  28. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -29
  29. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +1 -1
  30. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +1 -1
  31. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +20 -11
  32. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +3 -8
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  34. data/lib/rdoc/generator/template/darkfish/class.rhtml +84 -43
  35. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +391 -397
  36. data/lib/rdoc/generator/template/darkfish/index.rhtml +11 -10
  37. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +24 -1
  38. data/lib/rdoc/generator/template/darkfish/page.rhtml +5 -5
  39. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +10 -8
  40. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +5 -2
  41. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +11 -0
  42. data/lib/rdoc/markdown.kpeg +8 -6
  43. data/lib/rdoc/markdown.rb +55 -32
  44. data/lib/rdoc/markup/attribute_manager.rb +2 -2
  45. data/lib/rdoc/markup/formatter.rb +19 -12
  46. data/lib/rdoc/markup/heading.rb +7 -1
  47. data/lib/rdoc/markup/pre_process.rb +26 -6
  48. data/lib/rdoc/markup/to_bs.rb +1 -1
  49. data/lib/rdoc/markup/to_html.rb +7 -2
  50. data/lib/rdoc/markup/to_html_crossref.rb +63 -12
  51. data/lib/rdoc/markup/to_rdoc.rb +5 -5
  52. data/lib/rdoc/markup.rb +18 -13
  53. data/lib/rdoc/options.rb +90 -12
  54. data/lib/rdoc/parser/c.rb +30 -9
  55. data/lib/rdoc/parser/changelog.rb +5 -4
  56. data/lib/rdoc/parser/prism_ruby.rb +1092 -0
  57. data/lib/rdoc/parser/ripper_state_lex.rb +7 -305
  58. data/lib/rdoc/parser/ruby.rb +23 -17
  59. data/lib/rdoc/parser/simple.rb +1 -1
  60. data/lib/rdoc/parser.rb +5 -4
  61. data/lib/rdoc/rd/block_parser.rb +3 -3
  62. data/lib/rdoc/rd/inline_parser.rb +3 -3
  63. data/lib/rdoc/rdoc.rb +9 -21
  64. data/lib/rdoc/ri/driver.rb +85 -32
  65. data/lib/rdoc/rubygems_hook.rb +91 -15
  66. data/lib/rdoc/servlet.rb +8 -7
  67. data/lib/rdoc/stats.rb +2 -2
  68. data/lib/rdoc/store.rb +21 -13
  69. data/lib/rdoc/task.rb +2 -3
  70. data/lib/rdoc/text.rb +2 -2
  71. data/lib/rdoc/tom_doc.rb +1 -7
  72. data/lib/rdoc/version.rb +1 -1
  73. data/lib/rdoc.rb +22 -24
  74. data/lib/rubygems_plugin.rb +23 -0
  75. metadata +27 -28
  76. data/RI.rdoc +0 -57
  77. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  78. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  79. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  80. data/lib/rdoc/generator/template/json_index/.document +0 -1
  81. /data/lib/rdoc/{anon_class.rb → code_object/anon_class.rb} +0 -0
  82. /data/lib/rdoc/{extend.rb → code_object/extend.rb} +0 -0
  83. /data/lib/rdoc/{ghost_method.rb → code_object/ghost_method.rb} +0 -0
  84. /data/lib/rdoc/{include.rb → code_object/include.rb} +0 -0
  85. /data/lib/rdoc/{meta_method.rb → code_object/meta_method.rb} +0 -0
  86. /data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +0 -0
  87. /data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +0 -0
  88. /data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +0 -0
  89. /data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +0 -0
@@ -63,19 +63,13 @@ class RDoc::MethodAttr < RDoc::CodeObject
63
63
 
64
64
  attr_reader :arglists
65
65
 
66
- ##
67
- # Pretty parameter list for this method
68
-
69
- attr_reader :param_seq
70
-
71
-
72
66
  ##
73
67
  # Creates a new MethodAttr from token stream +text+ and method or attribute
74
68
  # name +name+.
75
69
  #
76
70
  # Usually this is called by super from a subclass.
77
71
 
78
- def initialize text, name
72
+ def initialize(text, name, singleton: false)
79
73
  super()
80
74
 
81
75
  @text = text
@@ -84,14 +78,13 @@ class RDoc::MethodAttr < RDoc::CodeObject
84
78
  @aliases = []
85
79
  @is_alias_for = nil
86
80
  @parent_name = nil
87
- @singleton = nil
81
+ @singleton = singleton
88
82
  @visibility = :public
89
83
  @see = false
90
84
 
91
85
  @arglists = nil
92
86
  @block_params = nil
93
87
  @call_seq = nil
94
- @param_seq = nil
95
88
  @params = nil
96
89
  end
97
90
 
@@ -114,8 +107,8 @@ class RDoc::MethodAttr < RDoc::CodeObject
114
107
  return unless other.respond_to?(:singleton) &&
115
108
  other.respond_to?(:name)
116
109
 
117
- [ @singleton ? 0 : 1, name] <=>
118
- [other.singleton ? 0 : 1, other.name]
110
+ [@singleton ? 0 : 1, name_ord_range, name] <=>
111
+ [other.singleton ? 0 : 1, other.name_ord_range, other.name]
119
112
  end
120
113
 
121
114
  def == other # :nodoc:
@@ -268,8 +261,8 @@ class RDoc::MethodAttr < RDoc::CodeObject
268
261
  when 'const_get' then 'const'
269
262
  when 'new' then
270
263
  $1.split('::').last. # ClassName => class_name
271
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
272
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
264
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
265
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
273
266
  downcase
274
267
  else
275
268
  $2
@@ -291,7 +284,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
291
284
  def html_name
292
285
  require 'cgi/util'
293
286
 
294
- CGI.escape(@name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '')
287
+ CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
295
288
  end
296
289
 
297
290
  ##
@@ -320,19 +313,6 @@ class RDoc::MethodAttr < RDoc::CodeObject
320
313
  @singleton ? '::' : '#'
321
314
  end
322
315
 
323
- ##
324
- # Name for output to HTML. For class methods the full name with a "." is
325
- # used like +SomeClass.method_name+. For instance methods the class name is
326
- # used if +context+ does not match the parent.
327
- #
328
- # This is to help prevent people from using :: to call class methods.
329
-
330
- def output_name context
331
- return "#{name_prefix}#{@name}" if context == parent
332
-
333
- "#{parent_name}#{@singleton ? '.' : '#'}#{@name}"
334
- end
335
-
336
316
  ##
337
317
  # Method/attribute name with class/instance indicator
338
318
 
@@ -415,4 +395,16 @@ class RDoc::MethodAttr < RDoc::CodeObject
415
395
  end
416
396
  end
417
397
 
398
+ def name_ord_range # :nodoc:
399
+ case name.ord
400
+ when 0..64 # anything below "A"
401
+ 1
402
+ when 91..96 # the symbols between "Z" and "a"
403
+ 2
404
+ when 123..126 # 7-bit symbols above "z": "{", "|", "}", "~"
405
+ 3
406
+ else # everythig else can be sorted as normal
407
+ 4
408
+ end
409
+ end
418
410
  end
@@ -24,7 +24,7 @@ class RDoc::Require < RDoc::CodeObject
24
24
  self.class,
25
25
  object_id,
26
26
  @name,
27
- parent_file_name,
27
+ @parent ? @parent.base_name : '(unknown)'
28
28
  ]
29
29
  end
30
30
 
@@ -6,11 +6,6 @@ class RDoc::TopLevel < RDoc::Context
6
6
 
7
7
  MARSHAL_VERSION = 0 # :nodoc:
8
8
 
9
- ##
10
- # This TopLevel's File::Stat struct
11
-
12
- attr_accessor :file_stat
13
-
14
9
  ##
15
10
  # Relative name of this file
16
11
 
@@ -28,8 +23,6 @@ class RDoc::TopLevel < RDoc::Context
28
23
 
29
24
  attr_reader :classes_or_modules
30
25
 
31
- attr_accessor :diagram # :nodoc:
32
-
33
26
  ##
34
27
  # The parser class that processed this file
35
28
 
@@ -45,8 +38,6 @@ class RDoc::TopLevel < RDoc::Context
45
38
  @name = nil
46
39
  @absolute_name = absolute_name
47
40
  @relative_name = relative_name
48
- @file_stat = File.stat(absolute_name) rescue nil # HACK for testing
49
- @diagram = nil
50
41
  @parser = nil
51
42
 
52
43
  @classes_or_modules = []
@@ -173,28 +164,19 @@ class RDoc::TopLevel < RDoc::Context
173
164
  ##
174
165
  # URL for this with a +prefix+
175
166
 
176
- def http_url(prefix)
177
- path = [prefix, @relative_name.tr('.', '_')]
178
-
179
- File.join(*path.compact) + '.html'
167
+ def http_url
168
+ @relative_name.tr('.', '_') + '.html'
180
169
  end
181
170
 
182
171
  def inspect # :nodoc:
183
172
  "#<%s:0x%x %p modules: %p classes: %p>" % [
184
173
  self.class, object_id,
185
174
  base_name,
186
- @modules.map { |n,m| m },
187
- @classes.map { |n,c| c }
175
+ @modules.map { |n, m| m },
176
+ @classes.map { |n, c| c }
188
177
  ]
189
178
  end
190
179
 
191
- ##
192
- # Time this file was last modified, if known
193
-
194
- def last_modified
195
- @file_stat ? file_stat.mtime : nil
196
- end
197
-
198
180
  ##
199
181
  # Dumps this TopLevel for use by ri. See also #marshal_load
200
182
 
@@ -214,9 +196,7 @@ class RDoc::TopLevel < RDoc::Context
214
196
  initialize array[1]
215
197
 
216
198
  @parser = array[2]
217
- @comment = array[3]
218
-
219
- @file_stat = nil
199
+ @comment = RDoc::Comment.from_document array[3]
220
200
  end
221
201
 
222
202
  ##
@@ -246,7 +226,9 @@ class RDoc::TopLevel < RDoc::Context
246
226
  # Path to this file for use with HTML generator output.
247
227
 
248
228
  def path
249
- http_url @store.rdoc.generator.file_dir
229
+ prefix = options.file_path_prefix
230
+ return http_url unless prefix
231
+ File.join(prefix, http_url)
250
232
  end
251
233
 
252
234
  def pretty_print q # :nodoc:
@@ -254,8 +236,8 @@ class RDoc::TopLevel < RDoc::Context
254
236
  q.text "base name: #{base_name.inspect}"
255
237
  q.breakable
256
238
 
257
- items = @modules.map { |n,m| m }
258
- items.concat @modules.map { |n,c| c }
239
+ items = @modules.map { |n, m| m }
240
+ items.concat @modules.map { |n, c| c }
259
241
  q.seplist items do |mod| q.pp mod end
260
242
  end
261
243
  end
@@ -21,9 +21,10 @@
21
21
  # * RDoc::MetaMethod
22
22
  # * RDoc::Alias
23
23
  # * RDoc::Constant
24
+ # * RDoc::Require
24
25
  # * RDoc::Mixin
25
- # * RDoc::Require
26
26
  # * RDoc::Include
27
+ # * RDoc::Extend
27
28
 
28
29
  class RDoc::CodeObject
29
30
 
@@ -90,11 +91,9 @@ class RDoc::CodeObject
90
91
  attr_reader :store
91
92
 
92
93
  ##
93
- # We are the model of the code, but we know that at some point we will be
94
- # worked on by viewers. By implementing the Viewable protocol, viewers can
95
- # associated themselves with these objects.
94
+ # When mixed-in to a class, this points to the Context in which it was originally defined.
96
95
 
97
- attr_accessor :viewer
96
+ attr_accessor :mixin_from
98
97
 
99
98
  ##
100
99
  # Creates a new CodeObject that will document itself and its children
@@ -111,6 +110,7 @@ class RDoc::CodeObject
111
110
  @full_name = nil
112
111
  @store = nil
113
112
  @track_visibility = true
113
+ @mixin_from = nil
114
114
 
115
115
  initialize_visibility
116
116
  end
@@ -135,7 +135,6 @@ class RDoc::CodeObject
135
135
  def comment=(comment)
136
136
  @comment = case comment
137
137
  when NilClass then ''
138
- when RDoc::Markup::Document then comment
139
138
  when RDoc::Comment then comment.normalize
140
139
  else
141
140
  if comment and not comment.empty? then
@@ -211,20 +210,6 @@ class RDoc::CodeObject
211
210
  @document_children = @document_self
212
211
  end
213
212
 
214
- ##
215
- # Yields each parent of this CodeObject. See also
216
- # RDoc::ClassModule#each_ancestor
217
-
218
- def each_parent
219
- code_object = self
220
-
221
- while code_object = code_object.parent do
222
- yield code_object
223
- end
224
-
225
- self
226
- end
227
-
228
213
  ##
229
214
  # File name where this CodeObject was found.
230
215
  #
@@ -295,11 +280,7 @@ class RDoc::CodeObject
295
280
  # This is used by Text#snippet
296
281
 
297
282
  def options
298
- if @store and @store.rdoc then
299
- @store.rdoc.options
300
- else
301
- RDoc::Options.new
302
- end
283
+ @store&.options || RDoc::Options.new
303
284
  end
304
285
 
305
286
  ##
@@ -325,13 +306,6 @@ class RDoc::CodeObject
325
306
  end
326
307
  end
327
308
 
328
- ##
329
- # File name of our parent
330
-
331
- def parent_file_name
332
- @parent ? @parent.base_name : '(unknown)'
333
- end
334
-
335
309
  ##
336
310
  # Name of our parent
337
311
 
data/lib/rdoc/comment.rb CHANGED
@@ -92,7 +92,7 @@ class RDoc::Comment
92
92
  # # ARGF.to_a(limit) -> array
93
93
  # # ARGF.to_a(sep, limit) -> array
94
94
 
95
- def extract_call_seq method
95
+ def extract_call_seq
96
96
  # we must handle situations like the above followed by an unindented first
97
97
  # comment. The difficulty is to make sure not to match lines starting
98
98
  # with ARGF at the same indent, but that are after the first description
@@ -116,17 +116,14 @@ class RDoc::Comment
116
116
  @text.slice! all_start...all_stop
117
117
 
118
118
  seq.gsub!(/^\s*/, '')
119
- method.call_seq = seq
120
119
  end
121
-
122
- method
123
120
  end
124
121
 
125
122
  ##
126
123
  # A comment is empty if its text String is empty.
127
124
 
128
125
  def empty?
129
- @text.empty?
126
+ @text.empty? && (@document.nil? || @document.empty?)
130
127
  end
131
128
 
132
129
  ##
@@ -226,4 +223,14 @@ class RDoc::Comment
226
223
  @format == 'tomdoc'
227
224
  end
228
225
 
226
+ ##
227
+ # Create a new parsed comment from a document
228
+
229
+ def self.from_document(document) # :nodoc:
230
+ comment = RDoc::Comment.new('')
231
+ comment.document = document
232
+ comment.location = RDoc::TopLevel.new(document.file) if document.file
233
+ comment
234
+ end
235
+
229
236
  end
@@ -73,12 +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
76
  ##
83
77
  # Release Version
84
78
 
@@ -184,22 +178,6 @@ class RDoc::Generator::Darkfish
184
178
  $stderr.puts(*msg)
185
179
  end
186
180
 
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
181
  ##
204
182
  # Create the directories the generated docs will live in if they don't
205
183
  # already exist.
@@ -301,8 +279,6 @@ class RDoc::Generator::Darkfish
301
279
  # Generate an index page which lists all the classes which are documented.
302
280
 
303
281
  def generate_index
304
- setup
305
-
306
282
  template_file = @template_dir + 'index.rhtml'
307
283
  return unless template_file.exist?
308
284
 
@@ -316,11 +292,14 @@ class RDoc::Generator::Darkfish
316
292
  asset_rel_prefix = rel_prefix + @asset_rel_path
317
293
 
318
294
  @title = @options.title
295
+ @main_page = @files.find { |f| f.full_name == @options.main_page }
319
296
 
320
297
  render_template template_file, out_file do |io|
321
298
  here = binding
322
299
  # suppress 1.9.3 warning
323
300
  here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
301
+ # some partials rely on the presence of current variable to render
302
+ here.local_variable_set(:current, @main_page) if @main_page
324
303
  here
325
304
  end
326
305
  rescue => e
@@ -335,8 +314,6 @@ class RDoc::Generator::Darkfish
335
314
  # Generates a class file for +klass+
336
315
 
337
316
  def generate_class klass, template_file = nil
338
- setup
339
-
340
317
  current = klass
341
318
 
342
319
  template_file ||= @template_dir + 'class.rhtml'
@@ -348,7 +325,9 @@ class RDoc::Generator::Darkfish
348
325
  search_index_rel_prefix += @asset_rel_path if @file_output
349
326
 
350
327
  asset_rel_prefix = rel_prefix + @asset_rel_path
351
- svninfo = get_svninfo(current)
328
+
329
+ breadcrumb = # used in templates
330
+ breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix)
352
331
 
353
332
  @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
354
333
 
@@ -357,7 +336,6 @@ class RDoc::Generator::Darkfish
357
336
  here = binding
358
337
  # suppress 1.9.3 warning
359
338
  here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
360
- here.local_variable_set(:svninfo, svninfo)
361
339
  here
362
340
  end
363
341
  end
@@ -366,8 +344,6 @@ class RDoc::Generator::Darkfish
366
344
  # Generate a documentation file for each class and module
367
345
 
368
346
  def generate_class_files
369
- setup
370
-
371
347
  template_file = @template_dir + 'class.rhtml'
372
348
  template_file = @template_dir + 'classpage.rhtml' unless
373
349
  template_file.exist?
@@ -393,8 +369,6 @@ class RDoc::Generator::Darkfish
393
369
  # Generate a documentation file for each file
394
370
 
395
371
  def generate_file_files
396
- setup
397
-
398
372
  page_file = @template_dir + 'page.rhtml'
399
373
  fileinfo_file = @template_dir + 'fileinfo.rhtml'
400
374
 
@@ -462,8 +436,6 @@ class RDoc::Generator::Darkfish
462
436
  # Generate a page file for +file+
463
437
 
464
438
  def generate_page file
465
- setup
466
-
467
439
  template_file = @template_dir + 'page.rhtml'
468
440
 
469
441
  out_file = @outputdir + file.path
@@ -491,8 +463,6 @@ class RDoc::Generator::Darkfish
491
463
  # Generates the 404 page for the RDoc servlet
492
464
 
493
465
  def generate_servlet_not_found message
494
- setup
495
-
496
466
  template_file = @template_dir + 'servlet_not_found.rhtml'
497
467
  return unless template_file.exist?
498
468
 
@@ -524,8 +494,6 @@ class RDoc::Generator::Darkfish
524
494
  # Generates the servlet root page for the RDoc servlet
525
495
 
526
496
  def generate_servlet_root installed
527
- setup
528
-
529
497
  template_file = @template_dir + 'servlet_root.rhtml'
530
498
  return unless template_file.exist?
531
499
 
@@ -551,8 +519,6 @@ class RDoc::Generator::Darkfish
551
519
  # Generate an index page which lists all the classes which are documented.
552
520
 
553
521
  def generate_table_of_contents
554
- setup
555
-
556
522
  template_file = @template_dir + 'table_of_contents.rhtml'
557
523
  return unless template_file.exist?
558
524
 
@@ -614,58 +580,6 @@ class RDoc::Generator::Darkfish
614
580
  @modsort = get_sorted_module_list @classes
615
581
  end
616
582
 
617
- ##
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
635
-
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
- }
667
- end
668
-
669
583
  ##
670
584
  # Creates a template from its components and the +body_file+.
671
585
  #
@@ -677,7 +591,6 @@ class RDoc::Generator::Darkfish
677
591
  return body if body =~ /<html/
678
592
 
679
593
  head_file = @template_dir + '_head.rhtml'
680
- footer_file = @template_dir + '_footer.rhtml'
681
594
 
682
595
  <<-TEMPLATE
683
596
  <!DOCTYPE html>
@@ -687,8 +600,6 @@ class RDoc::Generator::Darkfish
687
600
  #{head_file.read}
688
601
 
689
602
  #{body}
690
-
691
- #{footer_file.read}
692
603
  TEMPLATE
693
604
  end
694
605
 
@@ -783,4 +694,119 @@ class RDoc::Generator::Darkfish
783
694
  template
784
695
  end
785
696
 
697
+ # :stopdoc:
698
+ ParagraphExcerptRegexpOther = %r[\b\w[^./:]++\.]
699
+ # use \p/\P{letter} instead of \w/\W in Unicode
700
+ ParagraphExcerptRegexpUnicode = %r[\b\p{letter}[^./:]++\.]
701
+ # :startdoc:
702
+
703
+ # Returns an excerpt of the comment for usage in meta description tags
704
+ def excerpt(comment)
705
+ text = case comment
706
+ when RDoc::Comment
707
+ comment.text
708
+ else
709
+ comment
710
+ end
711
+
712
+ # Match from a capital letter to the first period, discarding any links, so
713
+ # that we don't end up matching badges in the README
714
+ pattern = ParagraphExcerptRegexpUnicode
715
+ begin
716
+ first_paragraph_match = text.match(pattern)
717
+ rescue Encoding::CompatibilityError
718
+ # The doc is non-ASCII text and encoded in other than Unicode base encodings.
719
+ raise if pattern == ParagraphExcerptRegexpOther
720
+ pattern = ParagraphExcerptRegexpOther
721
+ retry
722
+ end
723
+ return text[0...150].tr_s("\n", " ").squeeze(" ") unless first_paragraph_match
724
+
725
+ extracted_text = first_paragraph_match[0]
726
+ second_paragraph = text.match(pattern, first_paragraph_match.end(0))
727
+ extracted_text << " " << second_paragraph[0] if second_paragraph
728
+
729
+ extracted_text[0...150].tr_s("\n", " ").squeeze(" ")
730
+ end
731
+
732
+ def generate_ancestor_list(ancestors, klass)
733
+ return '' if ancestors.empty?
734
+
735
+ ancestor = ancestors.shift
736
+ content = +'<ul><li>'
737
+
738
+ if ancestor.is_a?(RDoc::NormalClass)
739
+ content << "<a href=\"#{klass.aref_to ancestor.path}\">#{ancestor.full_name}</a>"
740
+ else
741
+ content << ancestor.to_s
742
+ end
743
+
744
+ # Recursively call the method for the remaining ancestors
745
+ content << generate_ancestor_list(ancestors, klass)
746
+
747
+ content << '</li></ul>'
748
+ end
749
+
750
+ def generate_class_link(klass, rel_prefix)
751
+ if klass.display?
752
+ %(<code><a href="#{rel_prefix}/#{klass.path}">#{klass.name}</a></code>)
753
+ else
754
+ %(<code>#{klass.name}</code>)
755
+ end
756
+ end
757
+
758
+ def generate_class_index_content(classes, rel_prefix)
759
+ grouped_classes = group_classes_by_namespace_for_sidebar(classes)
760
+ return '' unless top = grouped_classes[nil]
761
+
762
+ solo = top.one? { |klass| klass.display? }
763
+ traverse_classes(top, grouped_classes, rel_prefix, solo)
764
+ end
765
+
766
+ def traverse_classes(klasses, grouped_classes, rel_prefix, solo = false)
767
+ content = +'<ul class="link-list">'
768
+
769
+ klasses.each do |index_klass|
770
+ if children = grouped_classes[index_klass.full_name]
771
+ content << %(<li><details#{solo ? ' open' : ''}><summary>#{generate_class_link(index_klass, rel_prefix)}</summary>)
772
+ content << traverse_classes(children, grouped_classes, rel_prefix)
773
+ content << '</details></li>'
774
+ solo = false
775
+ elsif index_klass.display?
776
+ content << %(<li>#{generate_class_link(index_klass, rel_prefix)}</li>)
777
+ end
778
+ end
779
+
780
+ "#{content}</ul>"
781
+ end
782
+
783
+ def group_classes_by_namespace_for_sidebar(classes)
784
+ grouped_classes = classes.group_by do |klass|
785
+ klass.full_name[/\A[^:]++(?:::[^:]++(?=::))*+(?=::[^:]*+\z)/]
786
+ end.select do |_, klasses|
787
+ klasses.any?(&:display?)
788
+ end
789
+
790
+ grouped_classes.values.each(&:uniq!)
791
+ grouped_classes
792
+ end
793
+
794
+ private
795
+
796
+ def nesting_namespaces_to_class_modules klass
797
+ tree = {}
798
+
799
+ klass.nesting_namespaces.zip(klass.fully_qualified_nesting_namespaces) do |ns, fqns|
800
+ tree[ns] = @store.classes_hash[fqns] || @store.modules_hash[fqns]
801
+ end
802
+
803
+ tree
804
+ end
805
+
806
+ def generate_nesting_namespaces_breadcrumb klass, rel_prefix
807
+ nesting_namespaces_to_class_modules(klass).map do |namespace, class_module|
808
+ path = class_module ? (rel_prefix + class_module.path).to_s : ""
809
+ { name: namespace, path: path, self: klass.full_name == class_module&.full_name }
810
+ end
811
+ end
786
812
  end
@@ -86,9 +86,7 @@ class RDoc::Generator::JsonIndex
86
86
  attr_reader :index # :nodoc:
87
87
 
88
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
- #
89
+ # Creates a new generator.
92
90
  # +options+ are the same options passed to the parent generator.
93
91
 
94
92
  def initialize parent_generator, options
@@ -265,20 +263,6 @@ class RDoc::Generator::JsonIndex
265
263
  end
266
264
  end
267
265
 
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
266
  def reset files, classes # :nodoc:
283
267
  @files = files
284
268
  @classes = classes