defmodule MicrowavepropWeb.Layouts do
@moduledoc """
This module holds layouts and related functionality
used by your application.
"""
use MicrowavepropWeb, :html
# Embed all files in layouts/* within this module.
# The default root.html.heex file contains the HTML
# skeleton of your application, namely HTML headers
# and other static content.
embed_templates "layouts/*"
@doc """
Renders your app layout.
This function is typically invoked from every template,
and it often contains your application menu, sidebar,
or similar.
## Examples
Content
"""
attr :flash, :map, required: true, doc: "the map of flash messages"
attr :current_scope, :map,
default: nil,
doc: "the current [scope](https://hexdocs.pm/phoenix/scopes.html)"
attr :max_width, :string, default: "max-w-2xl", doc: "max width class for the content container"
slot :inner_block, required: true
def app(assigns) do
~H"""
<.flash_group flash={@flash} />
"""
end
@doc """
Shows the flash group with standard titles and content.
## Examples
<.flash_group flash={@flash} />
"""
attr :flash, :map, required: true, doc: "the map of flash messages"
attr :id, :string, default: "flash-group", doc: "the optional id of flash container"
def flash_group(assigns) do
~H"""
"""
end
@doc """
Shows when the running release was deployed, as a compact relative timestamp
with the full UTC time in the tooltip.
"""
def deploy_stamp(assigns) do
ts = Microwaveprop.Application.build_timestamp()
iso = Calendar.strftime(ts, "%Y-%m-%d %H:%M UTC")
assigns = assign(assigns, build_time: ts, iso: iso, ago: format_time_ago(ts))
~H"""
Deployed {@ago} ยท {@iso}
"""
end
defp format_time_ago(%DateTime{} = dt) do
diff = max(DateTime.diff(DateTime.utc_now(), dt, :second), 0)
cond do
diff < 60 -> "just now"
diff < 3600 -> "#{div(diff, 60)}m ago"
diff < 86_400 -> "#{div(diff, 3600)}h ago"
diff < 2_592_000 -> "#{div(diff, 86_400)}d ago"
diff < 31_536_000 -> "#{div(diff, 2_592_000)}mo ago"
true -> "#{div(diff, 31_536_000)}y ago"
end
end
@doc """
Provides dark vs light theme toggle based on themes defined in app.css.
See in root.html.heex which applies the theme before page load.
"""
def theme_toggle(assigns) do
~H"""