summaryrefslogtreecommitdiff
path: root/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml
blob: b1e047b5f71b36070987e8f69916b7b4246cc246 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<%- comment = if current.respond_to? :comment_location then
               current.comment_location
             else
               current.comment
             end
   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">
    <% list_siblings.call %>
  </ul>
</div>
<%- end -%>