diff --git a/lib/ash_admin/components/layouts.ex b/lib/ash_admin/components/layouts.ex deleted file mode 100644 index bfc3140..0000000 --- a/lib/ash_admin/components/layouts.ex +++ /dev/null @@ -1,61 +0,0 @@ -defmodule AshAdmin.Layouts do - @moduledoc false - use AshAdmin.Web, :html - use Phoenix.Component - - js_path = Path.join(__DIR__, "../../../priv/static/assets/app.js") - css_path = Path.join(__DIR__, "../../../priv/static/assets/app.css") - - @external_resource js_path - @external_resource css_path - - @app_js File.read!(js_path) - @app_css File.read!(css_path) - - def render("app.js", _), do: @app_js - def render("app.css", _), do: @app_css - - def render("root.html", assigns) do - ~H""" - - - - - - - <%= Phoenix.HTML.Tag.csrf_meta_tag() %> - <%= assigns[:page_title] || "Ash Admin" %> - - - - - - - - <%= @inner_content %> - - - - """ - end - - def render(assigns) do - ~H""" - ... - """ - end - - def live_socket_path(conn) do - [Enum.map(conn.script_name, &["/" | &1]) | conn.private.live_socket_path] - end -end diff --git a/lib/ash_admin/layouts.ex b/lib/ash_admin/layouts.ex new file mode 100644 index 0000000..7798091 --- /dev/null +++ b/lib/ash_admin/layouts.ex @@ -0,0 +1,25 @@ +defmodule AshAdmin.Layouts do + @moduledoc false + use AshAdmin.Web, :html + + embed_templates "layouts/*" + + def live_socket_path(conn) do + [Enum.map(conn.script_name, &["/" | &1]) | conn.private.live_socket_path] + end + + def asset_hash("/statics/" <> path) do + file = + Application.app_dir(:ash_admin, ["priv", "static", path]) + |> File.read!() + + :crypto.hash(:md5, file) + |> Base.encode16(case: :lower) + end + + def asset_path(conn, asset) do + hash = asset_hash(asset) + + ash_admin_path(conn, "#{asset}?vsn=#{hash}") + end +end diff --git a/lib/ash_admin/layouts/root.html.heex b/lib/ash_admin/layouts/root.html.heex new file mode 100644 index 0000000..649c409 --- /dev/null +++ b/lib/ash_admin/layouts/root.html.heex @@ -0,0 +1,29 @@ + + + + + + + + <%= assigns[:page_title] || "Ash Admin" %> + + + + + +