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 325
325:     def initialize(context, options)
326:       @context = context
327:       @options = options
328:     end

Public Instance methods

create table of contents if we contain sections

[Source]

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

[Source]

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

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

[Source]

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

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

[Source]

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

Build a list of constants

[Source]

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

[Source]

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

Build a summary list of all the methods in this context

[Source]

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

[Source]

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

[Source]

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

[Source]

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

Find a filenames in ourselves or our parent

[Source]

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

Find a symbol in ourselves or our parent

[Source]

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

convenience method to build a hyperlink

[Source]

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

[Source]

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

[Validate]