swornforged/lib/swornforged_web/controllers/page_html.ex

108 lines
3.0 KiB
Elixir

defmodule SwornforgedWeb.PageHTML do
use SwornforgedWeb, :html
embed_templates "page_html/*"
def get_in(data, keys, default) do
case get_in(data, keys) do
nil -> default
result -> result
end
end
def srd_category_card(assigns) do
assigns =
assign(assigns,
card_colors: %{
:asset_types => "bg-blue-500",
:encounters => "bg-rose-500",
:move_categories => "bg-violet-500",
:oracle_categories => "bg-amber-500"
}
)
~H"""
<a
href="/"
class={[
"block grid place-items-center text-white text-xl text-center md:text-2xl lg:text-3xl text-white rounded shadow-xl focus:shadow-2xl hover:shadow-2xl transition-shadow border-2 border-solid border-black border-opacity-10",
@card_colors[@category]
]}
>
<%= @title %>
</a>
"""
end
def srd_header(assigns) do
~H"""
<header class="bg-white dark:bg-slate-700 shadow-md p-4">
<h1 class="text-4xl font-bold text-center dark:text-white"><%= @title %></h1>
</header>
"""
end
def srd_type_title(assigns) do
~H"""
<h2 class="text-3xl dark:text-white font-bold"><%= render_slot(@inner_block) %></h2>
"""
end
def srd_subtype_title(assigns) do
~H"""
<h3 class="text-2xl font-bold mb-2 dark:text-white"><%= render_slot(@inner_block) %></h3>
"""
end
def srd_type_container(assigns) do
~H"""
<div class="flex flex-col gap-4">
<%= render_slot(@inner_block) %>
</div>
"""
end
def srd_item_inner_title(assigns) do
~H"""
<h4 class="font-bold dark:text-white"><%= render_slot(@inner_block) %></h4>
"""
end
def srd_item(assigns) do
~H"""
<div class="max-w-prose shadow bg-white dark:bg-slate-700 rounded-b">
<h3
class="font-bold text-white px-4 py-2 rounded-t"
style={"background-color: #{get_in(@item, ["Display", "Color"], "rgb(100 116 139)")}"}
>
<a href={"#" <> @item["$id"]}><%= render_slot(@title) %></a>
</h3>
<div class="flex flex-col gap-2">
<div :if={@inner_block != nil} class="p-4 flex flex-col gap-2">
<%= render_slot(@inner_block) %>
<p class="text-right text-sm text-gray-400 dark:text-gray-500">
<strong>Source</strong>
<br />
<%= get_in(@item, ["Source", "Title"]) %>
<span :if={get_in(@item, ["Source", "Page"])}>
p.<%= get_in(@item, ["Source", "Page"]) %>
</span>
</p>
</div>
<div
:if={false && Application.get_env(:swornforged, :datasworn_debug, false)}
class="bg-red-500 rounded-b p-2 text-white"
>
<details class="hover:cursor-default">
<summary>Raw JSON</summary>
<div class="prose align-left">
<pre><code><%= Jason.encode!(@item, pretty: true, escape: :html_safe) %></code></pre>
</div>
</details>
</div>
</div>
</div>
"""
end
end