rdoc 5.1.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 (179) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.rdoc +5 -6
  3. data/ExampleMarkdown.md +2 -0
  4. data/ExampleRDoc.rdoc +2 -0
  5. data/History.rdoc +68 -66
  6. data/LEGAL.rdoc +1 -1
  7. data/LICENSE.rdoc +2 -0
  8. data/README.rdoc +18 -6
  9. data/RI.md +842 -0
  10. data/TODO.rdoc +8 -7
  11. data/exe/rdoc +0 -1
  12. data/lib/rdoc/{alias.rb → code_object/alias.rb} +4 -12
  13. data/lib/rdoc/{anon_class.rb → code_object/anon_class.rb} +1 -2
  14. data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +83 -26
  15. data/lib/rdoc/{attr.rb → code_object/attr.rb} +5 -9
  16. data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +112 -24
  17. data/lib/rdoc/{constant.rb → code_object/constant.rb} +4 -5
  18. data/lib/rdoc/{context → code_object/context}/section.rb +13 -83
  19. data/lib/rdoc/{context.rb → code_object/context.rb} +69 -70
  20. data/lib/rdoc/{extend.rb → code_object/extend.rb} +1 -2
  21. data/lib/rdoc/{ghost_method.rb → code_object/ghost_method.rb} +1 -2
  22. data/lib/rdoc/{include.rb → code_object/include.rb} +1 -2
  23. data/lib/rdoc/{meta_method.rb → code_object/meta_method.rb} +1 -2
  24. data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +22 -31
  25. data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +1 -2
  26. data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +4 -5
  27. data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +2 -3
  28. data/lib/rdoc/{require.rb → code_object/require.rb} +2 -3
  29. data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +6 -2
  30. data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +22 -32
  31. data/lib/rdoc/code_object.rb +8 -41
  32. data/lib/rdoc/code_objects.rb +2 -3
  33. data/lib/rdoc/comment.rb +48 -41
  34. data/lib/rdoc/cross_reference.rb +77 -33
  35. data/lib/rdoc/encoding.rb +50 -38
  36. data/lib/rdoc/erb_partial.rb +2 -3
  37. data/lib/rdoc/erbio.rb +4 -5
  38. data/lib/rdoc/generator/darkfish.rb +178 -125
  39. data/lib/rdoc/generator/json_index.rb +9 -22
  40. data/lib/rdoc/generator/markup.rb +6 -17
  41. data/lib/rdoc/generator/pot/message_extractor.rb +4 -4
  42. data/lib/rdoc/generator/pot/po.rb +3 -3
  43. data/lib/rdoc/generator/pot/po_entry.rb +12 -12
  44. data/lib/rdoc/generator/pot.rb +4 -8
  45. data/lib/rdoc/generator/ri.rb +1 -2
  46. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
  47. data/lib/rdoc/generator/template/darkfish/_head.rhtml +35 -12
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -5
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +19 -10
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +26 -6
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +4 -9
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -1
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +27 -6
  58. data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  59. data/lib/rdoc/generator/template/darkfish/class.rhtml +125 -78
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +430 -339
  61. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/index.rhtml +13 -13
  64. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -92
  65. data/lib/rdoc/generator/template/darkfish/js/search.js +35 -34
  66. data/lib/rdoc/generator/template/darkfish/page.rhtml +5 -5
  67. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +10 -8
  68. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +20 -18
  69. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +32 -20
  70. data/lib/rdoc/generator/template/json_index/js/navigation.js +12 -49
  71. data/lib/rdoc/generator/template/json_index/js/searcher.js +6 -6
  72. data/lib/rdoc/generator.rb +6 -6
  73. data/lib/rdoc/i18n/locale.rb +1 -1
  74. data/lib/rdoc/i18n/text.rb +5 -5
  75. data/lib/rdoc/i18n.rb +4 -4
  76. data/lib/rdoc/known_classes.rb +6 -5
  77. data/lib/rdoc/markdown/entities.rb +1 -2
  78. data/lib/rdoc/markdown/literals.kpeg +1 -2
  79. data/lib/rdoc/markdown/literals.rb +99 -50
  80. data/lib/rdoc/markdown.kpeg +115 -58
  81. data/lib/rdoc/markdown.rb +1584 -902
  82. data/lib/rdoc/markup/attr_changer.rb +1 -2
  83. data/lib/rdoc/markup/attr_span.rb +9 -4
  84. data/lib/rdoc/markup/attribute_manager.rb +118 -57
  85. data/lib/rdoc/markup/attributes.rb +7 -8
  86. data/lib/rdoc/markup/blank_line.rb +1 -2
  87. data/lib/rdoc/markup/block_quote.rb +1 -2
  88. data/lib/rdoc/markup/document.rb +1 -2
  89. data/lib/rdoc/markup/formatter.rb +44 -37
  90. data/lib/rdoc/markup/hard_break.rb +1 -2
  91. data/lib/rdoc/markup/heading.rb +11 -6
  92. data/lib/rdoc/markup/include.rb +1 -2
  93. data/lib/rdoc/markup/indented_paragraph.rb +1 -2
  94. data/lib/rdoc/markup/list.rb +1 -2
  95. data/lib/rdoc/markup/list_item.rb +1 -2
  96. data/lib/rdoc/markup/paragraph.rb +1 -2
  97. data/lib/rdoc/markup/parser.rb +90 -48
  98. data/lib/rdoc/markup/pre_process.rb +38 -11
  99. data/lib/rdoc/markup/raw.rb +1 -2
  100. data/lib/rdoc/markup/regexp_handling.rb +40 -0
  101. data/lib/rdoc/markup/rule.rb +1 -2
  102. data/lib/rdoc/markup/table.rb +56 -0
  103. data/lib/rdoc/markup/to_ansi.rb +1 -2
  104. data/lib/rdoc/markup/to_bs.rb +30 -5
  105. data/lib/rdoc/markup/to_html.rb +95 -40
  106. data/lib/rdoc/markup/to_html_crossref.rb +108 -43
  107. data/lib/rdoc/markup/to_html_snippet.rb +13 -11
  108. data/lib/rdoc/markup/to_joined_paragraph.rb +6 -32
  109. data/lib/rdoc/markup/to_label.rb +11 -12
  110. data/lib/rdoc/markup/to_markdown.rb +13 -14
  111. data/lib/rdoc/markup/to_rdoc.rb +49 -31
  112. data/lib/rdoc/markup/to_table_of_contents.rb +2 -2
  113. data/lib/rdoc/markup/to_test.rb +1 -2
  114. data/lib/rdoc/markup/to_tt_only.rb +3 -4
  115. data/lib/rdoc/markup/verbatim.rb +1 -2
  116. data/lib/rdoc/markup.rb +64 -694
  117. data/lib/rdoc/options.rb +226 -44
  118. data/lib/rdoc/parser/c.rb +231 -246
  119. data/lib/rdoc/parser/changelog.rb +169 -23
  120. data/lib/rdoc/parser/markdown.rb +1 -3
  121. data/lib/rdoc/parser/prism_ruby.rb +1092 -0
  122. data/lib/rdoc/parser/rd.rb +1 -2
  123. data/lib/rdoc/parser/ripper_state_lex.rb +302 -0
  124. data/lib/rdoc/parser/ruby.rb +695 -478
  125. data/lib/rdoc/parser/ruby_tools.rb +33 -36
  126. data/lib/rdoc/parser/simple.rb +4 -4
  127. data/lib/rdoc/parser/text.rb +1 -2
  128. data/lib/rdoc/parser.rb +37 -42
  129. data/lib/rdoc/rd/block_parser.rb +708 -57
  130. data/lib/rdoc/rd/block_parser.ry +15 -11
  131. data/lib/rdoc/rd/inline.rb +5 -6
  132. data/lib/rdoc/rd/inline_parser.rb +787 -140
  133. data/lib/rdoc/rd/inline_parser.ry +1 -1
  134. data/lib/rdoc/rd.rb +4 -5
  135. data/lib/rdoc/rdoc.rb +72 -87
  136. data/lib/rdoc/ri/driver.rb +236 -152
  137. data/lib/rdoc/ri/formatter.rb +1 -1
  138. data/lib/rdoc/ri/paths.rb +4 -18
  139. data/lib/rdoc/ri/store.rb +1 -2
  140. data/lib/rdoc/ri/task.rb +2 -2
  141. data/lib/rdoc/ri.rb +5 -6
  142. data/lib/rdoc/rubygems_hook.rb +98 -20
  143. data/lib/rdoc/servlet.rb +30 -20
  144. data/lib/rdoc/stats/normal.rb +24 -18
  145. data/lib/rdoc/stats/quiet.rb +1 -2
  146. data/lib/rdoc/stats/verbose.rb +1 -3
  147. data/lib/rdoc/stats.rb +6 -7
  148. data/lib/rdoc/store.rb +84 -55
  149. data/lib/rdoc/task.rb +35 -10
  150. data/lib/rdoc/text.rb +40 -27
  151. data/lib/rdoc/token_stream.rb +56 -34
  152. data/lib/rdoc/tom_doc.rb +18 -19
  153. data/lib/rdoc/version.rb +10 -0
  154. data/lib/rdoc.rb +80 -56
  155. data/lib/rubygems_plugin.rb +23 -0
  156. data/man/ri.1 +247 -0
  157. metadata +45 -99
  158. data/.document +0 -5
  159. data/.gitignore +0 -13
  160. data/.travis.yml +0 -24
  161. data/Gemfile +0 -3
  162. data/RI.rdoc +0 -57
  163. data/Rakefile +0 -133
  164. data/bin/console +0 -7
  165. data/bin/setup +0 -6
  166. data/lib/gauntlet_rdoc.rb +0 -82
  167. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  168. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  169. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  170. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
  171. data/lib/rdoc/generator/template/json_index/.document +0 -1
  172. data/lib/rdoc/markup/formatter_test_case.rb +0 -764
  173. data/lib/rdoc/markup/inline.rb +0 -2
  174. data/lib/rdoc/markup/special.rb +0 -41
  175. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -115
  176. data/lib/rdoc/ruby_lex.rb +0 -1367
  177. data/lib/rdoc/ruby_token.rb +0 -461
  178. data/lib/rdoc/test_case.rb +0 -204
  179. data/rdoc.gemspec +0 -57
data/lib/rdoc/encoding.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: US-ASCII
2
- # frozen_string_literal: false
2
+ # frozen_string_literal: true
3
3
 
4
4
  ##
5
5
  # This class is a wrapper around File IO and Encoding that helps RDoc load
@@ -7,6 +7,18 @@
7
7
 
8
8
  module RDoc::Encoding
9
9
 
10
+ HEADER_REGEXP = /^
11
+ (?:
12
+ \A\#!.*\n
13
+ |
14
+ ^\#\s+frozen[-_]string[-_]literal[=:].+\n
15
+ |
16
+ ^\#[^\n]+\b(?:en)?coding[=:]\s*(?<name>[^\s;]+).*\n
17
+ |
18
+ <\?xml[^?]*encoding=(?<quote>["'])(?<name>.*?)\k<quote>.*\n
19
+ )+
20
+ /xi # :nodoc:
21
+
10
22
  ##
11
23
  # Reads the contents of +filename+ and handles any encoding directives in
12
24
  # the file.
@@ -18,31 +30,32 @@ module RDoc::Encoding
18
30
  # unknown character in the target encoding will be replaced with '?'
19
31
 
20
32
  def self.read_file filename, encoding, force_transcode = false
21
- content = open filename, "rb" do |f| f.read end
33
+ content = File.open filename, "rb" do |f| f.read end
22
34
  content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/
23
35
 
24
36
  utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
25
37
 
26
- RDoc::Encoding.set_encoding content
38
+ enc = RDoc::Encoding.detect_encoding content
39
+ content = RDoc::Encoding.change_encoding content, enc if enc
27
40
 
28
41
  begin
29
42
  encoding ||= Encoding.default_external
30
43
  orig_encoding = content.encoding
31
44
 
32
45
  if not orig_encoding.ascii_compatible? then
33
- content.encode! encoding
46
+ content = content.encode encoding
34
47
  elsif utf8 then
35
- content.force_encoding Encoding::UTF_8
36
- content.encode! encoding
48
+ content = RDoc::Encoding.change_encoding content, Encoding::UTF_8
49
+ content = content.encode encoding
37
50
  else
38
51
  # assume the content is in our output encoding
39
- content.force_encoding encoding
52
+ content = RDoc::Encoding.change_encoding content, encoding
40
53
  end
41
54
 
42
55
  unless content.valid_encoding? then
43
56
  # revert and try to transcode
44
- content.force_encoding orig_encoding
45
- content.encode! encoding
57
+ content = RDoc::Encoding.change_encoding content, orig_encoding
58
+ content = content.encode encoding
46
59
  end
47
60
 
48
61
  unless content.valid_encoding? then
@@ -52,10 +65,11 @@ module RDoc::Encoding
52
65
  rescue Encoding::InvalidByteSequenceError,
53
66
  Encoding::UndefinedConversionError => e
54
67
  if force_transcode then
55
- content.force_encoding orig_encoding
56
- content.encode!(encoding,
57
- :invalid => :replace, :undef => :replace,
58
- :replace => '?')
68
+ content = RDoc::Encoding.change_encoding content, orig_encoding
69
+ content = content.encode(encoding,
70
+ :invalid => :replace,
71
+ :undef => :replace,
72
+ :replace => '?')
59
73
  return content
60
74
  else
61
75
  warn "unable to convert #{e.message} for #{filename}, skipping"
@@ -72,37 +86,35 @@ module RDoc::Encoding
72
86
  nil
73
87
  end
74
88
 
75
- def self.remove_frozen_string_literal string
76
- string =~ /\A(?:#!.*\n)?(.*\n)/
77
- first_line = $1
78
-
79
- if first_line =~ /\A# +frozen[-_]string[-_]literal[=:].+$/i
80
- string.sub! first_line, ''
81
- end
82
- end
83
-
84
89
  ##
85
- # Sets the encoding of +string+ based on the magic comment
86
-
87
- def self.set_encoding string
88
- remove_frozen_string_literal string
89
-
90
- string =~ /\A(?:#!.*\n)?(.*\n)/
90
+ # Detects the encoding of +string+ based on the magic comment
91
91
 
92
- first_line = $1
92
+ def self.detect_encoding string
93
+ result = HEADER_REGEXP.match string
94
+ name = result && result[:name]
93
95
 
94
- name = case first_line
95
- when /^<\?xml[^?]*encoding=(["'])(.*?)\1/ then $2
96
- when /\b(?:en)?coding[=:]\s*([^\s;]+)/i then $1
97
- else return
98
- end
96
+ name ? Encoding.find(name) : nil
97
+ end
99
98
 
100
- string.sub! first_line, ''
99
+ ##
100
+ # Removes magic comments and shebang
101
101
 
102
- remove_frozen_string_literal string
102
+ def self.remove_magic_comment string
103
+ string.sub HEADER_REGEXP do |s|
104
+ s.gsub(/[^\n]/, '')
105
+ end
106
+ end
103
107
 
104
- enc = Encoding.find name
105
- string.force_encoding enc if enc
108
+ ##
109
+ # Changes encoding based on +encoding+ without converting and returns new
110
+ # string
111
+
112
+ def self.change_encoding text, encoding
113
+ if text.kind_of? RDoc::Comment
114
+ text.encode! encoding
115
+ else
116
+ String.new text, encoding: encoding
117
+ end
106
118
  end
107
119
 
108
120
  end
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # Allows an ERB template to be rendered in the context (binding) of an
4
4
  # existing ERB template evaluation.
@@ -12,8 +12,7 @@ class RDoc::ERBPartial < ERB
12
12
  def set_eoutvar compiler, eoutvar = '_erbout'
13
13
  super
14
14
 
15
- compiler.pre_cmd = ["#{eoutvar} ||= ''"]
15
+ compiler.pre_cmd = ["#{eoutvar} ||= +''"]
16
16
  end
17
17
 
18
18
  end
19
-
data/lib/rdoc/erbio.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  require 'erb'
3
3
 
4
4
  ##
@@ -9,7 +9,7 @@ require 'erb'
9
9
  #
10
10
  # erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil
11
11
  #
12
- # open 'hello.txt', 'w' do |io|
12
+ # File.open 'hello.txt', 'w' do |io|
13
13
  # erbio.result binding
14
14
  # end
15
15
  #
@@ -20,8 +20,8 @@ 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, trim_mode = nil, eoutvar = 'io'
24
- super
23
+ def initialize str, trim_mode: nil, eoutvar: 'io'
24
+ super(str, trim_mode: trim_mode, eoutvar: eoutvar)
25
25
  end
26
26
 
27
27
  ##
@@ -35,4 +35,3 @@ class RDoc::ERBIO < ERB
35
35
  end
36
36
 
37
37
  end
38
-
@@ -1,10 +1,10 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  # -*- mode: ruby; ruby-indent-level: 2; tab-width: 2 -*-
3
3
 
4
4
  require 'erb'
5
5
  require 'fileutils'
6
6
  require 'pathname'
7
- require 'rdoc/generator/markup'
7
+ require_relative 'markup'
8
8
 
9
9
  ##
10
10
  # Darkfish RDoc HTML Generator
@@ -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.
@@ -220,8 +198,8 @@ class RDoc::Generator::Darkfish
220
198
  install_rdoc_static_file @template_dir + item, "./#{item}", options
221
199
  end
222
200
 
223
- @options.template_stylesheets.each do |stylesheet|
224
- FileUtils.cp stylesheet, '.', options
201
+ unless @options.template_stylesheets.empty?
202
+ FileUtils.cp @options.template_stylesheets, '.', **options
225
203
  end
226
204
 
227
205
  Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
@@ -269,7 +247,7 @@ class RDoc::Generator::Darkfish
269
247
 
270
248
  @options.static_path.each do |path|
271
249
  unless File.directory? path then
272
- FileUtils.install path, @outputdir, fu_options.merge(:mode => 0644)
250
+ FileUtils.install path, @outputdir, **fu_options.merge(:mode => 0644)
273
251
  next
274
252
  end
275
253
 
@@ -278,9 +256,9 @@ class RDoc::Generator::Darkfish
278
256
  dest_file = @outputdir + entry
279
257
 
280
258
  if File.directory? entry then
281
- FileUtils.mkdir_p entry, fu_options
259
+ FileUtils.mkdir_p entry, **fu_options
282
260
  else
283
- FileUtils.install entry, dest_file, fu_options.merge(:mode => 0644)
261
+ FileUtils.install entry, dest_file, **fu_options.merge(:mode => 0644)
284
262
  end
285
263
  end
286
264
  end
@@ -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
 
@@ -313,12 +289,19 @@ class RDoc::Generator::Darkfish
313
289
  search_index_rel_prefix = rel_prefix
314
290
  search_index_rel_prefix += @asset_rel_path if @file_output
315
291
 
316
- # suppress 1.9.3 warning
317
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
292
+ asset_rel_prefix = rel_prefix + @asset_rel_path
318
293
 
319
294
  @title = @options.title
295
+ @main_page = @files.find { |f| f.full_name == @options.main_page }
320
296
 
321
- render_template template_file, out_file do |io| binding end
297
+ render_template template_file, out_file do |io|
298
+ here = binding
299
+ # suppress 1.9.3 warning
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
303
+ here
304
+ end
322
305
  rescue => e
323
306
  error = RDoc::Error.new \
324
307
  "error generating index.html: #{e.message} (#{e.class})"
@@ -331,8 +314,6 @@ class RDoc::Generator::Darkfish
331
314
  # Generates a class file for +klass+
332
315
 
333
316
  def generate_class klass, template_file = nil
334
- setup
335
-
336
317
  current = klass
337
318
 
338
319
  template_file ||= @template_dir + 'class.rhtml'
@@ -343,22 +324,26 @@ class RDoc::Generator::Darkfish
343
324
  search_index_rel_prefix = rel_prefix
344
325
  search_index_rel_prefix += @asset_rel_path if @file_output
345
326
 
346
- # suppress 1.9.3 warning
347
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
348
- svninfo = svninfo = get_svninfo(current)
327
+ asset_rel_prefix = rel_prefix + @asset_rel_path
328
+
329
+ breadcrumb = # used in templates
330
+ breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix)
349
331
 
350
332
  @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
351
333
 
352
334
  debug_msg " rendering #{out_file}"
353
- render_template template_file, out_file do |io| binding end
335
+ render_template template_file, out_file do |io|
336
+ here = binding
337
+ # suppress 1.9.3 warning
338
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
339
+ here
340
+ end
354
341
  end
355
342
 
356
343
  ##
357
344
  # Generate a documentation file for each class and module
358
345
 
359
346
  def generate_class_files
360
- setup
361
-
362
347
  template_file = @template_dir + 'class.rhtml'
363
348
  template_file = @template_dir + 'classpage.rhtml' unless
364
349
  template_file.exist?
@@ -384,8 +369,6 @@ class RDoc::Generator::Darkfish
384
369
  # Generate a documentation file for each file
385
370
 
386
371
  def generate_file_files
387
- setup
388
-
389
372
  page_file = @template_dir + 'page.rhtml'
390
373
  fileinfo_file = @template_dir + 'fileinfo.rhtml'
391
374
 
@@ -416,8 +399,7 @@ class RDoc::Generator::Darkfish
416
399
  search_index_rel_prefix = rel_prefix
417
400
  search_index_rel_prefix += @asset_rel_path if @file_output
418
401
 
419
- # suppress 1.9.3 warning
420
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
402
+ asset_rel_prefix = rel_prefix + @asset_rel_path
421
403
 
422
404
  unless filepage_file then
423
405
  if file.text? then
@@ -434,7 +416,13 @@ class RDoc::Generator::Darkfish
434
416
  @title += " - #{@options.title}"
435
417
  template_file ||= filepage_file
436
418
 
437
- render_template template_file, out_file do |io| binding end
419
+ render_template template_file, out_file do |io|
420
+ here = binding
421
+ # suppress 1.9.3 warning
422
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
423
+ here.local_variable_set(:current, current)
424
+ here
425
+ end
438
426
  end
439
427
  rescue => e
440
428
  error =
@@ -448,8 +436,6 @@ class RDoc::Generator::Darkfish
448
436
  # Generate a page file for +file+
449
437
 
450
438
  def generate_page file
451
- setup
452
-
453
439
  template_file = @template_dir + 'page.rhtml'
454
440
 
455
441
  out_file = @outputdir + file.path
@@ -458,22 +444,25 @@ class RDoc::Generator::Darkfish
458
444
  search_index_rel_prefix = rel_prefix
459
445
  search_index_rel_prefix += @asset_rel_path if @file_output
460
446
 
461
- # suppress 1.9.3 warning
462
- current = current = file
463
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
447
+ current = file
448
+ asset_rel_prefix = rel_prefix + @asset_rel_path
464
449
 
465
450
  @title = "#{file.page_name} - #{@options.title}"
466
451
 
467
452
  debug_msg " rendering #{out_file}"
468
- render_template template_file, out_file do |io| binding end
453
+ render_template template_file, out_file do |io|
454
+ here = binding
455
+ # suppress 1.9.3 warning
456
+ here.local_variable_set(:current, current)
457
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
458
+ here
459
+ end
469
460
  end
470
461
 
471
462
  ##
472
463
  # Generates the 404 page for the RDoc servlet
473
464
 
474
465
  def generate_servlet_not_found message
475
- setup
476
-
477
466
  template_file = @template_dir + 'servlet_not_found.rhtml'
478
467
  return unless template_file.exist?
479
468
 
@@ -483,12 +472,16 @@ class RDoc::Generator::Darkfish
483
472
  search_index_rel_prefix = rel_prefix
484
473
  search_index_rel_prefix += @asset_rel_path if @file_output
485
474
 
486
- # suppress 1.9.3 warning
487
- asset_rel_prefix = asset_rel_prefix = ''
475
+ asset_rel_prefix = ''
488
476
 
489
477
  @title = 'Not Found'
490
478
 
491
- render_template template_file do |io| binding end
479
+ render_template template_file do |io|
480
+ here = binding
481
+ # suppress 1.9.3 warning
482
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
483
+ here
484
+ end
492
485
  rescue => e
493
486
  error = RDoc::Error.new \
494
487
  "error generating servlet_not_found: #{e.message} (#{e.class})"
@@ -501,8 +494,6 @@ class RDoc::Generator::Darkfish
501
494
  # Generates the servlet root page for the RDoc servlet
502
495
 
503
496
  def generate_servlet_root installed
504
- setup
505
-
506
497
  template_file = @template_dir + 'servlet_root.rhtml'
507
498
  return unless template_file.exist?
508
499
 
@@ -528,8 +519,6 @@ class RDoc::Generator::Darkfish
528
519
  # Generate an index page which lists all the classes which are documented.
529
520
 
530
521
  def generate_table_of_contents
531
- setup
532
-
533
522
  template_file = @template_dir + 'table_of_contents.rhtml'
534
523
  return unless template_file.exist?
535
524
 
@@ -540,12 +529,16 @@ class RDoc::Generator::Darkfish
540
529
  search_index_rel_prefix = rel_prefix
541
530
  search_index_rel_prefix += @asset_rel_path if @file_output
542
531
 
543
- # suppress 1.9.3 warning
544
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
532
+ asset_rel_prefix = rel_prefix + @asset_rel_path
545
533
 
546
534
  @title = "Table of Contents - #{@options.title}"
547
535
 
548
- render_template template_file, out_file do |io| binding end
536
+ render_template template_file, out_file do |io|
537
+ here = binding
538
+ # suppress 1.9.3 warning
539
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
540
+ here
541
+ end
549
542
  rescue => e
550
543
  error = RDoc::Error.new \
551
544
  "error generating table_of_contents.html: #{e.message} (#{e.class})"
@@ -558,16 +551,16 @@ class RDoc::Generator::Darkfish
558
551
  return unless source.exist?
559
552
 
560
553
  begin
561
- FileUtils.mkdir_p File.dirname(destination), options
554
+ FileUtils.mkdir_p File.dirname(destination), **options
562
555
 
563
556
  begin
564
- FileUtils.ln source, destination, options
557
+ FileUtils.ln source, destination, **options
565
558
  rescue Errno::EEXIST
566
559
  FileUtils.rm destination
567
560
  retry
568
561
  end
569
562
  rescue
570
- FileUtils.cp source, destination, options
563
+ FileUtils.cp source, destination, **options
571
564
  end
572
565
  end
573
566
 
@@ -583,62 +576,10 @@ class RDoc::Generator::Darkfish
583
576
 
584
577
  @classes = @store.all_classes_and_modules.sort
585
578
  @files = @store.all_files.sort
586
- @methods = @classes.map { |m| m.method_list }.flatten.sort
579
+ @methods = @classes.flat_map { |m| m.method_list }.sort
587
580
  @modsort = get_sorted_module_list @classes
588
581
  end
589
582
 
590
- ##
591
- # Return a string describing the amount of time in the given number of
592
- # seconds in terms a human can understand easily.
593
-
594
- def time_delta_string seconds
595
- return 'less than a minute' if seconds < 60
596
- return "#{seconds / 60} minute#{seconds / 60 == 1 ? '' : 's'}" if
597
- seconds < 3000 # 50 minutes
598
- return 'about one hour' if seconds < 5400 # 90 minutes
599
- return "#{seconds / 3600} hours" if seconds < 64800 # 18 hours
600
- return 'one day' if seconds < 86400 # 1 day
601
- return 'about one day' if seconds < 172800 # 2 days
602
- return "#{seconds / 86400} days" if seconds < 604800 # 1 week
603
- return 'about one week' if seconds < 1209600 # 2 week
604
- return "#{seconds / 604800} weeks" if seconds < 7257600 # 3 months
605
- return "#{seconds / 2419200} months" if seconds < 31536000 # 1 year
606
- return "#{seconds / 31536000} years"
607
- end
608
-
609
- # %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $"
610
- SVNID_PATTERN = /
611
- \$Id:\s
612
- (\S+)\s # filename
613
- (\d+)\s # rev
614
- (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
615
- (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ)
616
- (\w+)\s # committer
617
- \$$
618
- /x
619
-
620
- ##
621
- # Try to extract Subversion information out of the first constant whose
622
- # value looks like a subversion Id tag. If no matching constant is found,
623
- # and empty hash is returned.
624
-
625
- def get_svninfo klass
626
- constants = klass.constants or return {}
627
-
628
- constants.find { |c| c.value =~ SVNID_PATTERN } or return {}
629
-
630
- filename, rev, date, time, committer = $~.captures
631
- commitdate = Time.parse "#{date} #{time}"
632
-
633
- return {
634
- :filename => filename,
635
- :rev => Integer(rev),
636
- :commitdate => commitdate,
637
- :commitdelta => time_delta_string(Time.now - commitdate),
638
- :committer => committer,
639
- }
640
- end
641
-
642
583
  ##
643
584
  # Creates a template from its components and the +body_file+.
644
585
  #
@@ -650,7 +591,6 @@ class RDoc::Generator::Darkfish
650
591
  return body if body =~ /<html/
651
592
 
652
593
  head_file = @template_dir + '_head.rhtml'
653
- footer_file = @template_dir + '_footer.rhtml'
654
594
 
655
595
  <<-TEMPLATE
656
596
  <!DOCTYPE html>
@@ -660,8 +600,6 @@ class RDoc::Generator::Darkfish
660
600
  #{head_file.read}
661
601
 
662
602
  #{body}
663
-
664
- #{footer_file.read}
665
603
  TEMPLATE
666
604
  end
667
605
 
@@ -751,9 +689,124 @@ class RDoc::Generator::Darkfish
751
689
  erbout = "_erbout_#{file_var}"
752
690
  end
753
691
 
754
- template = klass.new template, nil, '<>', erbout
692
+ template = klass.new template, trim_mode: '-', eoutvar: erbout
755
693
  @template_cache[file] = template
756
694
  template
757
695
  end
758
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
759
812
  end