diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb index 562e68461c3cea..3d0b60790d3a15 100644 --- a/lib/rdoc/any_method.rb +++ b/lib/rdoc/any_method.rb @@ -26,6 +26,9 @@ class RDoc::AnyMethod < RDoc::MethodAttr 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 3080ae35787f5e..88078c9cefca56 100644 --- a/lib/rdoc/markup/pre_process.rb +++ b/lib/rdoc/markup/pre_process.rb @@ -163,6 +163,8 @@ def handle_directive prefix, directive, param, code_object = nil, 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 111f6e20917b0e..b89aaa6dcc9795 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -1030,7 +1030,12 @@ def handle_method(type, var_name, meth_name, function, param_count, 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 93d19dd26f3f61..8f51f32f261504 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -1600,6 +1600,39 @@ def test_define_method 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