As I was looking to implement the new Spaces feature (see forem/forem#16842), I began looking at how to adjust the admin menu. I found the Menu and AdminMenu. I wanted to add the "spaces" item under the `:content_manager` scope. Looking at the implementation, I saw I would need some additional branching logic. To get an understanding of the implementation, I chose factor towards classes. This refactor does a few things: 1) Clarifies a method name (e.g. "children?" becomes "has_multiple_children?") 2) Adds some tests of the menu implementation. 3) Removes deeply nested hashs in favor of first class objects. 4) Removes a complex method for determining menu visibility, instead favoring a method that either takes a boolean OR a lambda. There are further refactors to consider, especially in regards to the helper methods and some of the coercion of strings into different formats. But this refactor gets me the part I most am interested in: Making it easier to specify a menu item as visible or not.
23 lines
879 B
Text
23 lines
879 B
Text
<% if menu_items&.has_children? %>
|
|
<header class="mb-3 admin__tabbed-navbar">
|
|
<h1 class="crayons-title"><%= menu_items.name.to_s.titleize %></h1>
|
|
<div class="block s:flex items-center space-between">
|
|
<nav>
|
|
<ul class="crayons-tabs crayons-tabs--wrapped">
|
|
<% menu_items.children.each do |item| %>
|
|
<% if item.visible? %>
|
|
<li>
|
|
<a
|
|
data-text="<%= item.name.to_s.titleize %>"
|
|
href="/admin/<%= deduced_scope(request) %>/<%= item.controller %>"
|
|
class="crayons-tabs__item <%= "crayons-tabs__item--current" if deduced_controller(request)&.match?(item.controller) %>">
|
|
<%= item.name.to_s.titleize %>
|
|
</a>
|
|
</li>
|
|
<% end %>
|
|
<% end %>
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
</header>
|
|
<% end %>
|