Class RDoc::Generator::RI

  1. lib/rdoc/generator/ri.rb
Parent: Object
ClassModule NormalModule AnonClass SingleClass NormalClass AnyMethod GhostMethod MetaMethod CodeObject Context Alias Attr Constant Require Include TopLevel RubyLex IRB RuntimeError Error Error Token TkUnknownChar TkVal TkNode TkOp TkId TkError TkOPASGN TkKW AttributeFormatter HtmlFormatter OverstrikeFormatter AnsiFormatter NamedThing AliasName IncludedModule Constant Attribute MethodSummary DefaultDisplay ClassEntry TopLevelEntry Formatter SimpleFormatter Description MethodDescription ModuleDescription ClassDescription HTML XML HTMLInOne CHM Method Context Class File Generator::MarkUp TEXINFO SimpleElement Port Element Node Subgraph Edge Digraph Stats Parser Options RDoc TemplatePage Markup Diagram NameDescriptor Cache Reader Writer Driver MethodEntry RI TexinfoTemplate AllReferences RubyToken Display Paths RI MarkUp Generator TokenStream DOT RDoc dot/f_5.png

Methods

public class

  1. for
  2. new

public instance

  1. generate
  2. generate_class_info
  3. generate_method_info
  4. process_class

Public class methods

for (options)

Generator may need to return specific subclasses depending on the options they are passed. Because of this we create them using a factory

[show source]
# File lib/rdoc/generator/ri.rb, line 15
  def self.for(options)
    new(options)
  end
new (options)

Set up a new ri generator

[show source]
# File lib/rdoc/generator/ri.rb, line 22
  def initialize(options) #:not-new:
    @options   = options
    @ri_writer = RDoc::RI::Writer.new "."
    @markup    = RDoc::Markup.new
    @to_flow   = RDoc::Markup::ToFlow.new

    @generated = {}
  end

Public instance methods

generate (toplevels)

Build the initial indices and output objects based on an array of TopLevel objects containing the extracted information.

[show source]
# File lib/rdoc/generator/ri.rb, line 35
  def generate(toplevels)
    RDoc::TopLevel.all_classes_and_modules.each do |cls|
      process_class cls
    end
  end
generate_class_info (cls)
[show source]
# File lib/rdoc/generator/ri.rb, line 50
  def generate_class_info(cls)
    case cls
    when RDoc::NormalModule then
      cls_desc = RDoc::RI::ModuleDescription.new
    else
      cls_desc = RDoc::RI::ClassDescription.new
      cls_desc.superclass = cls.superclass
    end

    cls_desc.name        = cls.name
    cls_desc.full_name   = cls.full_name
    cls_desc.comment     = markup(cls.comment)

    cls_desc.attributes = cls.attributes.sort.map do |a|
      RDoc::RI::Attribute.new(a.name, a.rw, markup(a.comment))
    end

    cls_desc.constants = cls.constants.map do |c|
      RDoc::RI::Constant.new(c.name, c.value, markup(c.comment))
    end

    cls_desc.includes = cls.includes.map do |i|
      RDoc::RI::IncludedModule.new(i.name)
    end

    class_methods, instance_methods = method_list(cls)

    cls_desc.class_methods = class_methods.map do |m|
      RDoc::RI::MethodSummary.new(m.name)
    end

    cls_desc.instance_methods = instance_methods.map do |m|
      RDoc::RI::MethodSummary.new(m.name)
    end

    update_or_replace(cls_desc)

    class_methods.each do |m|
      generate_method_info(cls_desc, m)
    end

    instance_methods.each do |m|
      generate_method_info(cls_desc, m)
    end
  end
generate_method_info (cls_desc, method)
[show source]
# File lib/rdoc/generator/ri.rb, line 96
  def generate_method_info(cls_desc, method)
    meth_desc = RDoc::RI::MethodDescription.new
    meth_desc.name = method.name
    meth_desc.full_name = cls_desc.full_name
    if method.singleton
      meth_desc.full_name += "::"
    else
      meth_desc.full_name += "#"
    end
    meth_desc.full_name << method.name

    meth_desc.comment = markup(method.comment)
    meth_desc.params = params_of(method)
    meth_desc.visibility = method.visibility.to_s
    meth_desc.is_singleton = method.singleton
    meth_desc.block_params = method.block_params

    meth_desc.aliases = method.aliases.map do |a|
      RDoc::RI::AliasName.new(a.name)
    end

    @ri_writer.add_method(cls_desc, meth_desc)
  end
process_class (from_class)
[show source]
# File lib/rdoc/generator/ri.rb, line 41
  def process_class(from_class)
    generate_class_info(from_class)

    # now recurse into this class' constituent classes
    from_class.each_classmodule do |mod|
      process_class(mod)
    end
  end