Skip to content

Commit

Permalink
Merge pull request #872 from nobu/index-details
Browse files Browse the repository at this point in the history
Fold "class and module index" list
  • Loading branch information
nobu authored Mar 14, 2022
2 parents acb91ea + 6bb9300 commit c5ce8e5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
<div id="classindex-section" class="nav-section">
<h3>Class and Module Index</h3>

<%-
all_classes = @classes.group_by do |klass|
klass.full_name[/\A[^:]++(?:::[^:]++(?=::))*+(?=::[^:]*+\z)/]
end.delete_if do |_, klasses|
!klasses.any?(&:display?)
end
link = proc do |index_klass, display = index_klass.display?|
if display
-%><code><a href="<%= rel_prefix %>/<%= index_klass.path %>"><%= index_klass.name %></a></code><%-
else
-%><code><%= index_klass.name %></code><%-
end
end
if top = all_classes[nil]
solo = top.one? {|klass| klass.display?}
traverse = proc do |klasses| -%>
<ul class="link-list">
<%- @modsort.each do |index_klass| -%>
<li><a href="<%= rel_prefix %>/<%= index_klass.path %>"><%= index_klass.full_name %></a>
<%- klasses.each do |index_klass| -%>
<%- if children = all_classes[index_klass.full_name] -%>
<li><details<% if solo; solo = false %> open<% end %>><summary><% link.call(index_klass) %></summary>
<%- traverse.call(children) -%>
</ul></details>
<%- elsif index_klass.display? -%>
<li><% link.call(index_klass, true) %>
<%- end -%>
<%- end -%>
<%- end -%>
<%- traverse.call(top) -%>
<%- end -%>
</ul>
</div>
16 changes: 16 additions & 0 deletions lib/rdoc/generator/template/darkfish/css/rdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,22 @@ main header h3 {

/* @group Method Details */

details summary {
display: block;
}
details summary::-webkit-details-marker {
display: none;
}
details summary:before {
content: "";
}
details summary:after {
content: " ▶";
}
details[open] > summary:after {
content: " ▽";
}

main .method-source-code {
max-height: 0;
overflow: hidden;
Expand Down
5 changes: 5 additions & 0 deletions test/rdoc/test_rdoc_generator_darkfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ def teardown
def test_generate
top_level = @store.add_file 'file.rb'
top_level.add_class @klass.class, @klass.name
@klass.add_class RDoc::NormalClass, 'Inner'

@g.generate

assert_file 'index.html'
assert_file 'Object.html'
assert_file 'Klass.html'
assert_file 'Klass/Inner.html'
assert_file 'table_of_contents.html'
assert_file 'js/search_index.js'

Expand All @@ -92,6 +95,8 @@ def test_generate
assert_match %r%<meta charset="#{encoding}">%, File.read('Object.html')

refute_match(/Ignored/, File.read('index.html'))
summary = File.read('index.html')[%r[<summary.*Klass\.html.*</summary>.*</details>]m]
assert_match(%r[Klass/Inner\.html".*>Inner<], summary)
end

def test_generate_dry_run
Expand Down

0 comments on commit c5ce8e5

Please sign in to comment.