Skip to content

Commit 12ed114

Browse files
Render breadcrumb links for module's parents
This converts the name displayed at the top of each module's page into breadcrumb links. Each part of the name now links to the corresponding parent module's page. Closes #212.
1 parent 5a0789b commit 12ed114

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

lib/rdoc/generator/template/rails/class.rhtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<main id="content">
2222
<div class="content__full-name">
2323
<span class="qualifier"><%= klass.type %></span>
24-
<%= full_name klass %>
24+
<%= module_breadcrumbs klass %>
2525
<% if !klass.module? && superclass = klass.superclass %>
2626
<span class="qualifier">&lt;</span>
2727
<%= superclass.is_a?(String) ? full_name(superclass) : link_to(superclass) %>

lib/rdoc/generator/template/rails/resources/css/main.css

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ a {
5555
a:has(> code:only-child) {
5656
text-decoration: none;
5757
}
58+
code a {
59+
text-decoration: none;
60+
}
5861

5962
/* TODO: Remove this hack when Firefox supports `:has()` */
6063
a code {

lib/sdoc/helpers.rb

+11
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ def more_less_ul(items, limit)
116116
end
117117
end
118118

119+
def module_breadcrumbs(rdoc_module)
120+
crumbs = [h(rdoc_module.name)]
121+
122+
rdoc_module.each_parent do |parent|
123+
break if parent.is_a?(RDoc::TopLevel)
124+
crumbs.unshift(link_to(h(parent.name), parent))
125+
end
126+
127+
"<code>#{crumbs.join("::<wbr>")}</code>"
128+
end
129+
119130
def method_signature(rdoc_method)
120131
if rdoc_method.call_seq
121132
rdoc_method.call_seq.split(/\n+/).map do |line|

spec/helpers_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,27 @@ def ul(items)
502502
end
503503
end
504504

505+
describe "#module_breadcrumbs" do
506+
it "renders links for each of the module's parents" do
507+
top_level = rdoc_top_level_for <<~RUBY
508+
module Foo; module Bar; module Qux; end; end; end
509+
RUBY
510+
511+
foo = top_level.find_module_named("Foo")
512+
bar = top_level.find_module_named("Foo::Bar")
513+
qux = top_level.find_module_named("Foo::Bar::Qux")
514+
515+
_(@helpers.module_breadcrumbs(foo)).
516+
must_equal "<code>Foo</code>"
517+
518+
_(@helpers.module_breadcrumbs(bar)).
519+
must_equal "<code>#{@helpers.link_to "Foo", foo}::<wbr>Bar</code>"
520+
521+
_(@helpers.module_breadcrumbs(qux)).
522+
must_equal "<code>#{@helpers.link_to "Foo", foo}::<wbr>#{@helpers.link_to "Bar", bar}::<wbr>Qux</code>"
523+
end
524+
end
525+
505526
describe "#method_signature" do
506527
it "returns the method signature wrapped in <code>" do
507528
method = rdoc_top_level_for(<<~RUBY).find_module_named("Foo").find_method("bar", false)

0 commit comments

Comments
 (0)