From 25d11c2521998faad58449f9eb13186d6f3794b6 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Mon, 6 Feb 2023 19:43:39 +0900 Subject: [PATCH 1/8] Add #namespace and #fully_qualified_namespaces to RDoc::ClassModule --- lib/rdoc/code_object/class_module.rb | 19 +++++++++++++++++++ test/rdoc/test_rdoc_class_module.rb | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index 33e71ab3f3..a68775e48d 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 namespaces + @namespaces ||= full_name.split("::").reject(&:empty?) + end + + ## + # Return array of fully qualified namespaces. + # + # For example, if full_name is +A::B::C+, this method returns ["A", "A::B", "A::B::C"] + + def fully_qualified_namespaces + return namespaces if namespaces.length < 2 + @fqns ||= namespaces.map.with_index do |_, i| + namespaces[0..i].join("::") + end + end + ## # TODO: filter included items by #display? diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index ded5bc8d09..a980267ca0 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_namespaces + cm1 = RDoc::ClassModule.new "A" + assert_equal ["A"], cm1.namespaces + + cm2 = RDoc::ClassModule.new "A::B" + assert_equal ["A", "B"], cm2.namespaces + + cm3 = RDoc::ClassModule.new "::A::B::C" + assert_equal ["A", "B", "C"], cm3.namespaces + end + + def test_fully_qualified_namespaces + cm1 = RDoc::ClassModule.new "A" + assert_equal ["A"], cm1.fully_qualified_namespaces + + cm2 = RDoc::ClassModule.new "A::B" + assert_equal ["A", "A::B"], cm2.fully_qualified_namespaces + + cm3 = RDoc::ClassModule.new "::A::B::C" + assert_equal ["A", "A::B", "A::B::C"], cm3.fully_qualified_namespaces + end + class TestRDocClassModuleMixins < XrefTestCase def setup super From e03a3ea16bb08798057b3137aa07195a2bd0bc07 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Mon, 6 Feb 2023 19:44:59 +0900 Subject: [PATCH 2/8] Create medhods to build metadata to create breadcrumb --- lib/rdoc/generator/darkfish.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index cfd46b5ed4..e5e75e73e9 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_namespaces_breadcrumb(current, rel_prefix) + @title = "#{klass.type} #{klass.full_name} - #{@options.title}" debug_msg " rendering #{out_file}" @@ -828,4 +830,22 @@ def generate_ancestor_list(ancestors, klass) content << '' end + + private + + def namespaces_to_class_modules klass + tree = {} + + klass.namespaces.zip(klass.fully_qualified_namespaces) do |ns, fqns| + tree[ns] = @store.classes_hash[fqns] || @store.modules_hash[fqns] + end + + tree + end + + def generate_namespaces_breadcrumb klass, rel_prefix + namespaces_to_class_modules(klass).map do |namespace, class_module| + { name: namespace, path: (rel_prefix + class_module.path).to_s, self: klass.full_name == class_module.full_name } + end + end end From 4ccc93e7ee98d35b147cba1ac6c8e3fc4d247546 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Mon, 6 Feb 2023 19:46:20 +0900 Subject: [PATCH 3/8] Show breadcrumb on top of a class document --- .../generator/template/darkfish/class.rhtml | 14 ++++++++++++ .../generator/template/darkfish/css/rdoc.css | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml index 0bec9fc9ce..68f0cadcf6 100644 --- a/lib/rdoc/generator/template/darkfish/class.rhtml +++ b/lib/rdoc/generator/template/darkfish/class.rhtml @@ -17,6 +17,20 @@ <%= render '_footer.rhtml' %> + +

<%= 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..177916a14b 100644 --- a/lib/rdoc/generator/template/darkfish/css/rdoc.css +++ b/lib/rdoc/generator/template/darkfish/css/rdoc.css @@ -199,6 +199,28 @@ nav h3, font-size: 1em; } +nav.breadcrumb { + display: block; + float: unset; + width: unset; + height: unset; + border: none; + position: unset; + top: unset; + padding-top: 10px; + padding-left: 20px; + margin-bottom: 1em; +} + +nav.breadcrumb ol { + display: inline-block; +} + +nav.breadcrumb li { + display: inline-block; + font-size: 125%; +} + nav ul, nav dl, nav p { From ec240da9f54623bd0682798d93cd8824e2cba279 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Thu, 9 Feb 2023 00:43:59 +0900 Subject: [PATCH 4/8] Add nil guard to generate_namespaces_breadcrumb --- lib/rdoc/generator/darkfish.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index e5e75e73e9..e56bac9757 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -845,7 +845,8 @@ def namespaces_to_class_modules klass def generate_namespaces_breadcrumb klass, rel_prefix namespaces_to_class_modules(klass).map do |namespace, class_module| - { name: namespace, path: (rel_prefix + class_module.path).to_s, self: klass.full_name == class_module.full_name } + 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 From ed7c0918595d81866f327199fddab06f9d68c202 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Thu, 6 Jul 2023 18:00:12 +0900 Subject: [PATCH 5/8] Rename to nesting_namespaces --- lib/rdoc/code_object/class_module.rb | 12 ++++++------ lib/rdoc/generator/darkfish.rb | 10 +++++----- test/rdoc/test_rdoc_class_module.rb | 16 ++++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index a68775e48d..1d4046750b 100644 --- a/lib/rdoc/code_object/class_module.rb +++ b/lib/rdoc/code_object/class_module.rb @@ -298,19 +298,19 @@ def full_name ## # Return array of full_name splitted by +::+. - def namespaces + def nesting_namespaces @namespaces ||= full_name.split("::").reject(&:empty?) end ## - # Return array of fully qualified namespaces. + # 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_namespaces - return namespaces if namespaces.length < 2 - @fqns ||= namespaces.map.with_index do |_, i| - namespaces[0..i].join("::") + def fully_qualified_nesting_namespaces + return nesting_namespaces if nesting_namespaces.length < 2 + @fqns ||= nesting_namespaces.map.with_index do |_, i| + nesting_namespaces[0..i].join("::") end end diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index e56bac9757..8cd477a9b5 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -353,7 +353,7 @@ def generate_class klass, template_file = nil asset_rel_prefix = rel_prefix + @asset_rel_path svninfo = get_svninfo(current) - breadcrumb = generate_namespaces_breadcrumb(current, rel_prefix) + breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix) @title = "#{klass.type} #{klass.full_name} - #{@options.title}" @@ -833,18 +833,18 @@ def generate_ancestor_list(ancestors, klass) private - def namespaces_to_class_modules klass + def nesting_namespaces_to_class_modules klass tree = {} - klass.namespaces.zip(klass.fully_qualified_namespaces) do |ns, fqns| + 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_namespaces_breadcrumb klass, rel_prefix - namespaces_to_class_modules(klass).map do |namespace, class_module| + 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 diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index a980267ca0..64740b22ac 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -1526,26 +1526,26 @@ def test_update_extends_with_colons assert_equal [a, c], @c1.extends end - def test_namespaces + def test_nesting_namespaces cm1 = RDoc::ClassModule.new "A" - assert_equal ["A"], cm1.namespaces + assert_equal ["A"], cm1.nesting_namespaces cm2 = RDoc::ClassModule.new "A::B" - assert_equal ["A", "B"], cm2.namespaces + assert_equal ["A", "B"], cm2.nesting_namespaces cm3 = RDoc::ClassModule.new "::A::B::C" - assert_equal ["A", "B", "C"], cm3.namespaces + assert_equal ["A", "B", "C"], cm3.nesting_namespaces end - def test_fully_qualified_namespaces + def test_fully_qualified_nesting_namespaces cm1 = RDoc::ClassModule.new "A" - assert_equal ["A"], cm1.fully_qualified_namespaces + assert_equal ["A"], cm1.fully_qualified_nesting_namespaces cm2 = RDoc::ClassModule.new "A::B" - assert_equal ["A", "A::B"], cm2.fully_qualified_namespaces + 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_namespaces + assert_equal ["A", "A::B", "A::B::C"], cm3.fully_qualified_nesting_namespaces end class TestRDocClassModuleMixins < XrefTestCase From e2fb0fad666baa4391f26a1344e4173b3f5f9a59 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Thu, 6 Jul 2023 18:01:21 +0900 Subject: [PATCH 6/8] Refactor fully_qualified_nesting_namespaces --- lib/rdoc/code_object/class_module.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index 1d4046750b..f0f0c4c89a 100644 --- a/lib/rdoc/code_object/class_module.rb +++ b/lib/rdoc/code_object/class_module.rb @@ -309,8 +309,8 @@ def nesting_namespaces def fully_qualified_nesting_namespaces return nesting_namespaces if nesting_namespaces.length < 2 - @fqns ||= nesting_namespaces.map.with_index do |_, i| - nesting_namespaces[0..i].join("::") + @fqns ||= nesting_namespaces.inject([]) do |list, n| + list << (list.empty? ? n : "#{list.last}::#{n}") end end From b9124e2c08f472ba88fe4931570d40ca887f24d0 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Thu, 23 Jan 2025 09:44:00 +0000 Subject: [PATCH 7/8] Adjust breadcrumb style --- .../generator/template/darkfish/class.rhtml | 6 ++--- .../generator/template/darkfish/css/rdoc.css | 23 ++++++------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml index 68f0cadcf6..8467c552b7 100644 --- a/lib/rdoc/generator/template/darkfish/class.rhtml +++ b/lib/rdoc/generator/template/darkfish/class.rhtml @@ -17,8 +17,8 @@ <%= render '_footer.rhtml' %> - -

<%= 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 177916a14b..4a8bc98b47 100644 --- a/lib/rdoc/generator/template/darkfish/css/rdoc.css +++ b/lib/rdoc/generator/template/darkfish/css/rdoc.css @@ -199,25 +199,16 @@ nav h3, font-size: 1em; } -nav.breadcrumb { - display: block; - float: unset; - width: unset; - height: unset; - border: none; - position: unset; - top: unset; - padding-top: 10px; - padding-left: 20px; - margin-bottom: 1em; -} +ol.breadcrumb { + display: flex; -nav.breadcrumb ol { - display: inline-block; + padding: 0; + margin: 0 0 1em; } -nav.breadcrumb li { - display: inline-block; +ol.breadcrumb li { + display: block; + list-style: none; font-size: 125%; } From c6b4fbb07d4fd11b9a8d7696cf838294d966b8d1 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Thu, 13 Feb 2025 18:15:08 +0900 Subject: [PATCH 8/8] Display breadcrumb only nested two or more levels --- .../generator/template/darkfish/class.rhtml | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml index 8467c552b7..628945d886 100644 --- a/lib/rdoc/generator/template/darkfish/class.rhtml +++ b/lib/rdoc/generator/template/darkfish/class.rhtml @@ -18,17 +18,20 @@
- + <% end %>

<%= klass.type %> <%= klass.full_name %>