Skip to content

Commit

Permalink
Merge pull request #876 from nobu/pages-details
Browse files Browse the repository at this point in the history
Fold "Pages" list
  • Loading branch information
nobu committed Mar 21, 2022
2 parents d3137cc + f9f90ef commit 2325a3b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
<%- simple_files = @files.select { |f| f.text? } %>
<%- if defined?(current) -%>
<%- dir = current.full_name[%r{\A[^/]+(?=/)}] || current.page_name -%>
<%- end -%>
<%- unless simple_files.empty? then -%>
<div id="fileindex-section" class="nav-section">
<h3>Pages</h3>

<ul class="link-list">
<%- simple_files.each do |f| -%>
<%- simple_files.group_by do |f| -%>
<%- f.full_name[%r{\A[^/]+(?=/)}] || f.page_name -%>
<%- end.each do |n, files| -%>
<%- f = files.shift -%>
<%- if files.empty? -%>
<li><a href="<%= rel_prefix %>/<%= f.path %>"><%= h f.page_name %></a>
<%- next -%>
<%- end -%>
<li><details<% if dir == n %> open<% end %>><summary><%
if n == f.page_name
%><a href="<%= rel_prefix %>/<%= f.path %>"><%= h n %></a><%
else
%><%= h n %><% files.unshift(f)
end %></summary>
<ul class="link-list">
<%- files.each do |f| -%>
<li><a href="<%= rel_prefix %>/<%= f.path %>"><%= h f.page_name %></a>
<%- end -%>
</ul></details>
<%- end -%>
</ul>
</div>
Expand Down
17 changes: 17 additions & 0 deletions test/rdoc/test_rdoc_generator_darkfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ def test_generate
assert_match(%r[Klass/Inner\.html".*>Inner<], summary)
end

def test_generate_page
@store.add_file 'outer.rdoc', parser: RDoc::Parser::Simple
@store.add_file 'outer/inner.rdoc', parser: RDoc::Parser::Simple
@g.generate
assert_file 'outer_rdoc.html'
assert_file 'outer/inner_rdoc.html'
index = File.read('index.html')
re = %r[<summary><a href="\./outer_rdoc\.html">outer</a></summary>.*?</details>]m
assert_match(re, index)
summary = index[re]
assert_match %r[<a href="\./outer/inner_rdoc.html">inner</a>], summary
re = %r[<details open><summary><a href="\./outer_rdoc\.html">outer</a></summary>.*?</details>]m
assert_match(re, File.read('outer_rdoc.html'))
re = %r[<details open><summary><a href="\.\./outer_rdoc\.html">outer</a></summary>.*?</details>]m
assert_match(re, File.read('outer/inner_rdoc.html'))
end

def test_generate_dry_run
@g.dry_run = true
top_level = @store.add_file 'file.rb'
Expand Down

0 comments on commit 2325a3b

Please sign in to comment.