Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of section comments #373

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/rails/_context.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</div>
<% end %>

<%= description_for section %>
<%= comments_for @context, section %>

<!-- Constants -->
<% unless constants.empty? %>
Expand Down
6 changes: 6 additions & 0 deletions lib/sdoc/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def description_for(rdoc_object)
end
end

def comments_for(context, section)
return if section.comments.empty?

%(<div class="description">#{context.markup section.comments}</div>)
end

def base_tag_for_context(context)
relative_root = "../" * context.path.count("/")
%(<base href="./#{relative_root}" data-current-path="#{context.path}">)
Expand Down
2 changes: 1 addition & 1 deletion lib/sdoc/rdoc_monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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\(/)
Expand Down
33 changes: 33 additions & 0 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div class="description">
<p>First comment for Section 1 in <code>Foo</code>.</p>

<p>Second comment for Section 1 in <code>Foo</code>.</p>
</div>
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 <base> tag with an appropriate path for the given RDoc::Context" do
top_level = rdoc_top_level_for <<~RUBY
Expand Down