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 breadcrumbs for flattened class declarations #311

Merged
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
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