From efb93560b8ff951a355fc342e6e47230a67761d6 Mon Sep 17 00:00:00 2001 From: Alexis Bernard Date: Mon, 30 Sep 2024 15:16:35 +0200 Subject: [PATCH] List all class ancestors --- lib/rdoc/code_object/class_module.rb | 14 ++++++++++++++ lib/rdoc/generator/darkfish.rb | 18 ++++++++++++++++++ .../template/darkfish/_sidebar_parent.rhtml | 11 +++-------- test/rdoc/test_rdoc_class_module.rb | 6 ++++++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index a99acb8956..9230c46983 100644 --- a/lib/rdoc/code_object/class_module.rb +++ b/lib/rdoc/code_object/class_module.rb @@ -711,6 +711,20 @@ def superclass=(superclass) @superclass = superclass end + ## + # Get all super classes of this class in an array. The last element might be + # a string if the name is unknown. + + def super_classes + result = [] + parent = self + while parent = parent.superclass + result << parent + return result if parent.is_a?(String) + end + result + end + def to_s # :nodoc: if is_alias_for then "#{self.class.name} #{self.full_name} -> #{is_alias_for}" diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 5709fabf81..25ade1e9f1 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -795,4 +795,22 @@ def excerpt(content) extracted_text[0...150].gsub(/\n/, " ").squeeze(" ") end + + def generate_ancestor_list(ancestors, klass) + return '' if ancestors.empty? + + ancestor = ancestors.shift + content = +'' + end end diff --git a/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml b/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml index 1420da3201..6808b2bf87 100644 --- a/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +++ b/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml @@ -1,11 +1,6 @@ -<%- if klass.type == 'class' then %> +<%- if klass.type == 'class' && (ancestors = klass.super_classes).any? -%> <%- end -%> diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index d70a3ea033..50b3dec796 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -1279,6 +1279,12 @@ def test_superclass assert_equal @c3_h1, @c3_h2.superclass end + def test_super_classes + rdoc_c3_h1 = @xref_data.find_module_named('C3::H1') + rdoc_object = @xref_data.find_module_named('Object') + assert_equal [rdoc_c3_h1, rdoc_object, "BasicObject"], @c3_h2.super_classes + end + def test_update_aliases_class n1 = @xref_data.add_module RDoc::NormalClass, 'N1' n1_k2 = n1.add_module RDoc::NormalClass, 'N2'