Class: Generators::HtmlMethod
- Inherits:
-
Object
- Object
- Generators::HtmlMethod
show all
- Includes:
- MarkUp
- Defined in:
- lib/rdoc/generators/html_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) ⇒ HtmlMethod
Returns a new instance of HtmlMethod.
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
|
# File 'lib/rdoc/generators/html_generator.rb', line 914
def initialize(context, html_class, options)
@context = context
@html_class = html_class
@options = options
@@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 = HTMLGenerator.gen_url(path, 'source.png')
end
end
AllReferences.add(name, self)
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context
901
902
903
|
# File 'lib/rdoc/generators/html_generator.rb', line 901
def context
@context
end
|
#img_url ⇒ Object
Returns the value of attribute img_url
903
904
905
|
# File 'lib/rdoc/generators/html_generator.rb', line 903
def img_url
@img_url
end
|
#source_code ⇒ Object
Returns the value of attribute source_code
904
905
906
|
# File 'lib/rdoc/generators/html_generator.rb', line 904
def source_code
@source_code
end
|
#src_url ⇒ Object
Returns the value of attribute src_url
902
903
904
|
# File 'lib/rdoc/generators/html_generator.rb', line 902
def src_url
@src_url
end
|
Class Method Details
.all_methods ⇒ Object
1044
1045
1046
|
# File 'lib/rdoc/generators/html_generator.rb', line 1044
def HtmlMethod.all_methods
@@all_methods
end
|
.reset ⇒ Object
910
911
912
|
# File 'lib/rdoc/generators/html_generator.rb', line 910
def HtmlMethod::reset
@@all_methods = []
end
|
Instance Method Details
#<=>(other) ⇒ Object
1048
1049
1050
|
# File 'lib/rdoc/generators/html_generator.rb', line 1048
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
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
|
# File 'lib/rdoc/generators/html_generator.rb', line 1095
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
|
#aliases ⇒ Object
1115
1116
1117
|
# File 'lib/rdoc/generators/html_generator.rb', line 1115
def aliases
@context.aliases
end
|
#aref ⇒ Object
967
968
969
|
# File 'lib/rdoc/generators/html_generator.rb', line 967
def aref
@seq
end
|
#as_href(from_path) ⇒ Object
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
939
940
941
942
943
944
945
|
# File 'lib/rdoc/generators/html_generator.rb', line 939
def as_href(from_path)
if @options.all_one_file
"#" + path
else
HTMLGenerator.gen_url(from_path, path)
end
end
|
#call_seq ⇒ Object
991
992
993
994
995
996
997
998
|
# File 'lib/rdoc/generators/html_generator.rb', line 991
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
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
|
# File 'lib/rdoc/generators/html_generator.rb', line 1026
def create_source_code_file(code_body)
meth_path = @html_class.path.sub(/\.html$/, '.src')
File.makedirs(meth_path)
file_path = File.join(meth_path, @seq) + ".html"
template = TemplatePage.new(RDoc::Page::SRC_PAGE)
File.open(file_path, "w") do |f|
values = {
'title' => CGI.escapeHTML(index_name),
'code' => code_body,
'style_url' => style_url(file_path, @options.css),
'charset' => @options.charset
}
template.write_html_on(f, values)
end
HTMLGenerator.gen_url(path, file_path)
end
|
#description ⇒ Object
979
980
981
|
# File 'lib/rdoc/generators/html_generator.rb', line 979
def description
markup(@context.)
end
|
#document_self ⇒ Object
1111
1112
1113
|
# File 'lib/rdoc/generators/html_generator.rb', line 1111
def document_self
@context.document_self
end
|
#find_symbol(symbol, method = nil) ⇒ Object
1119
1120
1121
1122
1123
1124
1125
|
# File 'lib/rdoc/generators/html_generator.rb', line 1119
def find_symbol(symbol, method=nil)
res = @context.parent.find_symbol(symbol, method)
if res
res = res.viewer
end
res
end
|
#index_name ⇒ Object
955
956
957
|
# File 'lib/rdoc/generators/html_generator.rb', line 955
def index_name
"#{@context.name} (#{@html_class.name})"
end
|
#markup_code(tokens) ⇒ Object
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
|
# File 'lib/rdoc/generators/html_generator.rb', line 1057
def markup_code(tokens)
src = ""
tokens.each do |t|
next unless t
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.instance.include_line_numbers
src
end
|
#name ⇒ Object
947
948
949
|
# File 'lib/rdoc/generators/html_generator.rb', line 947
def name
@context.name
end
|
#params ⇒ Object
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
|
# File 'lib/rdoc/generators/html_generator.rb', line 1000
def params
p = @context.params
if p !~ /^\w/
p = @context.params.gsub(/\s*\#.*/, '')
p = p.tr("\n", " ").squeeze(" ")
p = "(" + p + ")" unless p[0] == ?(
if (block = @context.block_params)
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_name ⇒ Object
959
960
961
962
963
964
965
|
# File 'lib/rdoc/generators/html_generator.rb', line 959
def parent_name
if @context.parent.parent
@context.parent.parent.full_name
else
nil
end
end
|
#path ⇒ Object
971
972
973
974
975
976
977
|
# File 'lib/rdoc/generators/html_generator.rb', line 971
def path
if @options.all_one_file
aref
else
@html_class.path + "#" + aref
end
end
|
#section ⇒ Object
951
952
953
|
# File 'lib/rdoc/generators/html_generator.rb', line 951
def section
@context.section
end
|
#singleton ⇒ Object
987
988
989
|
# File 'lib/rdoc/generators/html_generator.rb', line 987
def singleton
@context.singleton
end
|
#visibility ⇒ Object
983
984
985
|
# File 'lib/rdoc/generators/html_generator.rb', line 983
def visibility
@context.visibility
end
|