In Files

  • rdoc/generator.rb

Files

Class/Module Index [+]

Quicksearch

RDoc::Generator::Method

Attributes

context[R]
img_url[R]
source_code[R]
src_url[R]

Public Class Methods

all_methods() click to toggle source
 
               # File rdoc/generator.rb, line 824
def self.all_methods
  @@all_methods
end
            
new(context, html_class, options) click to toggle source
 
               # File rdoc/generator.rb, line 836
def initialize(context, html_class, options)
  # TODO: rethink the class hierarchy here...
  @context    = context
  @html_class = html_class
  @options    = options

  @@seq       = @@seq.succ
  @seq        = @@seq

  # HACK ugly
  @template = options.template_class

  @@all_methods << self

  context.viewer = self

  if (ts = @context.token_stream)
    @source_code = markup_code(ts)
    unless @options.inline_source
      @src_url = create_source_code_file(@source_code)
      @img_url = RDoc::Markup::ToHtml.gen_relative_url path, 'source.png'
    end
  end

  AllReferences.add(name, self)
end
            
reset() click to toggle source
 
               # File rdoc/generator.rb, line 828
def self.reset
  @@all_methods = []
  @@seq = "M000000"
end
            

Public Instance Methods

<=>(other) click to toggle source
 
               # File rdoc/generator.rb, line 996
def <=>(other)
  @context <=> other.context
end
            
add_line_numbers(src) click to toggle source

We rely on the fact that the first line of a source code listing has

# File xxxxx, line dddd
 
               # File rdoc/generator.rb, line 1041
def add_line_numbers(src)
  if src =~ /\A.*, line (\d+)/
    first = $1.to_i - 1
    last  = first + src.count("\n")
    size = last.to_s.length
    fmt = "%#{size}d: "
    is_first_line = true
    line_num = first
    src.gsub!(/^/) do
      if is_first_line then
        is_first_line = false
        res = " " * (size+2)
      else
        res = sprintf(fmt, line_num)
      end

      line_num += 1
      res
    end
  end
end
            
aliases() click to toggle source
 
               # File rdoc/generator.rb, line 1067
def aliases
  @context.aliases
end
            
aref() click to toggle source
 
               # File rdoc/generator.rb, line 917
def aref
  @seq
end
            
as_href(from_path) click to toggle source

Returns 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

 
               # File rdoc/generator.rb, line 867
def as_href(from_path)
  if @options.all_one_file
    "#" + path
  else
    RDoc::Markup::ToHtml.gen_relative_url from_path, path
  end
end
            
call_seq() click to toggle source
 
               # File rdoc/generator.rb, line 941
def call_seq
  cs = @context.call_seq
  if cs
    cs.gsub(/\n/, "<br />\n")
  else
    nil
  end
end
            
create_source_code_file(code_body) click to toggle source
 
               # File rdoc/generator.rb, line 976
def create_source_code_file(code_body)
  meth_path = @html_class.path.sub(/\.html$/, '.src')
  FileUtils.mkdir_p(meth_path)
  file_path = ::File.join meth_path, "#{@seq}.html"

  template = RDoc::TemplatePage.new(@template::SRC_PAGE)

  open file_path, 'w' do |f|
    values = {
      'title'     => CGI.escapeHTML(index_name),
      'code'      => code_body,
      'style_url' => style_url(file_path, @options.css),
      'charset'   => @options.charset
    }
    template.write_html_on(f, values)
  end

  RDoc::Markup::ToHtml.gen_relative_url path, file_path
end
            
description() click to toggle source
 
               # File rdoc/generator.rb, line 929
def description
  markup(@context.comment)
end
            
document_self() click to toggle source
 
               # File rdoc/generator.rb, line 1063
def document_self
  @context.document_self
end
            
find_symbol(symbol, method=nil) click to toggle source
 
               # File rdoc/generator.rb, line 1071
def find_symbol(symbol, method=nil)
  res = @context.parent.find_symbol(symbol, method)
  if res
    res = res.viewer
  end
  res
end
            
formatter() click to toggle source
 
               # File rdoc/generator.rb, line 875
def formatter
  @formatter ||= @options.formatter ||
    RDoc::Markup::ToHtmlCrossref.new(path, self, @options.show_hash)
end
            
index_name() click to toggle source
 
               # File rdoc/generator.rb, line 905
def index_name
  "#{@context.name} (#{@html_class.name})"
end
            
inspect() click to toggle source
 
               # File rdoc/generator.rb, line 880
def inspect
  alias_for = if @context.is_alias_for then
                " (alias_for #{@context.is_alias_for})"
              else
                nil
              end

  "#<%s:0x%x %s%s%s (%s)%s>" % [
    self.class, object_id,
    @context.parent.name,
    @context.singleton ? '::' : '#',
    name,
    @context.visibility,
    alias_for
  ]
end
            
markup_code(tokens) click to toggle source

Given a sequence of source tokens, mark up the source code to make it look purty.

 
               # File rdoc/generator.rb, line 1004
    def markup_code(tokens)
      src = ""
      tokens.each do |t|
        next unless t
#        style = STYLE_MAP[t.class]
        style = case t
                when RDoc::RubyToken::TkCONSTANT then "ruby-constant"
                when RDoc::RubyToken::TkKW       then "ruby-keyword kw"
                when RDoc::RubyToken::TkIVAR     then "ruby-ivar"
                when RDoc::RubyToken::TkOp       then "ruby-operator"
                when RDoc::RubyToken::TkId       then "ruby-identifier"
                when RDoc::RubyToken::TkNode     then "ruby-node"
                when RDoc::RubyToken::TkCOMMENT  then "ruby-comment cmt"
                when RDoc::RubyToken::TkREGEXP   then "ruby-regexp re"
                when RDoc::RubyToken::TkSTRING   then "ruby-value str"
                when RDoc::RubyToken::TkVal      then "ruby-value"
                else
                    nil
                end

        text = CGI.escapeHTML(t.text)

        if style
          src << "<span class=\"#{style}\">#{text}</span>"
        else
          src << text
        end
      end

      add_line_numbers(src) if @options.include_line_numbers
      src
    end
            
name() click to toggle source
 
               # File rdoc/generator.rb, line 897
def name
  @context.name
end
            
params() click to toggle source
 
               # File rdoc/generator.rb, line 950
def params
  # params coming from a call-seq in 'C' will start with the
  # method name
  params = @context.params
  if params !~ /^\w/
    params = @context.params.gsub(/\s*\#.*/, '')
    params = params.tr("\n", " ").squeeze(" ")
    params = "(" + params + ")" unless params[0] == ?(

    if (block = @context.block_params)
     # If this method has explicit block parameters, remove any
     # explicit &block

     params.sub!(/,?\s*&\w+/, '')

      block.gsub!(/\s*\#.*/, '')
      block = block.tr("\n", " ").squeeze(" ")
      if block[0] == ?(
        block.sub!(/^\(/, '').sub!(/\)/, '')
      end
      params << " {|#{block.strip}| ...}"
    end
  end
  CGI.escapeHTML(params)
end
            
parent_name() click to toggle source
 
               # File rdoc/generator.rb, line 909
def parent_name
  if @context.parent.parent
    @context.parent.parent.full_name
  else
    nil
  end
end
            
path() click to toggle source
 
               # File rdoc/generator.rb, line 921
def path
  if @options.all_one_file
    aref
  else
    @html_class.path + "#" + aref
  end
end
            
section() click to toggle source
 
               # File rdoc/generator.rb, line 901
def section
  @context.section
end
            
singleton() click to toggle source
 
               # File rdoc/generator.rb, line 937
def singleton
  @context.singleton
end
            
visibility() click to toggle source
 
               # File rdoc/generator.rb, line 933
def visibility
  @context.visibility
end