diff --git a/lib/rdoc/generator/template/rails/_context.rhtml b/lib/rdoc/generator/template/rails/_context.rhtml index d4b1bfab..a3558d13 100644 --- a/lib/rdoc/generator/template/rails/_context.rhtml +++ b/lib/rdoc/generator/template/rails/_context.rhtml @@ -52,7 +52,7 @@ <% end %> - <%= description_for section %> + <%= comments_for @context, section %> <% unless constants.empty? %> diff --git a/lib/sdoc/helpers.rb b/lib/sdoc/helpers.rb index d608f112..6fbc8942 100644 --- a/lib/sdoc/helpers.rb +++ b/lib/sdoc/helpers.rb @@ -64,6 +64,12 @@ def description_for(rdoc_object) end end + def comments_for(context, section) + return if section.comments.empty? + + %(
#{context.markup section.comments}
) + end + def base_tag_for_context(context) relative_root = "../" * context.path.count("/") %() diff --git a/lib/sdoc/rdoc_monkey_patches.rb b/lib/sdoc/rdoc_monkey_patches.rb index ce858e5e..354ed62f 100644 --- a/lib/sdoc/rdoc_monkey_patches.rb +++ b/lib/sdoc/rdoc_monkey_patches.rb @@ -32,7 +32,7 @@ def params RDoc::Markup::ToHtmlCrossref.prepend(Module.new do - def cross_reference(name, text = nil, code = true) + def cross_reference(name, text = nil, code = true, rdoc_ref: false) if text # Style ref links that look like code, such as `{Rails}[rdoc-ref:Rails]`. code ||= !text.include?(" ") || text.match?(/\S\(/) diff --git a/spec/helpers_spec.rb b/spec/helpers_spec.rb index 2d51b9ab..12ac93e8 100644 --- a/spec/helpers_spec.rb +++ b/spec/helpers_spec.rb @@ -300,6 +300,39 @@ module Foo; end end end + describe "#comments_for" do + it "returns RDoc::Context::Section#comments wrapped in div.description" do + rdoc_module = rdoc_top_level_for(<<~RUBY).find_module_named("Foo") + module Foo + # :section: Section 1 + # First comment for Section 1 in +Foo+. + + # :section: Section 1 + # Second comment for Section 1 in +Foo+. + end + RUBY + + _(@helpers.comments_for(rdoc_module, rdoc_module.sections.last)). + must_equal <<~HTML.chomp +
+

First comment for Section 1 in Foo.

+ +

Second comment for Section 1 in Foo.

+
+ HTML + end + + it "returns nil when RDoc::CodeObject#description is empty" do + rdoc_module = rdoc_top_level_for(<<~RUBY).find_module_named("Foo") + module Foo + # :section: One + end + RUBY + + _(@helpers.comments_for(rdoc_module, rdoc_module.sections.last)).must_be_nil + end + end + describe "#base_tag_for_context" do it "returns a tag with an appropriate path for the given RDoc::Context" do top_level = rdoc_top_level_for <<~RUBY