sloane.sh/lib/sloane_sh/layouts.ex

44 lines
1,022 B
Elixir
Raw Normal View History

defmodule SloaneSH.Layouts do
@moduledoc """
`EEx` based layouts
"""
require EEx
2024-02-24 13:40:20 -05:00
import SloaneSH.Layouts.Partials, warn: false
import SloaneSH.Layouts.Helpers, warn: false
@layouts_dir Path.join(:code.priv_dir(:sloane_sh), "site/layouts")
2024-02-24 13:16:56 -05:00
EEx.function_from_file(:def, :root, Path.join(@layouts_dir, "root.html.eex"), [
:inner_content,
:ctx,
2024-02-24 13:16:56 -05:00
:attrs
])
2024-02-24 13:16:56 -05:00
EEx.function_from_file(:defp, :page_layout, Path.join(@layouts_dir, "page.html.eex"), [
:inner_content,
:ctx,
2024-02-24 13:16:56 -05:00
:attrs
])
2024-02-24 13:16:56 -05:00
EEx.function_from_file(:defp, :post_layout, Path.join(@layouts_dir, "post.html.eex"), [
:inner_content,
:ctx,
2024-02-24 13:16:56 -05:00
:attrs
])
2024-02-24 08:43:08 -05:00
2024-02-24 13:16:56 -05:00
def page(inner_content, ctx, attrs) do
inner_content
|> page_layout(ctx, attrs)
|> root(ctx, attrs)
end
def post(inner_content, ctx, attrs) do
inner_content
|> post_layout(ctx, attrs)
|> root(ctx, attrs)
end
2024-02-24 08:43:08 -05:00
defp prefix_title(prefix, nil), do: prefix
defp prefix_title(prefix, page_title), do: [prefix, " | ", page_title]
end