rdoc 3.12.2 → 4.0.0.preview2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (200) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +3 -2
  5. data/DEVELOPERS.rdoc +53 -0
  6. data/History.rdoc +159 -25
  7. data/LEGAL.rdoc +12 -0
  8. data/Manifest.txt +56 -3
  9. data/README.rdoc +87 -19
  10. data/Rakefile +11 -2
  11. data/TODO.rdoc +20 -13
  12. data/bin/rdoc +4 -0
  13. data/lib/gauntlet_rdoc.rb +1 -1
  14. data/lib/rdoc.rb +32 -71
  15. data/lib/rdoc/any_method.rb +75 -21
  16. data/lib/rdoc/attr.rb +49 -10
  17. data/lib/rdoc/class_module.rb +182 -32
  18. data/lib/rdoc/code_object.rb +54 -12
  19. data/lib/rdoc/comment.rb +8 -1
  20. data/lib/rdoc/constant.rb +100 -6
  21. data/lib/rdoc/context.rb +93 -41
  22. data/lib/rdoc/context/section.rb +143 -28
  23. data/lib/rdoc/cross_reference.rb +58 -50
  24. data/lib/rdoc/encoding.rb +34 -29
  25. data/lib/rdoc/erb_partial.rb +18 -0
  26. data/lib/rdoc/extend.rb +117 -0
  27. data/lib/rdoc/generator.rb +11 -6
  28. data/lib/rdoc/generator/darkfish.rb +250 -62
  29. data/lib/rdoc/generator/json_index.rb +20 -12
  30. data/lib/rdoc/generator/markup.rb +10 -12
  31. data/lib/rdoc/generator/ri.rb +7 -60
  32. data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
  39. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
  41. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
  42. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
  43. data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
  44. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  45. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
  46. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  47. data/lib/rdoc/include.rb +12 -3
  48. data/lib/rdoc/markdown.kpeg +1186 -0
  49. data/lib/rdoc/markdown.rb +16336 -0
  50. data/lib/rdoc/markdown/entities.rb +2128 -0
  51. data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
  52. data/lib/rdoc/markdown/literals_1_8.rb +454 -0
  53. data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
  54. data/lib/rdoc/markdown/literals_1_9.rb +417 -0
  55. data/lib/rdoc/markup.rb +69 -10
  56. data/lib/rdoc/markup/attr_changer.rb +2 -5
  57. data/lib/rdoc/markup/attribute_manager.rb +23 -14
  58. data/lib/rdoc/markup/attributes.rb +70 -0
  59. data/lib/rdoc/markup/block_quote.rb +14 -0
  60. data/lib/rdoc/markup/document.rb +20 -4
  61. data/lib/rdoc/markup/formatter.rb +17 -6
  62. data/lib/rdoc/markup/formatter_test_case.rb +93 -24
  63. data/lib/rdoc/markup/hard_break.rb +31 -0
  64. data/lib/rdoc/markup/heading.rb +1 -1
  65. data/lib/rdoc/markup/indented_paragraph.rb +14 -0
  66. data/lib/rdoc/markup/list.rb +23 -4
  67. data/lib/rdoc/markup/list_item.rb +17 -4
  68. data/lib/rdoc/markup/paragraph.rb +14 -0
  69. data/lib/rdoc/markup/parser.rb +107 -60
  70. data/lib/rdoc/markup/raw.rb +4 -4
  71. data/lib/rdoc/markup/special.rb +3 -3
  72. data/lib/rdoc/markup/to_ansi.rb +7 -1
  73. data/lib/rdoc/markup/to_html.rb +42 -14
  74. data/lib/rdoc/markup/to_html_crossref.rb +10 -9
  75. data/lib/rdoc/markup/to_html_snippet.rb +20 -4
  76. data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
  77. data/lib/rdoc/markup/to_label.rb +20 -1
  78. data/lib/rdoc/markup/to_markdown.rb +134 -0
  79. data/lib/rdoc/markup/to_rdoc.rb +36 -5
  80. data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
  81. data/lib/rdoc/markup/to_tt_only.rb +11 -2
  82. data/lib/rdoc/markup/verbatim.rb +19 -0
  83. data/lib/rdoc/method_attr.rb +33 -19
  84. data/lib/rdoc/normal_class.rb +26 -7
  85. data/lib/rdoc/normal_module.rb +10 -5
  86. data/lib/rdoc/options.rb +95 -21
  87. data/lib/rdoc/parser.rb +6 -2
  88. data/lib/rdoc/parser/c.rb +212 -97
  89. data/lib/rdoc/parser/markdown.rb +23 -0
  90. data/lib/rdoc/parser/ruby.rb +115 -35
  91. data/lib/rdoc/parser/ruby_tools.rb +8 -3
  92. data/lib/rdoc/rd.rb +8 -4
  93. data/lib/rdoc/rd/block_parser.rb +1 -1
  94. data/lib/rdoc/rd/block_parser.ry +1 -1
  95. data/lib/rdoc/rdoc.rb +45 -21
  96. data/lib/rdoc/ri/driver.rb +322 -76
  97. data/lib/rdoc/ri/paths.rb +90 -31
  98. data/lib/rdoc/ri/store.rb +2 -353
  99. data/lib/rdoc/ruby_lex.rb +5 -21
  100. data/lib/rdoc/ruby_token.rb +2 -3
  101. data/lib/rdoc/rubygems_hook.rb +21 -9
  102. data/lib/rdoc/servlet.rb +302 -0
  103. data/lib/rdoc/stats.rb +28 -20
  104. data/lib/rdoc/store.rb +881 -0
  105. data/lib/rdoc/task.rb +2 -1
  106. data/lib/rdoc/test_case.rb +103 -1
  107. data/lib/rdoc/text.rb +5 -4
  108. data/lib/rdoc/tom_doc.rb +17 -16
  109. data/lib/rdoc/top_level.rb +43 -285
  110. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
  111. data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
  112. data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
  113. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
  114. data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
  115. data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
  116. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
  117. data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
  118. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
  119. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
  120. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
  121. data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
  122. data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
  123. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
  124. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
  125. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
  126. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
  127. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
  128. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
  129. data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
  130. data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
  131. data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
  132. data/test/test_attribute_manager.rb +7 -4
  133. data/test/test_rdoc_any_method.rb +84 -13
  134. data/test/test_rdoc_attr.rb +59 -9
  135. data/test/test_rdoc_class_module.rb +670 -73
  136. data/test/test_rdoc_code_object.rb +21 -1
  137. data/test/test_rdoc_comment.rb +1 -1
  138. data/test/test_rdoc_constant.rb +132 -0
  139. data/test/test_rdoc_context.rb +84 -18
  140. data/test/test_rdoc_context_section.rb +99 -15
  141. data/test/test_rdoc_cross_reference.rb +1 -1
  142. data/test/test_rdoc_encoding.rb +17 -1
  143. data/test/test_rdoc_extend.rb +94 -0
  144. data/test/test_rdoc_generator_darkfish.rb +45 -19
  145. data/test/test_rdoc_generator_json_index.rb +27 -7
  146. data/test/test_rdoc_generator_markup.rb +3 -3
  147. data/test/test_rdoc_generator_ri.rb +11 -9
  148. data/test/test_rdoc_include.rb +12 -0
  149. data/test/test_rdoc_markdown.rb +977 -0
  150. data/test/test_rdoc_markdown_test.rb +1891 -0
  151. data/test/test_rdoc_markup.rb +1 -1
  152. data/test/test_rdoc_markup_attribute_manager.rb +2 -2
  153. data/test/test_rdoc_markup_attributes.rb +39 -0
  154. data/test/test_rdoc_markup_document.rb +16 -1
  155. data/test/test_rdoc_markup_formatter.rb +7 -4
  156. data/test/test_rdoc_markup_hard_break.rb +31 -0
  157. data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
  158. data/test/test_rdoc_markup_paragraph.rb +15 -1
  159. data/test/test_rdoc_markup_parser.rb +152 -89
  160. data/test/test_rdoc_markup_to_ansi.rb +23 -2
  161. data/test/test_rdoc_markup_to_bs.rb +24 -0
  162. data/test/test_rdoc_markup_to_html.rb +50 -19
  163. data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
  164. data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
  165. data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
  166. data/test/test_rdoc_markup_to_label.rb +63 -1
  167. data/test/test_rdoc_markup_to_markdown.rb +352 -0
  168. data/test/test_rdoc_markup_to_rdoc.rb +22 -2
  169. data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
  170. data/test/test_rdoc_markup_to_tt_only.rb +20 -0
  171. data/test/test_rdoc_markup_verbatim.rb +13 -0
  172. data/test/test_rdoc_method_attr.rb +5 -0
  173. data/test/test_rdoc_normal_class.rb +24 -5
  174. data/test/test_rdoc_normal_module.rb +1 -1
  175. data/test/test_rdoc_options.rb +21 -6
  176. data/test/test_rdoc_parser.rb +24 -0
  177. data/test/test_rdoc_parser_c.rb +151 -26
  178. data/test/test_rdoc_parser_markdown.rb +55 -0
  179. data/test/test_rdoc_parser_rd.rb +2 -2
  180. data/test/test_rdoc_parser_ruby.rb +468 -109
  181. data/test/test_rdoc_parser_simple.rb +2 -2
  182. data/test/test_rdoc_rd_block_parser.rb +0 -4
  183. data/test/test_rdoc_rdoc.rb +110 -22
  184. data/test/test_rdoc_ri_driver.rb +415 -80
  185. data/test/test_rdoc_ri_paths.rb +122 -13
  186. data/test/test_rdoc_ruby_lex.rb +5 -61
  187. data/test/test_rdoc_ruby_token.rb +19 -0
  188. data/test/test_rdoc_rubygems_hook.rb +64 -43
  189. data/test/test_rdoc_servlet.rb +429 -0
  190. data/test/test_rdoc_stats.rb +83 -24
  191. data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
  192. data/test/test_rdoc_task.rb +2 -2
  193. data/test/test_rdoc_text.rb +37 -11
  194. data/test/test_rdoc_tom_doc.rb +59 -62
  195. data/test/test_rdoc_top_level.rb +71 -113
  196. data/test/xref_test_case.rb +7 -9
  197. metadata +122 -39
  198. metadata.gz.sig +0 -0
  199. data/CVE-2013-0256.rdoc +0 -49
  200. data/lib/rdoc/markup/attribute.rb +0 -51
@@ -0,0 +1,117 @@
1
+ ##
2
+ # A Module extension in a class with \#extend
3
+
4
+ class RDoc::Extend < RDoc::CodeObject
5
+
6
+ ##
7
+ # Name of extension module
8
+
9
+ attr_accessor :name
10
+
11
+ ##
12
+ # Creates a new Extend for +name+ with +comment+
13
+
14
+ def initialize(name, comment)
15
+ super()
16
+ @name = name
17
+ self.comment = comment
18
+ @module = nil # cache for module if found
19
+ end
20
+
21
+ ##
22
+ # Extends are sorted by name
23
+
24
+ def <=> other
25
+ return unless self.class === other
26
+
27
+ name <=> other.name
28
+ end
29
+
30
+ def == other # :nodoc:
31
+ self.class === other and @name == other.name
32
+ end
33
+
34
+ alias eql? ==
35
+
36
+ ##
37
+ # Full name based on #module
38
+
39
+ def full_name
40
+ m = self.module
41
+ RDoc::ClassModule === m ? m.full_name : @name
42
+ end
43
+
44
+ def hash # :nodoc:
45
+ [@name, self.module].hash
46
+ end
47
+
48
+ def inspect # :nodoc:
49
+ "#<%s:0x%x %s.extend %s>" % [
50
+ self.class,
51
+ object_id,
52
+ parent_name, @name,
53
+ ]
54
+ end
55
+
56
+ ##
57
+ # Attempts to locate the extend module object. Returns the name if not
58
+ # known.
59
+ #
60
+ # The scoping rules of Ruby to resolve the name of an extension module are:
61
+ # - first look into the children of the current context;
62
+ # - if not found, look into the children of extension modules,
63
+ # in reverse extend order;
64
+ # - if still not found, go up the hierarchy of names.
65
+ #
66
+ # This method has <code>O(n!)</code> behavior when the module calling
67
+ # extend is referencing nonexistent modules. Avoid calling #module until
68
+ # after all the files are parsed. This behavior is due to ruby's constant
69
+ # lookup behavior.
70
+
71
+ def module
72
+ return @module if @module
73
+
74
+ # search the current context
75
+ return @name unless parent
76
+ full_name = parent.child_name(@name)
77
+ @module = @store.modules_hash[full_name]
78
+ return @module if @module
79
+ return @name if @name =~ /^::/
80
+
81
+ # search the includes before this one, in reverse order
82
+ searched = parent.extends.take_while { |i| i != self }.reverse
83
+ searched.each do |i|
84
+ ext = i.module
85
+ next if String === ext
86
+ full_name = ext.child_name(@name)
87
+ @module = @store.modules_hash[full_name]
88
+ return @module if @module
89
+ end
90
+
91
+ # go up the hierarchy of names
92
+ up = parent.parent
93
+ while up
94
+ full_name = up.child_name(@name)
95
+ @module = @store.modules_hash[full_name]
96
+ return @module if @module
97
+ up = up.parent
98
+ end
99
+
100
+ @name
101
+ end
102
+
103
+ ##
104
+ # Sets the store for this class or module and its contained code objects.
105
+
106
+ def store= store
107
+ super
108
+
109
+ @file = @store.add_file @file.full_name if @file
110
+ end
111
+
112
+ def to_s # :nodoc:
113
+ "extend #@name in: #{parent}"
114
+ end
115
+
116
+ end
117
+
@@ -18,7 +18,8 @@
18
18
  # Before option processing in +rdoc+, RDoc::Options will call ::setup_options
19
19
  # on the generator class with an RDoc::Options instance. The generator can
20
20
  # use RDoc::Options#option_parser to add command-line options to the +rdoc+
21
- # tool. See OptionParser for details on how to add options.
21
+ # tool. See RDoc::Options@Custom+Options for an example and see OptionParser
22
+ # for details on how to add options.
22
23
  #
23
24
  # You can extend the RDoc::Options instance with additional accessors for your
24
25
  # generator.
@@ -26,12 +27,16 @@
26
27
  # == Generator Instantiation
27
28
  #
28
29
  # After parsing, RDoc::RDoc will instantiate a generator by calling
29
- # #initialize with an RDoc::Options instance.
30
+ # #initialize with an RDoc::Store instance and an RDoc::Options instance.
30
31
  #
31
- # RDoc will then call #generate on the generator instance and pass in an Array
32
- # of RDoc::TopLevel instances, each representing a parsed file. You can use
33
- # the various class methods on RDoc::TopLevel and in the RDoc::CodeObject tree
34
- # to create your desired output format.
32
+ # The RDoc::Store instance holds documentation for parsed source code. In
33
+ # RDoc 3 and earlier the RDoc::TopLevel class held this data. When upgrading
34
+ # a generator from RDoc 3 and earlier you should only need to replace
35
+ # RDoc::TopLevel with the store instance.
36
+ #
37
+ # RDoc will then call #generate on the generator instance. You can use the
38
+ # various methods on RDoc::Store and in the RDoc::CodeObject tree to create
39
+ # your desired output format.
35
40
 
36
41
  module RDoc::Generator
37
42
 
@@ -73,6 +73,12 @@ class RDoc::Generator::Darkfish
73
73
 
74
74
  DESCRIPTION = 'HTML generator, written by Michael Granger'
75
75
 
76
+ ##
77
+ # The relative path to style sheets and javascript. By default this is set
78
+ # the same as the rel_prefix.
79
+
80
+ attr_accessor :asset_rel_path
81
+
76
82
  ##
77
83
  # The path to generate files into, combined with <tt>--op</tt> from the
78
84
  # options for a full path.
@@ -80,27 +86,75 @@ class RDoc::Generator::Darkfish
80
86
  attr_reader :base_dir
81
87
 
82
88
  ##
83
- # Initialize a few instance variables before we start
89
+ # Classes and modules to be used by this generator, not necessarily
90
+ # displayed. See also #modsort
84
91
 
85
- def initialize options
86
- @options = options
92
+ attr_reader :classes
87
93
 
88
- @template_dir = Pathname.new options.template_dir
89
- @template_cache = {}
94
+ ##
95
+ # No files will be written when dry_run is true.
96
+
97
+ attr_accessor :dry_run
90
98
 
91
- @files = nil
92
- @classes = nil
99
+ ##
100
+ # When false the generate methods return a String instead of writing to a
101
+ # file. The default is true.
93
102
 
94
- @base_dir = Pathname.pwd.expand_path
103
+ attr_accessor :file_output
95
104
 
96
- @json_index = RDoc::Generator::JsonIndex.new self, options
97
- end
105
+ ##
106
+ # Files to be displayed by this generator
107
+
108
+ attr_reader :files
109
+
110
+ ##
111
+ # The JSON index generator for this Darkfish generator
112
+
113
+ attr_reader :json_index
114
+
115
+ ##
116
+ # Methods to be displayed by this generator
117
+
118
+ attr_reader :methods
119
+
120
+ ##
121
+ # Sorted list of classes and modules to be displayed by this generator
122
+
123
+ attr_reader :modsort
124
+
125
+ ##
126
+ # The RDoc::Store that is the source of the generated content
127
+
128
+ attr_reader :store
98
129
 
99
130
  ##
100
131
  # The output directory
101
132
 
102
133
  attr_reader :outputdir
103
134
 
135
+ ##
136
+ # Initialize a few instance variables before we start
137
+
138
+ def initialize store, options
139
+ @store = store
140
+ @options = options
141
+
142
+ @asset_rel_path = ''
143
+ @base_dir = Pathname.pwd.expand_path
144
+ @dry_run = @options.dry_run
145
+ @file_output = true
146
+ @template_dir = Pathname.new options.template_dir
147
+ @template_cache = {}
148
+
149
+ @classes = nil
150
+ @context = nil
151
+ @files = nil
152
+ @methods = nil
153
+ @modsort = nil
154
+
155
+ @json_index = RDoc::Generator::JsonIndex.new self, options
156
+ end
157
+
104
158
  ##
105
159
  # Output progress information if debugging is enabled
106
160
 
@@ -139,7 +193,7 @@ class RDoc::Generator::Darkfish
139
193
 
140
194
  def write_style_sheet
141
195
  debug_msg "Copying static files"
142
- options = { :verbose => $DEBUG_RDOC, :noop => @options.dry_run }
196
+ options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
143
197
 
144
198
  FileUtils.cp @template_dir + 'rdoc.css', '.', options
145
199
 
@@ -147,7 +201,7 @@ class RDoc::Generator::Darkfish
147
201
  next if File.directory? path
148
202
  next if File.basename(path) =~ /^\./
149
203
 
150
- dst = Pathname.new(path).relative_path_from @template_dir
204
+ dst = Pathname.new(path).relative_path_from @template_dir
151
205
 
152
206
  # I suck at glob
153
207
  dst_dir = dst.dirname
@@ -161,21 +215,15 @@ class RDoc::Generator::Darkfish
161
215
  # Build the initial indices and output objects based on an array of TopLevel
162
216
  # objects containing the extracted information.
163
217
 
164
- def generate top_levels
165
- @outputdir = Pathname.new(@options.op_dir).expand_path(@base_dir)
218
+ def generate
219
+ setup
166
220
 
167
- @files = top_levels.sort
168
- @classes = RDoc::TopLevel.all_classes_and_modules.sort
169
- @methods = @classes.map { |m| m.method_list }.flatten.sort
170
- @modsort = get_sorted_module_list(@classes)
171
-
172
- # Now actually write the output
173
221
  write_style_sheet
174
222
  generate_index
175
223
  generate_class_files
176
224
  generate_file_files
177
225
  generate_table_of_contents
178
- @json_index.generate top_levels
226
+ @json_index.generate
179
227
 
180
228
  copy_static
181
229
 
@@ -187,15 +235,13 @@ class RDoc::Generator::Darkfish
187
235
  raise
188
236
  end
189
237
 
190
- protected
191
-
192
238
  ##
193
239
  # Copies static files from the static_path into the output directory
194
240
 
195
241
  def copy_static
196
242
  return if @options.static_path.empty?
197
243
 
198
- fu_options = { :verbose => $DEBUG_RDOC, :noop => @options.dry_run }
244
+ fu_options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
199
245
 
200
246
  @options.static_path.each do |path|
201
247
  unless File.directory? path then
@@ -221,38 +267,31 @@ class RDoc::Generator::Darkfish
221
267
  # Return a list of the documented modules sorted by salience first, then
222
268
  # by name.
223
269
 
224
- def get_sorted_module_list(classes)
225
- nscounts = classes.inject({}) do |counthash, klass|
226
- top_level = klass.full_name.gsub(/::.*/, '')
227
- counthash[top_level] ||= 0
228
- counthash[top_level] += 1
229
-
230
- counthash
231
- end
232
-
233
- # Sort based on how often the top level namespace occurs, and then on the
234
- # name of the module -- this works for projects that put their stuff into
235
- # a namespace, of course, but doesn't hurt if they don't.
236
- classes.sort_by do |klass|
237
- top_level = klass.full_name.gsub( /::.*/, '' )
238
- [nscounts[top_level] * -1, klass.full_name]
239
- end.select do |klass|
270
+ def get_sorted_module_list classes
271
+ classes.select do |klass|
240
272
  klass.display?
241
- end
273
+ end.sort
242
274
  end
243
275
 
244
276
  ##
245
277
  # Generate an index page which lists all the classes which are documented.
246
278
 
247
279
  def generate_index
280
+ setup
281
+
248
282
  template_file = @template_dir + 'index.rhtml'
249
283
  return unless template_file.exist?
250
284
 
251
285
  debug_msg "Rendering the index page..."
252
286
 
253
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
291
+
254
292
  # suppress 1.9.3 warning
255
- rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
293
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
294
+
256
295
  @title = @options.title
257
296
 
258
297
  render_template template_file, out_file do |io| binding end
@@ -264,10 +303,38 @@ class RDoc::Generator::Darkfish
264
303
  raise error
265
304
  end
266
305
 
306
+ ##
307
+ # Generates a class file for +klass+
308
+
309
+ def generate_class klass, template_file = nil
310
+ setup
311
+
312
+ current = klass
313
+
314
+ template_file ||= @template_dir + 'class.rhtml'
315
+
316
+ debug_msg " working on %s (%s)" % [klass.full_name, klass.path]
317
+ out_file = @outputdir + klass.path
318
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
319
+ search_index_rel_prefix = rel_prefix
320
+ search_index_rel_prefix += @asset_rel_path if @file_output
321
+
322
+ # suppress 1.9.3 warning
323
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
324
+ svninfo = svninfo = get_svninfo(current)
325
+
326
+ @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
327
+
328
+ debug_msg " rendering #{out_file}"
329
+ render_template template_file, out_file do |io| binding end
330
+ end
331
+
267
332
  ##
268
333
  # Generate a documentation file for each class and module
269
334
 
270
335
  def generate_class_files
336
+ setup
337
+
271
338
  template_file = @template_dir + 'class.rhtml'
272
339
  template_file = @template_dir + 'classpage.rhtml' unless
273
340
  template_file.exist?
@@ -278,15 +345,8 @@ class RDoc::Generator::Darkfish
278
345
 
279
346
  @classes.each do |klass|
280
347
  current = klass
281
- debug_msg " working on %s (%s)" % [klass.full_name, klass.path]
282
- out_file = @outputdir + klass.path
283
- # suppress 1.9.3 warning
284
- rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
285
- svninfo = svninfo = self.get_svninfo(klass)
286
- @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
287
348
 
288
- debug_msg " rendering #{out_file}"
289
- render_template template_file, out_file do |io| binding end
349
+ generate_class klass, template_file
290
350
  end
291
351
  rescue => e
292
352
  error = RDoc::Error.new \
@@ -300,6 +360,8 @@ class RDoc::Generator::Darkfish
300
360
  # Generate a documentation file for each file
301
361
 
302
362
  def generate_file_files
363
+ setup
364
+
303
365
  page_file = @template_dir + 'page.rhtml'
304
366
  fileinfo_file = @template_dir + 'fileinfo.rhtml'
305
367
 
@@ -308,17 +370,30 @@ class RDoc::Generator::Darkfish
308
370
  page_file.exist? or fileinfo_file.exist?
309
371
 
310
372
  return unless
311
- page_file.exist? or fileinfo_file.exist? or template_file.exist?
373
+ page_file.exist? or fileinfo_file.exist? or filepage_file.exist?
374
+
312
375
  debug_msg "Generating file documentation in #{@outputdir}"
313
376
 
314
377
  out_file = nil
378
+ current = nil
315
379
 
316
380
  @files.each do |file|
381
+ current = file
382
+
383
+ if file.text? and page_file.exist? then
384
+ generate_page file
385
+ next
386
+ end
387
+
317
388
  template_file = nil
318
389
  out_file = @outputdir + file.path
319
390
  debug_msg " working on %s (%s)" % [file.full_name, out_file]
391
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
392
+ search_index_rel_prefix = rel_prefix
393
+ search_index_rel_prefix += @asset_rel_path if @file_output
394
+
320
395
  # suppress 1.9.3 warning
321
- rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
396
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
322
397
 
323
398
  unless filepage_file then
324
399
  if file.text? then
@@ -345,18 +420,105 @@ class RDoc::Generator::Darkfish
345
420
  raise error
346
421
  end
347
422
 
423
+ ##
424
+ # Generate a page file for +file+
425
+
426
+ def generate_page file
427
+ setup
428
+
429
+ template_file = @template_dir + 'page.rhtml'
430
+
431
+ out_file = @outputdir + file.path
432
+ debug_msg " working on %s (%s)" % [file.full_name, out_file]
433
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
434
+ search_index_rel_prefix = rel_prefix
435
+ search_index_rel_prefix += @asset_rel_path if @file_output
436
+
437
+ # suppress 1.9.3 warning
438
+ current = current = file
439
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
440
+
441
+ @title = "#{file.page_name} - #{@options.title}"
442
+
443
+ debug_msg " rendering #{out_file}"
444
+ render_template template_file, out_file do |io| binding end
445
+ end
446
+
447
+ ##
448
+ # Generates the 404 page for the RDoc servlet
449
+
450
+ def generate_servlet_not_found path
451
+ setup
452
+
453
+ template_file = @template_dir + 'servlet_not_found.rhtml'
454
+ return unless template_file.exist?
455
+
456
+ debug_msg "Rendering the servlet root page..."
457
+
458
+ rel_prefix = rel_prefix = ''
459
+ search_index_rel_prefix = rel_prefix
460
+ search_index_rel_prefix += @asset_rel_path if @file_output
461
+
462
+ # suppress 1.9.3 warning
463
+ asset_rel_prefix = asset_rel_prefix = ''
464
+
465
+ @title = 'Not Found'
466
+
467
+ render_template template_file do |io| binding end
468
+ rescue => e
469
+ error = RDoc::Error.new \
470
+ "error generating servlet_not_found: #{e.message} (#{e.class})"
471
+ error.set_backtrace e.backtrace
472
+
473
+ raise error
474
+ end
475
+
476
+ ##
477
+ # Generates the servlet root page for the RDoc servlet
478
+
479
+ def generate_servlet_root installed
480
+ setup
481
+
482
+ template_file = @template_dir + 'servlet_root.rhtml'
483
+ return unless template_file.exist?
484
+
485
+ debug_msg 'Rendering the servlet root page...'
486
+
487
+ rel_prefix = '.'
488
+ asset_rel_prefix = rel_prefix
489
+ search_index_rel_prefix = asset_rel_prefix
490
+ search_index_rel_prefix += @asset_rel_path if @file_output
491
+
492
+ @title = 'Local RDoc Documentation'
493
+
494
+ render_template template_file do |io| binding end
495
+ rescue => e
496
+ error = RDoc::Error.new \
497
+ "error generating servlet_root: #{e.message} (#{e.class})"
498
+ error.set_backtrace e.backtrace
499
+
500
+ raise error
501
+ end
502
+
348
503
  ##
349
504
  # Generate an index page which lists all the classes which are documented.
350
505
 
351
506
  def generate_table_of_contents
507
+ setup
508
+
352
509
  template_file = @template_dir + 'table_of_contents.rhtml'
353
510
  return unless template_file.exist?
354
511
 
355
512
  debug_msg "Rendering the Table of Contents..."
356
513
 
357
514
  out_file = @outputdir + 'table_of_contents.html'
515
+ rel_prefix = @outputdir.relative_path_from out_file.dirname
516
+ search_index_rel_prefix = rel_prefix
517
+ search_index_rel_prefix += @asset_rel_path if @file_output
518
+
358
519
  # suppress 1.9.3 warning
359
- rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
520
+ asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
521
+
360
522
  @title = "Table of Contents - #{@options.title}"
361
523
 
362
524
  render_template template_file, out_file do |io| binding end
@@ -368,6 +530,22 @@ class RDoc::Generator::Darkfish
368
530
  raise error
369
531
  end
370
532
 
533
+ ##
534
+ # Prepares for generation of output from the current directory
535
+
536
+ def setup
537
+ return if instance_variable_defined? :@outputdir
538
+
539
+ @outputdir = Pathname.new(@options.op_dir).expand_path @base_dir
540
+
541
+ return unless @store
542
+
543
+ @classes = @store.all_classes_and_modules.sort
544
+ @files = @store.all_files.sort
545
+ @methods = @classes.map { |m| m.method_list }.flatten.sort
546
+ @modsort = get_sorted_module_list @classes
547
+ end
548
+
371
549
  ##
372
550
  # Return a string describing the amount of time in the given number of
373
551
  # seconds in terms a human can understand easily.
@@ -453,7 +631,7 @@ class RDoc::Generator::Darkfish
453
631
  def render file_name
454
632
  template_file = @template_dir + file_name
455
633
 
456
- template = template_for template_file, false, ERB
634
+ template = template_for template_file, false, RDoc::ERBPartial
457
635
 
458
636
  template.filename = template_file.to_s
459
637
 
@@ -468,10 +646,13 @@ class RDoc::Generator::Darkfish
468
646
  #
469
647
  # An io will be yielded which must be captured by binding in the caller.
470
648
 
471
- def render_template template_file, out_file # :yield: io
472
- template = template_for template_file
649
+ def render_template template_file, out_file = nil # :yield: io
650
+ io_output = out_file && !@dry_run && @file_output
651
+ erb_klass = io_output ? RDoc::ERBIO : ERB
652
+
653
+ template = template_for template_file, true, erb_klass
473
654
 
474
- unless @options.dry_run then
655
+ if io_output then
475
656
  debug_msg "Outputting to %s" % [out_file.expand_path]
476
657
 
477
658
  out_file.dirname.mkpath
@@ -489,7 +670,9 @@ class RDoc::Generator::Darkfish
489
670
 
490
671
  debug_msg " would have written %d characters to %s" % [
491
672
  output.length, out_file.expand_path
492
- ]
673
+ ] if @dry_run
674
+
675
+ output
493
676
  end
494
677
  end
495
678
 
@@ -510,20 +693,25 @@ class RDoc::Generator::Darkfish
510
693
  ##
511
694
  # Retrieves a cache template for +file+, if present, or fills the cache.
512
695
 
513
- def template_for file, page = true, klass = nil
696
+ def template_for file, page = true, klass = ERB
514
697
  template = @template_cache[file]
515
698
 
516
699
  return template if template
517
700
 
518
- klass = @options.dry_run ? ERB : RDoc::ERBIO unless klass
519
-
520
701
  template = if page then
521
702
  assemble_template file
522
703
  else
523
704
  file.read
524
705
  end
525
706
 
526
- template = klass.new template, nil, '<>'
707
+ erbout = if page then
708
+ 'io'
709
+ else
710
+ file_var = File.basename(file).sub(/\..*/, '')
711
+ "_erbout_#{file_var}"
712
+ end
713
+
714
+ template = klass.new template, nil, '<>', erbout
527
715
  @template_cache[file] = template
528
716
  template
529
717
  end