defmodule SpazioSolazzoWeb.EmailView do
use SpazioSolazzoWeb, :html
embed_templates "email_templates/*"
def render(template, assigns) when is_binary(template) do
template
|> Path.rootname()
|> String.to_atom()
|> then(fn name ->
if function_exported?(__MODULE__, name, 1) do
apply(__MODULE__, name, [assigns])
else
raise "template #{template} not implemented in #{__MODULE__}"
end
end)
end
@doc """
Renders the main container for the email.
"""
slot :inner_block, required: true
def email_container(assigns) do
~H"""
{render_slot(@inner_block)}
"""
end
@doc """
Renders a primary or secondary action button.
accepts: :primary (orange) or :danger (red)
"""
attr :href, :string, required: true
attr :variant, :atom, default: :primary, values: [:primary, :danger]
slot :inner_block, required: true
def email_button(assigns) do
~H"""
<.link href={@href} class={["btn", "btn-#{@variant}"]} target="_blank">
{render_slot(@inner_block)}
"""
end
@doc """
Renders a styled list for booking details.
"""
slot :inner_block, required: true
def details_list(assigns) do
~H"""
{render_slot(@inner_block)}
"""
end
@doc """
Renders a single detail item.
"""
attr :label, :string, required: true
slot :inner_block, required: true
def detail_item(assigns) do
~H"""
{@label}: {render_slot(@inner_block)}
"""
end
end