rdoc 2.3.0 → 2.4.0

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 (81) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +14 -0
  3. data/History.txt +27 -0
  4. data/Manifest.txt +29 -9
  5. data/Rakefile +2 -0
  6. data/bin/rdoc +13 -2
  7. data/lib/rdoc.rb +11 -3
  8. data/lib/rdoc/alias.rb +54 -0
  9. data/lib/rdoc/anon_class.rb +10 -0
  10. data/lib/rdoc/any_method.rb +190 -0
  11. data/lib/rdoc/attr.rb +79 -0
  12. data/lib/rdoc/cache.rb +11 -2
  13. data/lib/rdoc/class_module.rb +87 -0
  14. data/lib/rdoc/code_object.rb +152 -0
  15. data/lib/rdoc/code_objects.rb +18 -1118
  16. data/lib/rdoc/constant.rb +36 -0
  17. data/lib/rdoc/context.rb +712 -0
  18. data/lib/rdoc/diagram.rb +8 -8
  19. data/lib/rdoc/generator.rb +3 -1140
  20. data/lib/rdoc/generator/darkfish.rb +107 -133
  21. data/lib/rdoc/generator/markup.rb +194 -0
  22. data/lib/rdoc/generator/ri.rb +4 -2
  23. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +92 -113
  24. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +33 -35
  25. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -15
  26. data/lib/rdoc/ghost_method.rb +8 -0
  27. data/lib/rdoc/include.rb +39 -0
  28. data/lib/rdoc/markup/attribute_manager.rb +46 -0
  29. data/lib/rdoc/markup/formatter.rb +11 -0
  30. data/lib/rdoc/markup/fragments.rb +42 -2
  31. data/lib/rdoc/markup/inline.rb +29 -4
  32. data/lib/rdoc/markup/lines.rb +4 -0
  33. data/lib/rdoc/markup/preprocess.rb +4 -0
  34. data/lib/rdoc/markup/to_flow.rb +27 -1
  35. data/lib/rdoc/markup/to_html.rb +33 -33
  36. data/lib/rdoc/markup/to_html_crossref.rb +4 -11
  37. data/lib/rdoc/markup/to_latex.rb +31 -31
  38. data/lib/rdoc/markup/to_test.rb +3 -0
  39. data/lib/rdoc/markup/to_texinfo.rb +18 -14
  40. data/lib/rdoc/meta_method.rb +8 -0
  41. data/lib/rdoc/normal_class.rb +18 -0
  42. data/lib/rdoc/normal_module.rb +34 -0
  43. data/lib/rdoc/options.rb +26 -159
  44. data/lib/rdoc/parser/c.rb +16 -8
  45. data/lib/rdoc/parser/ruby.rb +16 -10
  46. data/lib/rdoc/parser/simple.rb +1 -1
  47. data/lib/rdoc/rdoc.rb +50 -34
  48. data/lib/rdoc/require.rb +32 -0
  49. data/lib/rdoc/ri/descriptions.rb +1 -1
  50. data/lib/rdoc/ri/driver.rb +4 -4
  51. data/lib/rdoc/ri/formatter.rb +70 -32
  52. data/lib/rdoc/single_class.rb +8 -0
  53. data/lib/rdoc/top_level.rb +232 -0
  54. data/test/test_rdoc_any_method.rb +10 -0
  55. data/test/test_rdoc_code_object.rb +80 -0
  56. data/test/test_rdoc_constant.rb +15 -0
  57. data/test/test_rdoc_context.rb +250 -0
  58. data/test/test_rdoc_include.rb +17 -0
  59. data/test/test_rdoc_markup.rb +13 -2
  60. data/test/test_rdoc_markup_to_html.rb +22 -0
  61. data/test/test_rdoc_markup_to_html_crossref.rb +50 -115
  62. data/test/test_rdoc_normal_module.rb +26 -0
  63. data/test/test_rdoc_parser_c.rb +33 -0
  64. data/test/test_rdoc_parser_ruby.rb +54 -36
  65. data/test/test_rdoc_require.rb +25 -0
  66. data/test/test_rdoc_ri_default_display.rb +2 -1
  67. data/test/test_rdoc_ri_html_formatter.rb +141 -0
  68. data/test/test_rdoc_top_level.rb +85 -0
  69. data/test/xref_data.rb +46 -0
  70. data/test/xref_test_case.rb +48 -0
  71. metadata +42 -13
  72. metadata.gz.sig +0 -0
  73. data/lib/rdoc/generator/html.rb +0 -456
  74. data/lib/rdoc/generator/html/common.rb +0 -24
  75. data/lib/rdoc/generator/html/html.rb +0 -769
  76. data/lib/rdoc/generator/html/one_page_html.rb +0 -122
  77. data/lib/rdoc/generator/xml.rb +0 -124
  78. data/lib/rdoc/generator/xml/rdf.rb +0 -113
  79. data/lib/rdoc/generator/xml/xml.rb +0 -123
  80. data/lib/rdoc/parser/f95.rb +0 -1835
  81. data/lib/rdoc/template.rb +0 -68
@@ -10,7 +10,7 @@ module RDoc
10
10
 
11
11
  ##
12
12
  # Draw a set of diagrams representing the modules and classes in the
13
- # system. We draw one diagram for each file, and one for each toplevel
13
+ # system. We draw one diagram for each file, and one for each top-level
14
14
  # class or module. This means there will be overlap. However, it also
15
15
  # means that you'll get better context for objects.
16
16
  #
@@ -71,9 +71,9 @@ module RDoc
71
71
  'fontsize' => 8)
72
72
 
73
73
  i.modules.each do |mod|
74
- draw_module(mod, graph, true, i.file_relative_name)
74
+ draw_module(mod, graph, true, i.relative_name)
75
75
  end
76
- add_classes(i, graph, i.file_relative_name)
76
+ add_classes(i, graph, i.relative_name)
77
77
 
78
78
  i.diagram = convert_to_png("f_#{file_count}", graph)
79
79
 
@@ -122,8 +122,8 @@ module RDoc
122
122
  return name
123
123
  end
124
124
 
125
- def draw_module(mod, graph, toplevel = false, file = nil)
126
- return if @done_modules[mod.full_name] and not toplevel
125
+ def draw_module(mod, graph, top_level = false, file = nil)
126
+ return if @done_modules[mod.full_name] and not top_level
127
127
 
128
128
  @counter += 1
129
129
  url = mod.http_url("classes")
@@ -133,7 +133,7 @@ module RDoc
133
133
  'color' => 'blue',
134
134
  'style' => 'filled',
135
135
  'URL' => %{"#{url}"},
136
- 'fillcolor' => toplevel ? 'palegreen1' : 'palegreen3')
136
+ 'fillcolor' => top_level ? 'palegreen1' : 'palegreen3')
137
137
 
138
138
  @done_modules[mod.full_name] = m
139
139
  add_classes(mod, m, file)
@@ -183,7 +183,7 @@ module RDoc
183
183
  end
184
184
 
185
185
  container.classes.each_with_index do |cl, cl_index|
186
- last_file = cl.in_files[-1].file_relative_name
186
+ last_file = cl.in_files[-1].relative_name
187
187
 
188
188
  if use_fileboxes && !files.include?(last_file)
189
189
  @counter += 1
@@ -203,7 +203,7 @@ module RDoc
203
203
  if use_fileboxes && cl.in_files.length > 1
204
204
  label << '\n[' +
205
205
  cl.in_files.collect {|i|
206
- i.file_relative_name
206
+ i.relative_name
207
207
  }.sort.join( '\n' ) +
208
208
  ']'
209
209
  end
@@ -1,1145 +1,8 @@
1
- require 'cgi'
2
1
  require 'rdoc'
3
- require 'rdoc/options'
4
- require 'rdoc/markup/to_html_crossref'
5
- require 'rdoc/template'
6
- require 'rdoc/cache'
7
2
 
8
- module RDoc::Generator
9
-
10
- ##
11
- # Name of sub-directory that holds file descriptions
12
-
13
- FILE_DIR = "files"
14
-
15
- ##
16
- # Name of sub-directory that holds class descriptions
17
-
18
- CLASS_DIR = "classes"
19
-
20
- ##
21
- # Name of the RDoc CSS file
22
-
23
- CSS_NAME = "rdoc-style.css"
24
-
25
- ##
26
- # Build a hash of all items that can be cross-referenced. This is used when
27
- # we output required and included names: if the names appear in this hash,
28
- # we can generate an html cross reference to the appropriate description.
29
- # We also use this when parsing comment blocks: any decorated words matching
30
- # an entry in this list are hyperlinked.
31
-
32
- class AllReferences
33
- @@refs = {}
34
-
35
- def AllReferences::reset
36
- @@refs = {}
37
- end
38
-
39
- def AllReferences.add(name, html_class)
40
- @@refs[name] = html_class
41
- end
42
-
43
- def AllReferences.[](name)
44
- @@refs[name]
45
- end
46
-
47
- def AllReferences.keys
48
- @@refs.keys
49
- end
50
- end
51
-
52
- ##
53
- # Handle common markup tasks for the various Context subclasses
54
-
55
- module MarkUp
56
-
57
- ##
58
- # Convert a string in markup format into HTML.
59
-
60
- def markup(str, remove_para = false)
61
- return '' unless str
62
-
63
- # Convert leading comment markers to spaces, but only if all non-blank
64
- # lines have them
65
- if str =~ /^(?>\s*)[^\#]/ then
66
- content = str
67
- else
68
- content = str.gsub(/^\s*(#+)/) { $1.tr '#', ' ' }
69
- end
70
-
71
- res = formatter.convert content
72
-
73
- if remove_para then
74
- res.sub!(/^<p>/, '')
75
- res.sub!(/<\/p>$/, '')
76
- end
77
-
78
- res
79
- end
80
-
81
- ##
82
- # Qualify a stylesheet URL; if if +css_name+ does not begin with '/' or
83
- # 'http[s]://', prepend a prefix relative to +path+. Otherwise, return it
84
- # unmodified.
85
-
86
- def style_url(path, css_name=nil)
87
- # $stderr.puts "style_url( #{path.inspect}, #{css_name.inspect} )"
88
- css_name ||= CSS_NAME
89
- if %r{^(https?:/)?/} =~ css_name
90
- css_name
91
- else
92
- RDoc::Markup::ToHtml.gen_relative_url path, css_name
93
- end
94
- end
95
-
96
- ##
97
- # Build a webcvs URL with the given 'url' argument. URLs with a '%s' in them
98
- # get the file's path sprintfed into them; otherwise they're just catenated
99
- # together.
100
-
101
- def cvs_url(url, full_path)
102
- if /%s/ =~ url
103
- return sprintf( url, full_path )
104
- else
105
- return url + full_path
106
- end
107
- end
108
-
109
- end
110
-
111
- ##
112
- # A Context is built by the parser to represent a container: contexts hold
113
- # classes, modules, methods, require lists and include lists. ClassModule
114
- # and TopLevel are the context objects we process here
115
-
116
- class Context
117
-
118
- include MarkUp
119
-
120
- attr_reader :context
121
-
122
- ##
123
- # Generate:
124
- #
125
- # * a list of RDoc::Generator::File objects for each TopLevel object
126
- # * a list of RDoc::Generator::Class objects for each first level class or
127
- # module in the TopLevel objects
128
- # * a complete list of all hyperlinkable terms (file, class, module, and
129
- # method names)
130
-
131
- def self.build_indices(toplevels, options, template_cache = nil)
132
- files = []
133
- classes = []
134
- template_cache ||= RDoc::Cache.instance
135
-
136
- file_dir = if defined? options.generator::FILE_DIR then
137
- options.generator::FILE_DIR
138
- else
139
- RDoc::Generator::FILE_DIR
140
- end
141
-
142
- toplevels.each do |toplevel|
143
- files << RDoc::Generator::File.new(template_cache, toplevel, options,
144
- file_dir)
145
- end
146
-
147
- class_dir = if defined? options.generator::CLASS_DIR then
148
- options.generator::CLASS_DIR
149
- else
150
- RDoc::Generator::CLASS_DIR
151
- end
152
-
153
- RDoc::TopLevel.all_classes_and_modules.each do |cls|
154
- build_class_list(template_cache, classes, options, cls, files[0],
155
- class_dir)
156
- end
157
-
158
- return files, classes
159
- end
160
-
161
- def self.build_class_list(template_cache, classes, options, from, html_file, class_dir)
162
- classes << RDoc::Generator::Class.new(template_cache, from, html_file, class_dir, options)
163
-
164
- from.each_classmodule do |mod|
165
- build_class_list(template_cache, classes, options, mod, html_file, class_dir)
166
- end
167
- end
168
-
169
- def initialize(context, options)
170
- @context = context
171
- @options = options
172
-
173
- # HACK ugly
174
- @template = options.template_class
175
- end
176
-
177
- def formatter
178
- @formatter ||= @options.formatter ||
179
- RDoc::Markup::ToHtmlCrossref.new(path, self, @options.show_hash)
180
- end
181
-
182
- ##
183
- # convenience method to build a hyperlink
184
-
185
- def href(link, cls, name)
186
- %{<a href="#{link}" class="#{cls}">#{name}</a>} #"
187
- end
188
-
189
- ##
190
- # Returns a reference to outselves to be used as an href= the form depends
191
- # on whether we're all in one file or in multiple files
192
-
193
- def as_href(from_path)
194
- if @options.all_one_file
195
- "#" + path
196
- else
197
- RDoc::Markup::ToHtml.gen_relative_url from_path, path
198
- end
199
- end
200
-
201
- ##
202
- # Create a list of Method objects for each method in the corresponding
203
- # context object. If the @options.show_all variable is set (corresponding
204
- # to the <tt>--all</tt> option, we include all methods, otherwise just the
205
- # public ones.
206
-
207
- def collect_methods
208
- list = @context.method_list
209
-
210
- unless @options.show_all then
211
- list = list.select do |m|
212
- m.visibility == :public or
213
- m.visibility == :protected or
214
- m.force_documentation
215
- end
216
- end
217
-
218
- @methods = list.collect do |m|
219
- RDoc::Generator::Method.new m, self, @options
220
- end
221
- end
222
-
223
- ##
224
- # Build a summary list of all the methods in this context
225
-
226
- def build_method_summary_list(path_prefix = "")
227
- collect_methods unless @methods
228
-
229
- @methods.sort.map do |meth|
230
- {
231
- :name => CGI.escapeHTML(meth.name),
232
- :aref => "##{meth.aref}"
233
- }
234
- end
235
- end
236
-
237
- ##
238
- # Build a list of aliases for which we couldn't find a
239
- # corresponding method
240
-
241
- def build_alias_summary_list(section)
242
- @context.aliases.map do |al|
243
- next unless al.section == section
244
-
245
- res = {
246
- :old_name => al.old_name,
247
- :new_name => al.new_name,
248
- }
249
-
250
- if al.comment and not al.comment.empty? then
251
- res[:desc] = markup al.comment, true
252
- end
253
-
254
- res
255
- end.compact
256
- end
257
-
258
- ##
259
- # Build a list of constants
260
-
261
- def build_constants_summary_list(section)
262
- @context.constants.map do |co|
263
- next unless co.section == section
264
-
265
- res = {
266
- :name => co.name,
267
- :value => CGI.escapeHTML(co.value)
268
- }
269
-
270
- if co.comment and not co.comment.empty? then
271
- res[:desc] = markup co.comment, true
272
- end
273
-
274
- res
275
- end.compact
276
- end
277
-
278
- def build_requires_list(context)
279
- potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] }
280
- end
281
-
282
- def build_include_list(context)
283
- potentially_referenced_list(context.includes)
284
- end
285
-
286
- ##
287
- # Build a list from an array of Context items. Look up each in the
288
- # AllReferences hash: if we find a corresponding entry, we generate a
289
- # hyperlink to it, otherwise just output the name. However, some names
290
- # potentially need massaging. For example, you may require a Ruby file
291
- # without the .rb extension, but the file names we know about may have it.
292
- # To deal with this, we pass in a block which performs the massaging,
293
- # returning an array of alternative names to match
294
-
295
- def potentially_referenced_list(array)
296
- res = []
297
- array.each do |i|
298
- ref = AllReferences[i.name]
299
- # if !ref
300
- # container = @context.parent
301
- # while !ref && container
302
- # name = container.name + "::" + i.name
303
- # ref = AllReferences[name]
304
- # container = container.parent
305
- # end
306
- # end
307
-
308
- ref = @context.find_symbol(i.name)
309
- ref = ref.viewer if ref
310
-
311
- if !ref && block_given?
312
- possibles = yield(i.name)
313
- while !ref and !possibles.empty?
314
- ref = AllReferences[possibles.shift]
315
- end
316
- end
317
- h_name = CGI.escapeHTML(i.name)
318
- if ref and ref.document_self
319
- path = url(ref.path)
320
- res << { :name => h_name, :aref => path }
321
- else
322
- res << { :name => h_name }
323
- end
324
- end
325
- res
326
- end
327
-
328
- ##
329
- # Build an array of arrays of method details. The outer array has up
330
- # to six entries, public, private, and protected for both class
331
- # methods, the other for instance methods. The inner arrays contain
332
- # a hash for each method
333
-
334
- def build_method_detail_list(section)
335
- outer = []
336
-
337
- methods = @methods.sort.select do |m|
338
- m.document_self and m.section == section
339
- end
340
-
341
- for singleton in [true, false]
342
- for vis in [ :public, :protected, :private ]
343
- res = []
344
- methods.each do |m|
345
- next unless m.visibility == vis and m.singleton == singleton
346
-
347
- row = {}
348
-
349
- if m.call_seq then
350
- row[:callseq] = m.call_seq.gsub(/->/, '&rarr;')
351
- else
352
- row[:name] = CGI.escapeHTML(m.name)
353
- row[:params] = m.params
354
- end
355
-
356
- desc = m.description.strip
357
- row[:m_desc] = desc unless desc.empty?
358
- row[:aref] = m.aref
359
- row[:visibility] = m.visibility.to_s
360
-
361
- alias_names = []
362
-
363
- m.aliases.each do |other|
364
- if other.viewer then # won't be if the alias is private
365
- alias_names << {
366
- :name => other.name,
367
- :aref => other.viewer.as_href(path)
368
- }
369
- end
370
- end
371
-
372
- row[:aka] = alias_names unless alias_names.empty?
373
-
374
- if @options.inline_source then
375
- code = m.source_code
376
- row[:sourcecode] = code if code
377
- else
378
- code = m.src_url
379
- if code then
380
- row[:codeurl] = code
381
- row[:imgurl] = m.img_url
382
- end
383
- end
384
-
385
- res << row
386
- end
387
-
388
- if res.size > 0 then
389
- outer << {
390
- :type => vis.to_s.capitalize,
391
- :category => singleton ? "Class" : "Instance",
392
- :methods => res
393
- }
394
- end
395
- end
396
- end
397
-
398
- outer
399
- end
400
-
401
- ##
402
- # Build the structured list of classes and modules contained
403
- # in this context.
404
-
405
- def build_class_list(level, from, section, infile=nil)
406
- prefix = '&nbsp;&nbsp;::' * level;
407
- res = ''
408
-
409
- from.modules.sort.each do |mod|
410
- next unless mod.section == section
411
- next if infile && !mod.defined_in?(infile)
412
- if mod.document_self
413
- res <<
414
- prefix <<
415
- 'Module ' <<
416
- href(url(mod.viewer.path), 'link', mod.full_name) <<
417
- "<br />\n" <<
418
- build_class_list(level + 1, mod, section, infile)
419
- end
420
- end
421
-
422
- from.classes.sort.each do |cls|
423
- next unless cls.section == section
424
- next if infile and not cls.defined_in?(infile)
425
-
426
- if cls.document_self
427
- res <<
428
- prefix <<
429
- 'Class ' <<
430
- href(url(cls.viewer.path), 'link', cls.full_name) <<
431
- "<br />\n" <<
432
- build_class_list(level + 1, cls, section, infile)
433
- end
434
- end
435
-
436
- res
437
- end
438
-
439
- def url(target)
440
- RDoc::Markup::ToHtml.gen_relative_url path, target
441
- end
442
-
443
- def aref_to(target)
444
- if @options.all_one_file
445
- "#" + target
446
- else
447
- url(target)
448
- end
449
- end
450
-
451
- def document_self
452
- @context.document_self
453
- end
454
-
455
- def diagram_reference(diagram)
456
- res = diagram.gsub(/((?:src|href)=")(.*?)"/) {
457
- $1 + url($2) + '"'
458
- }
459
- res
460
- end
461
-
462
- ##
463
- # Find a symbol in ourselves or our parent
464
-
465
- def find_symbol(symbol, method=nil)
466
- res = @context.find_symbol(symbol, method)
467
- if res
468
- res = res.viewer
469
- end
470
- res
471
- end
472
-
473
- ##
474
- # create table of contents if we contain sections
475
-
476
- def add_table_of_sections
477
- toc = []
478
- @context.sections.each do |section|
479
- if section.title then
480
- toc << {
481
- :secname => section.title,
482
- :href => section.sequence
483
- }
484
- end
485
- end
486
-
487
- @values[:toc] = toc unless toc.empty?
488
- end
489
-
490
- end
491
-
492
- ##
493
- # Wrap a ClassModule context
494
-
495
- class Class < Context
496
-
497
- attr_reader :methods
498
- attr_reader :path
499
- attr_reader :values
500
-
501
- def initialize(template_cache, context, html_file, prefix, options)
502
- super context, options
503
-
504
- @template_cache = template_cache
505
- @html_file = html_file
506
- @html_class = self
507
- @is_module = context.module?
508
- @values = {}
509
-
510
- context.viewer = self
511
-
512
- if options.all_one_file
513
- @path = context.full_name
514
- else
515
- @path = http_url(context.full_name, prefix)
516
- end
517
-
518
- collect_methods
519
-
520
- AllReferences.add(name, self)
521
- end
522
-
523
- ##
524
- # Returns the relative file name to store this class in, which is also its
525
- # url
526
-
527
- def http_url(full_name, prefix)
528
- path = full_name.dup
529
-
530
- path.gsub!(/<<\s*(\w*)/, 'from-\1') if path['<<']
531
-
532
- path = [prefix] + path.split('::')
533
-
534
- ::File.join(*path.compact) + ".html"
535
- end
536
-
537
- def name
538
- @context.full_name
539
- end
540
-
541
- def parent_name
542
- @context.parent.full_name
543
- end
544
-
545
- def index_name
546
- name
547
- end
548
-
549
- def write_on(f, file_list, class_list, method_list, overrides = {})
550
- value_hash
551
-
552
- @values[:file_list] = file_list
553
- @values[:class_list] = class_list
554
- @values[:method_list] = method_list
555
-
556
- @values.update overrides
557
-
558
- template_page = @template_cache.cache(@template) do
559
- RDoc::TemplatePage.new(@template::BODY,
560
- @template::CLASS_PAGE,
561
- @template::METHOD_LIST)
562
- end
563
- template_page.write_html_on(f, @values)
564
- end
565
-
566
- def value_hash
567
- class_attribute_values
568
- add_table_of_sections
569
-
570
- @values[:charset] = @options.charset
571
- @values[:style_url] = style_url(path, @options.css)
572
-
573
- d = markup(@context.comment)
574
- @values[:description] = d unless d.empty?
575
-
576
- ml = build_method_summary_list @path
577
- @values[:methods] = ml unless ml.empty?
578
-
579
- il = build_include_list @context
580
- @values[:includes] = il unless il.empty?
581
-
582
- @values[:sections] = @context.sections.map do |section|
583
- secdata = {
584
- :sectitle => section.title,
585
- :secsequence => section.sequence,
586
- :seccomment => markup(section.comment),
587
- }
588
-
589
- al = build_alias_summary_list section
590
- secdata[:aliases] = al unless al.empty?
591
-
592
- co = build_constants_summary_list section
593
- secdata[:constants] = co unless co.empty?
594
-
595
- al = build_attribute_list section
596
- secdata[:attributes] = al unless al.empty?
597
-
598
- cl = build_class_list 0, @context, section
599
- secdata[:classlist] = cl unless cl.empty?
600
-
601
- mdl = build_method_detail_list section
602
- secdata[:method_list] = mdl unless mdl.empty?
603
-
604
- secdata
605
- end
606
-
607
- @values
608
- end
609
-
610
- def build_attribute_list(section)
611
- @context.attributes.sort.map do |att|
612
- next unless att.section == section
613
-
614
- if att.visibility == :public or att.visibility == :protected or
615
- @options.show_all then
616
-
617
- entry = {
618
- :name => CGI.escapeHTML(att.name),
619
- :rw => att.rw,
620
- :a_desc => markup(att.comment, true)
621
- }
622
-
623
- unless att.visibility == :public or att.visibility == :protected then
624
- entry[:rw] << "-"
625
- end
626
-
627
- entry
628
- end
629
- end.compact
630
- end
631
-
632
- def class_attribute_values
633
- h_name = CGI.escapeHTML(name)
634
-
635
- @values[:href] = @path
636
- @values[:classmod] = @is_module ? "Module" : "Class"
637
- @values[:title] = "#{@values['classmod']}: #{h_name} [#{@options.title}]"
638
-
639
- c = @context
640
- c = c.parent while c and not c.diagram
641
-
642
- if c and c.diagram then
643
- @values[:diagram] = diagram_reference(c.diagram)
644
- end
645
-
646
- @values[:full_name] = h_name
647
-
648
- if not @context.module? and @context.superclass then
649
- parent_class = @context.superclass
650
- @values[:parent] = CGI.escapeHTML(parent_class)
651
-
652
- if parent_name
653
- lookup = parent_name + "::" + parent_class
654
- else
655
- lookup = parent_class
656
- end
657
-
658
- parent_url = AllReferences[lookup] || AllReferences[parent_class]
659
-
660
- if parent_url and parent_url.document_self
661
- @values[:par_url] = aref_to(parent_url.path)
662
- end
663
- end
664
-
665
- files = []
666
- @context.in_files.each do |f|
667
- res = {}
668
- full_path = CGI.escapeHTML(f.file_absolute_name)
669
-
670
- res[:full_path] = full_path
671
- res[:full_path_url] = aref_to(f.viewer.path) if f.document_self
672
-
673
- if @options.webcvs
674
- res[:cvsurl] = cvs_url( @options.webcvs, full_path )
675
- end
676
-
677
- files << res
678
- end
679
-
680
- @values[:infiles] = files
681
- end
682
-
683
- def <=>(other)
684
- self.name <=> other.name
685
- end
686
-
687
- def inspect
688
- "#<#{self.class} name: #{name} path: #{@path}>"
689
- end
690
-
691
- def pretty_print(q)
692
- q.group 1, "#<#{self.class} ", '>' do
693
- q.text 'name: '
694
- q.pp name
695
- q.text ','
696
- q.breakable
697
-
698
- q.text 'path: '
699
- q.pp @path
700
- q.text ','
701
- q.breakable
702
-
703
- q.text 'values: '
704
- q.pp @values
705
- q.text ','
706
- q.breakable
707
-
708
- q.text 'methods: '
709
- q.pp @methods
710
- end
711
- end
712
-
713
- end
714
-
715
- ##
716
- # Handles the mapping of a file's information to HTML. In reality, a file
717
- # corresponds to a +TopLevel+ object, containing modules, classes, and
718
- # top-level methods. In theory it _could_ contain attributes and aliases,
719
- # but we ignore these for now.
720
-
721
- class File < Context
722
-
723
- attr_reader :path
724
- attr_reader :name
725
- attr_reader :values
726
-
727
- def initialize(template_cache, context, options, file_dir)
728
- super context, options
729
-
730
- @values = {}
731
- @template_cache = template_cache
732
-
733
- if options.all_one_file
734
- @path = filename_to_label
735
- else
736
- @path = http_url(file_dir)
737
- end
738
-
739
- @name = @context.file_relative_name
740
-
741
- collect_methods
742
- AllReferences.add(name, self)
743
- context.viewer = self
744
- end
745
-
746
- def http_url(file_dir)
747
- path = [file_dir, "#{@context.file_relative_name.tr '.', '_'}.html"]
748
-
749
- ::File.join path.compact
750
- end
751
-
752
- def filename_to_label
753
- @context.file_relative_name.gsub(/%|\/|\?|\#/) do
754
- ('%%%x' % $&[0]).unpack('C')
755
- end
756
- end
757
-
758
- def index_name
759
- name
760
- end
761
-
762
- def parent_name
763
- nil
764
- end
765
-
766
- def value_hash
767
- file_attribute_values
768
- add_table_of_sections
769
-
770
- @values[:charset] = @options.charset
771
- @values[:href] = path
772
- @values[:parser] = @context.parser
773
- @values[:style_url] = style_url(path, @options.css)
774
-
775
- if @context.comment
776
- d = markup(@context.comment)
777
- @values[:description] = d if d.size > 0
778
- end
779
-
780
- ml = build_method_summary_list
781
- @values[:methods] = ml unless ml.empty?
782
-
783
- il = build_include_list(@context)
784
- @values[:includes] = il unless il.empty?
785
-
786
- rl = build_requires_list(@context)
787
- @values[:requires] = rl unless rl.empty?
788
-
789
- file_context = @context unless @options.promiscuous
790
-
791
- @values[:sections] = @context.sections.map do |section|
792
- secdata = {
793
- :sectitle => section.title,
794
- :secsequence => section.sequence,
795
- :seccomment => markup(section.comment)
796
- }
797
-
798
- cl = build_class_list(0, @context, section, file_context)
799
- secdata[:classlist] = cl unless cl.empty?
800
-
801
- mdl = build_method_detail_list(section)
802
- secdata[:method_list] = mdl unless mdl.empty?
803
-
804
- al = build_alias_summary_list(section)
805
- secdata[:aliases] = al unless al.empty?
806
-
807
- co = build_constants_summary_list(section)
808
- secdata[:constants] = co unless co.empty?
809
-
810
- secdata
811
- end
812
-
813
- @values
814
- end
815
-
816
- def write_on(f, file_list, class_list, method_list, overrides = {})
817
- value_hash
818
-
819
- @values[:file_list] = file_list
820
- @values[:class_list] = class_list
821
- @values[:method_list] = method_list
822
-
823
- @values.update overrides
824
-
825
- template_page = @template_cache.cache(@template) do
826
- RDoc::TemplatePage.new(@template::BODY,
827
- @template::FILE_PAGE,
828
- @template::METHOD_LIST)
829
- end
830
- template_page.write_html_on(f, @values)
831
- end
832
-
833
- def file_attribute_values
834
- full_path = @context.file_absolute_name
835
- short_name = ::File.basename full_path
836
-
837
- @values[:title] = CGI.escapeHTML("File: #{short_name} [#{@options.title}]")
838
-
839
- if @context.diagram then
840
- @values[:diagram] = diagram_reference(@context.diagram)
841
- end
842
-
843
- @values[:short_name] = CGI.escapeHTML(short_name)
844
- @values[:full_path] = CGI.escapeHTML(full_path)
845
- @values[:dtm_modified] = @context.file_stat.mtime.to_s
846
-
847
- if @options.webcvs then
848
- @values[:cvsurl] = cvs_url @options.webcvs, @values[:full_path]
849
- end
850
- end
851
-
852
- def <=>(other)
853
- self.name <=> other.name
854
- end
855
-
856
- def inspect
857
- "#<#{self.class} name: #{@name} path: #{@path}>"
858
- end
859
-
860
- def pretty_print(q)
861
- q.group 1, "#<#{self.class} ", '>' do
862
- q.text 'name: '
863
- q.pp @name
864
- q.text ','
865
- q.breakable
866
-
867
- q.text 'path: '
868
- q.pp @path
869
- q.text ','
870
- q.breakable
871
-
872
- q.text 'values: '
873
- q.pp @values
874
- end
875
- end
876
-
877
- end
878
-
879
- class Method
880
-
881
- include MarkUp
882
-
883
- attr_reader :context
884
- attr_reader :src_url
885
- attr_reader :img_url
886
- attr_reader :source_code
887
-
888
- def self.all_methods
889
- @@all_methods
890
- end
891
-
892
- def self.reset
893
- @@all_methods = []
894
- @@seq = "M000000"
895
- end
896
-
897
- # Initialize the class variables.
898
- self.reset
899
-
900
- def initialize(context, html_class, options)
901
- # TODO: rethink the class hierarchy here...
902
- @context = context
903
- @html_class = html_class
904
- @options = options
905
-
906
- @@seq = @@seq.succ
907
- @seq = @@seq
908
-
909
- # HACK ugly
910
- @template = options.template_class
911
-
912
- @@all_methods << self
913
-
914
- context.viewer = self
915
-
916
- if ts = @context.token_stream then
917
- @source_code = markup_code ts
918
-
919
- unless @options.inline_source then
920
- @src_url = create_source_code_file @source_code
921
- @img_url = RDoc::Markup::ToHtml.gen_relative_url path, 'source.png'
922
- end
923
- end
924
-
925
- AllReferences.add name, self
926
- end
927
-
928
- ##
929
- # Returns a reference to outselves to be used as an href= the form depends
930
- # on whether we're all in one file or in multiple files
931
-
932
- def as_href(from_path)
933
- if @options.all_one_file
934
- "#" + path
935
- else
936
- RDoc::Markup::ToHtml.gen_relative_url from_path, path
937
- end
938
- end
939
-
940
- def formatter
941
- @formatter ||= @options.formatter ||
942
- RDoc::Markup::ToHtmlCrossref.new(path, self, @options.show_hash)
943
- end
944
-
945
- def inspect
946
- alias_for = if @context.is_alias_for then
947
- " (alias_for #{@context.is_alias_for})"
948
- else
949
- nil
950
- end
951
-
952
- "#<%s:0x%x %s%s%s (%s)%s>" % [
953
- self.class, object_id,
954
- @context.parent.name,
955
- @context.singleton ? '::' : '#',
956
- name,
957
- @context.visibility,
958
- alias_for
959
- ]
960
- end
961
-
962
- def name
963
- @context.name
964
- end
965
-
966
- def section
967
- @context.section
968
- end
969
-
970
- def index_name
971
- "#{@context.name} (#{@html_class.name})"
972
- end
973
-
974
- def parent_name
975
- if @context.parent.parent
976
- @context.parent.parent.full_name
977
- else
978
- nil
979
- end
980
- end
981
-
982
- def aref
983
- @seq
984
- end
985
-
986
- def path
987
- if @options.all_one_file
988
- aref
989
- else
990
- @html_class.path + "#" + aref
991
- end
992
- end
993
-
994
- def description
995
- markup(@context.comment)
996
- end
997
-
998
- def visibility
999
- @context.visibility
1000
- end
1001
-
1002
- def singleton
1003
- @context.singleton
1004
- end
1005
-
1006
- def call_seq
1007
- cs = @context.call_seq
1008
- if cs
1009
- cs.gsub(/\n/, "<br />\n")
1010
- else
1011
- nil
1012
- end
1013
- end
1014
-
1015
- def params
1016
- # params coming from a call-seq in 'C' will start with the
1017
- # method name
1018
- params = @context.params
1019
- if params !~ /^\w/
1020
- params = @context.params.gsub(/\s*\#.*/, '')
1021
- params = params.tr("\n", " ").squeeze(" ")
1022
- params = "(" + params + ")" unless params[0] == ?(
1023
-
1024
- if (block = @context.block_params)
1025
- # If this method has explicit block parameters, remove any
1026
- # explicit &block
1027
-
1028
- params.sub!(/,?\s*&\w+/, '')
1029
-
1030
- block.gsub!(/\s*\#.*/, '')
1031
- block = block.tr("\n", " ").squeeze(" ")
1032
- if block[0] == ?(
1033
- block.sub!(/^\(/, '').sub!(/\)/, '')
1034
- end
1035
- params << " {|#{block.strip}| ...}"
1036
- end
1037
- end
1038
- CGI.escapeHTML(params)
1039
- end
1040
-
1041
- def create_source_code_file(code_body)
1042
- meth_path = @html_class.path.sub(/\.html$/, '.src')
1043
- FileUtils.mkdir_p(meth_path)
1044
- file_path = ::File.join meth_path, "#{@seq}.html"
1045
-
1046
- template = RDoc::TemplatePage.new(@template::SRC_PAGE)
1047
-
1048
- open file_path, 'w' do |f|
1049
- values = {
1050
- :title => CGI.escapeHTML(index_name),
1051
- :code => code_body,
1052
- :style_url => style_url(file_path, @options.css),
1053
- :charset => @options.charset
1054
- }
1055
- template.write_html_on(f, values)
1056
- end
1057
-
1058
- RDoc::Markup::ToHtml.gen_relative_url path, file_path
1059
- end
1060
-
1061
- def <=>(other)
1062
- @context <=> other.context
1063
- end
1064
-
1065
- ##
1066
- # Given a sequence of source tokens, mark up the source code
1067
- # to make it look purty.
1068
-
1069
- def markup_code(tokens)
1070
- src = ""
1071
- tokens.each do |t|
1072
- next unless t
1073
- # style = STYLE_MAP[t.class]
1074
- style = case t
1075
- when RDoc::RubyToken::TkCONSTANT then "ruby-constant"
1076
- when RDoc::RubyToken::TkKW then "ruby-keyword kw"
1077
- when RDoc::RubyToken::TkIVAR then "ruby-ivar"
1078
- when RDoc::RubyToken::TkOp then "ruby-operator"
1079
- when RDoc::RubyToken::TkId then "ruby-identifier"
1080
- when RDoc::RubyToken::TkNode then "ruby-node"
1081
- when RDoc::RubyToken::TkCOMMENT then "ruby-comment cmt"
1082
- when RDoc::RubyToken::TkREGEXP then "ruby-regexp re"
1083
- when RDoc::RubyToken::TkSTRING then "ruby-value str"
1084
- when RDoc::RubyToken::TkVal then "ruby-value"
1085
- else
1086
- nil
1087
- end
1088
-
1089
- text = CGI.escapeHTML(t.text)
1090
-
1091
- if style
1092
- src << "<span class=\"#{style}\">#{text}</span>"
1093
- else
1094
- src << text
1095
- end
1096
- end
1097
-
1098
- add_line_numbers(src) if @options.include_line_numbers
1099
- src
1100
- end
1101
-
1102
- ##
1103
- # We rely on the fact that the first line of a source code listing has
1104
- # # File xxxxx, line dddd
1105
-
1106
- def add_line_numbers(src)
1107
- if src =~ /\A.*, line (\d+)/ then
1108
- first = $1.to_i - 1
1109
- last = first + src.count("\n")
1110
- size = last.to_s.length
1111
-
1112
- line = first
1113
- src.gsub!(/^/) do
1114
- res = if line == first then
1115
- " " * (size + 2)
1116
- else
1117
- "%#{size}d: " % line
1118
- end
1119
-
1120
- line += 1
1121
- res
1122
- end
1123
- end
1124
- end
1125
-
1126
- def document_self
1127
- @context.document_self
1128
- end
1129
-
1130
- def aliases
1131
- @context.aliases
1132
- end
1133
-
1134
- def find_symbol(symbol, method=nil)
1135
- res = @context.parent.find_symbol(symbol, method)
1136
- if res
1137
- res = res.viewer
1138
- end
1139
- res
1140
- end
1141
-
1142
- end
3
+ ##
4
+ # Namespace for generators
1143
5
 
6
+ module RDoc::Generator
1144
7
  end
1145
8