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 1089
1089:     def HtmlMethod.all_methods
1090:       @@all_methods
1091:     end

[Source]

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

[Source]

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

Public Instance methods

[Source]

      # File generators/html_generator.rb, line 1093
1093:     def <=>(other)
1094:       @context <=> other.context
1095:     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 1140
1140:     def add_line_numbers(src)
1141:       if src =~ /\A.*, line (\d+)/
1142:         first = $1.to_i - 1
1143:         last  = first + src.count("\n")
1144:         size = last.to_s.length
1145:         real_fmt = "%#{size}d: "
1146:         fmt = " " * (size+2)
1147:         src.gsub!(/^/) do
1148:           res = sprintf(fmt, first) 
1149:           first += 1
1150:           fmt = real_fmt
1151:           res
1152:         end
1153:       end
1154:     end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

Find a filenames in ourselves or our parent

[Source]

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

[Source]

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

[Source]

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

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Validate]