-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AshAdmin.Layouts and Phoenix.VerifiedRoutes #68
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" phx-socket={live_socket_path(@conn)}> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0" | ||
/> | ||
<meta name="csrf-token" content={get_csrf_token()} /> | ||
<title><%= assigns[:page_title] || "Ash Admin" %></title> | ||
<link | ||
href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.5.1/jsoneditor.min.css" | ||
rel="stylesheet" | ||
type="text/css" | ||
/> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.5.1/jsoneditor.min.js"></script> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/easymde/dist/easymde.min.css" | ||
/> | ||
<script src="https://unpkg.com/easymde/dist/easymde.min.js"></script> | ||
<link phx-track-static rel="stylesheet" href={asset_path(@conn, "/statics/assets/app.css")} /> | ||
<script defer phx-track-static type="text/javascript" src={asset_path(@conn, "/statics/assets/app.js")} /> | ||
</head> | ||
<body> | ||
<%= @inner_content %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems strange. I've not seen something like this in a phoenix application before, how is it normally done for static assets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what exacly it is stange? the way I am reading the asset or reading the assets to get the md5 hash to append to the url?
Let me give you more context, phoenix application normally manages the asset and cache running the task mix phx.digest, the result for that is an asset minified and zipped with this pattern name
asset-#{hash}.#{ext}.gz
But because ash admin is not an application, its assets are not handle for mix phx.digest, we have to do it runtime or manual (digest each asset before release any version)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what feels strange to me is that we're reading a file to hash it to figure out where its minified version is, but we're doing it every time a page load happens. I think it would be better to make this a macro or use a module attribute to store the hash of it at compile time. You can use
@external_dependency
to cause external files to trigger recompiles.