lib/rdoc/ri/display.rb in rdoc-2.2.1 vs lib/rdoc/ri/display.rb in rdoc-2.3.0
- old
+ new
@@ -1,17 +1,7 @@
require 'rdoc/ri'
-# readline support might not be present, so be careful
-# when requiring it.
-begin
- require('readline')
- require('abbrev')
- CAN_USE_READLINE = true
-rescue
- CAN_USE_READLINE = false
-end
-
##
# This is a kind of 'flag' module. If you want to write your own 'ri' display
# module (perhaps because you're writing an IDE), you write a class which
# implements the various 'display' methods in RDoc::RI::DefaultDisplay, and
# include the RDoc::RI::Display module in that class.
@@ -40,10 +30,12 @@
class RDoc::RI::DefaultDisplay
include RDoc::RI::Display
+ attr_reader :formatter
+
def initialize(formatter, width, use_stdout, output = $stdout)
@use_stdout = use_stdout
@formatter = formatter.new output, width, " "
end
@@ -51,11 +43,11 @@
# Display information about +klass+. Fetches additional information from
# +ri_reader+ as necessary.
def display_class_info(klass)
page do
- superclass = klass.superclass_string
+ superclass = klass.superclass
if superclass
superclass = " < " + superclass
else
superclass = ""
@@ -117,88 +109,42 @@
end
return display_class_method_list(klass)
end
end
-
+
##
# Given a Hash mapping a class' methods to method types (returned by
- # display_class_method_list), this method allows the user to
- # choose one of the methods.
-
- def get_class_method_choice(method_map)
- if CAN_USE_READLINE
- # prepare abbreviations for tab completion
- abbreviations = method_map.keys.abbrev
- Readline.completion_proc = proc do |string|
- abbreviations.values.uniq.grep(/^#{string}/)
- end
- end
-
- @formatter.raw_print_line "\nEnter the method name you want.\n"
- @formatter.raw_print_line "Class methods can be preceeded by '::' and instance methods by '#'.\n"
+ # display_class_method_list), this method allows the user to choose one of
+ # the methods.
- if CAN_USE_READLINE
- @formatter.raw_print_line "You can use tab to autocomplete.\n"
- @formatter.raw_print_line "Enter a blank line to exit.\n"
-
- choice_string = Readline.readline(">> ").strip
- else
- @formatter.raw_print_line "Enter a blank line to exit.\n"
- @formatter.raw_print_line ">> "
- choice_string = $stdin.gets.strip
- end
-
- if choice_string == ''
- return nil
- else
- class_or_instance = method_map[choice_string]
-
- if class_or_instance
- # If the user's choice is not preceeded by a '::' or a '#', figure
- # out whether they want a class or an instance method and decorate
- # the choice appropriately.
- if(choice_string =~ /^[a-zA-Z]/)
- if(class_or_instance == :class)
- choice_string = "::#{choice_string}"
- else
- choice_string = "##{choice_string}"
- end
- end
-
- return choice_string
- else
- @formatter.raw_print_line "No method matched '#{choice_string}'.\n"
- return nil
- end
- end
+ def get_class_method_choice(method_map)
end
-
##
- # Display methods on +klass+
- # Returns a hash mapping method name to method contents (HACK?)
+ # Display methods on +klass+. Returns a hash mapping method name to method
+ # contents
def display_class_method_list(klass)
method_map = {}
class_data = [
:class_methods,
:class_method_extensions,
:instance_methods,
:instance_method_extensions,
]
-
+
class_data.each do |data_type|
data = klass.send data_type
-
+
unless data.nil? or data.empty? then
@formatter.blankline
-
+
heading = data_type.to_s.split('_').join(' ').capitalize << ':'
@formatter.display_heading heading, 2, ''
-
+
method_names = []
data.each do |item|
method_names << item.name
if(data_type == :class_methods ||
@@ -215,11 +161,11 @@
method_map[item.name] = :instance
end
end
method_names.sort!
- @formatter.wrap method_names.join(',')
+ @formatter.wrap method_names.join(', ')
end
end
method_map
end
@@ -266,11 +212,11 @@
methods.each do |method|
@formatter.raw_print_line "#{method.full_name} [#{method.source_path}]\n"
end
end
end
-
+
##
# Display a list of +methods+ and allow the user to select one of them.
def display_method_list_choice(methods)
page do
@@ -278,13 +224,13 @@
@formatter.blankline
methods.each_with_index do |method, index|
@formatter.raw_print_line "%3d %s [%s]\n" % [index + 1, method.full_name, method.source_path]
end
-
+
@formatter.raw_print_line ">> "
-
+
choice = $stdin.gets.strip!
if(choice == '')
return
end
@@ -292,11 +238,11 @@
choice = choice.to_i
if ((choice == 0) || (choice > methods.size)) then
@formatter.raw_print_line "Invalid choice!\n"
else
- method = methods[choice - 1]
+ method = methods[choice - 1]
display_method_info(method)
end
end
end
@@ -325,18 +271,20 @@
##
# List the classes in +classes+.
def list_known_classes(classes)
- if classes.empty?
+ if classes.empty? then
warn_no_database
else
page do
@formatter.draw_line "Known classes and modules"
@formatter.blankline
- @formatter.wrap classes.sort.join(', ')
+ classes.sort.each do |klass|
+ @formatter.wrap klass
+ end
end
end
end
##
@@ -388,6 +336,5 @@
output.puts "If you installed Ruby from a packaging system, then you may need to"
output.puts "install an additional package, or ask the packager to enable ri generation."
end
end
-