libertarian-party/partynest

View on GitHub
app/views/application/_navbar.html.erb

Summary

Maintainability
Test Coverage
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  <a class="navbar-brand" href="<%= root_path %>">
    <%= translate :title %>
  </a>

  <button class="navbar-toggler"
          type="button"
          data-toggle="collapse"
          data-target="#navbarSupportedContent"
          aria-controls="navbarSupportedContent"
          aria-expanded="false"
          aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <% if policy(:federal_subject).index? %>
        <li class="nav-item <%= :active if federal_subjects_controller? %>">
          <%= link_to federal_subjects_path, class: 'nav-link' do %>
            <%= FederalSubject.model_name.human count: 0 %>
          <% end %>
        </li>
      <% end %>

      <% if policy([:staff, :home]).show? %>
        <li class="nav-item <%= :active if staff_controller? %>">
          <%= link_to staff_root_path, class: 'nav-link' do %>
            <%= translate :staff_services %>
          <% end %>
        </li>
      <% end %>
    </ul>

    <ul class="navbar-nav ml-auto mr-3">
      <% if current_account %>
        <li class="nav-item dropdown">
          <%= link_to current_account.nickname,
                      '#',
                      id: :navbarDropdown,
                      role: :button,
                      class: 'nav-link dropdown-toggle',
                      'data-toggle': :dropdown,
                      'aria-haspopup': true,
                      'aria-expanded': false %>

          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
            <% if policy(current_account).show? %>
              <%= link_to translate('users.shared.links.profile'),
                          account_path(current_account),
                          role: :button,
                          class: 'dropdown-item' %>
            <% end %>

            <% if policy(%i[settings profile]).edit? %>
              <%= link_to translate('users.shared.links.settings'),
                          edit_settings_profile_path,
                          role: :button,
                          class: 'dropdown-item' %>
            <% end %>

            <% if policy(%i[users session]).destroy? %>
              <div class="dropdown-divider"></div>

              <%= link_to translate('users.shared.links.sign_out'),
                          destroy_user_session_path,
                          method: :delete,
                          role: :button,
                          class: 'dropdown-item' %>
            <% end %>
          </div>
        </li>
      <% end %>
    </ul>

    <div>
      <% if policy(%i[users session]).new? %>
        <%= link_to translate('users.shared.links.sign_in'),
                    new_user_session_path,
                    role: :button,
                    class: 'btn btn-light mr-2' %>
      <% end %>

      <% if policy(%i[users registration]).new? %>
        <%= link_to translate('users.shared.links.sign_up'),
                    new_user_registration_path,
                    role: :button,
                    class: 'btn btn-primary' %>
      <% end %>
    </div>
  </div>
</nav>