diff options
author | nick evans <nicholas.evans@gmail.com> | 2022-11-16 14:07:18 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-11-27 17:18:16 +0000 |
commit | ae3817bc61cb320524f153e82eb5eee752188a12 (patch) | |
tree | b8818e596216660cacd634c0c005f8d42fff5e62 /lib | |
parent | 511864d1a7188f78f8a7ec93a5fe3f406bb6899f (diff) |
[ruby/rdoc] Darkfish: Nest sidebar ToC as a tree of headings
This uses `<details><summary>heading</summary><ul>nested</ul></detail>`,
similar to how the classes and pages lists are now nested.
https://github.com/ruby/rdoc/commit/e57beff287
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml b/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml index bf70819f64..b1e047b5f7 100644 --- a/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +++ b/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml @@ -3,16 +3,37 @@ else current.comment end - table = current.parse(comment).table_of_contents + table = current.parse(comment).table_of_contents.dup if table.length > 1 then %> <div class="nav-section"> <h3>Table of Contents</h3> + <%- display_link = proc do |heading| -%> + <a href="#<%= heading.label current %>"><%= heading.plain_html %></a> + <%- end -%> + + <%- list_siblings = proc do -%> + <%- level = table.first&.level -%> + <%- while table.first && table.first.level >= level -%> + <%- heading = table.shift -%> + <%- if table.first.nil? || table.first.level <= heading.level -%> + <li><% display_link.call heading -%> + <%- else -%> + <li> + <details open> + <summary><%- display_link.call heading -%></summary> + <ul class="link-list" role="directory"> + <% list_siblings.call %> + </ul> + </details> + </li> + <%- end -%> + <%- end -%> + <%- end -%> + <ul class="link-list" role="directory"> -<%- table.each do |heading| -%> - <li><a href="#<%= heading.label current %>"><%= heading.plain_html %></a> -<%- end -%> + <% list_siblings.call %> </ul> </div> <%- end -%> |