diff --git a/lib/bones73k/util/list.ex b/lib/bones73k/util/list.ex deleted file mode 100644 index 311c0442..00000000 --- a/lib/bones73k/util/list.ex +++ /dev/null @@ -1,4 +0,0 @@ -defmodule Bones73k.Util.List do - def prepend_if(list, condition, item), do: (!!condition && [item | list]) || list - def append_if(list, condition, item), do: (!!condition && list ++ [item]) || list -end diff --git a/lib/bones73k_web/templates/layout/_navbar.html.eex b/lib/bones73k_web/templates/layout/_navbar.html.eex index e1362075..ade773de 100644 --- a/lib/bones73k_web/templates/layout/_navbar.html.eex +++ b/lib/bones73k_web/templates/layout/_navbar.html.eex @@ -2,7 +2,7 @@
<%= link to: Routes.page_path(@conn, :index), class: "navbar-brand" do %> - <%= icon_div @conn, "fas-skull-crossbones", class: "icon baseline" %> + <%= icon_div @conn, "fas-skull-crossbones", [class: "icon baseline"] %> Bones73k <% end %> @@ -12,29 +12,45 @@
diff --git a/lib/bones73k_web/templates/layout/_user_menu.html.eex b/lib/bones73k_web/templates/layout/_user_menu.html.eex deleted file mode 100644 index f281cfc6..00000000 --- a/lib/bones73k_web/templates/layout/_user_menu.html.eex +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/lib/bones73k_web/templates/layout/navbar/_user_menu.html.eex b/lib/bones73k_web/templates/layout/navbar/_user_menu.html.eex new file mode 100644 index 00000000..a6491042 --- /dev/null +++ b/lib/bones73k_web/templates/layout/navbar/_user_menu.html.eex @@ -0,0 +1,24 @@ + diff --git a/lib/bones73k_web/templates/layout/root.html.leex b/lib/bones73k_web/templates/layout/root.html.leex index 42e29631..4cfa7310 100644 --- a/lib/bones73k_web/templates/layout/root.html.leex +++ b/lib/bones73k_web/templates/layout/root.html.leex @@ -13,18 +13,6 @@ <%= render "_navbar.html", assigns %> - <%#
-
%> - - - <%= render "_user_menu.html", assigns %> - - <%= @inner_content %> diff --git a/lib/bones73k_web/views/icon_helper.ex b/lib/bones73k_web/views/icon_helper.ex deleted file mode 100644 index ed5f7c1d..00000000 --- a/lib/bones73k_web/views/icon_helper.ex +++ /dev/null @@ -1,35 +0,0 @@ -defmodule Bones73kWeb.IconHelpers do - @moduledoc """ - Generate SVG sprite use tags for SVG icons - """ - - use Phoenix.HTML - import Bones73k.Util.List - alias Bones73kWeb.Router.Helpers, as: Routes - - def icon_div(conn, name, div_opts \\ [], svg_opts \\ []) do - content_tag(:div, tag_opts(name, div_opts)) do - icon_svg(conn, name, svg_opts) - end - end - - def icon_svg(conn, name, opts \\ []) do - content_tag(:svg, tag_opts(name, opts)) do - tag(:use, "xlink:href": Routes.static_path(conn, "/images/icons.svg#" <> name)) - end - end - - defp tag_opts(name, opts) do - classes = "#{Keyword.get(opts, :class, "")} #{name}" |> String.trim_leading() - styles = Keyword.get(opts, :style) - width = Keyword.get(opts, :width) - height = Keyword.get(opts, :height) - id = Keyword.get(opts, :id) - - [class: classes] - |> prepend_if(styles, {:style, styles}) - |> prepend_if(width, {:style, width}) - |> prepend_if(height, {:style, height}) - |> prepend_if(id, {:id, id}) - end -end diff --git a/lib/bones73k_web/views/icon_helpers.ex b/lib/bones73k_web/views/icon_helpers.ex index ed5f7c1d..7a186315 100644 --- a/lib/bones73k_web/views/icon_helpers.ex +++ b/lib/bones73k_web/views/icon_helpers.ex @@ -4,7 +4,6 @@ defmodule Bones73kWeb.IconHelpers do """ use Phoenix.HTML - import Bones73k.Util.List alias Bones73kWeb.Router.Helpers, as: Routes def icon_div(conn, name, div_opts \\ [], svg_opts \\ []) do @@ -15,21 +14,11 @@ defmodule Bones73kWeb.IconHelpers do def icon_svg(conn, name, opts \\ []) do content_tag(:svg, tag_opts(name, opts)) do - tag(:use, "xlink:href": Routes.static_path(conn, "/images/icons.svg#" <> name)) + tag(:use, "xlink:href": Routes.static_path(conn, "/images/icons.svg##{name}")) end end defp tag_opts(name, opts) do - classes = "#{Keyword.get(opts, :class, "")} #{name}" |> String.trim_leading() - styles = Keyword.get(opts, :style) - width = Keyword.get(opts, :width) - height = Keyword.get(opts, :height) - id = Keyword.get(opts, :id) - - [class: classes] - |> prepend_if(styles, {:style, styles}) - |> prepend_if(width, {:style, width}) - |> prepend_if(height, {:style, height}) - |> prepend_if(id, {:id, id}) + Keyword.update(opts, :class, name, fn c -> "#{c} #{name}" end) end end diff --git a/lib/bones73k_web/views/layout_view.ex b/lib/bones73k_web/views/layout_view.ex index a0e3a46d..2cf21141 100644 --- a/lib/bones73k_web/views/layout_view.ex +++ b/lib/bones73k_web/views/layout_view.ex @@ -1,3 +1,10 @@ defmodule Bones73kWeb.LayoutView do use Bones73kWeb, :view + + def nav_link_opts(conn, opts) do + case Keyword.get(opts, :to) == Phoenix.Controller.current_path(conn) do + false -> opts + true -> Keyword.update(opts, :class, "active", fn c -> "#{c} active" end) + end + end end