-
Notifications
You must be signed in to change notification settings - Fork 441
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
Display class ancestors in the sidebar #1183
Display class ancestors in the sidebar #1183
Conversation
I believe the right name is |
c88c36e
to
a7331c8
Compare
Thanks for the PR. I think this is a great addition to the theme's functionalities. diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb
index 5709fabf..cdf7fdd2 100644
--- a/lib/rdoc/generator/darkfish.rb
+++ b/lib/rdoc/generator/darkfish.rb
@@ -795,4 +795,23 @@ class RDoc::Generator::Darkfish
extracted_text[0...150].gsub(/\n/, " ").squeeze(" ")
end
+
+ def generate_ancestor_list(ancestors, klass)
+ return '' if ancestors.empty?
+
+ ancestor = ancestors.shift
+ content = +'<ul><li>'
+
+ if ancestor.is_a?(RDoc::NormalClass)
+ content << "<a href=\"#{klass.aref_to ancestor.path}\">#{ancestor.full_name}</a>"
+ else
+ content << ancestor.to_s
+ end
+
+ # Recursively call the method for the remaining ancestors
+ content << generate_ancestor_list(ancestors, klass)
+
+ content << '</li></ul>'
+ content
+ end
end
diff --git a/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml b/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml
index 7bd1a7ca..6808b2bf 100644
--- a/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml
+++ b/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml
@@ -1,42 +1,6 @@
-<%- if klass.type == 'class' && (ancestors = klass.super_classes).any? then %>
+<%- if klass.type == 'class' && (ancestors = klass.super_classes).any? -%>
<div id="parent-class-section" class="nav-section">
<h3>Ancestors</h3>
- <% if ancestors.size > 1 %>
- <% parent = ancestors.shift %>
- <ul>
- <li>
- <details>
- <summary>
- <% if parent.is_a?(RDoc::NormalClass) %>
- <a href="<%= klass.aref_to parent.path -%>"><%= parent.full_name -%></a>
- <% else %>
- <%= parent -%>
- <% end %>
- </summary>
-
- <% for ancestor in ancestors %>
- <ul>
- <li>
- <% if ancestor.is_a?(RDoc::NormalClass) %>
- <a href="<%= klass.aref_to ancestor.path -%>"><%= ancestor.full_name -%></a>
- <% else %>
- <%= ancestor -%>
- <% end %>
- <% end %>
-
- <% for ancestor in ancestors # Sorry, templates cannot be recursive %>
- </li>
- </ul>
- <% end %>
- </details>
- </li>
- </ul>
- <% else %>
- <%- if klass.superclass and not String === klass.superclass then -%>
- <p class="link"><a href="<%= klass.aref_to klass.superclass.path %>"><%= klass.superclass.full_name %></a>
- <%- else -%>
- <p class="link"><%= klass.superclass %>
- <%- end -%>
- <% end %>
+ <%= generate_ancestor_list(ancestors, klass) %>
</div>
<%- end -%> This will remove the expanding toggle, which IMO isn't necessary as expanded list will make the ancestors list instantly understandable. We can make it folded later based on user feedback. |
a7331c8
to
efb9356
Compare
I applied the patch and I removed the last line of I also expanded the tree by default when I started building this feature. But after using it, it felt too repetitive because in most cases ancestors are only Object and BasicObject. Sure, let's adjust according to other user's feedback. |
To be honest, I feel the same. But my thinking is that if we only display it when it's patched (in the context of gems), it may be confusing to people new to Ruby as the timing to have parent classes will vary in an implicit way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing, thank you!
The purpose is to list all class ancestors in a new theme (see PR #1182).