| Class | RDoc::Generator::Method |
| In: |
generator.rb
doc-tmp/rdoc/generator.rb |
| Parent: | Object |
# File doc-tmp/rdoc/generator.rb, line 859
859: def initialize(context, html_class, options)
860: @context = context
861: @html_class = html_class
862: @options = options
863:
864: # HACK ugly
865: @template = options.template_class
866:
867: @@seq = @@seq.succ
868: @seq = @@seq
869: @@all_methods << self
870:
871: context.viewer = self
872:
873: if (ts = @context.token_stream)
874: @source_code = markup_code(ts)
875: unless @options.inline_source
876: @src_url = create_source_code_file(@source_code)
877: @img_url = RDoc::Generator.gen_url path, 'source.png'
878: end
879: end
880:
881: AllReferences.add(name, self)
882: end
# File generator.rb, line 859
859: def initialize(context, html_class, options)
860: @context = context
861: @html_class = html_class
862: @options = options
863:
864: # HACK ugly
865: @template = options.template_class
866:
867: @@seq = @@seq.succ
868: @seq = @@seq
869: @@all_methods << self
870:
871: context.viewer = self
872:
873: if (ts = @context.token_stream)
874: @source_code = markup_code(ts)
875: unless @options.inline_source
876: @src_url = create_source_code_file(@source_code)
877: @img_url = RDoc::Generator.gen_url path, 'source.png'
878: end
879: end
880:
881: AllReferences.add(name, self)
882: end
# File doc-tmp/rdoc/generator.rb, line 998
998: def <=>(other)
999: @context <=> other.context
1000: end
We rely on the fact that the first line of a source code listing has
# File xxxxx, line dddd
# File doc-tmp/rdoc/generator.rb, line 1044
1044: def add_line_numbers(src)
1045: if src =~ /\A.*, line (\d+)/
1046: first = $1.to_i - 1
1047: last = first + src.count("\n")
1048: size = last.to_s.length
1049: real_fmt = "%#{size}d: "
1050: fmt = " " * (size+2)
1051: src.gsub!(/^/) do
1052: res = sprintf(fmt, first)
1053: first += 1
1054: fmt = real_fmt
1055: res
1056: end
1057: end
1058: end
We rely on the fact that the first line of a source code listing has
# File xxxxx, line dddd
# File generator.rb, line 1044
1044: def add_line_numbers(src)
1045: if src =~ /\A.*, line (\d+)/
1046: first = $1.to_i - 1
1047: last = first + src.count("\n")
1048: size = last.to_s.length
1049: real_fmt = "%#{size}d: "
1050: fmt = " " * (size+2)
1051: src.gsub!(/^/) do
1052: res = sprintf(fmt, first)
1053: first += 1
1054: fmt = real_fmt
1055: res
1056: end
1057: end
1058: end
Returns 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 generator.rb, line 888
888: def as_href(from_path)
889: if @options.all_one_file
890: "#" + path
891: else
892: RDoc::Generator.gen_url from_path, path
893: end
894: end
Returns 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 doc-tmp/rdoc/generator.rb, line 888
888: def as_href(from_path)
889: if @options.all_one_file
890: "#" + path
891: else
892: RDoc::Generator.gen_url from_path, path
893: end
894: end
# File doc-tmp/rdoc/generator.rb, line 940
940: def call_seq
941: cs = @context.call_seq
942: if cs
943: cs.gsub(/\n/, "<br />\n")
944: else
945: nil
946: end
947: end
# File generator.rb, line 940
940: def call_seq
941: cs = @context.call_seq
942: if cs
943: cs.gsub(/\n/, "<br />\n")
944: else
945: nil
946: end
947: end
# File generator.rb, line 974
974: def create_source_code_file(code_body)
975: suffix = "html"
976: suffix = "xhtml" if @options.template == "xhtml"
977: template_regexp = Regexp.new("\\." + suffix + "$")
978: meth_path = @html_class.path.sub(template_regexp, '.src')
979: FileUtils.mkdir_p(meth_path)
980: file_path = ::File.join(meth_path, @seq) + '.' + suffix
981:
982: template = RDoc::TemplatePage.new(@template::SRC_PAGE)
983:
984: open file_path, 'w' do |f|
985: values = {
986: 'title' => CGI.escapeHTML(index_name),
987: 'code' => code_body,
988: 'style_url' => style_url(file_path, @options.css),
989: 'mathml_xsl_url' => style_url(file_path, "mathml.xsl"),
990: 'charset' => @options.charset
991: }
992: template.write_html_on(f, values)
993: end
994:
995: RDoc::Generator.gen_url path, file_path
996: end
# File doc-tmp/rdoc/generator.rb, line 974
974: def create_source_code_file(code_body)
975: suffix = "html"
976: suffix = "xhtml" if @options.template == "xhtml"
977: template_regexp = Regexp.new("\\." + suffix + "$")
978: meth_path = @html_class.path.sub(template_regexp, '.src')
979: FileUtils.mkdir_p(meth_path)
980: file_path = ::File.join(meth_path, @seq) + '.' + suffix
981:
982: template = RDoc::TemplatePage.new(@template::SRC_PAGE)
983:
984: open file_path, 'w' do |f|
985: values = {
986: 'title' => CGI.escapeHTML(index_name),
987: 'code' => code_body,
988: 'style_url' => style_url(file_path, @options.css),
989: 'mathml_xsl_url' => style_url(file_path, "mathml.xsl"),
990: 'charset' => @options.charset
991: }
992: template.write_html_on(f, values)
993: end
994:
995: RDoc::Generator.gen_url path, file_path
996: end
# File doc-tmp/rdoc/generator.rb, line 928
928: def description
929: markup(@context.comment)
930: end
# File doc-tmp/rdoc/generator.rb, line 1060
1060: def document_self
1061: @context.document_self
1062: end
Find a filenames in ourselves or our parent
# File generator.rb, line 1077
1077: def find_file(file, method=nil)
1078: res = @context.parent.find_file(file, method, @options.ignore_case)
1079: if res
1080: res = res.viewer
1081: end
1082: res
1083: end
Find a filenames in ourselves or our parent
# File doc-tmp/rdoc/generator.rb, line 1077
1077: def find_file(file, method=nil)
1078: res = @context.parent.find_file(file, method, @options.ignore_case)
1079: if res
1080: res = res.viewer
1081: end
1082: res
1083: end
# File generator.rb, line 1068
1068: def find_symbol(symbol, method=nil)
1069: res = @context.parent.find_symbol(symbol, method, @options.ignore_case)
1070: if res
1071: res = res.viewer
1072: end
1073: res
1074: end
# File doc-tmp/rdoc/generator.rb, line 1068
1068: def find_symbol(symbol, method=nil)
1069: res = @context.parent.find_symbol(symbol, method, @options.ignore_case)
1070: if res
1071: res = res.viewer
1072: end
1073: res
1074: end
# File generator.rb, line 904
904: def index_name
905: "#{@context.name} (#{@html_class.name})"
906: end
# File doc-tmp/rdoc/generator.rb, line 904
904: def index_name
905: "#{@context.name} (#{@html_class.name})"
906: end
Given a sequence of source tokens, mark up the source code to make it look purty.
# File doc-tmp/rdoc/generator.rb, line 1006
1006: def markup_code(tokens)
1007: src = ""
1008: tokens.each do |t|
1009: next unless t
1010: # p t.class
1011: # style = STYLE_MAP[t.class]
1012: style = case t
1013: when RubyToken::TkCONSTANT then "ruby-constant"
1014: when RubyToken::TkKW then "ruby-keyword kw"
1015: when RubyToken::TkIVAR then "ruby-ivar"
1016: when RubyToken::TkOp then "ruby-operator"
1017: when RubyToken::TkId then "ruby-identifier"
1018: when RubyToken::TkNode then "ruby-node"
1019: when RubyToken::TkCOMMENT then "ruby-comment cmt"
1020: when RubyToken::TkREGEXP then "ruby-regexp re"
1021: when RubyToken::TkSTRING then "ruby-value str"
1022: when RubyToken::TkVal then "ruby-value"
1023: else
1024: nil
1025: end
1026:
1027: text = CGI.escapeHTML(t.text)
1028:
1029: if style
1030: src << "<span class=\"#{style}\">#{text}</span>"
1031: else
1032: src << text
1033: end
1034: end
1035:
1036: add_line_numbers(src) if @options.include_line_numbers
1037: src
1038: end
Given a sequence of source tokens, mark up the source code to make it look purty.
# File generator.rb, line 1006
1006: def markup_code(tokens)
1007: src = ""
1008: tokens.each do |t|
1009: next unless t
1010: # p t.class
1011: # style = STYLE_MAP[t.class]
1012: style = case t
1013: when RubyToken::TkCONSTANT then "ruby-constant"
1014: when RubyToken::TkKW then "ruby-keyword kw"
1015: when RubyToken::TkIVAR then "ruby-ivar"
1016: when RubyToken::TkOp then "ruby-operator"
1017: when RubyToken::TkId then "ruby-identifier"
1018: when RubyToken::TkNode then "ruby-node"
1019: when RubyToken::TkCOMMENT then "ruby-comment cmt"
1020: when RubyToken::TkREGEXP then "ruby-regexp re"
1021: when RubyToken::TkSTRING then "ruby-value str"
1022: when RubyToken::TkVal then "ruby-value"
1023: else
1024: nil
1025: end
1026:
1027: text = CGI.escapeHTML(t.text)
1028:
1029: if style
1030: src << "<span class=\"#{style}\">#{text}</span>"
1031: else
1032: src << text
1033: end
1034: end
1035:
1036: add_line_numbers(src) if @options.include_line_numbers
1037: src
1038: end
# File generator.rb, line 949
949: def params
950: # params coming from a call-seq in 'C' will start with the
951: # method name
952: if p !~ /^\w/
953: p = @context.params.gsub(/\s*\#.*/, '')
954: p = p.tr("\n", " ").squeeze(" ")
955: p = "(" + p + ")" unless p[0] == ?( || p == ''
956:
957: if (block = @context.block_params)
958: # If this method has explicit block parameters, remove any
959: # explicit &block
960:
961: p.sub!(/,?\s*&\w+/, '')
962:
963: block.gsub!(/\s*\#.*/, '')
964: block = block.tr("\n", " ").squeeze(" ")
965: if block[0] == ?(
966: block.sub!(/^\(/, '').sub!(/\)/, '')
967: end
968: p << " {|#{block.strip}| ...}"
969: end
970: end
971: CGI.escapeHTML(p)
972: end
# File doc-tmp/rdoc/generator.rb, line 949
949: def params
950: # params coming from a call-seq in 'C' will start with the
951: # method name
952: if p !~ /^\w/
953: p = @context.params.gsub(/\s*\#.*/, '')
954: p = p.tr("\n", " ").squeeze(" ")
955: p = "(" + p + ")" unless p[0] == ?( || p == ''
956:
957: if (block = @context.block_params)
958: # If this method has explicit block parameters, remove any
959: # explicit &block
960:
961: p.sub!(/,?\s*&\w+/, '')
962:
963: block.gsub!(/\s*\#.*/, '')
964: block = block.tr("\n", " ").squeeze(" ")
965: if block[0] == ?(
966: block.sub!(/^\(/, '').sub!(/\)/, '')
967: end
968: p << " {|#{block.strip}| ...}"
969: end
970: end
971: CGI.escapeHTML(p)
972: end
# File doc-tmp/rdoc/generator.rb, line 908
908: def parent_name
909: if @context.parent.parent
910: @context.parent.parent.full_name
911: else
912: nil
913: end
914: end
# File generator.rb, line 908
908: def parent_name
909: if @context.parent.parent
910: @context.parent.parent.full_name
911: else
912: nil
913: end
914: end
# File generator.rb, line 920
920: def path
921: if @options.all_one_file
922: aref
923: else
924: @html_class.path + "#" + aref
925: end
926: end
# File doc-tmp/rdoc/generator.rb, line 920
920: def path
921: if @options.all_one_file
922: aref
923: else
924: @html_class.path + "#" + aref
925: end
926: end