Class Generators::ContextUser
In: 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

Included Modules

Attributes

context  [R] 

Public Class methods

[Source]

     # File rdoc/generators/html_generator.rb, line 287
287:     def initialize(context, options)
288:       @context = context
289:       @options = options
290:     end

Public Instance methods

create table of contents if we contain sections

[Source]

     # File rdoc/generators/html_generator.rb, line 558
558:     def add_table_of_sections
559:       toc = []
560:       @context.sections.each do |section|
561:         if section.title
562:           toc << {
563:             'secname' => section.title,
564:             'href'    => section.sequence
565:           }
566:         end
567:       end
568:       
569:       @values['toc'] = toc unless toc.empty?
570:     end

[Source]

     # File rdoc/generators/html_generator.rb, line 527
527:     def aref_to(target)
528:       if @options.all_one_file
529:         "#" + target
530:       else
531:         url(target)
532:       end
533:     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 rdoc/generators/html_generator.rb, line 301
301:     def as_href(from_path)
302:       if @options.all_one_file
303:         "#" + path
304:       else
305:         HTMLGenerator.gen_url(from_path, path)
306:       end
307:     end

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

[Source]

     # File rdoc/generators/html_generator.rb, line 339
339:     def build_alias_summary_list(section)
340:       values = []
341:       @context.aliases.each do |al|
342:         next unless al.section == section
343:         res = {
344:           'old_name' => al.old_name,
345:           'new_name' => al.new_name,
346:         }
347:         if al.comment && !al.comment.empty?
348:           res['desc'] = markup(al.comment, true)
349:         end
350:         values << res
351:       end
352:       values
353:     end

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

[Source]

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

Build a list of constants

[Source]

     # File rdoc/generators/html_generator.rb, line 356
356:     def build_constants_summary_list(section)
357:       values = []
358:       @context.constants.each do |co|
359:         next unless co.section == section
360:         res = {
361:           'name'  => co.name,
362:           'value' => CGI.escapeHTML(co.value)
363:         }
364:         res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty?
365:         values << res
366:       end
367:       values
368:     end

[Source]

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

Build a summary list of all the methods in this context

[Source]

     # File rdoc/generators/html_generator.rb, line 323
323:     def build_method_summary_list(path_prefix="")
324:       collect_methods unless @methods
325:       meths = @methods.sort
326:       res = []
327:       meths.each do |meth|
328:         res << {
329:           "name" => CGI.escapeHTML(meth.name),
330:           "aref" => "#{path_prefix}\##{meth.aref}" 
331:         }
332:       end
333:       res
334:     end

[Source]

     # File rdoc/generators/html_generator.rb, line 370
370:     def build_requires_list(context)
371:       potentially_referenced_list(context.requires) {|fn| [fn + ".rb"] }
372:     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 rdoc/generators/html_generator.rb, line 314
314:     def collect_methods
315:       list = @context.method_list
316:       unless @options.show_all
317:         list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation }
318:       end
319:       @methods = list.collect {|m| HtmlMethod.new(m, self, @options) }
320:     end

[Source]

     # File rdoc/generators/html_generator.rb, line 539
539:     def diagram_reference(diagram)
540:       res = diagram.gsub(/((?:src|href)=")(.*?)"/) {
541:         $1 + url($2) + '"'
542:       }
543:       res
544:     end

[Source]

     # File rdoc/generators/html_generator.rb, line 535
535:     def document_self
536:       @context.document_self
537:     end

Find a symbol in ourselves or our parent

[Source]

     # File rdoc/generators/html_generator.rb, line 548
548:     def find_symbol(symbol, method=nil)
549:       res = @context.find_symbol(symbol, method)
550:       if res
551:         res = res.viewer
552:       end
553:       res
554:     end

convenience method to build a hyperlink

[Source]

     # File rdoc/generators/html_generator.rb, line 293
293:     def href(link, cls, name)
294:       %{<a href="#{link}" class="#{cls}">#{name}</a>} #"
295:     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 rdoc/generators/html_generator.rb, line 387
387:     def potentially_referenced_list(array)
388:       res = []
389:       array.each do |i|
390:         ref = AllReferences[i.name] 
391: #         if !ref
392: #           container = @context.parent
393: #           while !ref && container
394: #             name = container.name + "::" + i.name
395: #             ref = AllReferences[name] 
396: #             container = container.parent
397: #           end
398: #         end
399: 
400:         ref = @context.find_symbol(i.name)
401:         ref = ref.viewer if ref
402: 
403:         if !ref && block_given?
404:           possibles = yield(i.name)
405:           while !ref and !possibles.empty?
406:             ref = AllReferences[possibles.shift]
407:           end
408:         end
409:         h_name = CGI.escapeHTML(i.name)
410:         if ref and ref.document_self
411:           path = url(ref.path)
412:           res << { "name" => h_name, "aref" => path }
413:         else
414:           res << { "name" => h_name }
415:         end
416:       end
417:       res
418:     end

[Source]

     # File rdoc/generators/html_generator.rb, line 523
523:     def url(target)
524:       HTMLGenerator.gen_url(path, target)
525:     end

Search

Google

Ruby API Docs

Links