rdoc 6.17.0 → 8.1.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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +193 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/LICENSE.rdoc +4 -0
  5. data/README.md +132 -8
  6. data/RI.md +75 -75
  7. data/doc/markup_reference/markdown.md +659 -0
  8. data/doc/markup_reference/rdoc.rdoc +1169 -0
  9. data/exe/rdoc +2 -2
  10. data/lib/rdoc/code_object/alias.rb +70 -74
  11. data/lib/rdoc/code_object/any_method.rb +308 -293
  12. data/lib/rdoc/code_object/attr.rb +150 -142
  13. data/lib/rdoc/code_object/class_module.rb +802 -715
  14. data/lib/rdoc/code_object/constant.rb +181 -144
  15. data/lib/rdoc/code_object/context/section.rb +140 -130
  16. data/lib/rdoc/code_object/context.rb +925 -941
  17. data/lib/rdoc/code_object/extend.rb +7 -5
  18. data/lib/rdoc/code_object/include.rb +7 -5
  19. data/lib/rdoc/code_object/method_attr.rb +328 -315
  20. data/lib/rdoc/code_object/mixin.rb +97 -92
  21. data/lib/rdoc/code_object/normal_class.rb +77 -78
  22. data/lib/rdoc/code_object/normal_module.rb +61 -59
  23. data/lib/rdoc/code_object/require.rb +23 -39
  24. data/lib/rdoc/code_object/single_class.rb +21 -19
  25. data/lib/rdoc/code_object/top_level.rb +215 -202
  26. data/lib/rdoc/code_object.rb +305 -305
  27. data/lib/rdoc/comment.rb +274 -337
  28. data/lib/rdoc/cross_reference.rb +195 -206
  29. data/lib/rdoc/encoding.rb +105 -103
  30. data/lib/rdoc/erb_partial.rb +13 -11
  31. data/lib/rdoc/erbio.rb +29 -27
  32. data/lib/rdoc/generator/aliki.rb +196 -30
  33. data/lib/rdoc/generator/darkfish.rb +647 -629
  34. data/lib/rdoc/generator/json_index.rb +233 -229
  35. data/lib/rdoc/generator/markup.rb +165 -122
  36. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  37. data/lib/rdoc/generator/pot/po.rb +52 -51
  38. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  39. data/lib/rdoc/generator/pot.rb +85 -81
  40. data/lib/rdoc/generator/ri.rb +23 -19
  41. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  42. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  43. data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
  44. data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
  45. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  46. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  47. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  48. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  49. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
  50. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  51. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  52. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  53. data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
  54. data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
  55. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
  57. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  58. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  59. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  60. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  61. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  62. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  63. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  64. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  65. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  66. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  67. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  68. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  69. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
  70. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  71. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  72. data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
  73. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
  74. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  75. data/lib/rdoc/generator.rb +48 -46
  76. data/lib/rdoc/i18n/locale.rb +99 -95
  77. data/lib/rdoc/i18n/text.rb +109 -105
  78. data/lib/rdoc/i18n.rb +7 -5
  79. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  80. data/lib/rdoc/markdown.kpeg +52 -33
  81. data/lib/rdoc/markdown.rb +365 -177
  82. data/lib/rdoc/markup/blank_line.rb +25 -23
  83. data/lib/rdoc/markup/block_quote.rb +12 -8
  84. data/lib/rdoc/markup/document.rb +127 -123
  85. data/lib/rdoc/markup/element.rb +21 -0
  86. data/lib/rdoc/markup/formatter.rb +220 -203
  87. data/lib/rdoc/markup/hard_break.rb +30 -27
  88. data/lib/rdoc/markup/heading.rb +163 -77
  89. data/lib/rdoc/markup/include.rb +33 -29
  90. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  91. data/lib/rdoc/markup/inline_parser.rb +316 -0
  92. data/lib/rdoc/markup/list.rb +80 -88
  93. data/lib/rdoc/markup/list_item.rb +73 -85
  94. data/lib/rdoc/markup/paragraph.rb +23 -19
  95. data/lib/rdoc/markup/parser.rb +501 -497
  96. data/lib/rdoc/markup/pre_process.rb +284 -305
  97. data/lib/rdoc/markup/raw.rb +52 -55
  98. data/lib/rdoc/markup/rule.rb +16 -12
  99. data/lib/rdoc/markup/table.rb +48 -40
  100. data/lib/rdoc/markup/to_ansi.rb +143 -92
  101. data/lib/rdoc/markup/to_bs.rb +86 -102
  102. data/lib/rdoc/markup/to_html.rb +608 -506
  103. data/lib/rdoc/markup/to_html_crossref.rb +219 -210
  104. data/lib/rdoc/markup/to_html_snippet.rb +210 -205
  105. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  106. data/lib/rdoc/markup/to_label.rb +64 -51
  107. data/lib/rdoc/markup/to_markdown.rb +212 -184
  108. data/lib/rdoc/markup/to_rdoc.rb +341 -277
  109. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  110. data/lib/rdoc/markup/to_test.rb +62 -50
  111. data/lib/rdoc/markup/to_tt_only.rb +83 -92
  112. data/lib/rdoc/markup/verbatim.rb +62 -58
  113. data/lib/rdoc/markup.rb +196 -215
  114. data/lib/rdoc/options.rb +1063 -1076
  115. data/lib/rdoc/parser/c.rb +1039 -1036
  116. data/lib/rdoc/parser/changelog.rb +320 -287
  117. data/lib/rdoc/parser/markdown.rb +17 -13
  118. data/lib/rdoc/parser/rbs.rb +279 -0
  119. data/lib/rdoc/parser/rd.rb +17 -13
  120. data/lib/rdoc/parser/ruby.rb +1231 -2222
  121. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  122. data/lib/rdoc/parser/simple.rb +31 -27
  123. data/lib/rdoc/parser/text.rb +12 -8
  124. data/lib/rdoc/parser.rb +230 -221
  125. data/lib/rdoc/rbs_helper.rb +186 -0
  126. data/lib/rdoc/rd/inline.rb +57 -53
  127. data/lib/rdoc/rd.rb +90 -88
  128. data/lib/rdoc/rdoc.rb +547 -366
  129. data/lib/rdoc/ri/driver.rb +1141 -1130
  130. data/lib/rdoc/ri/formatter.rb +7 -3
  131. data/lib/rdoc/ri/paths.rb +140 -136
  132. data/lib/rdoc/ri/servlet.rb +456 -0
  133. data/lib/rdoc/ri/store.rb +4 -2
  134. data/lib/rdoc/ri/task.rb +55 -51
  135. data/lib/rdoc/ri.rb +14 -11
  136. data/lib/rdoc/rubygems_hook.rb +194 -192
  137. data/lib/rdoc/server.rb +462 -0
  138. data/lib/rdoc/stats/normal.rb +46 -42
  139. data/lib/rdoc/stats/quiet.rb +39 -35
  140. data/lib/rdoc/stats/verbose.rb +35 -31
  141. data/lib/rdoc/stats.rb +363 -338
  142. data/lib/rdoc/store.rb +919 -725
  143. data/lib/rdoc/task.rb +260 -255
  144. data/lib/rdoc/text.rb +164 -240
  145. data/lib/rdoc/token_stream.rb +88 -106
  146. data/lib/rdoc/tom_doc.rb +203 -201
  147. data/lib/rdoc/version.rb +1 -1
  148. data/lib/rdoc.rb +35 -7
  149. data/lib/rubygems_plugin.rb +2 -11
  150. data/rdoc-logo.svg +43 -0
  151. data/rdoc.gemspec +9 -7
  152. metadata +46 -32
  153. data/CONTRIBUTING.rdoc +0 -219
  154. data/ExampleMarkdown.md +0 -39
  155. data/ExampleRDoc.rdoc +0 -210
  156. data/lib/rdoc/code_object/anon_class.rb +0 -10
  157. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  158. data/lib/rdoc/code_object/meta_method.rb +0 -6
  159. data/lib/rdoc/markdown/literals.kpeg +0 -21
  160. data/lib/rdoc/markdown/literals.rb +0 -454
  161. data/lib/rdoc/markup/attr_changer.rb +0 -22
  162. data/lib/rdoc/markup/attr_span.rb +0 -35
  163. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  164. data/lib/rdoc/markup/attributes.rb +0 -70
  165. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  166. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  167. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  168. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  169. data/lib/rdoc/servlet.rb +0 -452
@@ -6,811 +6,829 @@ require 'fileutils'
6
6
  require 'pathname'
7
7
  require_relative 'markup'
8
8
 
9
- ##
10
- # Darkfish RDoc HTML Generator
11
- #
12
- # $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
13
- #
14
- # == Author/s
15
- # * Michael Granger (ged@FaerieMUD.org)
16
- #
17
- # == Contributors
18
- # * Mahlon E. Smith (mahlon@martini.nu)
19
- # * Eric Hodel (drbrain@segment7.net)
20
- #
21
- # == License
22
- #
23
- # Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
24
- #
25
- # Redistribution and use in source and binary forms, with or without
26
- # modification, are permitted provided that the following conditions are met:
27
- #
28
- # * Redistributions of source code must retain the above copyright notice,
29
- # this list of conditions and the following disclaimer.
30
- #
31
- # * Redistributions in binary form must reproduce the above copyright notice,
32
- # this list of conditions and the following disclaimer in the documentation
33
- # and/or other materials provided with the distribution.
34
- #
35
- # * Neither the name of the author/s, nor the names of the project's
36
- # contributors may be used to endorse or promote products derived from this
37
- # software without specific prior written permission.
38
- #
39
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
43
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
- #
50
- # == Attributions
51
- #
52
- # Darkfish uses the {Silk Icons}[http://www.famfamfam.com/lab/icons/silk/] set
53
- # by Mark James.
54
-
55
- class RDoc::Generator::Darkfish
56
-
57
- RDoc::RDoc.add_generator self
58
-
59
- include ERB::Util
60
-
61
- ##
62
- # Stylesheets, fonts, etc. that are included in RDoc.
63
-
64
- BUILTIN_STYLE_ITEMS = # :nodoc:
65
- %w[
66
- css/fonts.css
67
- fonts/Lato-Light.ttf
68
- fonts/Lato-LightItalic.ttf
69
- fonts/Lato-Regular.ttf
70
- fonts/Lato-RegularItalic.ttf
71
- fonts/SourceCodePro-Bold.ttf
72
- fonts/SourceCodePro-Regular.ttf
73
- css/rdoc.css
74
- ]
75
-
76
- ##
77
- # Release Version
78
-
79
- VERSION = '3'
80
-
81
- ##
82
- # Description of this generator
83
-
84
- DESCRIPTION = 'HTML generator, written by Michael Granger'
85
-
86
- ##
87
- # The relative path to style sheets and javascript. By default this is set
88
- # the same as the rel_prefix.
89
-
90
- attr_accessor :asset_rel_path
91
-
92
- ##
93
- # The path to generate files into, combined with <tt>--op</tt> from the
94
- # options for a full path.
95
-
96
- attr_reader :base_dir
97
-
98
- ##
99
- # Classes and modules to be used by this generator, not necessarily
100
- # displayed. See also #modsort
101
-
102
- attr_reader :classes
103
-
104
- ##
105
- # No files will be written when dry_run is true.
106
-
107
- attr_accessor :dry_run
108
-
109
- ##
110
- # When false the generate methods return a String instead of writing to a
111
- # file. The default is true.
112
-
113
- attr_accessor :file_output
114
-
115
- ##
116
- # Files to be displayed by this generator
9
+ module RDoc
10
+ module Generator
11
+ ##
12
+ # Darkfish RDoc HTML Generator
13
+ #
14
+ # $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
15
+ #
16
+ # == Author/s
17
+ # * Michael Granger (ged@FaerieMUD.org)
18
+ #
19
+ # == Contributors
20
+ # * Mahlon E. Smith (mahlon@martini.nu)
21
+ # * Eric Hodel (drbrain@segment7.net)
22
+ #
23
+ # == License
24
+ #
25
+ # Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
26
+ #
27
+ # Redistribution and use in source and binary forms, with or without
28
+ # modification, are permitted provided that the following conditions are met:
29
+ #
30
+ # * Redistributions of source code must retain the above copyright notice,
31
+ # this list of conditions and the following disclaimer.
32
+ #
33
+ # * Redistributions in binary form must reproduce the above copyright notice,
34
+ # this list of conditions and the following disclaimer in the documentation
35
+ # and/or other materials provided with the distribution.
36
+ #
37
+ # * Neither the name of the author/s, nor the names of the project's
38
+ # contributors may be used to endorse or promote products derived from this
39
+ # software without specific prior written permission.
40
+ #
41
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
45
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51
+ #
52
+ # == Attributions
53
+ #
54
+ # Darkfish uses the {Silk Icons}[http://www.famfamfam.com/lab/icons/silk/] set
55
+ # by Mark James.
56
+
57
+ class Darkfish
58
+
59
+ RDoc.add_generator self
60
+
61
+ include ERB::Util
62
+
63
+ ##
64
+ # Stylesheets, fonts, etc. that are included in RDoc.
65
+
66
+ BUILTIN_STYLE_ITEMS = # :nodoc:
67
+ %w[
68
+ css/fonts.css
69
+ fonts/Lato-Light.ttf
70
+ fonts/Lato-LightItalic.ttf
71
+ fonts/Lato-Regular.ttf
72
+ fonts/Lato-RegularItalic.ttf
73
+ fonts/SourceCodePro-Bold.ttf
74
+ fonts/SourceCodePro-Regular.ttf
75
+ css/rdoc.css
76
+ ]
77
+
78
+ ##
79
+ # Description of this generator
80
+
81
+ DESCRIPTION = 'HTML generator, written by Michael Granger'
82
+
83
+ ##
84
+ # The relative path to style sheets and javascript. By default this is set
85
+ # the same as the rel_prefix.
86
+
87
+ attr_accessor :asset_rel_path
88
+
89
+ ##
90
+ # The path to generate files into, combined with <tt>--op</tt> from the
91
+ # options for a full path.
92
+
93
+ attr_reader :base_dir
94
+
95
+ ##
96
+ # Classes and modules to be used by this generator, not necessarily
97
+ # displayed. See also #modsort
98
+
99
+ attr_reader :classes
100
+
101
+ ##
102
+ # No files will be written when dry_run is true.
103
+
104
+ attr_accessor :dry_run
105
+
106
+ ##
107
+ # When false the generate methods return a String instead of writing to a
108
+ # file. The default is true.
109
+
110
+ attr_accessor :file_output
111
+
112
+ ##
113
+ # Files to be displayed by this generator
114
+
115
+ attr_reader :files
116
+
117
+ ##
118
+ # The JSON index generator for this Darkfish generator
119
+
120
+ attr_reader :json_index
117
121
 
118
- attr_reader :files
122
+ ##
123
+ # Methods to be displayed by this generator
119
124
 
120
- ##
121
- # The JSON index generator for this Darkfish generator
125
+ attr_reader :methods
122
126
 
123
- attr_reader :json_index
127
+ ##
128
+ # Sorted list of classes and modules to be displayed by this generator
124
129
 
125
- ##
126
- # Methods to be displayed by this generator
130
+ attr_reader :modsort
127
131
 
128
- attr_reader :methods
132
+ ##
133
+ # The RDoc::Store that is the source of the generated content
129
134
 
130
- ##
131
- # Sorted list of classes and modules to be displayed by this generator
135
+ attr_reader :store
132
136
 
133
- attr_reader :modsort
137
+ ##
138
+ # The directory where the template files live
134
139
 
135
- ##
136
- # The RDoc::Store that is the source of the generated content
140
+ attr_reader :template_dir # :nodoc:
137
141
 
138
- attr_reader :store
142
+ ##
143
+ # The output directory
139
144
 
140
- ##
141
- # The directory where the template files live
145
+ attr_reader :outputdir
142
146
 
143
- attr_reader :template_dir # :nodoc:
147
+ ##
148
+ # Initialize a few instance variables before we start
144
149
 
145
- ##
146
- # The output directory
150
+ def initialize(store, options)
151
+ @store = store
152
+ @options = options
147
153
 
148
- attr_reader :outputdir
154
+ @asset_rel_path = ''
155
+ @base_dir = Pathname.pwd.expand_path
156
+ @dry_run = @options.dry_run
157
+ @file_output = true
158
+ @template_dir = Pathname.new options.template_dir
159
+ @template_cache = {}
149
160
 
150
- ##
151
- # Initialize a few instance variables before we start
161
+ @classes = nil
162
+ @context = nil
163
+ @files = nil
164
+ @methods = nil
165
+ @modsort = nil
152
166
 
153
- def initialize(store, options)
154
- @store = store
155
- @options = options
167
+ @json_index = Generator::JsonIndex.new self, options
168
+ end
156
169
 
157
- @asset_rel_path = ''
158
- @base_dir = Pathname.pwd.expand_path
159
- @dry_run = @options.dry_run
160
- @file_output = true
161
- @template_dir = Pathname.new options.template_dir
162
- @template_cache = {}
170
+ ##
171
+ # Output progress information if debugging is enabled
163
172
 
164
- @classes = nil
165
- @context = nil
166
- @files = nil
167
- @methods = nil
168
- @modsort = nil
173
+ def debug_msg(*msg)
174
+ return unless $DEBUG_RDOC
175
+ $stderr.puts(*msg)
176
+ end
169
177
 
170
- @json_index = RDoc::Generator::JsonIndex.new self, options
171
- end
178
+ ##
179
+ # Create the directories the generated docs will live in if they don't
180
+ # already exist.
172
181
 
173
- ##
174
- # Output progress information if debugging is enabled
182
+ def gen_sub_directories
183
+ @outputdir.mkpath
184
+ end
175
185
 
176
- def debug_msg *msg
177
- return unless $DEBUG_RDOC
178
- $stderr.puts(*msg)
179
- end
186
+ ##
187
+ # Copy over the stylesheet into the appropriate place in the output
188
+ # directory.
180
189
 
181
- ##
182
- # Create the directories the generated docs will live in if they don't
183
- # already exist.
190
+ def write_style_sheet
191
+ debug_msg "Copying static files"
192
+ options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
184
193
 
185
- def gen_sub_directories
186
- @outputdir.mkpath
187
- end
194
+ BUILTIN_STYLE_ITEMS.each do |item|
195
+ install_rdoc_static_file @template_dir + item, "./#{item}", options
196
+ end
188
197
 
189
- ##
190
- # Copy over the stylesheet into the appropriate place in the output
191
- # directory.
198
+ unless @options.template_stylesheets.empty?
199
+ FileUtils.cp @options.template_stylesheets, '.', **options
200
+ end
192
201
 
193
- def write_style_sheet
194
- debug_msg "Copying static files"
195
- options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
202
+ Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
203
+ next if File.directory? path
204
+ next if File.basename(path) =~ /^\./
196
205
 
197
- BUILTIN_STYLE_ITEMS.each do |item|
198
- install_rdoc_static_file @template_dir + item, "./#{item}", options
199
- end
206
+ dst = Pathname.new(path).relative_path_from @template_dir
200
207
 
201
- unless @options.template_stylesheets.empty?
202
- FileUtils.cp @options.template_stylesheets, '.', **options
203
- end
208
+ install_rdoc_static_file @template_dir + path, dst, options
209
+ end
210
+ end
204
211
 
205
- Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
206
- next if File.directory? path
207
- next if File.basename(path) =~ /^\./
212
+ ##
213
+ # Build the initial indices and output objects based on an array of TopLevel
214
+ # objects containing the extracted information.
208
215
 
209
- dst = Pathname.new(path).relative_path_from @template_dir
216
+ def generate
217
+ warn "The Darkfish template is deprecated and will be removed in version 9.0."
210
218
 
211
- install_rdoc_static_file @template_dir + path, dst, options
212
- end
213
- end
219
+ setup
214
220
 
215
- ##
216
- # Build the initial indices and output objects based on an array of TopLevel
217
- # objects containing the extracted information.
221
+ write_style_sheet
222
+ generate_index
223
+ generate_class_files
224
+ generate_file_files
225
+ generate_table_of_contents
226
+ @json_index.generate
227
+ @json_index.generate_gzipped
218
228
 
219
- def generate
220
- setup
229
+ copy_static
221
230
 
222
- write_style_sheet
223
- generate_index
224
- generate_class_files
225
- generate_file_files
226
- generate_table_of_contents
227
- @json_index.generate
228
- @json_index.generate_gzipped
231
+ rescue => e
232
+ debug_msg "%s: %s\n %s" % [
233
+ e.class.name, e.message, e.backtrace.join("\n ")
234
+ ]
229
235
 
230
- copy_static
236
+ raise
237
+ end
231
238
 
232
- rescue => e
233
- debug_msg "%s: %s\n %s" % [
234
- e.class.name, e.message, e.backtrace.join("\n ")
235
- ]
239
+ ##
240
+ # Copies static files from the static_path into the output directory
236
241
 
237
- raise
238
- end
242
+ def copy_static
243
+ return if @options.static_path.empty?
239
244
 
240
- ##
241
- # Copies static files from the static_path into the output directory
245
+ fu_options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
242
246
 
243
- def copy_static
244
- return if @options.static_path.empty?
247
+ @options.static_path.each do |path|
248
+ unless File.directory? path
249
+ FileUtils.install path, @outputdir, **fu_options.merge(:mode => 0644)
250
+ next
251
+ end
245
252
 
246
- fu_options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
253
+ Dir.chdir path do
254
+ Dir[File.join('**', '*')].each do |entry|
255
+ dest_file = @outputdir + entry
247
256
 
248
- @options.static_path.each do |path|
249
- unless File.directory? path then
250
- FileUtils.install path, @outputdir, **fu_options.merge(:mode => 0644)
251
- next
257
+ if File.directory? entry
258
+ FileUtils.mkdir_p entry, **fu_options
259
+ else
260
+ FileUtils.install entry, dest_file, **fu_options.merge(:mode => 0644)
261
+ end
262
+ end
263
+ end
264
+ end
252
265
  end
253
266
 
254
- Dir.chdir path do
255
- Dir[File.join('**', '*')].each do |entry|
256
- dest_file = @outputdir + entry
267
+ ##
268
+ # Return a list of the documented modules sorted by salience first, then
269
+ # by name.
257
270
 
258
- if File.directory? entry then
259
- FileUtils.mkdir_p entry, **fu_options
260
- else
261
- FileUtils.install entry, dest_file, **fu_options.merge(:mode => 0644)
262
- end
263
- end
271
+ def get_sorted_module_list(classes)
272
+ classes.select do |klass|
273
+ klass.display?
274
+ end.sort
264
275
  end
265
- end
266
- end
267
276
 
268
- ##
269
- # Return a list of the documented modules sorted by salience first, then
270
- # by name.
277
+ ##
278
+ # Generate an index page which lists all the classes which are documented.
271
279
 
272
- def get_sorted_module_list(classes)
273
- classes.select do |klass|
274
- klass.display?
275
- end.sort
276
- end
280
+ def generate_index
281
+ template_file = @template_dir + 'index.rhtml'
282
+ return unless template_file.exist?
277
283
 
278
- ##
279
- # Generate an index page which lists all the classes which are documented.
284
+ debug_msg "Rendering the index page..."
280
285
 
281
- def generate_index
282
- template_file = @template_dir + 'index.rhtml'
283
- return unless template_file.exist?
286
+ out_file = @base_dir + @options.op_dir + 'index.html'
287
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
288
+ search_index_rel_prefix = rel_prefix
289
+ search_index_rel_prefix += @asset_rel_path if @file_output
284
290
 
285
- debug_msg "Rendering the index page..."
291
+ asset_rel_prefix = rel_prefix + @asset_rel_path
286
292
 
287
- out_file = @base_dir + @options.op_dir + 'index.html'
288
- rel_prefix = @outputdir.relative_path_from out_file.dirname
289
- search_index_rel_prefix = rel_prefix
290
- search_index_rel_prefix += @asset_rel_path if @file_output
293
+ @title = @options.title
294
+ @main_page = @files.find { |f| f.full_name == @options.main_page }
291
295
 
292
- asset_rel_prefix = rel_prefix + @asset_rel_path
296
+ render_template template_file, out_file do |io|
297
+ here = binding
298
+ # suppress 1.9.3 warning
299
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
300
+ # some partials rely on the presence of current variable to render
301
+ here.local_variable_set(:current, @main_page) if @main_page
302
+ here
303
+ end
304
+ rescue => e
305
+ error = Error.new \
306
+ "error generating index.html: #{e.message} (#{e.class})"
307
+ error.set_backtrace e.backtrace
293
308
 
294
- @title = @options.title
295
- @main_page = @files.find { |f| f.full_name == @options.main_page }
309
+ raise error
310
+ end
296
311
 
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
305
- rescue => e
306
- error = RDoc::Error.new \
307
- "error generating index.html: #{e.message} (#{e.class})"
308
- error.set_backtrace e.backtrace
312
+ ##
313
+ # Generates a class file for +klass+
309
314
 
310
- raise error
311
- end
315
+ def generate_class(klass, template_file = nil)
316
+ # This is used to auto-collapse Pages section on class/module pages
317
+ @inside_class_file = true
318
+ current = klass
312
319
 
313
- ##
314
- # Generates a class file for +klass+
320
+ template_file ||= @template_dir + 'class.rhtml'
315
321
 
316
- def generate_class(klass, template_file = nil)
317
- # This is used to auto-collapse Pages section on class/module pages
318
- @inside_class_file = true
319
- current = klass
322
+ debug_msg " working on %s (%s)" % [klass.full_name, klass.path]
323
+ out_file = @outputdir + klass.path
324
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
325
+ search_index_rel_prefix = rel_prefix
326
+ search_index_rel_prefix += @asset_rel_path if @file_output
320
327
 
321
- template_file ||= @template_dir + 'class.rhtml'
328
+ asset_rel_prefix = rel_prefix + @asset_rel_path
322
329
 
323
- debug_msg " working on %s (%s)" % [klass.full_name, klass.path]
324
- out_file = @outputdir + klass.path
325
- rel_prefix = @outputdir.relative_path_from out_file.dirname
326
- search_index_rel_prefix = rel_prefix
327
- search_index_rel_prefix += @asset_rel_path if @file_output
330
+ breadcrumb = # used in templates
331
+ breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix)
328
332
 
329
- asset_rel_prefix = rel_prefix + @asset_rel_path
333
+ @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
330
334
 
331
- breadcrumb = # used in templates
332
- breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix)
335
+ debug_msg " rendering #{out_file}"
336
+ render_template template_file, out_file do |io|
337
+ here = binding
338
+ # suppress 1.9.3 warning
339
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
340
+ here
341
+ end
342
+ ensure
343
+ @inside_class_file = false
344
+ end
333
345
 
334
- @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
346
+ ##
347
+ # Generate a documentation file for each class and module
335
348
 
336
- debug_msg " rendering #{out_file}"
337
- render_template template_file, out_file do |io|
338
- here = binding
339
- # suppress 1.9.3 warning
340
- here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
341
- here
342
- end
343
- ensure
344
- @inside_class_file = false
345
- end
349
+ def generate_class_files
350
+ template_file = @template_dir + 'class.rhtml'
351
+ template_file = @template_dir + 'classpage.rhtml' unless
352
+ template_file.exist?
353
+ return unless template_file.exist?
354
+ debug_msg "Generating class documentation in #{@outputdir}"
346
355
 
347
- ##
348
- # Generate a documentation file for each class and module
356
+ current = nil
349
357
 
350
- def generate_class_files
351
- template_file = @template_dir + 'class.rhtml'
352
- template_file = @template_dir + 'classpage.rhtml' unless
353
- template_file.exist?
354
- return unless template_file.exist?
355
- debug_msg "Generating class documentation in #{@outputdir}"
358
+ # Document files are generated only for non-alias classes/modules
359
+ @classes.reject(&:is_alias_for).each do |klass|
356
360
 
357
- current = nil
361
+ current = klass
358
362
 
359
- @classes.each do |klass|
360
- current = klass
363
+ generate_class klass, template_file
364
+ end
365
+ rescue => e
366
+ error = Error.new \
367
+ "error generating #{current.path}: #{e.message} (#{e.class})"
368
+ error.set_backtrace e.backtrace
361
369
 
362
- generate_class klass, template_file
363
- end
364
- rescue => e
365
- error = RDoc::Error.new \
366
- "error generating #{current.path}: #{e.message} (#{e.class})"
367
- error.set_backtrace e.backtrace
370
+ raise error
371
+ end
368
372
 
369
- raise error
370
- end
373
+ ##
374
+ # Generate a documentation file for each file
371
375
 
372
- ##
373
- # Generate a documentation file for each file
376
+ def generate_file_files
377
+ page_file = @template_dir + 'page.rhtml'
378
+ fileinfo_file = @template_dir + 'fileinfo.rhtml'
374
379
 
375
- def generate_file_files
376
- page_file = @template_dir + 'page.rhtml'
377
- fileinfo_file = @template_dir + 'fileinfo.rhtml'
380
+ # for legacy templates
381
+ filepage_file = @template_dir + 'filepage.rhtml' unless
382
+ page_file.exist? or fileinfo_file.exist?
378
383
 
379
- # for legacy templates
380
- filepage_file = @template_dir + 'filepage.rhtml' unless
381
- page_file.exist? or fileinfo_file.exist?
384
+ return unless
385
+ page_file.exist? or fileinfo_file.exist? or filepage_file.exist?
382
386
 
383
- return unless
384
- page_file.exist? or fileinfo_file.exist? or filepage_file.exist?
387
+ debug_msg "Generating file documentation in #{@outputdir}"
385
388
 
386
- debug_msg "Generating file documentation in #{@outputdir}"
389
+ out_file = nil
390
+ current = nil
387
391
 
388
- out_file = nil
389
- current = nil
392
+ @files.each do |file|
393
+ current = file
390
394
 
391
- @files.each do |file|
392
- current = file
395
+ next if file.text? && file.full_name == @options.main_page
393
396
 
394
- if file.text? and page_file.exist? then
395
- generate_page file
396
- next
397
- end
397
+ if file.text? and page_file.exist?
398
+ generate_page file
399
+ next
400
+ end
398
401
 
399
- template_file = nil
400
- out_file = @outputdir + file.path
401
- debug_msg " working on %s (%s)" % [file.full_name, out_file]
402
- rel_prefix = @outputdir.relative_path_from out_file.dirname
403
- search_index_rel_prefix = rel_prefix
404
- search_index_rel_prefix += @asset_rel_path if @file_output
402
+ template_file = nil
403
+ out_file = @outputdir + file.path
404
+ debug_msg " working on %s (%s)" % [file.full_name, out_file]
405
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
406
+ search_index_rel_prefix = rel_prefix
407
+ search_index_rel_prefix += @asset_rel_path if @file_output
408
+
409
+ asset_rel_prefix = rel_prefix + @asset_rel_path
410
+
411
+ unless filepage_file
412
+ if file.text?
413
+ next unless page_file.exist?
414
+ template_file = page_file
415
+ @title = file.page_name
416
+ else
417
+ next unless fileinfo_file.exist?
418
+ template_file = fileinfo_file
419
+ @title = "File: #{file.base_name}"
420
+ end
421
+ end
405
422
 
406
- asset_rel_prefix = rel_prefix + @asset_rel_path
423
+ @title += " - #{@options.title}"
424
+ template_file ||= filepage_file
407
425
 
408
- unless filepage_file then
409
- if file.text? then
410
- next unless page_file.exist?
411
- template_file = page_file
412
- @title = file.page_name
413
- else
414
- next unless fileinfo_file.exist?
415
- template_file = fileinfo_file
416
- @title = "File: #{file.base_name}"
426
+ render_template template_file, out_file do |io|
427
+ here = binding
428
+ # suppress 1.9.3 warning
429
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
430
+ here.local_variable_set(:current, current)
431
+ here
432
+ end
417
433
  end
418
- end
419
-
420
- @title += " - #{@options.title}"
421
- template_file ||= filepage_file
434
+ rescue => e
435
+ error =
436
+ Error.new "error generating #{out_file}: #{e.message} (#{e.class})"
437
+ error.set_backtrace e.backtrace
422
438
 
423
- render_template template_file, out_file do |io|
424
- here = binding
425
- # suppress 1.9.3 warning
426
- here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
427
- here.local_variable_set(:current, current)
428
- here
439
+ raise error
429
440
  end
430
- end
431
- rescue => e
432
- error =
433
- RDoc::Error.new "error generating #{out_file}: #{e.message} (#{e.class})"
434
- error.set_backtrace e.backtrace
435
-
436
- raise error
437
- end
438
441
 
439
- ##
440
- # Generate a page file for +file+
442
+ ##
443
+ # Generate a page file for +file+
441
444
 
442
- def generate_page(file)
443
- template_file = @template_dir + 'page.rhtml'
445
+ def generate_page(file)
446
+ template_file = @template_dir + 'page.rhtml'
444
447
 
445
- out_file = @outputdir + file.path
446
- debug_msg " working on %s (%s)" % [file.full_name, out_file]
447
- rel_prefix = @outputdir.relative_path_from out_file.dirname
448
- search_index_rel_prefix = rel_prefix
449
- search_index_rel_prefix += @asset_rel_path if @file_output
448
+ out_file = @outputdir + file.path
449
+ debug_msg " working on %s (%s)" % [file.full_name, out_file]
450
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
451
+ search_index_rel_prefix = rel_prefix
452
+ search_index_rel_prefix += @asset_rel_path if @file_output
450
453
 
451
- current = file
452
- asset_rel_prefix = rel_prefix + @asset_rel_path
454
+ current = file
455
+ asset_rel_prefix = rel_prefix + @asset_rel_path
453
456
 
454
- @title = "#{file.page_name} - #{@options.title}"
457
+ @title = "#{file.page_name} - #{@options.title}"
455
458
 
456
- debug_msg " rendering #{out_file}"
457
- render_template template_file, out_file do |io|
458
- here = binding
459
- # suppress 1.9.3 warning
460
- here.local_variable_set(:current, current)
461
- here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
462
- here
463
- end
464
- end
459
+ debug_msg " rendering #{out_file}"
460
+ render_template template_file, out_file do |io|
461
+ here = binding
462
+ # suppress 1.9.3 warning
463
+ here.local_variable_set(:current, current)
464
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
465
+ here
466
+ end
467
+ end
465
468
 
466
- ##
467
- # Generates the 404 page for the RDoc servlet
469
+ ##
470
+ # Generates the 404 page for the RDoc servlet
468
471
 
469
- def generate_servlet_not_found(message)
470
- template_file = @template_dir + 'servlet_not_found.rhtml'
471
- return unless template_file.exist?
472
+ def generate_servlet_not_found(message)
473
+ template_file = @template_dir + 'servlet_not_found.rhtml'
474
+ return unless template_file.exist?
472
475
 
473
- debug_msg "Rendering the servlet 404 Not Found page..."
476
+ debug_msg "Rendering the servlet 404 Not Found page..."
474
477
 
475
- rel_prefix = rel_prefix = ''
476
- search_index_rel_prefix = rel_prefix
477
- search_index_rel_prefix += @asset_rel_path if @file_output
478
+ rel_prefix = rel_prefix = ''
479
+ search_index_rel_prefix = rel_prefix
480
+ search_index_rel_prefix += @asset_rel_path if @file_output
478
481
 
479
- asset_rel_prefix = ''
482
+ asset_rel_prefix = ''
480
483
 
481
- @title = 'Not Found'
484
+ @title = 'Not Found'
482
485
 
483
- render_template template_file do |io|
484
- here = binding
485
- # suppress 1.9.3 warning
486
- here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
487
- here
488
- end
489
- rescue => e
490
- error = RDoc::Error.new \
491
- "error generating servlet_not_found: #{e.message} (#{e.class})"
492
- error.set_backtrace e.backtrace
486
+ render_template template_file do |io|
487
+ here = binding
488
+ # suppress 1.9.3 warning
489
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
490
+ here
491
+ end
492
+ rescue => e
493
+ error = Error.new \
494
+ "error generating servlet_not_found: #{e.message} (#{e.class})"
495
+ error.set_backtrace e.backtrace
493
496
 
494
- raise error
495
- end
497
+ raise error
498
+ end
496
499
 
497
- ##
498
- # Generates the servlet root page for the RDoc servlet
500
+ ##
501
+ # Generates the servlet root page for the RDoc servlet
499
502
 
500
- def generate_servlet_root(installed)
501
- template_file = @template_dir + 'servlet_root.rhtml'
502
- return unless template_file.exist?
503
+ def generate_servlet_root(installed)
504
+ template_file = @template_dir + 'servlet_root.rhtml'
505
+ return unless template_file.exist?
503
506
 
504
- debug_msg 'Rendering the servlet root page...'
507
+ debug_msg 'Rendering the servlet root page...'
505
508
 
506
- rel_prefix = '.'
507
- asset_rel_prefix = rel_prefix
508
- search_index_rel_prefix = asset_rel_prefix
509
- search_index_rel_prefix += @asset_rel_path if @file_output
509
+ rel_prefix = '.'
510
+ asset_rel_prefix = rel_prefix
511
+ search_index_rel_prefix = asset_rel_prefix
512
+ search_index_rel_prefix += @asset_rel_path if @file_output
510
513
 
511
- @title = 'Local RDoc Documentation'
514
+ @title = 'Local RDoc Documentation'
512
515
 
513
- render_template template_file do |io| binding end
514
- rescue => e
515
- error = RDoc::Error.new \
516
- "error generating servlet_root: #{e.message} (#{e.class})"
517
- error.set_backtrace e.backtrace
516
+ render_template template_file do |io| binding end
517
+ rescue => e
518
+ error = Error.new \
519
+ "error generating servlet_root: #{e.message} (#{e.class})"
520
+ error.set_backtrace e.backtrace
518
521
 
519
- raise error
520
- end
522
+ raise error
523
+ end
521
524
 
522
- ##
523
- # Generate an index page which lists all the classes which are documented.
525
+ ##
526
+ # Generate an index page which lists all the classes which are documented.
524
527
 
525
- def generate_table_of_contents
526
- template_file = @template_dir + 'table_of_contents.rhtml'
527
- return unless template_file.exist?
528
+ def generate_table_of_contents
529
+ template_file = @template_dir + 'table_of_contents.rhtml'
530
+ return unless template_file.exist?
528
531
 
529
- debug_msg "Rendering the Table of Contents..."
532
+ debug_msg "Rendering the Table of Contents..."
530
533
 
531
- out_file = @outputdir + 'table_of_contents.html'
532
- rel_prefix = @outputdir.relative_path_from out_file.dirname
533
- search_index_rel_prefix = rel_prefix
534
- search_index_rel_prefix += @asset_rel_path if @file_output
534
+ out_file = @outputdir + 'table_of_contents.html'
535
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
536
+ search_index_rel_prefix = rel_prefix
537
+ search_index_rel_prefix += @asset_rel_path if @file_output
535
538
 
536
- asset_rel_prefix = rel_prefix + @asset_rel_path
539
+ asset_rel_prefix = rel_prefix + @asset_rel_path
537
540
 
538
- @title = "Table of Contents - #{@options.title}"
541
+ @title = "Table of Contents - #{@options.title}"
539
542
 
540
- render_template template_file, out_file do |io|
541
- here = binding
542
- # suppress 1.9.3 warning
543
- here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
544
- here
545
- end
546
- rescue => e
547
- error = RDoc::Error.new \
548
- "error generating table_of_contents.html: #{e.message} (#{e.class})"
549
- error.set_backtrace e.backtrace
543
+ render_template template_file, out_file do |io|
544
+ here = binding
545
+ # suppress 1.9.3 warning
546
+ here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
547
+ here
548
+ end
549
+ rescue => e
550
+ error = Error.new \
551
+ "error generating table_of_contents.html: #{e.message} (#{e.class})"
552
+ error.set_backtrace e.backtrace
550
553
 
551
- raise error
552
- end
554
+ raise error
555
+ end
553
556
 
554
- def install_rdoc_static_file(source, destination, options) # :nodoc:
555
- return unless source.exist?
557
+ def install_rdoc_static_file(source, destination, options) # :nodoc:
558
+ return unless source.exist?
556
559
 
557
- begin
558
- FileUtils.mkdir_p File.dirname(destination), **options
560
+ begin
561
+ FileUtils.mkdir_p File.dirname(destination), **options
559
562
 
560
- begin
561
- FileUtils.ln source, destination, **options
562
- rescue Errno::EEXIST
563
- FileUtils.rm destination
564
- retry
563
+ begin
564
+ FileUtils.ln source, destination, **options
565
+ rescue Errno::EEXIST
566
+ FileUtils.rm destination
567
+ retry
568
+ end
569
+ rescue
570
+ FileUtils.cp source, destination, **options
571
+ end
565
572
  end
566
- rescue
567
- FileUtils.cp source, destination, **options
568
- end
569
- end
570
573
 
571
- ##
572
- # Prepares for generation of output from the current directory
574
+ ##
575
+ # Prepares for generation of output from the current directory
573
576
 
574
- def setup
575
- return if instance_variable_defined? :@outputdir
577
+ def setup
578
+ return if instance_variable_defined? :@outputdir
576
579
 
577
- @outputdir = Pathname.new(@options.op_dir).expand_path @base_dir
580
+ @outputdir = Pathname.new(@options.op_dir).expand_path @base_dir
578
581
 
579
- return unless @store
582
+ return unless @store
580
583
 
581
- @classes = @store.all_classes_and_modules.sort
582
- @files = @store.all_files.sort
583
- @methods = @classes.flat_map { |m| m.method_list }.sort
584
- @modsort = get_sorted_module_list @classes
585
- end
584
+ refresh_store_data
585
+ end
586
+
587
+ ##
588
+ # Refreshes the generator's data from the store. Called by #setup and
589
+ # can be called again after the store has been updated (e.g. in server
590
+ # mode after re-parsing changed files).
591
+
592
+ def refresh_store_data
593
+ @classes = @store.all_classes_and_modules.sort
594
+ @files = @store.all_files.sort
595
+ @methods = @classes.flat_map { |m| m.method_list }.sort
596
+ @modsort = get_sorted_module_list @classes
597
+ end
586
598
 
587
- ##
588
- # Creates a template from its components and the +body_file+.
589
- #
590
- # For backwards compatibility, if +body_file+ contains "<html" the body is
591
- # used directly.
599
+ ##
600
+ # Creates a template from its components and the +body_file+.
601
+ #
602
+ # For backwards compatibility, if +body_file+ contains "<html" the body is
603
+ # used directly.
592
604
 
593
- def assemble_template(body_file)
594
- body = body_file.read
595
- return body if body =~ /<html/
605
+ def assemble_template(body_file)
606
+ body = body_file.read(encoding: template_encoding)
607
+ return body if body =~ /<html/
596
608
 
597
- head_file = @template_dir + '_head.rhtml'
609
+ head_file = @template_dir + '_head.rhtml'
598
610
 
599
- <<-TEMPLATE
611
+ <<-TEMPLATE
600
612
  <!DOCTYPE html>
601
613
 
602
614
  <html lang="#{@options.locale&.name || 'en'}">
603
615
  <head>
604
- #{head_file.read}
616
+ #{head_file.read(encoding: template_encoding)}
605
617
 
606
618
  #{body}
607
619
  TEMPLATE
608
- end
620
+ end
609
621
 
610
- ##
611
- # Renders the ERb contained in +file_name+ relative to the template
612
- # directory and returns the result based on the current context.
622
+ ##
623
+ # Renders the ERb contained in +file_name+ relative to the template
624
+ # directory and returns the result based on the current context.
613
625
 
614
- def render(file_name)
615
- template_file = @template_dir + file_name
626
+ def render(file_name)
627
+ template_file = @template_dir + file_name
616
628
 
617
- template = template_for template_file, false, RDoc::ERBPartial
629
+ template = template_for template_file, false, ERBPartial
618
630
 
619
- template.filename = template_file.to_s
631
+ template.filename = template_file.to_s
620
632
 
621
- template.result @context
622
- end
633
+ template.result @context
634
+ end
623
635
 
624
- ##
625
- # Load and render the erb template in the given +template_file+ and write
626
- # it out to +out_file+.
627
- #
628
- # Both +template_file+ and +out_file+ should be Pathname-like objects.
629
- #
630
- # An io will be yielded which must be captured by binding in the caller.
636
+ ##
637
+ # Load and render the erb template in the given +template_file+ and write
638
+ # it out to +out_file+.
639
+ #
640
+ # Both +template_file+ and +out_file+ should be Pathname-like objects.
641
+ #
642
+ # An io will be yielded which must be captured by binding in the caller.
631
643
 
632
- def render_template(template_file, out_file = nil) # :yield: io
633
- io_output = out_file && !@dry_run && @file_output
634
- erb_klass = io_output ? RDoc::ERBIO : ERB
644
+ def render_template(template_file, out_file = nil) # :yield: io
645
+ io_output = out_file && !@dry_run && @file_output
646
+ erb_klass = io_output ? ERBIO : ERB
635
647
 
636
- template = template_for template_file, true, erb_klass
648
+ template = template_for template_file, true, erb_klass
637
649
 
638
- if io_output then
639
- debug_msg "Outputting to %s" % [out_file.expand_path]
650
+ if io_output
651
+ debug_msg "Outputting to %s" % [out_file.expand_path]
640
652
 
641
- out_file.dirname.mkpath
642
- out_file.open 'w', 0644 do |io|
643
- io.set_encoding @options.encoding
653
+ out_file.dirname.mkpath
654
+ out_file.open 'w', 0644 do |io|
655
+ io.set_encoding @options.encoding
644
656
 
645
- @context = yield io
657
+ @context = yield io
646
658
 
647
- template_result template, @context, template_file
648
- end
649
- else
650
- @context = yield nil
659
+ template_result template, @context, template_file
660
+ end
661
+ else
662
+ @context = yield nil
651
663
 
652
- output = template_result template, @context, template_file
664
+ output = template_result template, @context, template_file
653
665
 
654
- debug_msg " would have written %d characters to %s" % [
655
- output.length, out_file.expand_path
656
- ] if @dry_run
666
+ debug_msg " would have written %d characters to %s" % [
667
+ output.length, out_file.expand_path
668
+ ] if @dry_run
657
669
 
658
- output
659
- end
660
- end
670
+ output
671
+ end
672
+ end
661
673
 
662
- ##
663
- # Creates the result for +template+ with +context+. If an error is raised a
664
- # Pathname +template_file+ will indicate the file where the error occurred.
665
-
666
- def template_result(template, context, template_file)
667
- template.filename = template_file.to_s
668
- template.result context
669
- rescue NoMethodError => e
670
- raise RDoc::Error, "Error while evaluating %s: %s" % [
671
- template_file.expand_path,
672
- e.message,
673
- ], e.backtrace
674
- end
674
+ ##
675
+ # Creates the result for +template+ with +context+. If an error is raised a
676
+ # Pathname +template_file+ will indicate the file where the error occurred.
677
+
678
+ def template_result(template, context, template_file)
679
+ template.filename = template_file.to_s
680
+ template.result context
681
+ rescue NoMethodError => e
682
+ raise Error, "Error while evaluating %s: %s" % [
683
+ template_file.expand_path,
684
+ e.message,
685
+ ], e.backtrace
686
+ end
675
687
 
676
- ##
677
- # Retrieves a cache template for +file+, if present, or fills the cache.
688
+ ##
689
+ # Retrieves a cache template for +file+, if present, or fills the cache.
678
690
 
679
- def template_for(file, page = true, klass = ERB)
680
- template = @template_cache[file]
691
+ def template_for(file, page = true, klass = ERB)
692
+ template = @template_cache[file]
681
693
 
682
- return template if template
694
+ return template if template
683
695
 
684
- if page then
685
- template = assemble_template file
686
- erbout = 'io'
687
- else
688
- template = file.read
689
- template = template.encode @options.encoding
696
+ if page
697
+ template = assemble_template file
698
+ erbout = 'io'
699
+ else
700
+ template = file.read(encoding: template_encoding)
701
+ template = template.encode @options.encoding
690
702
 
691
- file_var = File.basename(file).sub(/\..*/, '')
703
+ file_var = File.basename(file).sub(/\..*/, '')
692
704
 
693
- erbout = "_erbout_#{file_var}"
694
- end
705
+ erbout = "_erbout_#{file_var}"
706
+ end
695
707
 
696
- template = klass.new template, trim_mode: '-', eoutvar: erbout
697
- @template_cache[file] = template
698
- template
699
- end
708
+ template = klass.new template, trim_mode: '-', eoutvar: erbout
709
+ @template_cache[file] = template
710
+ template
711
+ end
700
712
 
701
- # :stopdoc:
702
- ParagraphExcerptRegexpOther = %r[\b\w[^./:]++\.]
703
- # use \p/\P{letter} instead of \w/\W in Unicode
704
- ParagraphExcerptRegexpUnicode = %r[\b\p{letter}[^./:]++\.]
705
- # :startdoc:
706
-
707
- # Returns an excerpt of the comment for usage in meta description tags
708
- def excerpt(comment)
709
- text = case comment
710
- when RDoc::Comment
711
- comment.text
712
- else
713
- comment
714
- end
713
+ # :stopdoc:
714
+ ParagraphExcerptRegexpOther = %r[\b\w[^./:]++\.]
715
+ # use \p/\P{letter} instead of \w/\W in Unicode
716
+ ParagraphExcerptRegexpUnicode = %r[\b\p{letter}[^./:]++\.]
717
+ # :startdoc:
718
+
719
+ # Returns an excerpt of the comment for usage in meta description tags
720
+ def excerpt(comment)
721
+ text = case comment
722
+ when Comment
723
+ comment.text
724
+ else
725
+ comment
726
+ end
715
727
 
716
- # Match from a capital letter to the first period, discarding any links, so
717
- # that we don't end up matching badges in the README
718
- pattern = ParagraphExcerptRegexpUnicode
719
- begin
720
- first_paragraph_match = text.match(pattern)
721
- rescue Encoding::CompatibilityError
722
- # The doc is non-ASCII text and encoded in other than Unicode base encodings.
723
- raise if pattern == ParagraphExcerptRegexpOther
724
- pattern = ParagraphExcerptRegexpOther
725
- retry
726
- end
727
- return text[0...150].tr_s("\n", " ").squeeze(" ") unless first_paragraph_match
728
+ # Match from a capital letter to the first period, discarding any links, so
729
+ # that we don't end up matching badges in the README
730
+ pattern = ParagraphExcerptRegexpUnicode
731
+ begin
732
+ first_paragraph_match = text.match(pattern)
733
+ rescue ::Encoding::CompatibilityError
734
+ # The doc is non-ASCII text and encoded in other than Unicode base encodings.
735
+ raise if pattern == ParagraphExcerptRegexpOther
736
+ pattern = ParagraphExcerptRegexpOther
737
+ retry
738
+ end
739
+ return text[0...150].tr_s("\n", " ").squeeze(" ") unless first_paragraph_match
728
740
 
729
- extracted_text = first_paragraph_match[0]
730
- second_paragraph = text.match(pattern, first_paragraph_match.end(0))
731
- extracted_text << " " << second_paragraph[0] if second_paragraph
741
+ extracted_text = first_paragraph_match[0]
742
+ second_paragraph = text.match(pattern, first_paragraph_match.end(0))
743
+ extracted_text << " " << second_paragraph[0] if second_paragraph
732
744
 
733
- extracted_text[0...150].tr_s("\n", " ").squeeze(" ")
734
- end
745
+ extracted_text[0...150].tr_s("\n", " ").squeeze(" ")
746
+ end
735
747
 
736
- def generate_ancestor_list(ancestors, klass)
737
- return '' if ancestors.empty?
748
+ def generate_ancestor_list(ancestors, klass)
749
+ return '' if ancestors.empty?
738
750
 
739
- ancestor = ancestors.shift
740
- content = +'<ul><li>'
751
+ ancestor = ancestors.shift
752
+ content = +'<ul><li>'
741
753
 
742
- if ancestor.is_a?(RDoc::NormalClass)
743
- content << "<a href=\"#{klass.aref_to ancestor.path}\">#{ancestor.full_name}</a>"
744
- else
745
- content << ancestor.to_s
746
- end
754
+ if ancestor.is_a?(NormalClass)
755
+ content << "<a href=\"#{klass.aref_to ancestor.path}\">#{ancestor.full_name}</a>"
756
+ else
757
+ content << ancestor.to_s
758
+ end
747
759
 
748
- # Recursively call the method for the remaining ancestors
749
- content << generate_ancestor_list(ancestors, klass)
760
+ # Recursively call the method for the remaining ancestors
761
+ content << generate_ancestor_list(ancestors, klass)
750
762
 
751
- content << '</li></ul>'
752
- end
763
+ content << '</li></ul>'
764
+ end
753
765
 
754
- def generate_class_link(klass, rel_prefix)
755
- if klass.display?
756
- %(<code><a href="#{rel_prefix}/#{klass.path}">#{klass.name}</a></code>)
757
- else
758
- %(<code>#{klass.name}</code>)
759
- end
760
- end
766
+ def generate_class_link(klass, rel_prefix)
767
+ if klass.display?
768
+ %(<code><a href="#{rel_prefix}/#{klass.path}">#{klass.name}</a></code>)
769
+ else
770
+ %(<code>#{klass.name}</code>)
771
+ end
772
+ end
761
773
 
762
- def generate_class_index_content(classes, rel_prefix)
763
- grouped_classes = group_classes_by_namespace_for_sidebar(classes)
764
- return '' unless top = grouped_classes[nil]
774
+ def generate_class_index_content(classes, rel_prefix)
775
+ grouped_classes = group_classes_by_namespace_for_sidebar(classes)
776
+ return '' unless top = grouped_classes[nil]
765
777
 
766
- solo = top.one? { |klass| klass.display? }
767
- traverse_classes(top, grouped_classes, rel_prefix, solo)
768
- end
778
+ solo = top.one? { |klass| klass.display? }
779
+ traverse_classes(top, grouped_classes, rel_prefix, solo)
780
+ end
769
781
 
770
- def traverse_classes(klasses, grouped_classes, rel_prefix, solo = false)
771
- content = +'<ul class="link-list nav-list">'
782
+ def traverse_classes(klasses, grouped_classes, rel_prefix, solo = false)
783
+ content = +'<ul class="link-list nav-list">'
784
+
785
+ klasses.each do |index_klass|
786
+ if children = grouped_classes[index_klass.full_name]
787
+ content << %(<li><details#{solo ? ' open' : ''}><summary>#{generate_class_link(index_klass, rel_prefix)}</summary>)
788
+ content << traverse_classes(children, grouped_classes, rel_prefix)
789
+ content << '</details></li>'
790
+ solo = false
791
+ elsif index_klass.display?
792
+ content << %(<li>#{generate_class_link(index_klass, rel_prefix)}</li>)
793
+ end
794
+ end
772
795
 
773
- klasses.each do |index_klass|
774
- if children = grouped_classes[index_klass.full_name]
775
- content << %(<li><details#{solo ? ' open' : ''}><summary>#{generate_class_link(index_klass, rel_prefix)}</summary>)
776
- content << traverse_classes(children, grouped_classes, rel_prefix)
777
- content << '</details></li>'
778
- solo = false
779
- elsif index_klass.display?
780
- content << %(<li>#{generate_class_link(index_klass, rel_prefix)}</li>)
796
+ "#{content}</ul>"
781
797
  end
782
- end
783
798
 
784
- "#{content}</ul>"
785
- end
799
+ def group_classes_by_namespace_for_sidebar(classes)
800
+ grouped_classes = classes.group_by do |klass|
801
+ klass.full_name[/\A[^:]++(?:::[^:]++(?=::))*+(?=::[^:]*+\z)/]
802
+ end.select do |_, klasses|
803
+ klasses.any?(&:display?)
804
+ end
786
805
 
787
- def group_classes_by_namespace_for_sidebar(classes)
788
- grouped_classes = classes.group_by do |klass|
789
- klass.full_name[/\A[^:]++(?:::[^:]++(?=::))*+(?=::[^:]*+\z)/]
790
- end.select do |_, klasses|
791
- klasses.any?(&:display?)
792
- end
806
+ grouped_classes.values.each(&:uniq!)
807
+ grouped_classes
808
+ end
793
809
 
794
- grouped_classes.values.each(&:uniq!)
795
- grouped_classes
796
- end
810
+ private
797
811
 
798
- private
812
+ def template_encoding
813
+ nil
814
+ end
799
815
 
800
- def nesting_namespaces_to_class_modules(klass)
801
- tree = {}
816
+ def nesting_namespaces_to_class_modules(klass)
817
+ tree = {}
802
818
 
803
- klass.nesting_namespaces.zip(klass.fully_qualified_nesting_namespaces) do |ns, fqns|
804
- tree[ns] = @store.classes_hash[fqns] || @store.modules_hash[fqns]
805
- end
819
+ klass.nesting_namespaces.zip(klass.fully_qualified_nesting_namespaces) do |ns, fqns|
820
+ tree[ns] = @store.classes_hash[fqns] || @store.modules_hash[fqns]
821
+ end
806
822
 
807
- tree
808
- end
823
+ tree
824
+ end
809
825
 
810
- def generate_nesting_namespaces_breadcrumb(klass, rel_prefix)
811
- nesting_namespaces_to_class_modules(klass).map do |namespace, class_module|
812
- path = class_module ? (rel_prefix + class_module.path).to_s : ""
813
- { name: namespace, path: path, self: klass.full_name == class_module&.full_name }
826
+ def generate_nesting_namespaces_breadcrumb(klass, rel_prefix)
827
+ nesting_namespaces_to_class_modules(klass).map do |namespace, class_module|
828
+ path = class_module ? (rel_prefix + class_module.path).to_s : ""
829
+ { name: namespace, path: path, self: klass.full_name == class_module&.full_name }
830
+ end
831
+ end
814
832
  end
815
833
  end
816
834
  end