Class: Generators::HtmlMethod

Class | Generators::HtmlMethod
In: | rdoc/generators/html_generator.rb
Parent: | Object

### Methods

<=> add_line_numbers aliases all_methods aref as_href call_seq create_source_code_file description document_self find_symbol index_name markup_code name new params parent_name path reset section singleton visibility

### Included Modules

MarkUp

### Attributes

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

### Public Class methods

all_methods()

[Source]

    # File rdoc/generators/html_generator.rb, line 1037
        def HtmlMethod.all_methods
          @@all_methods
        end

new(context, html_class, options)

[Source]

    # File rdoc/generators/html_generator.rb, line 907
        def initialize(context, html_class, options)
          @context    = context
          @html_class = html_class
          @options    = options
          @@seq       = @@seq.succ
          @seq        = @@seq
          @@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 = HTMLGenerator.gen_url(path, 'source.png')
            end
          end

          AllReferences.add(name, self)
        end

reset()

[Source]

    # File rdoc/generators/html_generator.rb, line 903
        def HtmlMethod::reset
          @@all_methods = []
        end

### Public Instance methods

<=>(other)

[Source]

    # File rdoc/generators/html_generator.rb, line 1041
        def <=>(other)
          @context <=> other.context
        end

add_line_numbers(src)

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

       # File xxxxx, line dddd

[Source]

    # File rdoc/generators/html_generator.rb, line 1088
        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
            real_fmt = "%#{size}d: "
            fmt = " " * (size+2)
            src.gsub!(/^/) do
              res = sprintf(fmt, first)
              first += 1
              fmt = real_fmt
              res
            end
          end
        end

aliases()

[Source]

    # File rdoc/generators/html_generator.rb, line 1108
        def aliases
          @context.aliases
        end

aref()

[Source]

    # File rdoc/generators/html_generator.rb, line 960
        def aref
          @seq
        end

as_href(from_path)

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 932
        def as_href(from_path)
          if @options.all_one_file
            "#" + path
          else
            HTMLGenerator.gen_url(from_path, path)
          end
        end

call_seq()

[Source]

    # File rdoc/generators/html_generator.rb, line 984
        def call_seq
          cs = @context.call_seq
          if cs
            cs.gsub(/\n/, "<br />\n")
          else
            nil
          end
        end

create_source_code_file(code_body)

[Source]

    # File rdoc/generators/html_generator.rb, line 1019
        def create_source_code_file(code_body)
          meth_path = @html_class.path.sub(/\.html$/, '.src')
          File.makedirs(meth_path)
          file_path = File.join(meth_path, @seq) + ".html"

          template = TemplatePage.new(RDoc::Page::SRC_PAGE)
          File.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
          HTMLGenerator.gen_url(path, file_path)
        end

description()

[Source]

    # File rdoc/generators/html_generator.rb, line 972
        def description
          markup(@context.comment)
        end

document_self()

[Source]

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

find_symbol(symbol, method=nil)

[Source]

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

index_name()

[Source]

    # File rdoc/generators/html_generator.rb, line 948
        def index_name
          "#{@context.name} (#{@html_class.name})"
        end

markup_code(tokens)

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

[Source]

    # File rdoc/generators/html_generator.rb, line 1050
        def markup_code(tokens)
          src = ""
          tokens.each do |t|
            next unless t
            #    p t.class
    #        style = STYLE_MAP[t.class]
            style = case t
                    when RubyToken::TkCONSTANT then "ruby-constant"
                    when RubyToken::TkKW       then "ruby-keyword kw"
                    when RubyToken::TkIVAR     then "ruby-ivar"
                    when RubyToken::TkOp       then "ruby-operator"
                    when RubyToken::TkId       then "ruby-identifier"
                    when RubyToken::TkNode     then "ruby-node"
                    when RubyToken::TkCOMMENT  then "ruby-comment cmt"
                    when RubyToken::TkREGEXP   then "ruby-regexp re"
                    when RubyToken::TkSTRING   then "ruby-value str"
                    when 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.instance.include_line_numbers
          src
        end

name()

[Source]

    # File rdoc/generators/html_generator.rb, line 940
        def name
          @context.name
        end

params()

[Source]

    # File rdoc/generators/html_generator.rb, line 993
        def params
          # params coming from a call-seq in 'C' will start with the
          # method name
          p = @context.params
          if p !~ /^\w/
            p = @context.params.gsub(/\s*\#.*/, '')
            p = p.tr("\n", " ").squeeze(" ")
            p = "(" + p + ")" unless p[0] == ?(

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

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

              block.gsub!(/\s*\#.*/, '')
              block = block.tr("\n", " ").squeeze(" ")
              if block[0] == ?(
                block.sub!(/^\(/, '').sub!(/\)/, '')
              end
              p << " {|#{block.strip}| ...}"
            end
          end
          CGI.escapeHTML(p)
        end

parent_name()

[Source]

    # File rdoc/generators/html_generator.rb, line 952
        def parent_name
          if @context.parent.parent
            @context.parent.parent.full_name
          else
            nil
          end
        end

path()

[Source]

    # File rdoc/generators/html_generator.rb, line 964
        def path
          if @options.all_one_file
            aref
          else
            @html_class.path + "#" + aref
          end
        end

section()

[Source]

    # File rdoc/generators/html_generator.rb, line 944
        def section
          @context.section
        end

singleton()

[Source]

    # File rdoc/generators/html_generator.rb, line 980
        def singleton
          @context.singleton
        end

visibility()

[Source]

    # File rdoc/generators/html_generator.rb, line 976
        def visibility
          @context.visibility
        end

[Validate]