Skip to content

Commit

Permalink
Merge pull request #846 from flavorjones/flavorjones-support-category…
Browse files Browse the repository at this point in the history
…-in-c-function-comments

feature: add support for `:category:` on C functions
  • Loading branch information
tenderlove authored Oct 15, 2021
2 parents 836c829 + 45c9200 commit 50f0270
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rdoc/any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/rdoc/markup/pre_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions test/rdoc/test_rdoc_parser_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 50f0270

Please sign in to comment.