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

Render breadcrumb links for module's parents #286

Merged
merged 1 commit into from
Aug 20, 2023
Merged
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/class.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<main id="content">
<div class="content__full-name">
<span class="qualifier"><%= klass.type %></span>
<%= full_name klass %>
<%= module_breadcrumbs klass %>
<% if !klass.module? && superclass = klass.superclass %>
<span class="qualifier">&lt;</span>
<%= superclass.is_a?(String) ? full_name(superclass) : link_to(superclass) %>
Expand Down
3 changes: 3 additions & 0 deletions lib/rdoc/generator/template/rails/resources/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ a {
a:has(> code:only-child) {
text-decoration: none;
}
code a {
text-decoration: none;
}

/* TODO: Remove this hack when Firefox supports `:has()` */
a code {
Expand Down
11 changes: 11 additions & 0 deletions lib/sdoc/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ def more_less_ul(items, limit)
end
end

def module_breadcrumbs(rdoc_module)
crumbs = [h(rdoc_module.name)]

rdoc_module.each_parent do |parent|
break if parent.is_a?(RDoc::TopLevel)
crumbs.unshift(link_to(h(parent.name), parent))
end

"<code>#{crumbs.join("::<wbr>")}</code>"
end

def method_signature(rdoc_method)
if rdoc_method.call_seq
rdoc_method.call_seq.split(/\n+/).map do |line|
Expand Down
21 changes: 21 additions & 0 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,27 @@ def ul(items)
end
end

describe "#module_breadcrumbs" do
it "renders links for each of the module's parents" do
top_level = rdoc_top_level_for <<~RUBY
module Foo; module Bar; module Qux; end; end; end
RUBY

foo = top_level.find_module_named("Foo")
bar = top_level.find_module_named("Foo::Bar")
qux = top_level.find_module_named("Foo::Bar::Qux")

_(@helpers.module_breadcrumbs(foo)).
must_equal "<code>Foo</code>"

_(@helpers.module_breadcrumbs(bar)).
must_equal "<code>#{@helpers.link_to "Foo", foo}::<wbr>Bar</code>"

_(@helpers.module_breadcrumbs(qux)).
must_equal "<code>#{@helpers.link_to "Foo", foo}::<wbr>#{@helpers.link_to "Bar", bar}::<wbr>Qux</code>"
end
end

describe "#method_signature" do
it "returns the method signature wrapped in <code>" do
method = rdoc_top_level_for(<<~RUBY).find_module_named("Foo").find_method("bar", false)
Expand Down