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

ruby-changes:68484

From: Mike <ko1@a...>
Date: Sat, 16 Oct 2021 01:39:45 +0900 (JST)
Subject: [ruby-changes:68484] 7aec65add4 (master): [ruby/rdoc] feat: add support for :category: on C functions

https://git.ruby-lang.org/ruby.git/commit/?id=7aec65add4

From 7aec65add42d20ba8d70ad33c7b1e8978007e29e Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike.dalessio@g...>
Date: Mon, 11 Oct 2021 13:44:37 -0400
Subject: [ruby/rdoc] feat: add support for :category: on C functions

https://github.com/ruby/rdoc/commit/45c92005fe
---
 lib/rdoc/any_method.rb          |  3 +++
 lib/rdoc/markup/pre_process.rb  |  2 ++
 lib/rdoc/parser/c.rb            |  5 +++++
 test/rdoc/test_rdoc_parser_c.rb | 33 +++++++++++++++++++++++++++++++++
 4 files changed, 43 insertions(+)

diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb
index 562e68461c..3d0b60790d 100644
--- a/lib/rdoc/any_method.rb
+++ b/lib/rdoc/any_method.rb
@@ -26,6 +26,9 @@ class RDoc::AnyMethod < RDoc::MethodAttr https://github.com/ruby/ruby/blob/trunk/lib/rdoc/any_method.rb#L26
 
   attr_accessor :c_function
 
+  # The section title of the method (if defined in a C file via +:category:+)
+  attr_accessor :section_title
+
   # Parameters for this method
 
   attr_accessor :params
diff --git a/lib/rdoc/markup/pre_process.rb b/lib/rdoc/markup/pre_process.rb
index 3080ae3578..88078c9cef 100644
--- a/lib/rdoc/markup/pre_process.rb
+++ b/lib/rdoc/markup/pre_process.rb
@@ -163,6 +163,8 @@ class RDoc::Markup::PreProcess https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/pre_process.rb#L163
       if RDoc::Context === code_object then
         section = code_object.add_section param
         code_object.temporary_section = section
+      elsif RDoc::AnyMethod === code_object then
+        code_object.section_title = param
       end
 
       blankline # ignore category if we're not on an RDoc::Context
diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb
index 111f6e2091..b89aaa6dcc 100644
--- a/lib/rdoc/parser/c.rb
+++ b/lib/rdoc/parser/c.rb
@@ -1030,7 +1030,12 @@ class RDoc::Parser::C < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/c.rb#L1030
 
 
         meth_obj.record_location @top_level
+
+        if meth_obj.section_title
+          class_obj.temporary_section = class_obj.add_section(meth_obj.section_title)
+        end
         class_obj.add_method meth_obj
+
         @stats.add_method meth_obj
         meth_obj.visibility = :private if 'private_method' == type
       end
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb
index 93d19dd26f..8f51f32f26 100644
--- a/test/rdoc/test_rdoc_parser_c.rb
+++ b/test/rdoc/test_rdoc_parser_c.rb
@@ -1600,6 +1600,39 @@ Init_IO(void) { https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_c.rb#L1600
     assert_equal "Method Comment!   ", read_method.comment.text
     assert_equal "rb_io_s_read", read_method.c_function
     assert read_method.singleton
+    assert_nil read_method.section.title
+  end
+
+  def test_define_method_with_category
+    content = <<-EOF
+/* :category: Awesome Methods
+   Method Comment!
+ */
+static VALUE
+rb_io_s_read(argc, argv, io)
+    int argc;
+    VALUE *argv;
+    VALUE io;
+{
+}
+
+void
+Init_IO(void) {
+    /*
+     * a comment for class Foo on rb_define_class
+     */
+    VALUE rb_cIO = rb_define_class("IO", rb_cObject);
+    rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
+}
+    EOF
+
+    klass = util_get_class content, 'rb_cIO'
+    read_method = klass.method_list.first
+    assert_equal "read", read_method.name
+    assert_equal "Method Comment!", read_method.comment.text.strip
+    assert_equal "rb_io_s_read", read_method.c_function
+    assert read_method.singleton
+    assert_equal "Awesome Methods", read_method.section.title
   end
 
   def test_define_method_dynamically
-- 
cgit v1.2.1


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

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