rdoc 2.4.3 → 2.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (139) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +3 -1
  3. data/History.txt +68 -0
  4. data/LICENSE.txt +57 -0
  5. data/Manifest.txt +37 -19
  6. data/README.txt +2 -12
  7. data/Rakefile +12 -12
  8. data/bin/rdoc +4 -4
  9. data/lib/rdoc.rb +32 -9
  10. data/lib/rdoc/alias.rb +2 -2
  11. data/lib/rdoc/any_method.rb +108 -16
  12. data/lib/rdoc/attr.rb +87 -1
  13. data/lib/rdoc/class_module.rb +131 -5
  14. data/lib/rdoc/code_object.rb +28 -5
  15. data/lib/rdoc/constant.rb +22 -0
  16. data/lib/rdoc/context.rb +80 -37
  17. data/lib/rdoc/gauntlet.rb +48 -0
  18. data/lib/rdoc/generator/darkfish.rb +25 -23
  19. data/lib/rdoc/generator/markup.rb +6 -29
  20. data/lib/rdoc/generator/ri.rb +39 -189
  21. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +17 -1
  22. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +10 -0
  23. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  24. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  25. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  26. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  27. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  28. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  29. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  30. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  31. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  32. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  33. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  34. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  35. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  36. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  37. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  38. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  39. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +2 -2
  41. data/lib/rdoc/generator/template/darkfish/rdoc.css +38 -33
  42. data/lib/rdoc/include.rb +22 -0
  43. data/lib/rdoc/markup.rb +10 -262
  44. data/lib/rdoc/markup/attribute_manager.rb +57 -50
  45. data/lib/rdoc/markup/blank_line.rb +19 -0
  46. data/lib/rdoc/markup/document.rb +72 -0
  47. data/lib/rdoc/markup/formatter.rb +118 -0
  48. data/lib/rdoc/markup/formatter_test_case.rb +341 -0
  49. data/lib/rdoc/markup/heading.rb +17 -0
  50. data/lib/rdoc/markup/inline.rb +6 -5
  51. data/lib/rdoc/markup/list.rb +78 -0
  52. data/lib/rdoc/markup/list_item.rb +83 -0
  53. data/lib/rdoc/markup/paragraph.rb +66 -0
  54. data/lib/rdoc/markup/parser.rb +528 -0
  55. data/lib/rdoc/markup/rule.rb +17 -0
  56. data/lib/rdoc/markup/to_ansi.rb +72 -0
  57. data/lib/rdoc/markup/to_bs.rb +74 -0
  58. data/lib/rdoc/markup/to_html.rb +106 -172
  59. data/lib/rdoc/markup/to_html_crossref.rb +10 -4
  60. data/lib/rdoc/markup/to_rdoc.rb +243 -0
  61. data/lib/rdoc/markup/to_test.rb +27 -16
  62. data/lib/rdoc/markup/verbatim.rb +42 -0
  63. data/lib/rdoc/normal_class.rb +38 -1
  64. data/lib/rdoc/normal_module.rb +38 -8
  65. data/lib/rdoc/options.rb +39 -151
  66. data/lib/rdoc/parser.rb +36 -18
  67. data/lib/rdoc/parser/c.rb +102 -109
  68. data/lib/rdoc/parser/ruby.rb +359 -1662
  69. data/lib/rdoc/parser/ruby_tools.rb +157 -0
  70. data/lib/rdoc/parser/simple.rb +0 -2
  71. data/lib/rdoc/rdoc.rb +142 -82
  72. data/lib/rdoc/ri.rb +10 -0
  73. data/lib/rdoc/ri/driver.rb +674 -444
  74. data/lib/rdoc/ri/formatter.rb +2 -651
  75. data/lib/rdoc/ri/paths.rb +70 -45
  76. data/lib/rdoc/ri/store.rb +248 -0
  77. data/lib/rdoc/ruby_lex.rb +1284 -0
  78. data/lib/rdoc/ruby_token.rb +416 -0
  79. data/lib/rdoc/single_class.rb +5 -0
  80. data/lib/rdoc/stats.rb +152 -83
  81. data/lib/rdoc/task.rb +27 -49
  82. data/lib/rdoc/text.rb +130 -0
  83. data/lib/rdoc/tokenstream.rb +28 -9
  84. data/lib/rdoc/top_level.rb +49 -43
  85. data/test/hidden.zip.txt +1 -0
  86. data/test/test_attribute_manager.rb +9 -16
  87. data/test/test_rdoc_any_method.rb +23 -0
  88. data/test/test_rdoc_attr.rb +40 -0
  89. data/test/test_rdoc_class_module.rb +100 -0
  90. data/test/test_rdoc_code_object.rb +18 -2
  91. data/test/test_rdoc_context.rb +41 -0
  92. data/test/test_rdoc_generator_ri.rb +56 -0
  93. data/test/test_rdoc_markup.rb +21 -610
  94. data/test/test_rdoc_markup_attribute_manager.rb +14 -17
  95. data/test/test_rdoc_markup_document.rb +51 -0
  96. data/test/test_rdoc_markup_paragraph.rb +27 -0
  97. data/test/test_rdoc_markup_parser.rb +1327 -0
  98. data/test/test_rdoc_markup_to_ansi.rb +426 -0
  99. data/test/test_rdoc_markup_to_bs.rb +443 -0
  100. data/test/test_rdoc_markup_to_html.rb +183 -18
  101. data/test/test_rdoc_markup_to_html_crossref.rb +1 -3
  102. data/test/test_rdoc_markup_to_rdoc.rb +426 -0
  103. data/test/test_rdoc_normal_class.rb +17 -0
  104. data/test/test_rdoc_normal_module.rb +6 -6
  105. data/test/test_rdoc_options.rb +41 -0
  106. data/test/test_rdoc_parser.rb +66 -13
  107. data/test/test_rdoc_parser_c.rb +93 -38
  108. data/test/test_rdoc_parser_perl.rb +2 -3
  109. data/test/test_rdoc_parser_ruby.rb +291 -28
  110. data/test/test_rdoc_parser_simple.rb +48 -0
  111. data/test/test_rdoc_rdoc.rb +66 -0
  112. data/test/test_rdoc_ri_driver.rb +752 -38
  113. data/test/test_rdoc_ri_paths.rb +39 -0
  114. data/test/test_rdoc_ri_store.rb +309 -0
  115. data/test/test_rdoc_text.rb +157 -0
  116. data/test/test_rdoc_top_level.rb +35 -9
  117. data/test/xref_data.rb +9 -1
  118. data/test/xref_test_case.rb +8 -3
  119. metadata +110 -38
  120. metadata.gz.sig +0 -0
  121. data/lib/rdoc/cache.rb +0 -41
  122. data/lib/rdoc/diagram.rb +0 -340
  123. data/lib/rdoc/dot.rb +0 -249
  124. data/lib/rdoc/markup/fragments.rb +0 -377
  125. data/lib/rdoc/markup/lines.rb +0 -156
  126. data/lib/rdoc/markup/to_flow.rb +0 -211
  127. data/lib/rdoc/markup/to_latex.rb +0 -328
  128. data/lib/rdoc/markup/to_texinfo.rb +0 -73
  129. data/lib/rdoc/ri/cache.rb +0 -187
  130. data/lib/rdoc/ri/descriptions.rb +0 -156
  131. data/lib/rdoc/ri/display.rb +0 -340
  132. data/lib/rdoc/ri/reader.rb +0 -106
  133. data/lib/rdoc/ri/util.rb +0 -79
  134. data/lib/rdoc/ri/writer.rb +0 -68
  135. data/test/test_rdoc_ri_attribute_formatter.rb +0 -44
  136. data/test/test_rdoc_ri_default_display.rb +0 -302
  137. data/test/test_rdoc_ri_formatter.rb +0 -320
  138. data/test/test_rdoc_ri_html_formatter.rb +0 -141
  139. data/test/test_rdoc_ri_overstrike_formatter.rb +0 -71
@@ -1,73 +0,0 @@
1
- require 'rdoc/markup/formatter'
2
- require 'rdoc/markup/fragments'
3
- require 'rdoc/markup/inline'
4
-
5
- require 'rdoc/markup'
6
- require 'rdoc/markup/formatter'
7
-
8
- ##
9
- # Convert SimpleMarkup to basic TexInfo format
10
- #
11
- # TODO: WTF is AttributeManager for?
12
-
13
- class RDoc::Markup::ToTexInfo < RDoc::Markup::Formatter
14
-
15
- def format(text)
16
- text.txt.
17
- gsub(/@/, "@@").
18
- gsub(/\{/, "@{").
19
- gsub(/\}/, "@}").
20
- # gsub(/,/, "@,"). # technically only required in cross-refs
21
- gsub(/\+([\w]+)\+/, "@code{\\1}").
22
- gsub(/\<tt\>([^<]+)\<\/tt\>/, "@code{\\1}").
23
- gsub(/\*([\w]+)\*/, "@strong{\\1}").
24
- gsub(/\<b\>([^<]+)\<\/b\>/, "@strong{\\1}").
25
- gsub(/_([\w]+)_/, "@emph{\\1}").
26
- gsub(/\<em\>([^<]+)\<\/em\>/, "@emph{\\1}")
27
- end
28
-
29
- # :section: Visitor
30
-
31
- def start_accepting
32
- @text = []
33
- end
34
-
35
- def end_accepting
36
- @text.join("\n")
37
- end
38
-
39
- def accept_paragraph(attributes, text)
40
- @text << format(text)
41
- end
42
-
43
- def accept_verbatim(attributes, text)
44
- @text << "@verb{|#{format(text)}|}"
45
- end
46
-
47
- def accept_heading(attributes, text)
48
- heading = ['@majorheading', '@chapheading'][text.head_level - 1] || '@heading'
49
- @text << "#{heading} #{format(text)}"
50
- end
51
-
52
- def accept_list_start(attributes, text)
53
- @text << '@itemize @bullet'
54
- end
55
-
56
- def accept_list_end(attributes, text)
57
- @text << '@end itemize'
58
- end
59
-
60
- def accept_list_item(attributes, text)
61
- @text << "@item\n#{format(text)}"
62
- end
63
-
64
- def accept_blank_line(attributes, text)
65
- @text << "\n"
66
- end
67
-
68
- def accept_rule(attributes, text)
69
- @text << '-----'
70
- end
71
-
72
- end
73
-
@@ -1,187 +0,0 @@
1
- require 'rdoc/ri'
2
-
3
- class RDoc::RI::ClassEntry
4
-
5
- attr_reader :name
6
- attr_reader :path_names
7
-
8
- def initialize(path_name, name, in_class)
9
- @path_names = [ path_name ]
10
- @name = name
11
- @in_class = in_class
12
- @class_methods = []
13
- @instance_methods = []
14
- @inferior_classes = []
15
- end
16
-
17
- # We found this class in more than one place, so add
18
- # in the name from there.
19
- def add_path(path)
20
- @path_names << path
21
- end
22
-
23
- ##
24
- # read in our methods and any classes and modules in our namespace. Methods
25
- # are stored in files called name-c|i.yaml, where the 'name' portion is the
26
- # external form of the method name and the c|i is a class|instance flag
27
-
28
- def load_from(dir)
29
- return unless File.exist? dir
30
-
31
- Dir.foreach(dir) do |name|
32
- next if name =~ /^\./
33
-
34
- # convert from external to internal form, and
35
- # extract the instance/class flag
36
-
37
- if name =~ /^(.*?)-(c|i).yaml$/
38
- external_name = $1
39
- is_class_method = $2 == "c"
40
- internal_name = RDoc::RI::Writer.external_to_internal(external_name)
41
- list = is_class_method ? @class_methods : @instance_methods
42
- path = File.join(dir, name)
43
- list << RDoc::RI::MethodEntry.new(path, internal_name, is_class_method, self)
44
- else
45
- full_name = File.join(dir, name)
46
- if File.directory?(full_name)
47
- inf_class = @inferior_classes.find {|c| c.name == name }
48
- if inf_class
49
- inf_class.add_path(full_name)
50
- else
51
- inf_class = RDoc::RI::ClassEntry.new(full_name, name, self)
52
- @inferior_classes << inf_class
53
- end
54
- inf_class.load_from(full_name)
55
- end
56
- end
57
- end
58
- end
59
-
60
- # Return a list of any classes or modules that we contain
61
- # that match a given string
62
-
63
- def contained_modules_matching(name)
64
- @inferior_classes.find_all {|c| c.name[name]}
65
- end
66
-
67
- def classes_and_modules
68
- @inferior_classes
69
- end
70
-
71
- # Return an exact match to a particular name
72
- def contained_class_named(name)
73
- @inferior_classes.find {|c| c.name == name}
74
- end
75
-
76
- # return the list of local methods matching name
77
- # We're split into two because we need distinct behavior
78
- # when called from the _toplevel_
79
- def methods_matching(name, is_class_method)
80
- local_methods_matching(name, is_class_method)
81
- end
82
-
83
- # Find methods matching 'name' in ourselves and in
84
- # any classes we contain
85
- def recursively_find_methods_matching(name, is_class_method)
86
- res = local_methods_matching(name, is_class_method)
87
- @inferior_classes.each do |c|
88
- res.concat(c.recursively_find_methods_matching(name, is_class_method))
89
- end
90
- res
91
- end
92
-
93
-
94
- # Return our full name
95
- def full_name
96
- res = @in_class.full_name
97
- res << "::" unless res.empty?
98
- res << @name
99
- end
100
-
101
- # Return a list of all out method names
102
- def all_method_names
103
- res = @class_methods.map {|m| m.full_name }
104
- @instance_methods.each {|m| res << m.full_name}
105
- res
106
- end
107
-
108
- private
109
-
110
- # Return a list of all our methods matching a given string.
111
- # Is +is_class_methods+ if 'nil', we don't care if the method
112
- # is a class method or not, otherwise we only return
113
- # those methods that match
114
- def local_methods_matching(name, is_class_method)
115
-
116
- list = case is_class_method
117
- when nil then @class_methods + @instance_methods
118
- when true then @class_methods
119
- when false then @instance_methods
120
- else fail "Unknown is_class_method: #{is_class_method.inspect}"
121
- end
122
-
123
- list.find_all {|m| m.name; m.name[name]}
124
- end
125
- end
126
-
127
- ##
128
- # A TopLevelEntry is like a class entry, but when asked to search for methods
129
- # searches all classes, not just itself
130
-
131
- class RDoc::RI::TopLevelEntry < RDoc::RI::ClassEntry
132
- def methods_matching(name, is_class_method)
133
- res = recursively_find_methods_matching(name, is_class_method)
134
- end
135
-
136
- def full_name
137
- ""
138
- end
139
-
140
- def module_named(name)
141
-
142
- end
143
-
144
- end
145
-
146
- class RDoc::RI::MethodEntry
147
- attr_reader :name
148
- attr_reader :path_name
149
-
150
- def initialize(path_name, name, is_class_method, in_class)
151
- @path_name = path_name
152
- @name = name
153
- @is_class_method = is_class_method
154
- @in_class = in_class
155
- end
156
-
157
- def full_name
158
- res = @in_class.full_name
159
- unless res.empty?
160
- if @is_class_method
161
- res << "::"
162
- else
163
- res << "#"
164
- end
165
- end
166
- res << @name
167
- end
168
- end
169
-
170
- ##
171
- # We represent everything known about all 'ri' files accessible to this program
172
-
173
- class RDoc::RI::Cache
174
-
175
- attr_reader :toplevel
176
-
177
- def initialize(dirs)
178
- # At the top level we have a dummy module holding the
179
- # overall namespace
180
- @toplevel = RDoc::RI::TopLevelEntry.new('', '::', nil)
181
-
182
- dirs.each do |dir|
183
- @toplevel.load_from(dir)
184
- end
185
- end
186
-
187
- end
@@ -1,156 +0,0 @@
1
- require 'yaml'
2
- require 'rdoc/markup/fragments'
3
- require 'rdoc/ri'
4
-
5
- ##
6
- # Descriptions are created by RDoc (in ri_generator) and written out in
7
- # serialized form into the documentation tree. ri then reads these to generate
8
- # the documentation
9
-
10
- class RDoc::RI::NamedThing
11
- attr_reader :name
12
- def initialize(name)
13
- @name = name
14
- end
15
-
16
- def <=>(other)
17
- @name <=> other.name
18
- end
19
-
20
- def hash
21
- @name.hash
22
- end
23
-
24
- def eql?(other)
25
- @name.eql?(other)
26
- end
27
- end
28
-
29
- class RDoc::RI::AliasName < RDoc::RI::NamedThing; end
30
-
31
- class RDoc::RI::Attribute < RDoc::RI::NamedThing
32
- attr_reader :rw, :comment
33
-
34
- def initialize(name, rw, comment)
35
- super(name)
36
- @rw = rw
37
- @comment = comment
38
- end
39
- end
40
-
41
- class RDoc::RI::Constant < RDoc::RI::NamedThing
42
- attr_reader :value, :comment
43
-
44
- def initialize(name, value, comment)
45
- super(name)
46
- @value = value
47
- @comment = comment
48
- end
49
- end
50
-
51
- class RDoc::RI::IncludedModule < RDoc::RI::NamedThing; end
52
-
53
- class RDoc::RI::MethodSummary < RDoc::RI::NamedThing
54
- def initialize(name="")
55
- super
56
- end
57
- end
58
-
59
- class RDoc::RI::Description
60
- attr_accessor :name
61
- attr_accessor :full_name
62
- attr_accessor :comment
63
-
64
- def serialize
65
- self.to_yaml
66
- end
67
-
68
- def self.deserialize(from)
69
- YAML.load(from)
70
- end
71
-
72
- def <=>(other)
73
- @name <=> other.name
74
- end
75
- end
76
-
77
- class RDoc::RI::ModuleDescription < RDoc::RI::Description
78
-
79
- attr_accessor :class_methods
80
- attr_accessor :class_method_extensions
81
- attr_accessor :instance_methods
82
- attr_accessor :instance_method_extensions
83
- attr_accessor :attributes
84
- attr_accessor :constants
85
- attr_accessor :includes
86
-
87
- # merge in another class description into this one
88
- def merge_in(old)
89
- merge(@class_methods, old.class_methods)
90
- merge(@instance_methods, old.instance_methods)
91
- merge(@attributes, old.attributes)
92
- merge(@constants, old.constants)
93
- merge(@includes, old.includes)
94
- if @comment.nil? || @comment.empty?
95
- @comment = old.comment
96
- else
97
- unless old.comment.nil? or old.comment.empty? then
98
- if @comment.nil? or @comment.empty? then
99
- @comment = old.comment
100
- else
101
- @comment << RDoc::Markup::Flow::RULE.new
102
- @comment.concat old.comment
103
- end
104
- end
105
- end
106
- end
107
-
108
- def display_name
109
- "Module"
110
- end
111
-
112
- # the 'ClassDescription' subclass overrides this
113
- # to format up the name of a parent
114
- def superclass_string
115
- nil
116
- end
117
-
118
- private
119
-
120
- def merge(into, from)
121
- names = {}
122
- into.each {|i| names[i.name] = i }
123
- from.each {|i| names[i.name] = i }
124
- into.replace(names.keys.sort.map {|n| names[n]})
125
- end
126
- end
127
-
128
- class RDoc::RI::ClassDescription < RDoc::RI::ModuleDescription
129
- attr_accessor :superclass
130
-
131
- def display_name
132
- "Class"
133
- end
134
-
135
- def superclass_string
136
- if @superclass && @superclass != "Object"
137
- @superclass
138
- else
139
- nil
140
- end
141
- end
142
- end
143
-
144
- class RDoc::RI::MethodDescription < RDoc::RI::Description
145
-
146
- attr_accessor :is_class_method
147
- attr_accessor :visibility
148
- attr_accessor :block_params
149
- attr_accessor :is_singleton
150
- attr_accessor :aliases
151
- attr_accessor :is_alias_for
152
- attr_accessor :params
153
- attr_accessor :source_path
154
-
155
- end
156
-
@@ -1,340 +0,0 @@
1
- require 'rdoc/ri'
2
-
3
- ##
4
- # This is a kind of 'flag' module. If you want to write your own 'ri' display
5
- # module (perhaps because you're writing an IDE), you write a class which
6
- # implements the various 'display' methods in RDoc::RI::DefaultDisplay, and
7
- # include the RDoc::RI::Display module in that class.
8
- #
9
- # To access your class from the command line, you can do
10
- #
11
- # ruby -r <your source file> ../ri ....
12
-
13
- module RDoc::RI::Display
14
-
15
- @@display_class = nil
16
-
17
- def self.append_features(display_class)
18
- @@display_class = display_class
19
- end
20
-
21
- def self.new(*args)
22
- @@display_class.new(*args)
23
- end
24
-
25
- end
26
-
27
- ##
28
- # A paging display module. Uses the RDoc::RI::Formatter class to do the actual
29
- # presentation.
30
-
31
- class RDoc::RI::DefaultDisplay
32
-
33
- include RDoc::RI::Display
34
-
35
- attr_reader :formatter
36
-
37
- def initialize(formatter, width, use_stdout, output = $stdout)
38
- @use_stdout = use_stdout
39
- @formatter = formatter.new output, width, " "
40
- end
41
-
42
- ##
43
- # Display information about +klass+. Fetches additional information from
44
- # +ri_reader+ as necessary.
45
-
46
- def display_class_info(klass)
47
- page do
48
- superclass = klass.superclass
49
-
50
- if superclass
51
- superclass = " < " + superclass
52
- else
53
- superclass = ""
54
- end
55
-
56
- @formatter.draw_line(klass.display_name + ": " +
57
- klass.full_name + superclass)
58
-
59
- display_flow(klass.comment)
60
- @formatter.draw_line
61
-
62
- unless klass.includes.empty?
63
- @formatter.blankline
64
- @formatter.display_heading("Includes:", 2, "")
65
- incs = []
66
-
67
- klass.includes.each do |inc|
68
- incs << inc.name
69
- end
70
-
71
- @formatter.wrap(incs.sort.join(', '))
72
- end
73
-
74
- unless klass.constants.empty?
75
- @formatter.blankline
76
- @formatter.display_heading("Constants:", 2, "")
77
-
78
- constants = klass.constants.sort_by { |constant| constant.name }
79
-
80
- constants.each do |constant|
81
- @formatter.wrap "#{constant.name} = #{constant.value}"
82
- if constant.comment then
83
- @formatter.indent do
84
- @formatter.display_flow constant.comment
85
- end
86
- else
87
- @formatter.break_to_newline
88
- end
89
- end
90
- end
91
-
92
- unless klass.attributes.empty? then
93
- @formatter.blankline
94
- @formatter.display_heading 'Attributes:', 2, ''
95
-
96
- attributes = klass.attributes.sort_by { |attribute| attribute.name }
97
-
98
- attributes.each do |attribute|
99
- if attribute.comment then
100
- @formatter.wrap "#{attribute.name} (#{attribute.rw}):"
101
- @formatter.indent do
102
- @formatter.display_flow attribute.comment
103
- end
104
- else
105
- @formatter.wrap "#{attribute.name} (#{attribute.rw})"
106
- @formatter.break_to_newline
107
- end
108
- end
109
- end
110
-
111
- return display_class_method_list(klass)
112
- end
113
- end
114
-
115
- ##
116
- # Given a Hash mapping a class' methods to method types (returned by
117
- # display_class_method_list), this method allows the user to choose one of
118
- # the methods.
119
-
120
- def get_class_method_choice(method_map)
121
- end
122
-
123
- ##
124
- # Display methods on +klass+. Returns a hash mapping method name to method
125
- # contents
126
-
127
- def display_class_method_list(klass)
128
- method_map = {}
129
-
130
- class_data = [
131
- :class_methods,
132
- :class_method_extensions,
133
- :instance_methods,
134
- :instance_method_extensions,
135
- ]
136
-
137
- class_data.each do |data_type|
138
- data = klass.send data_type
139
-
140
- unless data.nil? or data.empty? then
141
- @formatter.blankline
142
-
143
- heading = data_type.to_s.split('_').join(' ').capitalize << ':'
144
- @formatter.display_heading heading, 2, ''
145
-
146
- method_names = []
147
- data.each do |item|
148
- method_names << item.name
149
-
150
- if(data_type == :class_methods ||
151
- data_type == :class_method_extensions) then
152
- method_map["::#{item.name}"] = :class
153
- method_map[item.name] = :class
154
- else
155
- #
156
- # Since we iterate over instance methods after class methods,
157
- # an instance method always will overwrite the unqualified
158
- # class method entry for a class method of the same name.
159
- #
160
- method_map["##{item.name}"] = :instance
161
- method_map[item.name] = :instance
162
- end
163
- end
164
- method_names.sort!
165
-
166
- @formatter.wrap method_names.join(', ')
167
- end
168
- end
169
-
170
- method_map
171
- end
172
- private :display_class_method_list
173
-
174
- ##
175
- # Display an Array of RDoc::Markup::Flow objects, +flow+.
176
-
177
- def display_flow(flow)
178
- if flow and not flow.empty? then
179
- @formatter.display_flow flow
180
- else
181
- @formatter.wrap '[no description]'
182
- end
183
- end
184
-
185
- ##
186
- # Display information about +method+.
187
-
188
- def display_method_info(method)
189
- page do
190
- @formatter.draw_line(method.full_name)
191
- display_params(method)
192
-
193
- @formatter.draw_line
194
- display_flow(method.comment)
195
-
196
- if method.aliases and not method.aliases.empty? then
197
- @formatter.blankline
198
- aka = "(also known as #{method.aliases.map { |a| a.name }.join(', ')})"
199
- @formatter.wrap aka
200
- end
201
- end
202
- end
203
-
204
- ##
205
- # Display the list of +methods+.
206
-
207
- def display_method_list(methods)
208
- page do
209
- @formatter.wrap "More than one method matched your request. You can refine your search by asking for information on one of:"
210
- @formatter.blankline
211
-
212
- methods.each do |method|
213
- @formatter.raw_print_line "#{method.full_name} [#{method.source_path}]\n"
214
- end
215
- end
216
- end
217
-
218
- ##
219
- # Display a list of +methods+ and allow the user to select one of them.
220
-
221
- def display_method_list_choice(methods)
222
- page do
223
- @formatter.wrap "More than one method matched your request. Please choose one of the possible matches."
224
- @formatter.blankline
225
-
226
- methods.each_with_index do |method, index|
227
- @formatter.raw_print_line "%3d %s [%s]\n" % [index + 1, method.full_name, method.source_path]
228
- end
229
-
230
- @formatter.raw_print_line ">> "
231
-
232
- choice = $stdin.gets.strip!
233
-
234
- if(choice == '')
235
- return
236
- end
237
-
238
- choice = choice.to_i
239
-
240
- if ((choice == 0) || (choice > methods.size)) then
241
- @formatter.raw_print_line "Invalid choice!\n"
242
- else
243
- method = methods[choice - 1]
244
- display_method_info(method)
245
- end
246
- end
247
- end
248
-
249
- ##
250
- # Display the params for +method+.
251
-
252
- def display_params(method)
253
- params = method.params
254
-
255
- if params[0,1] == "(" then
256
- if method.is_singleton
257
- params = method.full_name + params
258
- else
259
- params = method.name + params
260
- end
261
- end
262
-
263
- params.split(/\n/).each do |param|
264
- @formatter.wrap param
265
- @formatter.break_to_newline
266
- end
267
-
268
- @formatter.blankline
269
- @formatter.wrap("From #{method.source_path}")
270
- end
271
-
272
- ##
273
- # List the classes in +classes+.
274
-
275
- def list_known_classes(classes)
276
- if classes.empty? then
277
- warn_no_database
278
- else
279
- page do
280
- @formatter.draw_line "Known classes and modules"
281
- @formatter.blankline
282
-
283
- classes.sort.each do |klass|
284
- @formatter.wrap klass
285
- end
286
- end
287
- end
288
- end
289
-
290
- ##
291
- # Paginates output through a pager program.
292
-
293
- def page
294
- if pager = setup_pager then
295
- begin
296
- orig_output = @formatter.output
297
- @formatter.output = pager
298
- yield
299
- ensure
300
- @formatter.output = orig_output
301
- pager.close
302
- end
303
- else
304
- yield
305
- end
306
- rescue Errno::EPIPE
307
- end
308
-
309
- ##
310
- # Sets up a pager program to pass output through.
311
-
312
- def setup_pager
313
- unless @use_stdout then
314
- for pager in [ ENV['PAGER'], "less", "more", 'pager' ].compact.uniq
315
- return IO.popen(pager, "w") rescue nil
316
- end
317
- @use_stdout = true
318
- nil
319
- end
320
- end
321
-
322
- ##
323
- # Displays a message that describes how to build RI data.
324
-
325
- def warn_no_database
326
- output = @formatter.output
327
-
328
- output.puts "No ri data found"
329
- output.puts
330
- output.puts "If you've installed Ruby yourself, you need to generate documentation using:"
331
- output.puts
332
- output.puts " make install-doc"
333
- output.puts
334
- output.puts "from the same place you ran `make` to build ruby."
335
- output.puts
336
- output.puts "If you installed Ruby from a packaging system, then you may need to"
337
- output.puts "install an additional package, or ask the packager to enable ri generation."
338
- end
339
-
340
- end