~nicolaskempf57/elixir-starter-explaned

f925a85413da1e89cf0cec36c3592dec11535b44 — Nicolas KEMPF a month ago 5d3ab52
refac: Use templates

With Phoenix framework, you can use template inside template just like partials in Statamic.

Doing so avoid the repetition of Tailwind classes and other cases.
A apps/starter_web/lib/starter_web/templates/layout/_menu_item.html.heex => apps/starter_web/lib/starter_web/templates/layout/_menu_item.html.heex +5 -0
@@ 0,0 1,5 @@
<%= if assigns[:route] do %>
    <%= link @content, to: @route, class: "font-medium text-gray-500 hover:text-gray-900" %>
<% else %>
    <a class="font-medium text-gray-500"><%= @content %></a>
<% end %>
\ No newline at end of file

M apps/starter_web/lib/starter_web/templates/layout/_user_menu.html.heex => apps/starter_web/lib/starter_web/templates/layout/_user_menu.html.heex +5 -7
@@ 1,10 1,8 @@
<ul>
<%= if @current_user do %>
  <li><%= @current_user.email %></li>
  <li><%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %></li>
  <li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li>
  <%= render "_menu_item.html", content: @current_user.email %>
  <%= render "_menu_item.html", content: "Settings", route: Routes.user_settings_path(@conn, :edit) %>
  <%= render "_menu_item.html", content: "Log out", route: Routes.user_session_path(@conn, :delete), method: :delete %>
<% else %>
  <li><%= link "Register", to: Routes.user_registration_path(@conn, :new) %></li>
  <li><%= link "Log in", to: Routes.user_session_path(@conn, :new) %></li>
  <%= render "_menu_item.html", content: "Register", route: Routes.user_registration_path(@conn, :new) %>
  <%= render "_menu_item.html", content: "Log in", route: Routes.user_session_path(@conn, :new) %>
<% end %>
</ul>

M apps/starter_web/lib/starter_web/templates/layout/root.html.heex => apps/starter_web/lib/starter_web/templates/layout/root.html.heex +3 -3
@@ 18,10 18,10 @@
              <img class="h-8 w-auto sm:h-10" src={Routes.static_path(@conn, "/images/phoenix.png")} alt="Phoenix Framework Logo"/>
            </a>
            <div class="md:ml-10 md:pr-4 md:space-x-8">
              <a href="https://hexdocs.pm/phoenix/overview.html">Get Started</a>
              <%= link "LiveDashboard", to: Routes.live_dashboard_path(@conn, :home), class: "font-medium text-gray-500 hover:text-gray-900" %>
              <%= render "_menu_item.html", content: "Get Started", route: "https://hexdocs.pm/phoenix/overview.html"%>
              <%= render "_menu_item.html", content: "LiveDashboard", route: Routes.live_dashboard_path(@conn, :home)%>
              <%= render "_user_menu.html", assigns %>
            </div>
            <%= render "_user_menu.html", assigns %>
          </nav>
        </div>
    </header>