Skip to content

Commit

Permalink
Merge pull request #311 from jonathanhefner/breadcrumbs-handle-flat-d…
Browse files Browse the repository at this point in the history
…eclarations

Fix breadcrumbs for flattened class declarations
  • Loading branch information
jonathanhefner authored Sep 28, 2023
2 parents e1ee27c + f00c6d6 commit 444c4a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/sdoc/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ def more_less_ul(items, limit)
end

def module_breadcrumbs(rdoc_module)
crumbs = [h(rdoc_module.name)]
parent_names = rdoc_module.full_name.split("::")[0...-1]

rdoc_module.each_parent do |parent|
break if parent.is_a?(RDoc::TopLevel)
crumbs.unshift(link_to(h(parent.name), parent))
crumbs = parent_names.each_with_index.map do |name, i|
parent = rdoc_module.store.find_module_named(parent_names[0..i].join("::"))
parent ? link_to(h(name), parent) : h(name)
end

"<code>#{crumbs.join("::<wbr>")}</code>"
"<code>#{[*crumbs, h(rdoc_module.name)].join("::<wbr>")}</code>"
end

def module_ancestors(rdoc_module)
Expand Down
13 changes: 13 additions & 0 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,19 @@ module Foo; module Bar; module Qux; end; end; end
_(@helpers.module_breadcrumbs(qux)).
must_equal "<code>#{@helpers.link_to "Foo", foo}::<wbr>#{@helpers.link_to "Bar", bar}::<wbr>Qux</code>"
end

it "handles flattened class declarations" do
top_level = rdoc_top_level_for <<~RUBY
class Foo::Bar::Qux; 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(qux)).
must_equal "<code>#{@helpers.link_to "Foo", foo}::<wbr>#{@helpers.link_to "Bar", bar}::<wbr>Qux</code>"
end
end

describe "#module_ancestors" do
Expand Down

0 comments on commit 444c4a4

Please sign in to comment.