Class: RDocF95::Generator::Method

Inherits:
Object
  • Object
show all
Includes:
MarkUp
Defined in:
lib/rdoc-f95/generator.rb

Constant Summary collapse

@@seq =
"M000000"
@@all_methods =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MarkUp

#cvs_url, #markup, #style_url

Constructor Details

#initialize(context, html_class, options) ⇒ Method

Returns a new instance of Method.


859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
# File 'lib/rdoc-f95/generator.rb', line 859

def initialize(context, html_class, options)
  @context    = context
  @html_class = html_class
  @options    = options

  # HACK ugly
  @template = options.template_class

  @@seq       = @@seq.succ
  @seq        = @@seq
  @@all_methods << self

  context.viewer = self

  if (ts = @context.token_stream)
    @source_code = markup_code(ts)
    unless @options.inline_source
      @src_url = create_source_code_file(@source_code)
      @img_url = RDocF95::Generator.gen_url path, 'source.png'
    end
  end

  AllReferences.add(name, self)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context


842
843
844
# File 'lib/rdoc-f95/generator.rb', line 842

def context
  @context
end

#img_urlObject (readonly)

Returns the value of attribute img_url


844
845
846
# File 'lib/rdoc-f95/generator.rb', line 844

def img_url
  @img_url
end

#source_codeObject (readonly)

Returns the value of attribute source_code


845
846
847
# File 'lib/rdoc-f95/generator.rb', line 845

def source_code
  @source_code
end

#src_urlObject (readonly)

Returns the value of attribute src_url


843
844
845
# File 'lib/rdoc-f95/generator.rb', line 843

def src_url
  @src_url
end

Class Method Details

.all_methodsObject


851
852
853
# File 'lib/rdoc-f95/generator.rb', line 851

def self.all_methods
  @@all_methods
end

.resetObject


855
856
857
# File 'lib/rdoc-f95/generator.rb', line 855

def self.reset
  @@all_methods = []
end

Instance Method Details

#<=>(other) ⇒ Object


998
999
1000
# File 'lib/rdoc-f95/generator.rb', line 998

def <=>(other)
  @context <=> other.context
end

#add_line_numbers(src) ⇒ Object

We rely on the fact that the first line of a source code listing has

# File xxxxx, line dddd

1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
# File 'lib/rdoc-f95/generator.rb', line 1044

def add_line_numbers(src)
  if src =~ /\A.*, line (\d+)/
    first = $1.to_i - 1
    last  = first + src.count("\n")
    size = last.to_s.length
    real_fmt = "%#{size}d: "
    fmt = " " * (size+2)
    src.gsub!(/^/) do
      res = sprintf(fmt, first)
      first += 1
      fmt = real_fmt
      res
    end
  end
end

#aliasesObject


1064
1065
1066
# File 'lib/rdoc-f95/generator.rb', line 1064

def aliases
  @context.aliases
end

#arefObject


916
917
918
# File 'lib/rdoc-f95/generator.rb', line 916

def aref
  @seq
end

#as_href(from_path) ⇒ Object

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


888
889
890
891
892
893
894
# File 'lib/rdoc-f95/generator.rb', line 888

def as_href(from_path)
  if @options.all_one_file
    "#" + path
  else
    RDocF95::Generator.gen_url from_path, path
  end
end

#call_seqObject


940
941
942
943
944
945
946
947
# File 'lib/rdoc-f95/generator.rb', line 940

def call_seq
  cs = @context.call_seq
  if cs
    cs.gsub(/\n/, "<br />\n")
  else
    nil
  end
end

#create_source_code_file(code_body) ⇒ Object


974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
# File 'lib/rdoc-f95/generator.rb', line 974

def create_source_code_file(code_body)
  suffix = "html"
  suffix = "xhtml" if @options.template == "xhtml"
  template_regexp = Regexp.new("\\." + suffix + "$")
  meth_path = @html_class.path.sub(template_regexp, '.src')
  FileUtils.mkdir_p(meth_path)
  file_path = ::File.join(meth_path, @seq) + '.' + suffix

  template = RDocF95::TemplatePage.new(@template::SRC_PAGE)

  open file_path, 'w' do |f|
    values = {
      'title'     => CGI.escapeHTML(index_name),
      'code'      => code_body,
      'style_url' => style_url(file_path, @options.css),
      'mathml_xsl_url' => style_url(file_path, "mathml.xsl"),
      'charset'   => @options.charset
    }
    template.write_html_on(f, values)
  end

  RDocF95::Generator.gen_url path, file_path
end

#descriptionObject


928
929
930
# File 'lib/rdoc-f95/generator.rb', line 928

def description
  markup(@context.comment)
end

#document_selfObject


1060
1061
1062
# File 'lib/rdoc-f95/generator.rb', line 1060

def document_self
  @context.document_self
end

#find_file(file, method = nil) ⇒ Object

Find a filenames in ourselves or our parent


1077
1078
1079
1080
1081
1082
1083
# File 'lib/rdoc-f95/generator.rb', line 1077

def find_file(file, method=nil)
  res = @context.parent.find_file(file, method, @options.ignore_case)
  if res
    res = res.viewer
  end
  res
end

#find_symbol(symbol, method = nil) ⇒ Object


1068
1069
1070
1071
1072
1073
1074
# File 'lib/rdoc-f95/generator.rb', line 1068

def find_symbol(symbol, method=nil)
  res = @context.parent.find_symbol(symbol, method, @options.ignore_case)
  if res
    res = res.viewer
  end
  res
end

#index_nameObject


904
905
906
# File 'lib/rdoc-f95/generator.rb', line 904

def index_name
  "#{@context.name} (#{@html_class.name})"
end

#markup_code(tokens) ⇒ Object

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


1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
# File 'lib/rdoc-f95/generator.rb', line 1006

def markup_code(tokens)
  src = ""
  tokens.each do |t|
    next unless t
    #    p t.class
#        style = STYLE_MAP[t.class]
    style = case t
            when RubyToken::TkCONSTANT then "ruby-constant"
            when RubyToken::TkKW       then "ruby-keyword kw"
            when RubyToken::TkIVAR     then "ruby-ivar"
            when RubyToken::TkOp       then "ruby-operator"
            when RubyToken::TkId       then "ruby-identifier"
            when RubyToken::TkNode     then "ruby-node"
            when RubyToken::TkCOMMENT  then "ruby-comment cmt"
            when RubyToken::TkREGEXP   then "ruby-regexp re"
            when RubyToken::TkSTRING   then "ruby-value str"
            when RubyToken::TkVal      then "ruby-value"
            else
                nil
            end

    text = CGI.escapeHTML(t.text)

    if style
      src << "<span class=\"#{style}\">#{text}</span>"
    else
      src << text
    end
  end

  add_line_numbers(src) if @options.include_line_numbers
  src
end

#nameObject


896
897
898
# File 'lib/rdoc-f95/generator.rb', line 896

def name
  @context.name
end

#paramsObject


949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
# File 'lib/rdoc-f95/generator.rb', line 949

def params
  # params coming from a call-seq in 'C' will start with the
  # method name
  if p !~ /^\w/
    p = @context.params.gsub(/\s*\#.*/, '')
    p = p.tr("\n", " ").squeeze(" ")
    p = "(" + p + ")" unless p[0] == ?( || p == ''

    if (block = @context.block_params)
     # If this method has explicit block parameters, remove any
     # explicit &block

     p.sub!(/,?\s*&\w+/, '')

      block.gsub!(/\s*\#.*/, '')
      block = block.tr("\n", " ").squeeze(" ")
      if block[0] == ?(
        block.sub!(/^\(/, '').sub!(/\)/, '')
      end
      p << " {|#{block.strip}| ...}"
    end
  end
  CGI.escapeHTML(p)
end

#parent_nameObject


908
909
910
911
912
913
914
# File 'lib/rdoc-f95/generator.rb', line 908

def parent_name
  if @context.parent.parent
    @context.parent.parent.full_name
  else
    nil
  end
end

#pathObject


920
921
922
923
924
925
926
# File 'lib/rdoc-f95/generator.rb', line 920

def path
  if @options.all_one_file
    aref
  else
    @html_class.path + "#" + aref
  end
end

#sectionObject


900
901
902
# File 'lib/rdoc-f95/generator.rb', line 900

def section
  @context.section
end

#singletonObject


936
937
938
# File 'lib/rdoc-f95/generator.rb', line 936

def singleton
  @context.singleton
end

#visibilityObject


932
933
934
# File 'lib/rdoc-f95/generator.rb', line 932

def visibility
  @context.visibility
end