Class Generators::ContextUser
In: 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 generators/html_generator.rb, line 326
326:     def initialize(context, options)
327:       @context = context
328:       @options = options
329:     end

Public Instance methods

create table of contents if we contain sections

[Source]

     # File generators/html_generator.rb, line 608
608:     def add_table_of_sections
609:       toc = []
610:       @context.sections.each do |section|
611:         if section.title
612:           toc << {
613:             'secname' => section.title,
614:             'href'    => section.sequence
615:           }
616:         end
617:       end
618:       
619:       @values['toc'] = toc unless toc.empty?
620:     end

[Source]

     # File generators/html_generator.rb, line 567
567:     def aref_to(target)
568:       if @options.all_one_file
569:         "#" + target
570:       else
571:         url(target)
572:       end
573:     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 generators/html_generator.rb, line 340
340:     def as_href(from_path)
341:       if @options.all_one_file
342:         "#" + path
343:       else
344:         HTMLGenerator.gen_url(from_path, path)
345:       end
346:     end

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

[Source]

     # File generators/html_generator.rb, line 378
378:     def build_alias_summary_list(section)
379:       values = []
380:       @context.aliases.each do |al|
381:         next unless al.section == section
382:         res = {
383:           'old_name' => al.old_name,
384:           'new_name' => al.new_name,
385:         }
386:         if al.comment && !al.comment.empty?
387:           res['desc'] = markup(al.comment, true)
388:         end
389:         values << res
390:       end
391:       values
392:     end

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

[Source]

     # File generators/html_generator.rb, line 530
530:     def build_class_list(level, from, section, infile=nil)
531:       res = ""
532:       prefix = "&nbsp;&nbsp;::" * level;
533: 
534:       from.modules.sort.each do |mod|
535:         next unless mod.section == section
536:         next if infile && !mod.defined_in?(infile)
537:         if mod.document_self
538:           res << 
539:             prefix <<
540:             "Module " <<
541:             href(url(mod.viewer.path), "link", mod.full_name) <<
542:             "<br />\n" <<
543:             build_class_list(level + 1, mod, section, infile)
544:         end
545:       end
546: 
547:       from.classes.sort.each do |cls|
548:         next unless cls.section == section
549:         next if infile && !cls.defined_in?(infile)
550:         if cls.document_self
551:           res      <<
552:             prefix << 
553:             "Class " <<
554:             href(url(cls.viewer.path), "link", cls.full_name) <<
555:             "<br />\n" <<
556:             build_class_list(level + 1, cls, section, infile)
557:         end
558:       end
559: 
560:       res
561:     end

Build a list of constants

[Source]

     # File generators/html_generator.rb, line 395
395:     def build_constants_summary_list(section)
396:       values = []
397:       @context.constants.each do |co|
398:         next unless co.section == section
399:         res = {
400:           'name'  => co.name,
401:           'value' => CGI.escapeHTML(co.value)
402:         }
403:         res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty?
404:         values << res
405:       end
406:       values
407:     end

[Source]

     # File generators/html_generator.rb, line 413
413:     def build_include_list(context)
414:       potentially_referenced_list(context.includes)
415:     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 generators/html_generator.rb, line 465
465:     def build_method_detail_list(section)
466:       outer = []
467: 
468:       methods = @methods.sort
469:       for singleton in [true, false]
470:         for vis in [ :public, :protected, :private ] 
471:           res = []
472:           methods.each do |m|
473:             if m.section == section and
474:                 m.document_self and 
475:                 m.visibility == vis and 
476:                 m.singleton == singleton
477:               row = {}
478:               if m.call_seq
479:                 row["callseq"] = m.call_seq.gsub(/->/, '&rarr;')
480:               else
481:                 row["name"]        = CGI.escapeHTML(m.name)
482:                 row["params"]      = m.params
483:               end
484:               desc = m.description.strip
485:               row["m_desc"]      = desc unless desc.empty?
486:               row["aref"]        = m.aref
487:               row["visibility"]  = m.visibility.to_s
488: 
489:               alias_names = []
490:               m.aliases.each do |other|
491:                 if other.viewer   # won't be if the alias is private
492:                   alias_names << {
493:                     'name' => other.name,
494:                     'aref'  => other.viewer.as_href(path)
495:                   } 
496:                 end
497:               end
498:               unless alias_names.empty?
499:                 row["aka"] = alias_names
500:               end
501: 
502:               if @options.inline_source
503:                 code = m.source_code
504:                 row["sourcecode"] = code if code
505:               else
506:                 code = m.src_url
507:                 if code
508:                   row["codeurl"] = code
509:                   row["imgurl"]  = m.img_url
510:                 end
511:               end
512:               res << row
513:             end
514:           end
515:           if res.size > 0 
516:             outer << {
517:               "type"    => vis.to_s.capitalize,
518:               "category"    => singleton ? "Class" : "Instance",
519:               "methods" => res
520:             }
521:           end
522:         end
523:       end
524:       outer
525:     end

Build a summary list of all the methods in this context

[Source]

     # File generators/html_generator.rb, line 362
362:     def build_method_summary_list(path_prefix="")
363:       collect_methods unless @methods
364:       meths = @methods.sort
365:       res = []
366:       meths.each do |meth|
367:         res << {
368:           "name" => CGI.escapeHTML(meth.name),
369:           "aref" => "#{path_prefix}\##{meth.aref}" 
370:         }
371:       end
372:       res
373:     end

[Source]

     # File generators/html_generator.rb, line 409
409:     def build_requires_list(context)
410:       potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] }
411:     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 generators/html_generator.rb, line 353
353:     def collect_methods
354:       list = @context.method_list
355:       unless @options.show_all
356:         list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation }
357:       end
358:       @methods = list.collect {|m| HtmlMethod.new(m, self, @options) }
359:     end

[Source]

     # File generators/html_generator.rb, line 579
579:     def diagram_reference(diagram)
580:       res = diagram.gsub(/((?:src|href)=")(.*?)"/) {
581:         $1 + url($2) + '"'
582:       }
583:       res
584:     end

[Source]

     # File generators/html_generator.rb, line 575
575:     def document_self
576:       @context.document_self
577:     end

Find a filenames in ourselves or our parent

[Source]

     # File generators/html_generator.rb, line 597
597:     def find_file(file, method=nil)
598:       res = @context.find_file(file, method, 
599:                                @options.ignore_case)
600:       if res
601:         res = res.viewer
602:       end
603:       res
604:     end

Find a symbol in ourselves or our parent

[Source]

     # File generators/html_generator.rb, line 588
588:     def find_symbol(symbol, method=nil)
589:       res = @context.find_symbol(symbol, method, @options.ignore_case)
590:       if res
591:         res = res.viewer
592:       end
593:       res
594:     end

convenience method to build a hyperlink

[Source]

     # File generators/html_generator.rb, line 332
332:     def href(link, cls, name)
333:       %{<a href="#{link}" class="#{cls}">#{name}</a>} #"
334:     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 generators/html_generator.rb, line 426
426:     def potentially_referenced_list(array)
427:       res = []
428:       array.each do |i|
429:         ref = AllReferences[i.name] 
430: #         if !ref
431: #           container = @context.parent
432: #           while !ref && container
433: #             name = container.name + "::" + i.name
434: #             ref = AllReferences[name] 
435: #             container = container.parent
436: #           end
437: #         end
438: 
439:         ref = @context.find_symbol(i.name, nil, @options.ignore_case)  || \
440:               @context.find_file(i.name)
441:         ref = ref.viewer if ref
442: 
443:         if !ref && block_given?
444:           possibles = yield(i.name)
445:           while !ref and !possibles.empty?
446:             ref = AllReferences[possibles.shift]
447:           end
448:         end
449:         h_name = CGI.escapeHTML(i.name)
450:         if ref and ref.document_self
451:           path = url(ref.path)
452:           res << { "name" => h_name, "aref" => path }
453:         else
454:           res << { "name" => h_name }
455:         end
456:       end
457:       res
458:     end

[Source]

     # File generators/html_generator.rb, line 563
563:     def url(target)
564:       HTMLGenerator.gen_url(path, target)
565:     end

[Validate]