From c42a631063e79fab2369c1983a6f2a075b584f62 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sat, 26 Apr 2008 16:14:19 +0000 Subject: Import RDoc 2.0.0 r56. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/markup.rb | 29 ++-- lib/rdoc/markup/attribute_manager.rb | 274 +++++++++++++++++++++++++++++++++++ lib/rdoc/markup/inline.rb | 266 +--------------------------------- lib/rdoc/markup/to_html.rb | 3 +- lib/rdoc/parsers/parse_rb.rb | 2 +- lib/rdoc/rdoc.rb | 24 +-- lib/rdoc/ri/descriptions.rb | 3 + lib/rdoc/ri/display.rb | 238 +++++++++++++++++------------- lib/rdoc/ri/driver.rb | 15 +- lib/rdoc/ri/formatter.rb | 19 ++- lib/rdoc/template.rb | 8 +- 11 files changed, 474 insertions(+), 407 deletions(-) create mode 100644 lib/rdoc/markup/attribute_manager.rb (limited to 'lib/rdoc') diff --git a/lib/rdoc/markup.rb b/lib/rdoc/markup.rb index 9334329d6b..fdd1a11736 100644 --- a/lib/rdoc/markup.rb +++ b/lib/rdoc/markup.rb @@ -11,8 +11,8 @@ require 'rdoc' # RDoc::Markup itself does no output formatting: this is left to a different # set of classes. # -# RDoc::Markup is extendable at runtime: you can add new markup elements to be -# recognised in the documents that RDoc::Markup parses. +# RDoc::Markup is extendable at runtime: you can add \new markup elements to +# be recognised in the documents that RDoc::Markup parses. # # RDoc::Markup is intended to be the basis for a family of tools which share # the common requirement that simple, plain-text should be rendered in a @@ -29,10 +29,9 @@ require 'rdoc' # paragraph. # # * If a paragraph starts with a "*", "-", or with ".", then it is -# taken to be the start of a list. The margin in increased to be the -# first non-space following the list start flag. Subsequent lines -# should be indented to this new margin until the list ends. For -# example: +# taken to be the start of a list. The margin in increased to be the first +# non-space following the list start flag. Subsequent lines should be +# indented to this \new margin until the list ends. For example: # # * this is a list with three paragraphs in # the first item. This is the first paragraph. @@ -102,7 +101,7 @@ require 'rdoc' # Unlike conventional Wiki markup, general markup can cross line # boundaries. You can turn off the interpretation of markup by # preceding the first character with a backslash, so \\\bold -# text and \\\*bold* produce \bold text and \*bold +# text and \\\*bold* produce \bold text and \*bold* # respectively. # # * Hyperlinks to the web starting http:, mailto:, ftp:, or www. are @@ -118,17 +117,15 @@ require 'rdoc' # # == Synopsis # -# This code converts input_string to HTML. The conversion -# takes place in the +convert+ method, so you can use the same -# RDoc::Markup object to convert multiple input strings. +# This code converts +input_string+ to HTML. The conversion takes place in +# the +convert+ method, so you can use the same RDoc::Markup converter to +# convert multiple input strings. # -# require 'rdoc/markup' # require 'rdoc/markup/to_html' # -# p = RDoc::Markup.new # h = RDoc::Markup::ToHtml.new # -# puts p.convert(input_string, h) +# puts h.convert(input_string) # # You can extend the RDoc::Markup parser to recognise new markup # sequences, and to add special processing for text that matches a @@ -152,10 +149,10 @@ require 'rdoc' # # m.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD) # -# h = WikiHtml.new -# h.add_tag(:STRIKE, "", "") +# wh = WikiHtml.new +# wh.add_tag(:STRIKE, "", "") # -# puts "" + m.convert(ARGF.read, h) + "" +# puts "#{wh.convert ARGF.read}" # #-- # Author:: Dave Thomas, dave@pragmaticprogrammer.com diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb new file mode 100644 index 0000000000..72f70dadd7 --- /dev/null +++ b/lib/rdoc/markup/attribute_manager.rb @@ -0,0 +1,274 @@ +require 'rdoc/markup/inline' + +class RDoc::Markup::AttributeManager + + NULL = "\000".freeze + + ## + # We work by substituting non-printing characters in to the text. For now + # I'm assuming that I can substitute a character in the range 0..8 for a 7 + # bit character without damaging the encoded string, but this might be + # optimistic + + A_PROTECT = 004 + PROTECT_ATTR = A_PROTECT.chr + + ## + # This maps delimiters that occur around words (such as *bold* or +tt+) + # where the start and end delimiters and the same. This lets us optimize + # the regexp + + MATCHING_WORD_PAIRS = {} + + ## + # And this is used when the delimiters aren't the same. In this case the + # hash maps a pattern to the attribute character + + WORD_PAIR_MAP = {} + + ## + # This maps HTML tags to the corresponding attribute char + + HTML_TAGS = {} + + ## + # And this maps _special_ sequences to a name. A special sequence is + # something like a WikiWord + + SPECIAL = {} + + ## + # Return an attribute object with the given turn_on and turn_off bits set + + def attribute(turn_on, turn_off) + RDoc::Markup::AttrChanger.new turn_on, turn_off + end + + def change_attribute(current, new) + diff = current ^ new + attribute(new & diff, current & diff) + end + + def changed_attribute_by_name(current_set, new_set) + current = new = 0 + current_set.each do |name| + current |= RDoc::Markup::Attribute.bitmap_for(name) + end + + new_set.each do |name| + new |= RDoc::Markup::Attribute.bitmap_for(name) + end + + change_attribute(current, new) + end + + def copy_string(start_pos, end_pos) + res = @str[start_pos...end_pos] + res.gsub!(/\000/, '') + res + end + + ## + # Map attributes like textto the sequence + # \001\002\001\003, where is a per-attribute specific + # character + + def convert_attrs(str, attrs) + # first do matching ones + tags = MATCHING_WORD_PAIRS.keys.join("") + + re = /(^|\W)([#{tags}])([#:\\]?[\w.\/-]+?\S?)\2(\W|$)/ + + 1 while str.gsub!(re) do + attr = MATCHING_WORD_PAIRS[$2] + attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr) + $1 + NULL * $2.length + $3 + NULL * $2.length + $4 + end + + # then non-matching + unless WORD_PAIR_MAP.empty? then + WORD_PAIR_MAP.each do |regexp, attr| + str.gsub!(regexp) { + attrs.set_attrs($`.length + $1.length, $2.length, attr) + NULL * $1.length + $2 + NULL * $3.length + } + end + end + end + + def convert_html(str, attrs) + tags = HTML_TAGS.keys.join '|' + + 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { + attr = HTML_TAGS[$1.downcase] + html_length = $1.length + 2 + seq = NULL * html_length + attrs.set_attrs($`.length + html_length, $2.length, attr) + seq + $2 + seq + NULL + } + end + + def convert_specials(str, attrs) + unless SPECIAL.empty? + SPECIAL.each do |regexp, attr| + str.scan(regexp) do + attrs.set_attrs($`.length, $&.length, + attr | RDoc::Markup::Attribute::SPECIAL) + end + end + end + end + + ## + # A \ in front of a character that would normally be processed turns off + # processing. We do this by turning \< into <#{PROTECT} + + PROTECTABLE = %w[<\\] + + def mask_protected_sequences + protect_pattern = Regexp.new("\\\\([#{Regexp.escape(PROTECTABLE.join(''))}])") + @str.gsub!(protect_pattern, "\\1#{PROTECT_ATTR}") + end + + def unmask_protected_sequences + @str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000") + end + + def initialize + add_word_pair("*", "*", :BOLD) + add_word_pair("_", "_", :EM) + add_word_pair("+", "+", :TT) + + add_html("em", :EM) + add_html("i", :EM) + add_html("b", :BOLD) + add_html("tt", :TT) + add_html("code", :TT) + + add_special(//, :COMMENT) + end + + def add_word_pair(start, stop, name) + raise ArgumentError, "Word flags may not start with '<'" if + start[0,1] == '<' + + bitmap = RDoc::Markup::Attribute.bitmap_for name + + if start == stop then + MATCHING_WORD_PAIRS[start] = bitmap + else + pattern = /(#{Regexp.escape start})(\S+)(#{Regexp.escape stop})/ + WORD_PAIR_MAP[pattern] = bitmap + end + + PROTECTABLE << start[0,1] + PROTECTABLE.uniq! + end + + def add_html(tag, name) + HTML_TAGS[tag.downcase] = RDoc::Markup::Attribute.bitmap_for name + end + + def add_special(pattern, name) + SPECIAL[pattern] = RDoc::Markup::Attribute.bitmap_for name + end + + def flow(str) + @str = str + + puts("Before flow, str='#{@str.dump}'") if $DEBUG_RDOC + mask_protected_sequences + + @attrs = RDoc::Markup::AttrSpan.new @str.length + + puts("After protecting, str='#{@str.dump}'") if $DEBUG_RDOC + + convert_attrs(@str, @attrs) + convert_html(@str, @attrs) + convert_specials(str, @attrs) + + unmask_protected_sequences + + puts("After flow, str='#{@str.dump}'") if $DEBUG_RDOC + + return split_into_flow + end + + def display_attributes + puts + puts @str.tr(NULL, "!") + bit = 1 + 16.times do |bno| + line = "" + @str.length.times do |i| + if (@attrs[i] & bit) == 0 + line << " " + else + if bno.zero? + line << "S" + else + line << ("%d" % (bno+1)) + end + end + end + puts(line) unless line =~ /^ *$/ + bit <<= 1 + end + end + + def split_into_flow + display_attributes if $DEBUG_RDOC + + res = [] + current_attr = 0 + str = "" + + str_len = @str.length + + # skip leading invisible text + i = 0 + i += 1 while i < str_len and @str[i].chr == "\0" + start_pos = i + + # then scan the string, chunking it on attribute changes + while i < str_len + new_attr = @attrs[i] + if new_attr != current_attr + if i > start_pos + res << copy_string(start_pos, i) + start_pos = i + end + + res << change_attribute(current_attr, new_attr) + current_attr = new_attr + + if (current_attr & RDoc::Markup::Attribute::SPECIAL) != 0 then + i += 1 while + i < str_len and (@attrs[i] & RDoc::Markup::Attribute::SPECIAL) != 0 + + res << RDoc::Markup::Special.new(current_attr, + copy_string(start_pos, i)) + start_pos = i + next + end + end + + # move on, skipping any invisible characters + begin + i += 1 + end while i < str_len and @str[i].chr == "\0" + end + + # tidy up trailing text + if start_pos < str_len + res << copy_string(start_pos, str_len) + end + + # and reset to all attributes off + res << change_attribute(current_attr, 0) if current_attr != 0 + + return res + end + +end + diff --git a/lib/rdoc/markup/inline.rb b/lib/rdoc/markup/inline.rb index 418f254998..ee77679a11 100644 --- a/lib/rdoc/markup/inline.rb +++ b/lib/rdoc/markup/inline.rb @@ -39,12 +39,12 @@ class RDoc::Markup end end + AttrChanger = Struct.new(:turn_on, :turn_off) + ## # An AttrChanger records a change in attributes. It contains a bitmap of the # attributes to turn on, and a bitmap of those to turn off. - AttrChanger = Struct.new(:turn_on, :turn_off) - class AttrChanger def to_s "Attr: +#{Attribute.as_string(@turn_on)}/-#{Attribute.as_string(@turn_on)}" @@ -96,266 +96,6 @@ class RDoc::Markup end - class AttributeManager - - NULL = "\000".freeze - - ## - # We work by substituting non-printing characters in to the text. For now - # I'm assuming that I can substitute a character in the range 0..8 for a 7 - # bit character without damaging the encoded string, but this might be - # optimistic - - A_PROTECT = 004 - PROTECT_ATTR = A_PROTECT.chr - - ## - # This maps delimiters that occur around words (such as *bold* or +tt+) - # where the start and end delimiters and the same. This lets us optimize - # the regexp - - MATCHING_WORD_PAIRS = {} - - ## - # And this is used when the delimiters aren't the same. In this case the - # hash maps a pattern to the attribute character - - WORD_PAIR_MAP = {} - - ## - # This maps HTML tags to the corresponding attribute char - - HTML_TAGS = {} - - ## - # And this maps _special_ sequences to a name. A special sequence is - # something like a WikiWord - - SPECIAL = {} - - ## - # Return an attribute object with the given turn_on and turn_off bits set - - def attribute(turn_on, turn_off) - AttrChanger.new(turn_on, turn_off) - end - - def change_attribute(current, new) - diff = current ^ new - attribute(new & diff, current & diff) - end - - def changed_attribute_by_name(current_set, new_set) - current = new = 0 - current_set.each {|name| current |= Attribute.bitmap_for(name) } - new_set.each {|name| new |= Attribute.bitmap_for(name) } - change_attribute(current, new) - end - - def copy_string(start_pos, end_pos) - res = @str[start_pos...end_pos] - res.gsub!(/\000/, '') - res - end - - ## - # Map attributes like textto the sequence - # \001\002\001\003, where is a per-attribute specific - # character - - def convert_attrs(str, attrs) - # first do matching ones - tags = MATCHING_WORD_PAIRS.keys.join("") - - re = /(^|\W)([#{tags}])([#\\]?[\w.\/]+?\S?)\2(\W|$)/ - - 1 while str.gsub!(re) do - attr = MATCHING_WORD_PAIRS[$2] - attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr) - $1 + NULL * $2.length + $3 + NULL * $2.length + $4 - end - - # then non-matching - unless WORD_PAIR_MAP.empty? then - WORD_PAIR_MAP.each do |regexp, attr| - str.gsub!(regexp) { - attrs.set_attrs($`.length + $1.length, $2.length, attr) - NULL * $1.length + $2 + NULL * $3.length - } - end - end - end - - def convert_html(str, attrs) - tags = HTML_TAGS.keys.join '|' - - 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { - attr = HTML_TAGS[$1.downcase] - html_length = $1.length + 2 - seq = NULL * html_length - attrs.set_attrs($`.length + html_length, $2.length, attr) - seq + $2 + seq + NULL - } - end - - def convert_specials(str, attrs) - unless SPECIAL.empty? - SPECIAL.each do |regexp, attr| - str.scan(regexp) do - attrs.set_attrs($`.length, $&.length, attr | Attribute::SPECIAL) - end - end - end - end - - ## - # A \ in front of a character that would normally be processed turns off - # processing. We do this by turning \< into <#{PROTECT} - - PROTECTABLE = %w[<\\] - - def mask_protected_sequences - protect_pattern = Regexp.new("\\\\([#{Regexp.escape(PROTECTABLE.join(''))}])") - @str.gsub!(protect_pattern, "\\1#{PROTECT_ATTR}") - end - - def unmask_protected_sequences - @str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000") - end - - def initialize - add_word_pair("*", "*", :BOLD) - add_word_pair("_", "_", :EM) - add_word_pair("+", "+", :TT) - - add_html("em", :EM) - add_html("i", :EM) - add_html("b", :BOLD) - add_html("tt", :TT) - add_html("code", :TT) - - add_special(//, :COMMENT) - end - - def add_word_pair(start, stop, name) - raise "Word flags may not start '<'" if start[0] == ?< - bitmap = Attribute.bitmap_for(name) - if start == stop - MATCHING_WORD_PAIRS[start] = bitmap - else - pattern = Regexp.new("(" + Regexp.escape(start) + ")" + -# "([A-Za-z]+)" + - "(\\S+)" + - "(" + Regexp.escape(stop) +")") - WORD_PAIR_MAP[pattern] = bitmap - end - PROTECTABLE << start[0,1] - PROTECTABLE.uniq! - end - - def add_html(tag, name) - HTML_TAGS[tag.downcase] = Attribute.bitmap_for(name) - end - - def add_special(pattern, name) - SPECIAL[pattern] = Attribute.bitmap_for(name) - end - - def flow(str) - @str = str - - puts("Before flow, str='#{@str.dump}'") if $DEBUG_RDOC - mask_protected_sequences - - @attrs = AttrSpan.new(@str.length) - - puts("After protecting, str='#{@str.dump}'") if $DEBUG_RDOC - - convert_attrs(@str, @attrs) - convert_html(@str, @attrs) - convert_specials(str, @attrs) - - unmask_protected_sequences - - puts("After flow, str='#{@str.dump}'") if $DEBUG_RDOC - - return split_into_flow - end - - def display_attributes - puts - puts @str.tr(NULL, "!") - bit = 1 - 16.times do |bno| - line = "" - @str.length.times do |i| - if (@attrs[i] & bit) == 0 - line << " " - else - if bno.zero? - line << "S" - else - line << ("%d" % (bno+1)) - end - end - end - puts(line) unless line =~ /^ *$/ - bit <<= 1 - end - end - - def split_into_flow - display_attributes if $DEBUG_RDOC - - res = [] - current_attr = 0 - str = "" - - str_len = @str.length - - # skip leading invisible text - i = 0 - i += 1 while i < str_len and @str[i] == "\0" - start_pos = i - - # then scan the string, chunking it on attribute changes - while i < str_len - new_attr = @attrs[i] - if new_attr != current_attr - if i > start_pos - res << copy_string(start_pos, i) - start_pos = i - end - - res << change_attribute(current_attr, new_attr) - current_attr = new_attr - - if (current_attr & Attribute::SPECIAL) != 0 - i += 1 while i < str_len and (@attrs[i] & Attribute::SPECIAL) != 0 - res << Special.new(current_attr, copy_string(start_pos, i)) - start_pos = i - next - end - end - - # move on, skipping any invisible characters - begin - i += 1 - end while i < str_len and @str[i] == "\0" - end - - # tidy up trailing text - if start_pos < str_len - res << copy_string(start_pos, str_len) - end - - # and reset to all attributes off - res << change_attribute(current_attr, 0) if current_attr != 0 - - return res - end - - end - end +require 'rdoc/markup/attribute_manager' diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 3a500a4f0e..3c08d7bf6a 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -1,6 +1,7 @@ require 'rdoc/markup/formatter' require 'rdoc/markup/fragments' require 'rdoc/markup/inline' +require 'rdoc/generator' require 'cgi' @@ -47,7 +48,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter url = if path[0, 1] == '#' then # is this meaningful? path else - HTML.gen_url @from_path, path + RDoc::Generator.gen_url @from_path, path end end diff --git a/lib/rdoc/parsers/parse_rb.rb b/lib/rdoc/parsers/parse_rb.rb index 637789992d..64f49c97c2 100644 --- a/lib/rdoc/parsers/parse_rb.rb +++ b/lib/rdoc/parsers/parse_rb.rb @@ -2316,7 +2316,7 @@ class RDoc::RubyParser when "section" context.set_current_section(param, comment) - comment.clear + comment.replace '' break else diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 6b7de2f3b7..38f6374764 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -228,37 +228,37 @@ module RDoc def document(argv) TopLevel::reset - options = Options.new GENERATORS - options.parse argv + @options = Options.new GENERATORS + @options.parse argv @last_created = nil - unless options.all_one_file - @last_created = setup_output_dir(options.op_dir, options.force_update) + unless @options.all_one_file then + @last_created = setup_output_dir @options.op_dir, @options.force_update end start_time = Time.now - file_info = parse_files(options) + file_info = parse_files @options if file_info.empty? - $stderr.puts "\nNo newer files." unless options.quiet + $stderr.puts "\nNo newer files." unless @options.quiet else - gen = options.generator + gen = @options.generator - $stderr.puts "\nGenerating #{gen.key.upcase}..." unless options.quiet + $stderr.puts "\nGenerating #{gen.key.upcase}..." unless @options.quiet require gen.file_name gen_class = ::RDoc::Generator.const_get gen.class_name - gen = gen_class.for(options) + gen = gen_class.for @options pwd = Dir.pwd - Dir.chdir(options.op_dir) unless options.all_one_file + Dir.chdir @options.op_dir unless @options.all_one_file begin - Diagram.new(file_info, options).draw if options.diagram + Diagram.new(file_info, @options).draw if @options.diagram gen.generate(file_info) update_output_dir(".", start_time) ensure @@ -266,7 +266,7 @@ module RDoc end end - unless options.quiet + unless @options.quiet puts @stats.print end diff --git a/lib/rdoc/ri/descriptions.rb b/lib/rdoc/ri/descriptions.rb index 9887862e0a..adc3e7774b 100644 --- a/lib/rdoc/ri/descriptions.rb +++ b/lib/rdoc/ri/descriptions.rb @@ -13,6 +13,7 @@ class RDoc::RI::NamedThing def initialize(name) @name = name end + def <=>(other) @name <=> other.name end @@ -30,6 +31,7 @@ class RDoc::RI::AliasName < RDoc::RI::NamedThing; end class RDoc::RI::Attribute < RDoc::RI::NamedThing attr_reader :rw, :comment + def initialize(name, rw, comment) super(name) @rw = rw @@ -39,6 +41,7 @@ end class RDoc::RI::Constant < RDoc::RI::NamedThing attr_reader :value, :comment + def initialize(name, value, comment) super(name) @value = value diff --git a/lib/rdoc/ri/display.rb b/lib/rdoc/ri/display.rb index fa331c46c2..379cef11b3 100644 --- a/lib/rdoc/ri/display.rb +++ b/lib/rdoc/ri/display.rb @@ -2,9 +2,9 @@ require 'rdoc/ri' ## # This is a kind of 'flag' module. If you want to write your own 'ri' display -# module (perhaps because you'r writing an IDE or somesuch beast), you simply -# write a class which implements the various 'display' methods in -# 'DefaultDisplay', and include the 'RiDisplay' module in that class. +# 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. # # To access your class from the command line, you can do # @@ -32,26 +32,14 @@ class RDoc::RI::DefaultDisplay include RDoc::RI::Display - def initialize(formatter, width, use_stdout) + def initialize(formatter, width, use_stdout, output = $stdout) @use_stdout = use_stdout - @formatter = formatter.new $stdout, width, " " + @formatter = formatter.new output, width, " " end - def display_method_info(method) - page do - @formatter.draw_line(method.full_name) - display_params(method) - @formatter.draw_line - display_flow(method.comment) - if method.aliases && !method.aliases.empty? - @formatter.blankline - aka = "(also known as " - aka << method.aliases.map {|a| a.name }.join(", ") - aka << ")" - @formatter.wrap(aka) - end - end - end + ## + # Display information about +klass+. Fetches additional information from + # +ri_reader+ as necessary. def display_class_info(klass, ri_reader) page do @@ -90,89 +78,150 @@ class RDoc::RI::DefaultDisplay unless klass.constants.empty? @formatter.blankline @formatter.display_heading("Constants:", 2, "") - len = 0 - klass.constants.each { |c| len = c.name.length if c.name.length > len } - len += 2 - klass.constants.each do |c| - @formatter.wrap(c.value, - @formatter.indent+((c.name+":").ljust(len))) + + constants = klass.constants.sort_by { |constant| constant.name } + + constants.each do |constant| + if constant.comment then + @formatter.wrap "#{constant.name}:" + + @formatter.indent do + @formatter.display_flow constant.comment + end + else + @formatter.wrap constant.name + end end end - unless klass.class_methods.empty? - @formatter.blankline - @formatter.display_heading("Class methods:", 2, "") - @formatter.wrap(klass.class_methods.map{|m| m.name}.sort.join(', ')) - end + class_data = [ + :class_methods, + :class_method_extensions, + :instance_methods, + :instance_method_extensions, + ] - unless klass.class_method_extensions.empty? - @formatter.blankline - @formatter.display_heading("Class Method Extensions:", 2, "") - @formatter.wrap(klass.class_method_extensions.map{|m| m.name}.sort.join(', ')) - end + class_data.each do |data_type| + data = klass.send data_type - unless klass.instance_methods.empty? - @formatter.blankline - @formatter.display_heading("Instance methods:", 2, "") - @formatter.wrap(klass.instance_methods.map{|m| m.name}.sort.join(', ')) + unless data.empty? then + @formatter.blankline + + heading = data_type.to_s.split('_').join(' ').capitalize << ':' + @formatter.display_heading heading, 2, '' + + data = data.map { |item| item.name }.sort.join ', ' + @formatter.wrap data + end end - unless klass.instance_method_extensions.empty? + unless klass.attributes.empty? then @formatter.blankline - @formatter.display_heading("Instance Method Extensions:", 2, "") - @formatter.wrap(klass.instance_method_extensions.map{|m| m.name}.sort.join(', ')) + + @formatter.display_heading 'Attributes:', 2, '' + + attributes = klass.attributes.sort_by { |attribute| attribute.name } + + attributes.each do |attribute| + if attribute.comment then + @formatter.wrap "#{attribute.name} (#{attribute.rw}):" + @formatter.indent do + @formatter.display_flow attribute.comment + end + else + @formatter.wrap "#{attribute.name} (#{attribute.rw})" + end + end end + end + end + + ## + # Display an Array of RDoc::Markup::Flow objects, +flow+. + + def display_flow(flow) + if flow and not flow.empty? then + @formatter.display_flow flow + else + @formatter.wrap '[no description]' + end + end + + ## + # Display information about +method+. - unless klass.attributes.empty? + def display_method_info(method) + page do + @formatter.draw_line(method.full_name) + display_params(method) + + @formatter.draw_line + display_flow(method.comment) + + if method.aliases and not method.aliases.empty? then @formatter.blankline - @formatter.wrap("Attributes:", "") - @formatter.wrap(klass.attributes.map{|a| a.name}.sort.join(', ')) + aka = "(also known as #{method.aliases.map { |a| a.name }.join(', ')})" + @formatter.wrap aka end end end ## - # Display a list of method names + # Display the list of +methods+. def display_method_list(methods) page do - @formatter.raw_print_line("More than one method matched your request. You can refine") - @formatter.raw_print_line("your search by asking for information on one of:\n\n") - @formatter.wrap(methods.map {|m| m.full_name} .join(", ")) + @formatter.wrap "More than one method matched your request. You can refine your search by asking for information on one of:" + + @formatter.blankline + + @formatter.wrap methods.map { |m| m.full_name }.join(", ") end end - def display_class_list(namespaces) - page do - @formatter.raw_print_line("More than one class or module matched your request. You can refine") - @formatter.raw_print_line("your search by asking for information on one of:\n\n") - @formatter.wrap(namespaces.map {|m| m.full_name}.join(", ")) + ## + # Display the params for +method+. + + def display_params(method) + params = method.params + + if params[0,1] == "(" then + if method.is_singleton + params = method.full_name + params + else + params = method.name + params + end + end + + params.split(/\n/).each do |param| + @formatter.wrap param + @formatter.break_to_newline + end + + if method.source_path then + @formatter.blankline + @formatter.wrap("Extension from #{method.source_path}") end end + ## + # List the classes in +classes+. + def list_known_classes(classes) if classes.empty? warn_no_database else page do - @formatter.draw_line("Known classes and modules") + @formatter.draw_line "Known classes and modules" @formatter.blankline - @formatter.wrap(classes.sort.join(", ")) - end - end - end - def list_known_names(names) - if names.empty? - warn_no_database - else - page do - names.each {|n| @formatter.raw_print_line(n)} + @formatter.wrap classes.sort.join(', ') end end end - private + ## + # Paginates output through a pager program. def page if pager = setup_pager then @@ -190,6 +239,9 @@ class RDoc::RI::DefaultDisplay rescue Errno::EPIPE end + ## + # Sets up a pager program to pass output through. + def setup_pager unless @use_stdout then for pager in [ ENV['PAGER'], "less", "more", 'pager' ].compact.uniq @@ -200,45 +252,23 @@ class RDoc::RI::DefaultDisplay end end - def display_params(method) - params = method.params - - if params[0,1] == "(" - if method.is_singleton - params = method.full_name + params - else - params = method.name + params - end - end - params.split(/\n/).each do |p| - @formatter.wrap(p) - @formatter.break_to_newline - end - if method.source_path then - @formatter.blankline - @formatter.wrap("Extension from #{method.source_path}") - end - end - - def display_flow(flow) - if !flow || flow.empty? - @formatter.wrap("(no description...)") - else - @formatter.display_flow(flow) - end - end + ## + # Displays a message that describes how to build RI data. def warn_no_database - puts "No ri data found" - puts - puts "If you've installed Ruby yourself, you need to generate documentation using:" - puts - puts " make install-doc" - puts - puts "from the same place you ran `make` to build ruby." - puts - puts "If you installed Ruby from a packaging system, then you may need to" - puts "install an additional package, or ask the packager to enable ri generation." + output = @formatter.output + + output.puts "No ri data found" + output.puts + output.puts "If you've installed Ruby yourself, you need to generate documentation using:" + output.puts + output.puts " make install-doc" + output.puts + output.puts "from the same place you ran `make` to build ruby." + output.puts + 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 diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index b254d3574f..7ac2e0f15c 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -344,7 +344,11 @@ Options may also be set in the 'RI' environment variable. end def read_yaml(path) - YAML.load File.read(path).gsub(/ \!ruby\/(object|struct):(RDoc::RI|RI|SM).*/, '') + data = File.read path + data = data.gsub(/ \!ruby\/(object|struct):(RDoc::RI|RI).*/, '') + data = data.gsub(/ \!ruby\/(object|struct):SM::(\S+)/, + ' !ruby/\1:RDoc::Markup::\2') + YAML.load data end def get_info_for(arg) @@ -418,7 +422,7 @@ Options may also be set in the 'RI' environment variable. end -class Hash +class Hash # HACK don't add stuff to Hash. def method_missing method, *args self[method.to_s] end @@ -428,7 +432,12 @@ class Hash if self[k] then case v when Array then - self[k] += v + # HACK dunno + if String === self[k] and self[k].empty? then + self[k] = v + else + self[k] += v + end when Hash then self[k].merge! v else diff --git a/lib/rdoc/ri/formatter.rb b/lib/rdoc/ri/formatter.rb index df73bf5eb3..0a0c3f7380 100644 --- a/lib/rdoc/ri/formatter.rb +++ b/lib/rdoc/ri/formatter.rb @@ -3,7 +3,7 @@ require 'rdoc/markup' class RDoc::RI::Formatter - attr_reader :indent + attr_writer :indent attr_accessor :output FORMATTERS = { } @@ -20,6 +20,7 @@ class RDoc::RI::Formatter @output = output @width = width @indent = indent + @original_indent = indent.dup end def draw_line(label=nil) @@ -42,6 +43,18 @@ class RDoc::RI::Formatter end end + def indent + return @indent unless block_given? + + begin + indent = @indent.dup + @indent += @original_indent + yield + ensure + @indent = indent + end + end + def wrap(txt, prefix=@indent, linelen=@width) return unless txt && !txt.empty? @@ -481,13 +494,13 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter when :LABELED then list_type = "dl" prefixer = proc do |li| - "
" + escape(li.label) + "
" + "
" + escape(li.label) + "
" end when :NOTE then list_type = "table" prefixer = proc do |li| - %{#{li.label.gsub(/ /, ' ')}} + %{#{li.label.gsub(/ /, ' ')}} end else fail "unknown list type" diff --git a/lib/rdoc/template.rb b/lib/rdoc/template.rb index aa35927c8b..53d0e3ce68 100644 --- a/lib/rdoc/template.rb +++ b/lib/rdoc/template.rb @@ -1,10 +1,12 @@ require 'erb' +module RDoc; end + ## -# An ERB wrapper. +# An ERb wrapper that allows nesting of one ERb template inside another. # # This TemplatePage operates similarly to RDoc 1.x's TemplatePage, but uses -# ERB instead of a custom template language. +# ERb instead of a custom template language. # # Converting from a RDoc 1.x template to an RDoc 2.x template is fairly easy. # @@ -24,8 +26,6 @@ require 'erb' # # So you can see what is being used inside which loop. -module RDoc -end class RDoc::TemplatePage ## -- cgit v1.2.3