| Class | Generators::HtmlMethod |
| In: |
lib/rdoc/generators/html_generator.rb
|
| Parent: | Object |
| context | [R] | |
| img_url | [R] | |
| source_code | [R] | |
| src_url | [R] |
# File lib/rdoc/generators/html_generator.rb, line 1044
1044: def HtmlMethod.all_methods
1045: @@all_methods
1046: end
# File lib/rdoc/generators/html_generator.rb, line 914
914: def initialize(context, html_class, options)
915: @context = context
916: @html_class = html_class
917: @options = options
918: @@seq = @@seq.succ
919: @seq = @@seq
920: @@all_methods << self
921:
922: context.viewer = self
923:
924: if (ts = @context.token_stream)
925: @source_code = markup_code(ts)
926: unless @options.inline_source
927: @src_url = create_source_code_file(@source_code)
928: @img_url = HTMLGenerator.gen_url(path, 'source.png')
929: end
930: end
931:
932: AllReferences.add(name, self)
933: end
# File lib/rdoc/generators/html_generator.rb, line 910
910: def HtmlMethod::reset
911: @@all_methods = []
912: end
# File lib/rdoc/generators/html_generator.rb, line 1048
1048: def <=>(other)
1049: @context <=> other.context
1050: end
we rely on the fact that the first line of a source code listing has
# File xxxxx, line dddd
# File lib/rdoc/generators/html_generator.rb, line 1095
1095: def add_line_numbers(src)
1096: if src =~ /\A.*, line (\d+)/
1097: first = $1.to_i - 1
1098: last = first + src.count("\n")
1099: size = last.to_s.length
1100: real_fmt = "%#{size}d: "
1101: fmt = " " * (size+2)
1102: src.gsub!(/^/) do
1103: res = sprintf(fmt, first)
1104: first += 1
1105: fmt = real_fmt
1106: res
1107: end
1108: end
1109: end
# File lib/rdoc/generators/html_generator.rb, line 1115
1115: def aliases
1116: @context.aliases
1117: 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 lib/rdoc/generators/html_generator.rb, line 939
939: def as_href(from_path)
940: if @options.all_one_file
941: "#" + path
942: else
943: HTMLGenerator.gen_url(from_path, path)
944: end
945: end
# File lib/rdoc/generators/html_generator.rb, line 991
991: def call_seq
992: cs = @context.call_seq
993: if cs
994: cs.gsub(/\n/, "<br />\n")
995: else
996: nil
997: end
998: end
# File lib/rdoc/generators/html_generator.rb, line 1026
1026: def create_source_code_file(code_body)
1027: meth_path = @html_class.path.sub(/\.html$/, '.src')
1028: File.makedirs(meth_path)
1029: file_path = File.join(meth_path, @seq) + ".html"
1030:
1031: template = TemplatePage.new(RDoc::Page::SRC_PAGE)
1032: File.open(file_path, "w") do |f|
1033: values = {
1034: 'title' => CGI.escapeHTML(index_name),
1035: 'code' => code_body,
1036: 'style_url' => style_url(file_path, @options.css),
1037: 'charset' => @options.charset
1038: }
1039: template.write_html_on(f, values)
1040: end
1041: HTMLGenerator.gen_url(path, file_path)
1042: end
# File lib/rdoc/generators/html_generator.rb, line 979
979: def description
980: markup(@context.comment)
981: end
# File lib/rdoc/generators/html_generator.rb, line 1111
1111: def document_self
1112: @context.document_self
1113: end
# File lib/rdoc/generators/html_generator.rb, line 1119
1119: def find_symbol(symbol, method=nil)
1120: res = @context.parent.find_symbol(symbol, method)
1121: if res
1122: res = res.viewer
1123: end
1124: res
1125: end
# File lib/rdoc/generators/html_generator.rb, line 955
955: def index_name
956: "#{@context.name} (#{@html_class.name})"
957: end
Given a sequence of source tokens, mark up the source code to make it look purty.
# File lib/rdoc/generators/html_generator.rb, line 1057
1057: def markup_code(tokens)
1058: src = ""
1059: tokens.each do |t|
1060: next unless t
1061: # p t.class
1062: # style = STYLE_MAP[t.class]
1063: style = case t
1064: when RubyToken::TkCONSTANT then "ruby-constant"
1065: when RubyToken::TkKW then "ruby-keyword kw"
1066: when RubyToken::TkIVAR then "ruby-ivar"
1067: when RubyToken::TkOp then "ruby-operator"
1068: when RubyToken::TkId then "ruby-identifier"
1069: when RubyToken::TkNode then "ruby-node"
1070: when RubyToken::TkCOMMENT then "ruby-comment cmt"
1071: when RubyToken::TkREGEXP then "ruby-regexp re"
1072: when RubyToken::TkSTRING then "ruby-value str"
1073: when RubyToken::TkVal then "ruby-value"
1074: else
1075: nil
1076: end
1077:
1078: text = CGI.escapeHTML(t.text)
1079:
1080: if style
1081: src << "<span class=\"#{style}\">#{text}</span>"
1082: else
1083: src << text
1084: end
1085: end
1086:
1087: add_line_numbers(src) if Options.instance.include_line_numbers
1088: src
1089: end
# File lib/rdoc/generators/html_generator.rb, line 1000
1000: def params
1001: # params coming from a call-seq in 'C' will start with the
1002: # method name
1003: p = @context.params
1004: if p !~ /^\w/
1005: p = @context.params.gsub(/\s*\#.*/, '')
1006: p = p.tr("\n", " ").squeeze(" ")
1007: p = "(" + p + ")" unless p[0] == ?(
1008:
1009: if (block = @context.block_params)
1010: # If this method has explicit block parameters, remove any
1011: # explicit &block
1012:
1013: p.sub!(/,?\s*&\w+/, '')
1014:
1015: block.gsub!(/\s*\#.*/, '')
1016: block = block.tr("\n", " ").squeeze(" ")
1017: if block[0] == ?(
1018: block.sub!(/^\(/, '').sub!(/\)/, '')
1019: end
1020: p << " {|#{block.strip}| ...}"
1021: end
1022: end
1023: CGI.escapeHTML(p)
1024: end
# File lib/rdoc/generators/html_generator.rb, line 959
959: def parent_name
960: if @context.parent.parent
961: @context.parent.parent.full_name
962: else
963: nil
964: end
965: end
# File lib/rdoc/generators/html_generator.rb, line 971
971: def path
972: if @options.all_one_file
973: aref
974: else
975: @html_class.path + "#" + aref
976: end
977: end
# File lib/rdoc/generators/html_generator.rb, line 951
951: def section
952: @context.section
953: end
# File lib/rdoc/generators/html_generator.rb, line 987
987: def singleton
988: @context.singleton
989: end