Skip to content

Commit

Permalink
Simplify handling of empty nodes in module summary
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Nov 21, 2022
1 parent 148ad54 commit 5a0aa08
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions lib/ex_doc/formatter/epub/templates/module_template.eex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</section>
<% end %>

<%= if Enum.any?(summary, fn {_, v} -> v != [] end) do %>
<%= if summary != [] do %>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
Expand All @@ -28,7 +28,7 @@
</section>
<% end %>

<%= for {name, nodes} <- summary, nodes != [], key = HTML.text_to_id(name) do %>
<%= for {name, nodes} <- summary, key = HTML.text_to_id(name) do %>
<section id="<%= key %>" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#<%= key %>">
Expand Down
8 changes: 5 additions & 3 deletions lib/ex_doc/formatter/html/templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ defmodule ExDoc.Formatter.HTML.Templates do
extra =
module
|> module_summary()
|> Enum.reject(fn {_type, nodes_map} -> nodes_map == [] end)
|> case do
[] -> []
entries -> [nodeGroups: Enum.map(entries, &sidebar_entries/1)]
Expand Down Expand Up @@ -183,8 +182,11 @@ defmodule ExDoc.Formatter.HTML.Templates do
end

def module_summary(module_node) do
[Types: module_node.typespecs] ++
function_groups(module_node.function_groups, module_node.docs)
entries =
[Types: module_node.typespecs] ++
function_groups(module_node.function_groups, module_node.docs)

Enum.reject(entries, fn {_type, nodes} -> nodes == [] end)
end

defp function_groups(groups, docs) do
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_doc/formatter/html/templates/module_template.eex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</section>
<% end %>

<%= if Enum.any?(summary, fn {_, v} -> v != [] end) do %>
<%= if summary != [] do %>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
Expand All @@ -41,7 +41,7 @@
</section>
<% end %>

<%= for {name, nodes} <- summary, nodes != [], key = HTML.text_to_id(name) do %>
<%= for {name, nodes} <- summary, key = HTML.text_to_id(name) do %>
<section id="<%= key %>" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#<%= key %>">
Expand Down
34 changes: 16 additions & 18 deletions lib/ex_doc/formatter/html/templates/summary_template.eex
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<%= unless Enum.empty?(nodes) do %>
<div class="summary-<%= HTML.text_to_id(name) %> summary">
<h2>
<a href="#<%= HTML.text_to_id(name) %>"><%= name %></a>
</h2>
<%= for node <- nodes do %>
<div class="summary-row">
<div class="summary-signature">
<a href="#<%=enc node.id %>" translate="no"><%=h node.signature %></a>
<%= if deprecated = node.deprecated do %>
<span class="deprecated" title="<%= h(deprecated) %>">deprecated</span>
<% end %>
</div>
<%= if doc = node.rendered_doc do %>
<div class="summary-synopsis"><%= synopsis(doc) %></div>
<div class="summary-<%= HTML.text_to_id(name) %> summary">
<h2>
<a href="#<%= HTML.text_to_id(name) %>"><%= name %></a>
</h2>
<%= for node <- nodes do %>
<div class="summary-row">
<div class="summary-signature">
<a href="#<%=enc node.id %>" translate="no"><%=h node.signature %></a>
<%= if deprecated = node.deprecated do %>
<span class="deprecated" title="<%= h(deprecated) %>">deprecated</span>
<% end %>
</div>
<% end %>
</div>
<% end %>
<%= if doc = node.rendered_doc do %>
<div class="summary-synopsis"><%= synopsis(doc) %></div>
<% end %>
</div>
<% end %>
</div>

0 comments on commit 5a0aa08

Please sign in to comment.