Class Generators::ContextUser
In: lib/rdoc/generators/html_generator.rb
Parent: Object

A Context is built by the parser to represent a container: contexts hold classes, modules, methods, require lists and include lists. ClassModule and TopLevel are the context objects we process here

Methods

Included Modules

MarkUp

Attributes

context  [R] 

Public Class methods

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 294
294:     def initialize(context, options)
295:       @context = context
296:       @options = options
297:     end

Public Instance methods

create table of contents if we contain sections

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 565
565:     def add_table_of_sections
566:       toc = []
567:       @context.sections.each do |section|
568:         if section.title
569:           toc << {
570:             'secname' => section.title,
571:             'href'    => section.sequence
572:           }
573:         end
574:       end
575:       
576:       @values['toc'] = toc unless toc.empty?
577:     end

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 534
534:     def aref_to(target)
535:       if @options.all_one_file
536:         "#" + target
537:       else
538:         url(target)
539:       end
540:     end

return a reference to outselves to be used as an href= the form depends on whether we‘re all in one file or in multiple files

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 308
308:     def as_href(from_path)
309:       if @options.all_one_file
310:         "#" + path
311:       else
312:         HTMLGenerator.gen_url(from_path, path)
313:       end
314:     end

Build a list of aliases for which we couldn‘t find a corresponding method

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 346
346:     def build_alias_summary_list(section)
347:       values = []
348:       @context.aliases.each do |al|
349:         next unless al.section == section
350:         res = {
351:           'old_name' => al.old_name,
352:           'new_name' => al.new_name,
353:         }
354:         if al.comment && !al.comment.empty?
355:           res['desc'] = markup(al.comment, true)
356:         end
357:         values << res
358:       end
359:       values
360:     end

Build the structured list of classes and modules contained in this context.

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 497
497:     def build_class_list(level, from, section, infile=nil)
498:       res = ""
499:       prefix = "&nbsp;&nbsp;::" * level;
500: 
501:       from.modules.sort.each do |mod|
502:         next unless mod.section == section
503:         next if infile && !mod.defined_in?(infile)
504:         if mod.document_self
505:           res << 
506:             prefix <<
507:             "Module " <<
508:             href(url(mod.viewer.path), "link", mod.full_name) <<
509:             "<br />\n" <<
510:             build_class_list(level + 1, mod, section, infile)
511:         end
512:       end
513: 
514:       from.classes.sort.each do |cls|
515:         next unless cls.section == section
516:         next if infile && !cls.defined_in?(infile)
517:         if cls.document_self
518:           res      <<
519:             prefix << 
520:             "Class " <<
521:             href(url(cls.viewer.path), "link", cls.full_name) <<
522:             "<br />\n" <<
523:             build_class_list(level + 1, cls, section, infile)
524:         end
525:       end
526: 
527:       res
528:     end

Build a list of constants

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 363
363:     def build_constants_summary_list(section)
364:       values = []
365:       @context.constants.each do |co|
366:         next unless co.section == section
367:         res = {
368:           'name'  => co.name,
369:           'value' => CGI.escapeHTML(co.value)
370:         }
371:         res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty?
372:         values << res
373:       end
374:       values
375:     end

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 381
381:     def build_include_list(context)
382:       potentially_referenced_list(context.includes)
383:     end

Build an array of arrays of method details. The outer array has up to six entries, public, private, and protected for both class methods, the other for instance methods. The inner arrays contain a hash for each method

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 432
432:     def build_method_detail_list(section)
433:       outer = []
434: 
435:       methods = @methods.sort
436:       for singleton in [true, false]
437:         for vis in [ :public, :protected, :private ] 
438:           res = []
439:           methods.each do |m|
440:             if m.section == section and
441:                 m.document_self and 
442:                 m.visibility == vis and 
443:                 m.singleton == singleton
444:               row = {}
445:               if m.call_seq
446:                 row["callseq"] = m.call_seq.gsub(/->/, '&rarr;')
447:               else
448:                 row["name"]        = CGI.escapeHTML(m.name)
449:                 row["params"]      = m.params
450:               end
451:               desc = m.description.strip
452:               row["m_desc"]      = desc unless desc.empty?
453:               row["aref"]        = m.aref
454:               row["visibility"]  = m.visibility.to_s
455: 
456:               alias_names = []
457:               m.aliases.each do |other|
458:                 if other.viewer   # won't be if the alias is private
459:                   alias_names << {
460:                     'name' => other.name,
461:                     'aref'  => other.viewer.as_href(path)
462:                   } 
463:                 end
464:               end
465:               unless alias_names.empty?
466:                 row["aka"] = alias_names
467:               end
468: 
469:               if @options.inline_source
470:                 code = m.source_code
471:                 row["sourcecode"] = code if code
472:               else
473:                 code = m.src_url
474:                 if code
475:                   row["codeurl"] = code
476:                   row["imgurl"]  = m.img_url
477:                 end
478:               end
479:               res << row
480:             end
481:           end
482:           if res.size > 0 
483:             outer << {
484:               "type"    => vis.to_s.capitalize,
485:               "category"    => singleton ? "Class" : "Instance",
486:               "methods" => res
487:             }
488:           end
489:         end
490:       end
491:       outer
492:     end

Build a summary list of all the methods in this context

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 330
330:     def build_method_summary_list(path_prefix="")
331:       collect_methods unless @methods
332:       meths = @methods.sort
333:       res = []
334:       meths.each do |meth|
335:         res << {
336:           "name" => CGI.escapeHTML(meth.name),
337:           "aref" => "#{path_prefix}\##{meth.aref}" 
338:         }
339:       end
340:       res
341:     end

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 377
377:     def build_requires_list(context)
378:       potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] }
379:     end

Create a list of HtmlMethod objects for each method in the corresponding context object. If the @options.show_all variable is set (corresponding to the —all option, we include all methods, otherwise just the public ones.

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 321
321:     def collect_methods
322:       list = @context.method_list
323:       unless @options.show_all
324:         list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation }
325:       end
326:       @methods = list.collect {|m| HtmlMethod.new(m, self, @options) }
327:     end

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 546
546:     def diagram_reference(diagram)
547:       res = diagram.gsub(/((?:src|href)=")(.*?)"/) {
548:         $1 + url($2) + '"'
549:       }
550:       res
551:     end

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 542
542:     def document_self
543:       @context.document_self
544:     end

Find a symbol in ourselves or our parent

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 555
555:     def find_symbol(symbol, method=nil)
556:       res = @context.find_symbol(symbol, method)
557:       if res
558:         res = res.viewer
559:       end
560:       res
561:     end

convenience method to build a hyperlink

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 300
300:     def href(link, cls, name)
301:       %{<a href="#{link}" class="#{cls}">#{name}</a>} #"
302:     end

Build a list from an array of Htmlxxx items. Look up each in the AllReferences hash: if we find a corresponding entry, we generate a hyperlink to it, otherwise just output the name. However, some names potentially need massaging. For example, you may require a Ruby file without the .rb extension, but the file names we know about may have it. To deal with this, we pass in a block which performs the massaging, returning an array of alternative names to match

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 394
394:     def potentially_referenced_list(array)
395:       res = []
396:       array.each do |i|
397:         ref = AllReferences[i.name] 
398: #         if !ref
399: #           container = @context.parent
400: #           while !ref && container
401: #             name = container.name + "::" + i.name
402: #             ref = AllReferences[name] 
403: #             container = container.parent
404: #           end
405: #         end
406: 
407:         ref = @context.find_symbol(i.name)
408:         ref = ref.viewer if ref
409: 
410:         if !ref && block_given?
411:           possibles = yield(i.name)
412:           while !ref and !possibles.empty?
413:             ref = AllReferences[possibles.shift]
414:           end
415:         end
416:         h_name = CGI.escapeHTML(i.name)
417:         if ref and ref.document_self
418:           path = url(ref.path)
419:           res << { "name" => h_name, "aref" => path }
420:         else
421:           res << { "name" => h_name }
422:         end
423:       end
424:       res
425:     end

[Source]

     # File lib/rdoc/generators/html_generator.rb, line 530
530:     def url(target)
531:       HTMLGenerator.gen_url(path, target)
532:     end

[Validate]