Skip to content

Commit 50f0270

Browse files
authored
Merge pull request #846 from flavorjones/flavorjones-support-category-in-c-function-comments
feature: add support for `:category:` on C functions
2 parents 836c829 + 45c9200 commit 50f0270

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

lib/rdoc/any_method.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class RDoc::AnyMethod < RDoc::MethodAttr
2626

2727
attr_accessor :c_function
2828

29+
# The section title of the method (if defined in a C file via +:category:+)
30+
attr_accessor :section_title
31+
2932
# Parameters for this method
3033

3134
attr_accessor :params

lib/rdoc/markup/pre_process.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ def handle_directive prefix, directive, param, code_object = nil,
163163
if RDoc::Context === code_object then
164164
section = code_object.add_section param
165165
code_object.temporary_section = section
166+
elsif RDoc::AnyMethod === code_object then
167+
code_object.section_title = param
166168
end
167169

168170
blankline # ignore category if we're not on an RDoc::Context

lib/rdoc/parser/c.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,12 @@ def handle_method(type, var_name, meth_name, function, param_count,
10301030

10311031

10321032
meth_obj.record_location @top_level
1033+
1034+
if meth_obj.section_title
1035+
class_obj.temporary_section = class_obj.add_section(meth_obj.section_title)
1036+
end
10331037
class_obj.add_method meth_obj
1038+
10341039
@stats.add_method meth_obj
10351040
meth_obj.visibility = :private if 'private_method' == type
10361041
end

test/rdoc/test_rdoc_parser_c.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,39 @@ def test_define_method
16001600
assert_equal "Method Comment! ", read_method.comment.text
16011601
assert_equal "rb_io_s_read", read_method.c_function
16021602
assert read_method.singleton
1603+
assert_nil read_method.section.title
1604+
end
1605+
1606+
def test_define_method_with_category
1607+
content = <<-EOF
1608+
/* :category: Awesome Methods
1609+
Method Comment!
1610+
*/
1611+
static VALUE
1612+
rb_io_s_read(argc, argv, io)
1613+
int argc;
1614+
VALUE *argv;
1615+
VALUE io;
1616+
{
1617+
}
1618+
1619+
void
1620+
Init_IO(void) {
1621+
/*
1622+
* a comment for class Foo on rb_define_class
1623+
*/
1624+
VALUE rb_cIO = rb_define_class("IO", rb_cObject);
1625+
rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
1626+
}
1627+
EOF
1628+
1629+
klass = util_get_class content, 'rb_cIO'
1630+
read_method = klass.method_list.first
1631+
assert_equal "read", read_method.name
1632+
assert_equal "Method Comment!", read_method.comment.text.strip
1633+
assert_equal "rb_io_s_read", read_method.c_function
1634+
assert read_method.singleton
1635+
assert_equal "Awesome Methods", read_method.section.title
16031636
end
16041637

16051638
def test_define_method_dynamically

0 commit comments

Comments
 (0)