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

Included Modules

Attributes

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

Public Class methods

[Source]

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

[Source]

     # File rdoc/generators/html_generator.rb, line 907
907:     def initialize(context, html_class, options)
908:       @context    = context
909:       @html_class = html_class
910:       @options    = options
911:       @@seq       = @@seq.succ
912:       @seq        = @@seq
913:       @@all_methods << self
914: 
915:       context.viewer = self
916: 
917:       if (ts = @context.token_stream)
918:         @source_code = markup_code(ts)
919:         unless @options.inline_source
920:           @src_url = create_source_code_file(@source_code)
921:           @img_url = HTMLGenerator.gen_url(path, 'source.png')
922:         end
923:       end
924: 
925:       AllReferences.add(name, self)
926:     end

[Source]

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

Public Instance methods

[Source]

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

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
1088:     def add_line_numbers(src)
1089:       if src =~ /\A.*, line (\d+)/
1090:         first = $1.to_i - 1
1091:         last  = first + src.count("\n")
1092:         size = last.to_s.length
1093:         real_fmt = "%#{size}d: "
1094:         fmt = " " * (size+2)
1095:         src.gsub!(/^/) do
1096:           res = sprintf(fmt, first) 
1097:           first += 1
1098:           fmt = real_fmt
1099:           res
1100:         end
1101:       end
1102:     end

[Source]

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

[Source]

     # File rdoc/generators/html_generator.rb, line 960
960:     def aref
961:       @seq
962:     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 932
932:     def as_href(from_path)
933:       if @options.all_one_file
934:         "#" + path
935:       else
936:         HTMLGenerator.gen_url(from_path, path)
937:       end
938:     end

[Source]

     # File rdoc/generators/html_generator.rb, line 984
984:     def call_seq
985:       cs = @context.call_seq
986:       if cs
987:         cs.gsub(/\n/, "<br />\n")
988:       else
989:         nil
990:       end
991:     end

[Source]

      # File rdoc/generators/html_generator.rb, line 1019
1019:     def create_source_code_file(code_body)
1020:       meth_path = @html_class.path.sub(/\.html$/, '.src')
1021:       File.makedirs(meth_path)
1022:       file_path = File.join(meth_path, @seq) + ".html"
1023: 
1024:       template = TemplatePage.new(RDoc::Page::SRC_PAGE)
1025:       File.open(file_path, "w") do |f|
1026:         values = {
1027:           'title'     => CGI.escapeHTML(index_name),
1028:           'code'      => code_body,
1029:           'style_url' => style_url(file_path, @options.css),
1030:           'charset'   => @options.charset
1031:         }
1032:         template.write_html_on(f, values)
1033:       end
1034:       HTMLGenerator.gen_url(path, file_path)
1035:     end

[Source]

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

[Source]

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

[Source]

      # File rdoc/generators/html_generator.rb, line 1112
1112:     def find_symbol(symbol, method=nil)
1113:       res = @context.parent.find_symbol(symbol, method)
1114:       if res
1115:         res = res.viewer
1116:       end
1117:       res
1118:     end

[Source]

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

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
1050:     def markup_code(tokens)
1051:       src = ""
1052:       tokens.each do |t|
1053:         next unless t
1054:         #    p t.class
1055: #        style = STYLE_MAP[t.class]
1056:         style = case t
1057:                 when RubyToken::TkCONSTANT then "ruby-constant"
1058:                 when RubyToken::TkKW       then "ruby-keyword kw"
1059:                 when RubyToken::TkIVAR     then "ruby-ivar"
1060:                 when RubyToken::TkOp       then "ruby-operator"
1061:                 when RubyToken::TkId       then "ruby-identifier"
1062:                 when RubyToken::TkNode     then "ruby-node"
1063:                 when RubyToken::TkCOMMENT  then "ruby-comment cmt"
1064:                 when RubyToken::TkREGEXP   then "ruby-regexp re"
1065:                 when RubyToken::TkSTRING   then "ruby-value str"
1066:                 when RubyToken::TkVal      then "ruby-value"
1067:                 else
1068:                     nil
1069:                 end
1070: 
1071:         text = CGI.escapeHTML(t.text)
1072: 
1073:         if style
1074:           src << "<span class=\"#{style}\">#{text}</span>"
1075:         else
1076:           src << text
1077:         end
1078:       end
1079: 
1080:       add_line_numbers(src) if Options.instance.include_line_numbers
1081:       src
1082:     end

[Source]

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

[Source]

      # File rdoc/generators/html_generator.rb, line 993
 993:     def params
 994:       # params coming from a call-seq in 'C' will start with the
 995:       # method name
 996:       p = @context.params
 997:       if p !~ /^\w/
 998:         p = @context.params.gsub(/\s*\#.*/, '')
 999:         p = p.tr("\n", " ").squeeze(" ")
1000:         p = "(" + p + ")" unless p[0] == ?(
1001:         
1002:         if (block = @context.block_params)
1003:          # If this method has explicit block parameters, remove any
1004:          # explicit &block
1005: 
1006:          p.sub!(/,?\s*&\w+/, '')
1007: 
1008:           block.gsub!(/\s*\#.*/, '')
1009:           block = block.tr("\n", " ").squeeze(" ")
1010:           if block[0] == ?(
1011:             block.sub!(/^\(/, '').sub!(/\)/, '')
1012:           end
1013:           p << " {|#{block.strip}| ...}"
1014:         end
1015:       end
1016:       CGI.escapeHTML(p)
1017:     end

[Source]

     # File rdoc/generators/html_generator.rb, line 952
952:     def parent_name
953:       if @context.parent.parent
954:         @context.parent.parent.full_name
955:       else
956:         nil
957:       end
958:     end

[Source]

     # File rdoc/generators/html_generator.rb, line 964
964:     def path
965:       if @options.all_one_file
966:         aref
967:       else
968:         @html_class.path + "#" + aref
969:       end
970:     end

[Source]

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

[Source]

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

[Source]

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

Search

Google

Ruby API Docs

Links