Generators::ContextUser (Class)

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

Attributes

context  [R] 

Included Modules

MarkUp

Public Class methods

[Source]

# File rdoc/generators/html_generator.rb, line 281
    def initialize(context, options)
      @context = context
      @options = options
    end

Public Instance methods

[Source]

# File rdoc/generators/html_generator.rb, line 498
    def aref_to(target)
      if @options.all_one_file
        "#" + target
      else
        url(target)
      end
    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 295
    def as_href(from_path)
      if @options.all_one_file
        "#" + path
      else
        HTMLGenerator.gen_url(from_path, path)
      end
    end

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

[Source]

# File rdoc/generators/html_generator.rb, line 333
    def build_alias_summary_list
      @context.aliases.map do |al|
        res = {
          'old_name' => al.old_name,
          'new_name' => al.new_name,
        }
        if al.comment && !al.comment.empty?
          res['desc'] = markup(al.comment, true)
        end
        res
      end
    end

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

[Source]

# File rdoc/generators/html_generator.rb, line 463
    def build_class_list(level, from, infile=nil)
      res = ""
      prefix = "  ::" * level;

      from.modules.sort.each do |mod|
        next if infile && !mod.defined_in?(infile)
        if mod.document_self
          res << 
            prefix <<
            "Module " <<
            href(url(mod.viewer.path), "link", mod.full_name) <<
            "<br />\n" <<
            build_class_list(level + 1, mod, infile)
        end
      end

      from.classes.sort.each do |cls|
        next if infile && !cls.defined_in?(infile)
        if cls.document_self
          res      <<
            prefix << 
            "Class " <<
            href(url(cls.viewer.path), "link", cls.full_name) <<
            "<br />\n" <<
            build_class_list(level + 1, cls, infile)
        end
      end

      res
    end

Build a list of constants

[Source]

# File rdoc/generators/html_generator.rb, line 347
    def build_constants_summary_list
      @context.constants.map do |co|
        res = {
          'name'  => co.name,
          'value' => CGI.escapeHTML(co.value)
        }
        res['desc'] = markup(co.comment, true) if co.comment && !co.comment.empty?
        res
      end
    end

[Source]

# File rdoc/generators/html_generator.rb, line 362
    def build_include_list(context)
      potentially_referenced_list(context.includes)
    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 401
    def build_method_detail_list
      outer = []

      methods = @methods.sort
      for singleton in [true, false]
        for vis in [ :public, :protected, :private ] 
          res = []
          methods.each do |m|
            if m.document_self and m.visibility == vis and m.singleton == singleton
              row = {}
              if m.call_seq
                row["callseq"] = m.call_seq
              else
                row["name"]        = CGI.escapeHTML(m.name)
                row["params"]      = m.params
              end
              desc = m.description.strip
              row["m_desc"]      = desc unless desc.empty?
              row["aref"]        = m.aref
              row["visibility"]  = m.visibility.to_s

              alias_names = []
              m.aliases.each do |other|
                if other.viewer   # won't be if the alias is private

                  alias_names << {
                    'name' => other.name,
                    'aref'  => other.viewer.as_href(path)
                  } 
                end
              end
              unless alias_names.empty?
                row["aka"] = alias_names
              end

              if @options.inline_source
                code = m.source_code
                row["sourcecode"] = code if code
              else
                code = m.src_url
                if code
                  row["codeurl"] = code
                  row["imgurl"]  = m.img_url
                end
              end
              res << row
            end
          end
          if res.size > 0 
            outer << {
              "type"    => vis.to_s.capitalize,
              "category"    => singleton ? "Class" : "Instance",
              "methods" => res
            }
          end
        end
      end
      outer
    end

Build a summary list of all the methods in this context

[Source]

# File rdoc/generators/html_generator.rb, line 317
    def build_method_summary_list(path_prefix="")
      collect_methods unless @methods
      meths = @methods.sort
      res = []
      meths.each do |meth|
        res << {
          "name" => CGI.escapeHTML(meth.name),
          "aref" => "#{path_prefix}\##{meth.aref}" 
        }
      end
      res
    end

[Source]

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

[Source]

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

[Source]

# File rdoc/generators/html_generator.rb, line 506
    def document_self
      @context.document_self
    end

Find a symbol in ourselves or our parent

[Source]

# File rdoc/generators/html_generator.rb, line 519
    def find_symbol(symbol, method=nil)
      res = @context.find_symbol(symbol, method)
      if res
        res = res.viewer
      end
      res
    end

convenience method to build a hyperlink

[Source]

# File rdoc/generators/html_generator.rb, line 287
    def href(link, cls, name)
      %{<a href="#{link}" class="#{cls}">#{name}</a>} #"

    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 375
    def potentially_referenced_list(array)
      res = []
      array.each do |i|
        ref = AllReferences[i.name] 
        if !ref && block_given?
          possibles = yield(i.name)
          while !ref and !possibles.empty?
            ref = AllReferences[possibles.shift]
          end
        end
        h_name = CGI.escapeHTML(i.name)
        if ref and ref.document_self
          path = url(ref.path)
          res << { "name" => h_name, "aref" => path }
        else
          res << { "name" => h_name }
        end
      end
      res
    end

[Source]

# File rdoc/generators/html_generator.rb, line 494
    def url(target)
      HTMLGenerator.gen_url(path, target)
    end

[Validate]