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