[前][次][番号順一覧][スレッド一覧]

ruby-changes:20216

From: drbrain <ko1@a...>
Date: Tue, 28 Jun 2011 11:28:38 +0900 (JST)
Subject: [ruby-changes:20216] drbrain:r32264 (trunk): * lib/rdoc: Update to RDoc 3.7 (final)

drbrain	2011-06-28 11:28:25 +0900 (Tue, 28 Jun 2011)

  New Revision: 32264

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32264

  Log:
    * lib/rdoc:  Update to RDoc 3.7 (final)
    * NEWS:  ditto

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/rdoc/markup/document.rb
    trunk/lib/rdoc/markup/inline.rb
    trunk/lib/rdoc/markup/to_ansi.rb
    trunk/lib/rdoc/markup.rb
    trunk/lib/rdoc/ri/driver.rb
    trunk/test/rdoc/test_rdoc_markup.rb
    trunk/test/rdoc/test_rdoc_markup_document.rb
    trunk/test/rdoc/test_rdoc_markup_pre_process.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32263)
+++ ChangeLog	(revision 32264)
@@ -1,3 +1,8 @@
+Tue Jun 28 11:17:28 2011  Eric Hodel  <drbrain@s...>
+
+	* lib/rdoc:  Update to RDoc 3.7 (final)
+	* NEWS:  ditto
+
 Tue Jun 28 10:18:42 2011  NARUSE, Yui  <naruse@r...>
 
 	* process.c (rb_daemon): fix wrong #endif position.
Index: lib/rdoc/markup/document.rb
===================================================================
--- lib/rdoc/markup/document.rb	(revision 32263)
+++ lib/rdoc/markup/document.rb	(revision 32264)
@@ -56,7 +56,12 @@
     visitor.start_accepting
 
     @parts.each do |item|
-      item.accept visitor
+      case item
+      when RDoc::Markup::Document then # HACK
+        visitor.accept_document item
+      else
+        item.accept visitor
+      end
     end
 
     visitor.end_accepting
@@ -66,7 +71,9 @@
   # Does this document have no parts?
 
   def empty?
-    @parts.empty?
+    @parts.empty? or
+      (@parts.length == 1 and RDoc::Markup::Document === @parts.first and
+       @parts.first.empty?)
   end
 
   ##
Index: lib/rdoc/markup/inline.rb
===================================================================
--- lib/rdoc/markup/inline.rb	(revision 32263)
+++ lib/rdoc/markup/inline.rb	(revision 32264)
@@ -60,8 +60,15 @@
 
   class AttrChanger
     def to_s # :nodoc:
-      "Attr: +#{Attribute.as_string turn_on}/-#{Attribute.as_string turn_on}"
+      "Attr: +#{Attribute.as_string turn_on}/-#{Attribute.as_string turn_off}"
     end
+
+    def inspect # :nodoc:
+      "+%s/-%s" % [
+        Attribute.as_string(turn_on),
+        Attribute.as_string(turn_off),
+      ]
+    end
   end
 
   ##
Index: lib/rdoc/markup/to_ansi.rb
===================================================================
--- lib/rdoc/markup/to_ansi.rb	(revision 32263)
+++ lib/rdoc/markup/to_ansi.rb	(revision 32264)
@@ -12,9 +12,9 @@
     super
 
     @headings.clear
-    @headings[1] = ["\e[1;32m", "\e[m"]
-    @headings[2] = ["\e[4;32m", "\e[m"]
-    @headings[3] = ["\e[32m",   "\e[m"]
+    @headings[1] = ["\e[1;32m", "\e[m"] # bold
+    @headings[2] = ["\e[4;32m", "\e[m"] # underline
+    @headings[3] = ["\e[32m",   "\e[m"] # just green
   end
 
   ##
Index: lib/rdoc/markup.rb
===================================================================
--- lib/rdoc/markup.rb	(revision 32263)
+++ lib/rdoc/markup.rb	(revision 32264)
@@ -616,11 +616,16 @@
   end
 
   ##
-  # We take +text+, parse it then invoke the output +formatter+ using a
-  # Visitor to render the result.
+  # We take +input+, parse it if necessary, then invoke the output +formatter+
+  # using a Visitor to render the result.
 
-  def convert text, formatter
-    document = RDoc::Markup::Parser.parse text
+  def convert input, formatter
+    document = case input
+               when RDoc::Markup::Document then
+                 input
+               else
+                 RDoc::Markup::Parser.parse input
+               end
 
     document.accept formatter
   end
Index: lib/rdoc/ri/driver.rb
===================================================================
--- lib/rdoc/ri/driver.rb	(revision 32263)
+++ lib/rdoc/ri/driver.rb	(revision 32264)
@@ -344,8 +344,8 @@
     @stores   = []
 
     RDoc::RI::Paths.each(options[:use_system], options[:use_site],
-                                   options[:use_home], options[:use_gems],
-                                   *options[:extra_doc_dirs]) do |path, type|
+                         options[:use_home], options[:use_gems],
+                         *options[:extra_doc_dirs]) do |path, type|
       @doc_dirs << path
 
       store = RDoc::RI::Store.new path, type
@@ -505,6 +505,70 @@
   end
 
   ##
+  # Builds a RDoc::Markup::Document from +found+, +klasess+ and +includes+
+
+  def class_document name, found, klasses, includes
+    also_in = []
+
+    out = RDoc::Markup::Document.new
+
+    add_class out, name, klasses
+
+    add_includes out, includes
+
+    found.each do |store, klass|
+      comment = klass.comment
+      class_methods    = store.class_methods[klass.full_name]
+      instance_methods = store.instance_methods[klass.full_name]
+      attributes       = store.attributes[klass.full_name]
+
+      if comment.empty? and !(instance_methods or class_methods) then
+        also_in << store
+        next
+      end
+
+      add_from out, store
+
+      unless comment.empty? then
+        out << RDoc::Markup::Rule.new(1)
+        out << comment
+      end
+
+      if class_methods or instance_methods or not klass.constants.empty? then
+        out << RDoc::Markup::Rule.new(1)
+      end
+
+      unless klass.constants.empty? then
+        out << RDoc::Markup::Heading.new(1, "Constants:")
+        out << RDoc::Markup::BlankLine.new
+        list = RDoc::Markup::List.new :NOTE
+
+        constants = klass.constants.sort_by { |constant| constant.name }
+
+        list.push(*constants.map do |constant|
+          parts = constant.comment.parts if constant.comment
+          parts << RDoc::Markup::Paragraph.new('[not documented]') if
+            parts.empty?
+
+          RDoc::Markup::ListItem.new(constant.name, *parts)
+        end)
+
+        out << list
+      end
+
+      add_method_list out, class_methods,    'Class methods'
+      add_method_list out, instance_methods, 'Instance methods'
+      add_method_list out, attributes,       'Attributes'
+
+      out << RDoc::Markup::BlankLine.new
+    end
+
+    add_also_in out, also_in
+
+    out
+  end
+
+  ##
   # Hash mapping a known class or module to the stores it can be loaded from
 
   def classes
@@ -524,6 +588,29 @@
   end
 
   ##
+  # Returns the stores wherin +name+ is found along with the classes and
+  # includes that match it
+
+  def classes_and_includes_for name
+    klasses = []
+    includes = []
+
+    found = @stores.map do |store|
+      begin
+        klass = store.load_class name
+        klasses  << klass
+        includes << [klass.includes, store] if klass.includes
+        [store, klass]
+      rescue Errno::ENOENT
+      end
+    end.compact
+
+    includes.reject! do |modules,| modules.empty? end
+
+    [found, klasses, includes]
+  end
+
+  ##
   # Completes +name+ based on the caches.  For Readline
 
   def complete name
@@ -582,80 +669,12 @@
   def display_class name
     return if name =~ /#|\./
 
-    klasses = []
-    includes = []
+    found, klasses, includes = classes_and_includes_for name
 
-    found = @stores.map do |store|
-      begin
-        klass = store.load_class name
-        klasses  << klass
-        includes << [klass.includes, store] if klass.includes
-        [store, klass]
-      rescue Errno::ENOENT
-      end
-    end.compact
-
     return if found.empty?
 
-    also_in = []
+    out = class_document name, found, klasses, includes
 
-    includes.reject! do |modules,| modules.empty? end
-
-    out = RDoc::Markup::Document.new
-
-    add_class out, name, klasses
-
-    add_includes out, includes
-
-    found.each do |store, klass|
-      comment = klass.comment
-      class_methods    = store.class_methods[klass.full_name]
-      instance_methods = store.instance_methods[klass.full_name]
-      attributes       = store.attributes[klass.full_name]
-
-      if comment.empty? and !(instance_methods or class_methods) then
-        also_in << store
-        next
-      end
-
-      add_from out, store
-
-      unless comment.empty? then
-        out << RDoc::Markup::Rule.new(1)
-        out << comment
-      end
-
-      if class_methods or instance_methods or not klass.constants.empty? then
-        out << RDoc::Markup::Rule.new(1)
-      end
-
-      unless klass.constants.empty? then
-        out << RDoc::Markup::Heading.new(1, "Constants:")
-        out << RDoc::Markup::BlankLine.new
-        list = RDoc::Markup::List.new :NOTE
-
-        constants = klass.constants.sort_by { |constant| constant.name }
-
-        list.push(*constants.map do |constant|
-          parts = constant.comment.parts if constant.comment
-          parts << RDoc::Markup::Paragraph.new('[not documented]') if
-            parts.empty?
-
-          RDoc::Markup::ListItem.new(constant.name, *parts)
-        end)
-
-        out << list
-      end
-
-      add_method_list out, class_methods,    'Class methods'
-      add_method_list out, instance_methods, 'Instance methods'
-      add_method_list out, attributes,       'Attributes'
-
-      out << RDoc::Markup::BlankLine.new
-    end
-
-    add_also_in out, also_in
-
     display out
   end
 
@@ -669,33 +688,8 @@
 
     filtered = filter_methods found, name
 
-    out = RDoc::Markup::Document.new
+    out = method_document name, filtered
 
-    out << RDoc::Markup::Heading.new(1, name)
-    out << RDoc::Markup::BlankLine.new
-
-    filtered.each do |store, methods|
-      methods.each do |method|
-        out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})")
-
-        unless name =~ /^#{Regexp.escape method.parent_name}/ then
-          out << RDoc::Markup::Heading.new(3, "Implementation from #{method.parent_name}")
-        end
-        out << RDoc::Markup::Rule.new(1)
-
-        if method.arglists then
-          arglists = method.arglists.chomp.split "\n"
-          arglists = arglists.map { |line| line + "\n" }
-          out << RDoc::Markup::Verbatim.new(*arglists)
-          out << RDoc::Markup::Rule.new(1)
-        end
-
-        out << RDoc::Markup::BlankLine.new
-        out << method.comment
-        out << RDoc::Markup::BlankLine.new
-      end
-    end
-
     display out
   end
 
@@ -736,6 +730,7 @@
       display_name name
     end
   end
+
   ##
   # Expands abbreviated klass +klass+ into a fully-qualified class.  "Zl::Da"
   # will be expanded to Zlib::DataError.
@@ -1004,6 +999,40 @@
   end
 
   ##
+  # Builds a RDoc::Markup::Document from +found+, +klasess+ and +includes+
+
+  def method_document name, filtered
+    out = RDoc::Markup::Document.new
+
+    out << RDoc::Markup::Heading.new(1, name)
+    out << RDoc::Markup::BlankLine.new
+
+    filtered.each do |store, methods|
+      methods.each do |method|
+        out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})")
+
+        unless name =~ /^#{Regexp.escape method.parent_name}/ then
+          out << RDoc::Markup::Heading.new(3, "Implementation from #{method.parent_name}")
+        end
+        out << RDoc::Markup::Rule.new(1)
+
+        if method.arglists then
+          arglists = method.arglists.chomp.split "\n"
+          arglists = arglists.map { |line| line + "\n" }
+          out << RDoc::Markup::Verbatim.new(*arglists)
+          out << RDoc::Markup::Rule.new(1)
+        end
+
+        out << RDoc::Markup::BlankLine.new
+        out << method.comment
+        out << RDoc::Markup::BlankLine.new
+      end
+    end
+
+    out
+  end
+
+  ##
   # Returns the type of method (:both, :instance, :class) for +selector+
 
   def method_type selector
Index: NEWS
===================================================================
--- NEWS	(revision 32263)
+++ NEWS	(revision 32264)
@@ -199,7 +199,7 @@
     https://github.com/jimweirich/rake/blob/master/CHANGES
 
 * RDoc
-  * RDoc has been upgraded from 2.5.8 to 3.6.1.  For full release notes see
+  * RDoc has been upgraded from 2.5.8 to 3.7.  For full release notes see
     http://docs.seattlerb.org/rdoc/History_txt.html
 
 * rexml
Index: test/rdoc/test_rdoc_markup_document.rb
===================================================================
--- test/rdoc/test_rdoc_markup_document.rb	(revision 32263)
+++ test/rdoc/test_rdoc_markup_document.rb	(revision 32264)
@@ -55,6 +55,12 @@
     refute_empty @d
   end
 
+  def test_empty_eh_document
+    d = @RM::Document.new @d
+
+    assert_empty d
+  end
+
   def test_equals2
     d2 = @RM::Document.new
 
Index: test/rdoc/test_rdoc_markup.rb
===================================================================
--- test/rdoc/test_rdoc_markup.rb	(revision 32263)
+++ test/rdoc/test_rdoc_markup.rb	(revision 32264)
@@ -56,5 +56,36 @@
     assert_equal expected, out
   end
 
+  def test_convert_document
+    doc = RDoc::Markup::Parser.parse <<-STR
+now is
+the time
+
+  hello
+  dave
+
+1. l1
+2. l2
+    STR
+
+    m = RDoc::Markup.new
+
+    tt = RDoc::Markup::ToTest.new m
+
+    out = m.convert doc, tt
+
+    expected = [
+      "now is the time",
+      "\n",
+      "  hello\n  dave\n",
+      "1: ",
+      "l1",
+      "1: ",
+      "l2",
+    ]
+
+    assert_equal expected, out
+  end
+
 end
 
Index: test/rdoc/test_rdoc_markup_pre_process.rb
===================================================================
--- test/rdoc/test_rdoc_markup_pre_process.rb	(revision 32263)
+++ test/rdoc/test_rdoc_markup_pre_process.rb	(revision 32264)
@@ -43,7 +43,7 @@
     # FIXME 1.9 fix on windoze
     # preprocessor uses binread, so line endings are \r\n
     expected.gsub!("\n", "\r\n") if
-      RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/
+      RUBY_VERSION < "1.9.3" && RUBY_PLATFORM =~ /mswin|mingw/
 
     assert_equal expected, content
   end
@@ -67,7 +67,7 @@
     # FIXME 1.9 fix on windoze
     # preprocessor uses binread, so line endings are \r\n
     expected.gsub!("\n", "\r\n") if
-      RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/
+      RUBY_VERSION < "1.9.3" && RUBY_PLATFORM =~ /mswin|mingw/
 
     assert_equal expected, content
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]