diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb
index 33e71ab3f3..f0f0c4c89a 100644
--- a/lib/rdoc/code_object/class_module.rb
+++ b/lib/rdoc/code_object/class_module.rb
@@ -295,6 +295,25 @@ def full_name
end
end
+ ##
+ # Return array of full_name splitted by +::+.
+
+ def nesting_namespaces
+ @namespaces ||= full_name.split("::").reject(&:empty?)
+ end
+
+ ##
+ # Return array of fully qualified nesting namespaces.
+ #
+ # For example, if full_name is +A::B::C+, this method returns ["A", "A::B", "A::B::C"]
+
+ def fully_qualified_nesting_namespaces
+ return nesting_namespaces if nesting_namespaces.length < 2
+ @fqns ||= nesting_namespaces.inject([]) do |list, n|
+ list << (list.empty? ? n : "#{list.last}::#{n}")
+ end
+ end
+
##
# TODO: filter included items by #display?
diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb
index cfd46b5ed4..8cd477a9b5 100644
--- a/lib/rdoc/generator/darkfish.rb
+++ b/lib/rdoc/generator/darkfish.rb
@@ -353,6 +353,8 @@ def generate_class klass, template_file = nil
asset_rel_prefix = rel_prefix + @asset_rel_path
svninfo = get_svninfo(current)
+ breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix)
+
@title = "#{klass.type} #{klass.full_name} - #{@options.title}"
debug_msg " rendering #{out_file}"
@@ -828,4 +830,23 @@ def generate_ancestor_list(ancestors, klass)
content << ''
end
+
+ private
+
+ def nesting_namespaces_to_class_modules klass
+ tree = {}
+
+ klass.nesting_namespaces.zip(klass.fully_qualified_nesting_namespaces) do |ns, fqns|
+ tree[ns] = @store.classes_hash[fqns] || @store.modules_hash[fqns]
+ end
+
+ tree
+ end
+
+ def generate_nesting_namespaces_breadcrumb klass, rel_prefix
+ nesting_namespaces_to_class_modules(klass).map do |namespace, class_module|
+ path = class_module ? (rel_prefix + class_module.path).to_s : ""
+ { name: namespace, path: path, self: klass.full_name == class_module&.full_name }
+ end
+ end
end
diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml
index 0bec9fc9ce..8467c552b7 100644
--- a/lib/rdoc/generator/template/darkfish/class.rhtml
+++ b/lib/rdoc/generator/template/darkfish/class.rhtml
@@ -18,6 +18,18 @@
+
+ <% breadcrumb.each do |namespace| %>
+ -
+ <% if namespace[:self] %>
+ <%= namespace[:name] %>
+ <% else %>
+ <%= namespace[:name] %>::
+ <% end %>
+
+ <% end %>
+
+
<%= klass.type %> <%= klass.full_name %>
diff --git a/lib/rdoc/generator/template/darkfish/css/rdoc.css b/lib/rdoc/generator/template/darkfish/css/rdoc.css
index ed9b3e9c3b..4a8bc98b47 100644
--- a/lib/rdoc/generator/template/darkfish/css/rdoc.css
+++ b/lib/rdoc/generator/template/darkfish/css/rdoc.css
@@ -199,6 +199,19 @@ nav h3,
font-size: 1em;
}
+ol.breadcrumb {
+ display: flex;
+
+ padding: 0;
+ margin: 0 0 1em;
+}
+
+ol.breadcrumb li {
+ display: block;
+ list-style: none;
+ font-size: 125%;
+}
+
nav ul,
nav dl,
nav p {
diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb
index ded5bc8d09..64740b22ac 100644
--- a/test/rdoc/test_rdoc_class_module.rb
+++ b/test/rdoc/test_rdoc_class_module.rb
@@ -1526,6 +1526,28 @@ def test_update_extends_with_colons
assert_equal [a, c], @c1.extends
end
+ def test_nesting_namespaces
+ cm1 = RDoc::ClassModule.new "A"
+ assert_equal ["A"], cm1.nesting_namespaces
+
+ cm2 = RDoc::ClassModule.new "A::B"
+ assert_equal ["A", "B"], cm2.nesting_namespaces
+
+ cm3 = RDoc::ClassModule.new "::A::B::C"
+ assert_equal ["A", "B", "C"], cm3.nesting_namespaces
+ end
+
+ def test_fully_qualified_nesting_namespaces
+ cm1 = RDoc::ClassModule.new "A"
+ assert_equal ["A"], cm1.fully_qualified_nesting_namespaces
+
+ cm2 = RDoc::ClassModule.new "A::B"
+ assert_equal ["A", "A::B"], cm2.fully_qualified_nesting_namespaces
+
+ cm3 = RDoc::ClassModule.new "::A::B::C"
+ assert_equal ["A", "A::B", "A::B::C"], cm3.fully_qualified_nesting_namespaces
+ end
+
class TestRDocClassModuleMixins < XrefTestCase
def setup
super