voloko-sdoc 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/rdoc/History.txt +254 -0
  2. data/rdoc/Manifest.txt +126 -0
  3. data/rdoc/README.txt +47 -0
  4. data/rdoc/RI.txt +58 -0
  5. data/rdoc/Rakefile +70 -0
  6. data/rdoc/bin/rdoc +35 -0
  7. data/rdoc/bin/ri +5 -0
  8. data/rdoc/lib/rdoc/alias.rb +54 -0
  9. data/rdoc/lib/rdoc/anon_class.rb +10 -0
  10. data/rdoc/lib/rdoc/any_method.rb +190 -0
  11. data/rdoc/lib/rdoc/attr.rb +79 -0
  12. data/rdoc/lib/rdoc/cache.rb +41 -0
  13. data/rdoc/lib/rdoc/class_module.rb +87 -0
  14. data/rdoc/lib/rdoc/code_object.rb +152 -0
  15. data/rdoc/lib/rdoc/code_objects.rb +23 -0
  16. data/rdoc/lib/rdoc/constant.rb +36 -0
  17. data/rdoc/lib/rdoc/context.rb +712 -0
  18. data/rdoc/lib/rdoc/diagram.rb +340 -0
  19. data/rdoc/lib/rdoc/dot.rb +249 -0
  20. data/rdoc/lib/rdoc/generator/darkfish.rb +455 -0
  21. data/rdoc/lib/rdoc/generator/markup.rb +194 -0
  22. data/rdoc/lib/rdoc/generator/ri.rb +230 -0
  23. data/rdoc/lib/rdoc/generator/template/darkfish/classpage.rhtml +281 -0
  24. data/rdoc/lib/rdoc/generator/template/darkfish/filepage.rhtml +112 -0
  25. data/rdoc/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  26. data/rdoc/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  27. data/rdoc/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  28. data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  29. data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  30. data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  31. data/rdoc/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  32. data/rdoc/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  33. data/rdoc/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  34. data/rdoc/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  35. data/rdoc/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  36. data/rdoc/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  37. data/rdoc/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  38. data/rdoc/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  39. data/rdoc/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  40. data/rdoc/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  41. data/rdoc/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  42. data/rdoc/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  43. data/rdoc/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  44. data/rdoc/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  45. data/rdoc/lib/rdoc/generator/template/darkfish/index.rhtml +64 -0
  46. data/rdoc/lib/rdoc/generator/template/darkfish/js/darkfish.js +116 -0
  47. data/rdoc/lib/rdoc/generator/template/darkfish/js/jquery.js +32 -0
  48. data/rdoc/lib/rdoc/generator/template/darkfish/js/quicksearch.js +114 -0
  49. data/rdoc/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +10 -0
  50. data/rdoc/lib/rdoc/generator/template/darkfish/rdoc.css +696 -0
  51. data/rdoc/lib/rdoc/generator.rb +8 -0
  52. data/rdoc/lib/rdoc/ghost_method.rb +8 -0
  53. data/rdoc/lib/rdoc/include.rb +39 -0
  54. data/rdoc/lib/rdoc/known_classes.rb +68 -0
  55. data/rdoc/lib/rdoc/markup/attribute_manager.rb +311 -0
  56. data/rdoc/lib/rdoc/markup/formatter.rb +25 -0
  57. data/rdoc/lib/rdoc/markup/fragments.rb +377 -0
  58. data/rdoc/lib/rdoc/markup/inline.rb +126 -0
  59. data/rdoc/lib/rdoc/markup/lines.rb +156 -0
  60. data/rdoc/lib/rdoc/markup/preprocess.rb +80 -0
  61. data/rdoc/lib/rdoc/markup/to_flow.rb +211 -0
  62. data/rdoc/lib/rdoc/markup/to_html.rb +406 -0
  63. data/rdoc/lib/rdoc/markup/to_html_crossref.rb +140 -0
  64. data/rdoc/lib/rdoc/markup/to_latex.rb +328 -0
  65. data/rdoc/lib/rdoc/markup/to_test.rb +53 -0
  66. data/rdoc/lib/rdoc/markup/to_texinfo.rb +73 -0
  67. data/rdoc/lib/rdoc/markup.rb +378 -0
  68. data/rdoc/lib/rdoc/meta_method.rb +8 -0
  69. data/rdoc/lib/rdoc/normal_class.rb +18 -0
  70. data/rdoc/lib/rdoc/normal_module.rb +34 -0
  71. data/rdoc/lib/rdoc/options.rb +542 -0
  72. data/rdoc/lib/rdoc/parser/c.rb +678 -0
  73. data/rdoc/lib/rdoc/parser/perl.rb +165 -0
  74. data/rdoc/lib/rdoc/parser/ruby.rb +2904 -0
  75. data/rdoc/lib/rdoc/parser/simple.rb +39 -0
  76. data/rdoc/lib/rdoc/parser.rb +138 -0
  77. data/rdoc/lib/rdoc/rdoc.rb +375 -0
  78. data/rdoc/lib/rdoc/require.rb +32 -0
  79. data/rdoc/lib/rdoc/ri/cache.rb +187 -0
  80. data/rdoc/lib/rdoc/ri/descriptions.rb +156 -0
  81. data/rdoc/lib/rdoc/ri/display.rb +340 -0
  82. data/rdoc/lib/rdoc/ri/driver.rb +828 -0
  83. data/rdoc/lib/rdoc/ri/formatter.rb +654 -0
  84. data/rdoc/lib/rdoc/ri/paths.rb +93 -0
  85. data/rdoc/lib/rdoc/ri/reader.rb +106 -0
  86. data/rdoc/lib/rdoc/ri/util.rb +79 -0
  87. data/rdoc/lib/rdoc/ri/writer.rb +68 -0
  88. data/rdoc/lib/rdoc/ri.rb +8 -0
  89. data/rdoc/lib/rdoc/single_class.rb +8 -0
  90. data/rdoc/lib/rdoc/stats.rb +178 -0
  91. data/rdoc/lib/rdoc/task.rb +276 -0
  92. data/rdoc/lib/rdoc/tokenstream.rb +33 -0
  93. data/rdoc/lib/rdoc/top_level.rb +242 -0
  94. data/rdoc/lib/rdoc.rb +398 -0
  95. metadata +1 -1
@@ -0,0 +1,187 @@
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
@@ -0,0 +1,156 @@
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
+
@@ -0,0 +1,340 @@
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