| Class | Generators::HtmlMethod |
| In: |
generators/html_generator.rb
|
| Parent: | Object |
| context | [R] | |
| img_url | [R] | |
| source_code | [R] | |
| src_url | [R] |
# File generators/html_generator.rb, line 1090
1090: def HtmlMethod.all_methods
1091: @@all_methods
1092: end
# File generators/html_generator.rb, line 959
959: def initialize(context, html_class, options)
960: @context = context
961: @html_class = html_class
962: @options = options
963: @@seq = @@seq.succ
964: @seq = @@seq
965: @@all_methods << self
966:
967: context.viewer = self
968:
969: if (ts = @context.token_stream)
970: @source_code = markup_code(ts)
971: unless @options.inline_source
972: @src_url = create_source_code_file(@source_code)
973: @img_url = HTMLGenerator.gen_url(path, 'source.png')
974: end
975: end
976:
977: AllReferences.add(name, self)
978: end
# File generators/html_generator.rb, line 955
955: def HtmlMethod::reset
956: @@all_methods = []
957: end
# File generators/html_generator.rb, line 1094
1094: def <=>(other)
1095: @context <=> other.context
1096: end
we rely on the fact that the first line of a source code listing has
# File xxxxx, line dddd
# File generators/html_generator.rb, line 1141
1141: def add_line_numbers(src)
1142: if src =~ /\A.*, line (\d+)/
1143: first = $1.to_i - 1
1144: last = first + src.count("\n")
1145: size = last.to_s.length
1146: real_fmt = "%#{size}d: "
1147: fmt = " " * (size+2)
1148: src.gsub!(/^/) do
1149: res = sprintf(fmt, first)
1150: first += 1
1151: fmt = real_fmt
1152: res
1153: end
1154: end
1155: 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
# File generators/html_generator.rb, line 984
984: def as_href(from_path)
985: if @options.all_one_file
986: "#" + path
987: else
988: HTMLGenerator.gen_url(from_path, path)
989: end
990: end
# File generators/html_generator.rb, line 1036
1036: def call_seq
1037: cs = @context.call_seq
1038: if cs
1039: cs.gsub(/\n/, "<br />\n")
1040: else
1041: nil
1042: end
1043: end
# File generators/html_generator.rb, line 1071
1071: def create_source_code_file(code_body)
1072: template_regexp = Regexp.new("\\." + @options.template + "$")
1073: meth_path = @html_class.path.sub(template_regexp, '.src')
1074: File.makedirs(meth_path)
1075: file_path = File.join(meth_path, @seq) + '.' + @options.template
1076:
1077: template = TemplatePage.new(RDoc::Page::SRC_PAGE)
1078: File.open(file_path, "w") do |f|
1079: values = {
1080: 'title' => CGI.escapeHTML(index_name),
1081: 'code' => code_body,
1082: 'style_url' => style_url(file_path, @options.css),
1083: 'charset' => @options.charset
1084: }
1085: template.write_html_on(f, values)
1086: end
1087: HTMLGenerator.gen_url(path, file_path)
1088: end
# File generators/html_generator.rb, line 1024
1024: def description
1025: markup(@context.comment)
1026: end
# File generators/html_generator.rb, line 1157
1157: def document_self
1158: @context.document_self
1159: end
Find a filenames in ourselves or our parent
# File generators/html_generator.rb, line 1174
1174: def find_file(file, method=nil)
1175: res = @context.parent.find_file(file, method)
1176: if res
1177: res = res.viewer
1178: end
1179: res
1180: end
# File generators/html_generator.rb, line 1165
1165: def find_symbol(symbol, method=nil)
1166: res = @context.parent.find_symbol(symbol, method, @options.ignore_case)
1167: if res
1168: res = res.viewer
1169: end
1170: res
1171: end
# File generators/html_generator.rb, line 1000
1000: def index_name
1001: "#{@context.name} (#{@html_class.name})"
1002: end
Given a sequence of source tokens, mark up the source code to make it look purty.
# File generators/html_generator.rb, line 1103
1103: def markup_code(tokens)
1104: src = ""
1105: tokens.each do |t|
1106: next unless t
1107: # p t.class
1108: # style = STYLE_MAP[t.class]
1109: style = case t
1110: when RubyToken::TkCONSTANT then "ruby-constant"
1111: when RubyToken::TkKW then "ruby-keyword kw"
1112: when RubyToken::TkIVAR then "ruby-ivar"
1113: when RubyToken::TkOp then "ruby-operator"
1114: when RubyToken::TkId then "ruby-identifier"
1115: when RubyToken::TkNode then "ruby-node"
1116: when RubyToken::TkCOMMENT then "ruby-comment cmt"
1117: when RubyToken::TkREGEXP then "ruby-regexp re"
1118: when RubyToken::TkSTRING then "ruby-value str"
1119: when RubyToken::TkVal then "ruby-value"
1120: else
1121: nil
1122: end
1123:
1124: text = CGI.escapeHTML(t.text)
1125:
1126: if style
1127: src << "<span class=\"#{style}\">#{text}</span>"
1128: else
1129: src << text
1130: end
1131: end
1132:
1133: add_line_numbers(src) if Options.instance.include_line_numbers
1134: src
1135: end
# File generators/html_generator.rb, line 1045
1045: def params
1046: # params coming from a call-seq in 'C' will start with the
1047: # method name
1048: p = @context.params
1049: if p !~ /^\w/
1050: p = @context.params.gsub(/\s*\#.*/, '')
1051: p = p.tr("\n", " ").squeeze(" ")
1052: p = "(" + p + ")" unless p[0] == ?(
1053:
1054: if (block = @context.block_params)
1055: # If this method has explicit block parameters, remove any
1056: # explicit &block
1057:
1058: p.sub!(/,?\s*&\w+/, '')
1059:
1060: block.gsub!(/\s*\#.*/, '')
1061: block = block.tr("\n", " ").squeeze(" ")
1062: if block[0] == ?(
1063: block.sub!(/^\(/, '').sub!(/\)/, '')
1064: end
1065: p << " {|#{block.strip}| ...}"
1066: end
1067: end
1068: CGI.escapeHTML(p)
1069: end
# File generators/html_generator.rb, line 1004
1004: def parent_name
1005: if @context.parent.parent
1006: @context.parent.parent.full_name
1007: else
1008: nil
1009: end
1010: end
# File generators/html_generator.rb, line 1016
1016: def path
1017: if @options.all_one_file
1018: aref
1019: else
1020: @html_class.path + "#" + aref
1021: end
1022: end
# File generators/html_generator.rb, line 1032
1032: def singleton
1033: @context.singleton
1034: end