defmodule HumoWeb.LayoutView do use HumoWeb, :view import Phoenix.LiveView, only: [assign: 3] def root_menu(assigns) do ~H""" """ end def dashboard_menu(assigns) do endpoint = HumoWeb.endpoint() routes = HumoWeb.routes() nav = Application.fetch_env!(:humo, :plugins) |> Enum.reject(fn {_, data} -> Map.get(data, :dashboard_links, []) == [] end) |> Enum.map(fn {_, data} -> links = for link <- data.dashboard_links, args = [endpoint, link.action | Map.get(link, :opts, [])], path = apply(routes, link.route, args), method = Map.get(link, :method, :get), can_path?(assigns.conn, path, method) do %{title: link.title, path: path, method: method} end %{title: data.title, links: links} end) assigns = assign(assigns, :nav, nav) ~H""" """ end def account_menu(assigns) do endpoint = HumoWeb.endpoint() routes = HumoWeb.routes() nav = Application.fetch_env!(:humo, :plugins) |> Enum.reject(fn {_, data} -> Map.get(data, :account_links, []) == [] end) |> Enum.flat_map(fn {_, data} -> for link <- data.account_links, args = [endpoint, link.action | Map.get(link, :opts, [])], path = apply(routes, link.route, args), method = Map.get(link, :method, :get), can_path?(assigns.conn, path, method) do %{title: link.title, path: path, method: method} end end) assigns = assign(assigns, :nav, nav) ~H""" """ end # Phoenix LiveDashboard is available only in development by default, # so we instruct Elixir to not warn if the dashboard route is missing. @compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}} end