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

Methods

Included Modules

MarkUp

Attributes

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

Public Class methods

[Source]

      # File generators/html_generator.rb, line 1087
1087:     def HtmlMethod.all_methods
1088:       @@all_methods
1089:     end

[Source]

     # File generators/html_generator.rb, line 957
957:     def initialize(context, html_class, options)
958:       @context    = context
959:       @html_class = html_class
960:       @options    = options
961:       @@seq       = @@seq.succ
962:       @seq        = @@seq
963:       @@all_methods << self
964: 
965:       context.viewer = self
966: 
967:       if (ts = @context.token_stream)
968:         @source_code = markup_code(ts)
969:         unless @options.inline_source
970:           @src_url = create_source_code_file(@source_code)
971:           @img_url = HTMLGenerator.gen_url(path, 'source.png')
972:         end
973:       end
974: 
975:       AllReferences.add(name, self)
976:     end

[Source]

     # File generators/html_generator.rb, line 953
953:     def HtmlMethod::reset
954:       @@all_methods = []
955:     end

Public Instance methods

[Source]

      # File generators/html_generator.rb, line 1091
1091:     def <=>(other)
1092:       @context <=> other.context
1093:     end

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

   # File xxxxx, line dddd

[Source]

      # File generators/html_generator.rb, line 1138
1138:     def add_line_numbers(src)
1139:       if src =~ /\A.*, line (\d+)/
1140:         first = $1.to_i - 1
1141:         last  = first + src.count("\n")
1142:         size = last.to_s.length
1143:         real_fmt = "%#{size}d: "
1144:         fmt = " " * (size+2)
1145:         src.gsub!(/^/) do
1146:           res = sprintf(fmt, first) 
1147:           first += 1
1148:           fmt = real_fmt
1149:           res
1150:         end
1151:       end
1152:     end

[Source]

      # File generators/html_generator.rb, line 1158
1158:     def aliases
1159:       @context.aliases
1160:     end

[Source]

      # File generators/html_generator.rb, line 1010
1010:     def aref
1011:       @seq
1012:     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 generators/html_generator.rb, line 982
982:     def as_href(from_path)
983:       if @options.all_one_file
984:         "#" + path
985:       else
986:         HTMLGenerator.gen_url(from_path, path)
987:       end
988:     end

[Source]

      # File generators/html_generator.rb, line 1034
1034:     def call_seq
1035:       cs = @context.call_seq
1036:       if cs
1037:         cs.gsub(/\n/, "<br />\n")
1038:       else
1039:         nil
1040:       end
1041:     end

[Source]

      # File generators/html_generator.rb, line 1069
1069:     def create_source_code_file(code_body)
1070:       meth_path = @html_class.path.sub(/\.html$/, '.src')
1071:       File.makedirs(meth_path)
1072:       file_path = File.join(meth_path, @seq) + ".html"
1073: 
1074:       template = TemplatePage.new(RDoc::Page::SRC_PAGE)
1075:       File.open(file_path, "w") do |f|
1076:         values = {
1077:           'title'     => CGI.escapeHTML(index_name),
1078:           'code'      => code_body,
1079:           'style_url' => style_url(file_path, @options.css),
1080:           'charset'   => @options.charset
1081:         }
1082:         template.write_html_on(f, values)
1083:       end
1084:       HTMLGenerator.gen_url(path, file_path)
1085:     end

[Source]

      # File generators/html_generator.rb, line 1022
1022:     def description
1023:       markup(@context.comment)
1024:     end

[Source]

      # File generators/html_generator.rb, line 1154
1154:     def document_self
1155:       @context.document_self
1156:     end

Find a filenames in ourselves or our parent

[Source]

      # File generators/html_generator.rb, line 1171
1171:     def find_file(file, method=nil)
1172:       res = @context.parent.find_file(file, method)
1173:       if res
1174:         res = res.viewer
1175:       end
1176:       res
1177:     end

[Source]

      # File generators/html_generator.rb, line 1162
1162:     def find_symbol(symbol, method=nil)
1163:       res = @context.parent.find_symbol(symbol, method, @options.ignore_case)
1164:       if res
1165:         res = res.viewer
1166:       end
1167:       res
1168:     end

[Source]

      # File generators/html_generator.rb, line 998
 998:     def index_name
 999:       "#{@context.name} (#{@html_class.name})"
1000:     end

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

[Source]

      # File generators/html_generator.rb, line 1100
1100:     def markup_code(tokens)
1101:       src = ""
1102:       tokens.each do |t|
1103:         next unless t
1104:         #    p t.class
1105: #        style = STYLE_MAP[t.class]
1106:         style = case t
1107:                 when RubyToken::TkCONSTANT then "ruby-constant"
1108:                 when RubyToken::TkKW       then "ruby-keyword kw"
1109:                 when RubyToken::TkIVAR     then "ruby-ivar"
1110:                 when RubyToken::TkOp       then "ruby-operator"
1111:                 when RubyToken::TkId       then "ruby-identifier"
1112:                 when RubyToken::TkNode     then "ruby-node"
1113:                 when RubyToken::TkCOMMENT  then "ruby-comment cmt"
1114:                 when RubyToken::TkREGEXP   then "ruby-regexp re"
1115:                 when RubyToken::TkSTRING   then "ruby-value str"
1116:                 when RubyToken::TkVal      then "ruby-value"
1117:                 else
1118:                     nil
1119:                 end
1120: 
1121:         text = CGI.escapeHTML(t.text)
1122: 
1123:         if style
1124:           src << "<span class=\"#{style}\">#{text}</span>"
1125:         else
1126:           src << text
1127:         end
1128:       end
1129: 
1130:       add_line_numbers(src) if Options.instance.include_line_numbers
1131:       src
1132:     end

[Source]

     # File generators/html_generator.rb, line 990
990:     def name
991:       @context.name
992:     end

[Source]

      # File generators/html_generator.rb, line 1043
1043:     def params
1044:       # params coming from a call-seq in 'C' will start with the
1045:       # method name
1046:       p = @context.params
1047:       if p !~ /^\w/
1048:         p = @context.params.gsub(/\s*\#.*/, '')
1049:         p = p.tr("\n", " ").squeeze(" ")
1050:         p = "(" + p + ")" unless p[0] == ?(
1051:         
1052:         if (block = @context.block_params)
1053:          # If this method has explicit block parameters, remove any
1054:          # explicit &block
1055: 
1056:          p.sub!(/,?\s*&\w+/, '')
1057: 
1058:           block.gsub!(/\s*\#.*/, '')
1059:           block = block.tr("\n", " ").squeeze(" ")
1060:           if block[0] == ?(
1061:             block.sub!(/^\(/, '').sub!(/\)/, '')
1062:           end
1063:           p << " {|#{block.strip}| ...}"
1064:         end
1065:       end
1066:       CGI.escapeHTML(p)
1067:     end

[Source]

      # File generators/html_generator.rb, line 1002
1002:     def parent_name
1003:       if @context.parent.parent
1004:         @context.parent.parent.full_name
1005:       else
1006:         nil
1007:       end
1008:     end

[Source]

      # File generators/html_generator.rb, line 1014
1014:     def path
1015:       if @options.all_one_file
1016:         aref
1017:       else
1018:         @html_class.path + "#" + aref
1019:       end
1020:     end

[Source]

     # File generators/html_generator.rb, line 994
994:     def section
995:       @context.section
996:     end

[Source]

      # File generators/html_generator.rb, line 1030
1030:     def singleton
1031:       @context.singleton
1032:     end

[Source]

      # File generators/html_generator.rb, line 1026
1026:     def visibility
1027:       @context.visibility
1028:     end

[Validate]