145 lines
5.1 KiB
Elixir
145 lines
5.1 KiB
Elixir
defmodule SukaatoWeb.PageHTML do
|
|
@moduledoc """
|
|
This module contains pages rendered by PageController.
|
|
|
|
See the `page_html` directory for all templates available.
|
|
"""
|
|
alias SukaatoWeb.Marker
|
|
alias SukaatoWeb.Theme
|
|
use SukaatoWeb, :html
|
|
|
|
embed_templates "page_html/*"
|
|
|
|
@rel_proj_root "../../.."
|
|
@site_config_file Path.expand(@rel_proj_root <> "/site.toml", __DIR__)
|
|
@site_config elem(Toml.decode_file(@site_config_file), 1)
|
|
|
|
attr :audience, :string, default: "humans"
|
|
attr :home, :string, default: "but one recessed sulci of the global encephalon"
|
|
attr :site_name, :string, default: @site_config["site"]["name"]
|
|
attr :site_author, :string, default: @site_config["site"]["author"]
|
|
attr :site_desc, :string, default: @site_config["site"]["desc"]
|
|
attr :badge_collection, :list, default: []
|
|
attr :page_links, :list, default: [
|
|
%PageLink{name: "Home", uri: "/"},
|
|
%PageLink{name: "GPG", uri: "/pubkey"},
|
|
%PageLink{name: "Contact", uri: "/contact"}
|
|
]
|
|
attr :page_query, :string, default: ""
|
|
attr :thinkers, :list, default: [
|
|
%Thinker{name: "Plato", uri: "https://3.bp.blogspot.com/-4tLynuYBkhQ/TqcL1B3lDVI/AAAAAAAAAB0/DqucJFRCgxo/s1600/Plato.jpg", type: ["Philosopher", "Social Theorist", "Political Theorist"], desc: "An important philosopher", concepts: ["theory of forms", "divisions of the soul"]}
|
|
]
|
|
attr :icon, :string, default: "default"
|
|
attr :btn_name, :map, default: %{
|
|
names: [
|
|
"Log In",
|
|
"Log Out",
|
|
"Register"
|
|
],
|
|
choice: 0
|
|
}
|
|
|
|
def greet(assigns) do
|
|
~H"""
|
|
<h1>Welcome, <%= @audience %>, to <%= @home %>!</h1>
|
|
"""
|
|
end
|
|
|
|
def html_head(assigns) do
|
|
~H"""
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<% # <meta name="keywords" content={@site_keywords}> %>
|
|
<meta name="author" content={@site_author}>
|
|
<meta name="description" content={@site_desc}>
|
|
<link rel="stylesheet" href={~p"/assets/app.css"}>
|
|
<title><%= @site_name %></title>
|
|
</head>
|
|
"""
|
|
end
|
|
|
|
def navify(assigns) do
|
|
~H"""
|
|
<%= if @page_links != nil do %>
|
|
<%= if length(@page_links) > 0 do %>
|
|
<%= for anchor <- @page_links do %>
|
|
<a href={anchor.uri}><%= anchor.name %></a>
|
|
<% end %>
|
|
<% else %>
|
|
<a href={~p"/"}>Home</a>
|
|
<% end %>
|
|
<% end %>
|
|
"""
|
|
end
|
|
|
|
def submission(assigns) do
|
|
~H"""
|
|
<% button_name = Enum.at(@btn_name.names, @btn_name.choice) %>
|
|
<input type="submit" class="acct_manager" value={button_name}>
|
|
"""
|
|
end
|
|
|
|
def markdown_content(assigns) do
|
|
~H"""
|
|
<% result = Marker.render_mark(@page_query) %>
|
|
<% content = if elem(result, 0) == :ok, do: elem(result, 1) %>
|
|
<%= raw content %>
|
|
"""
|
|
end
|
|
|
|
def thinkify(assigns) do
|
|
~H"""
|
|
<%= if @thinkers != nil do %>
|
|
<%= if length(@thinkers) > 0 do %>
|
|
<%= for thinker <- @thinkers do %>
|
|
<!-- @TODO move the style attribute and width/height attribute values to respective SASS files -->
|
|
<% underscored_name = String.split(thinker.name, " ") %>
|
|
<% underscored_name = Enum.join(underscored_name, "_") %>
|
|
<figure id={underscored_name} class="thinker">
|
|
<span class="tname"><p><%= thinker.name %></p></span>
|
|
<%= if Map.has_key?(thinker, :uri) do %>
|
|
<img src={thinker.uri} /><br>
|
|
<% end %>
|
|
<figcaption>
|
|
<%= if Map.has_key?(thinker, :type) do %>
|
|
<% thinker_types = Enum.map(thinker.type, fn tt -> "<span>" <> tt <> "</span>" end) %>
|
|
<% thinker_type = Enum.join(thinker_types, ", ") %>
|
|
<span class="ttype"><%= raw thinker_type %></span><br>
|
|
<% end %>
|
|
<%= if Map.has_key?(thinker, :concepts) do %>
|
|
<% thinker_concepts = Enum.map(thinker.concepts, fn tc -> "<span>" <> tc <> "</span>" end) %>
|
|
<% thinker_concepts = Enum.join(thinker_concepts, ", ") %>
|
|
<span class="concept_tags">concepts:<br><%= raw thinker_concepts %></span><br>
|
|
<% end %>
|
|
<%= if Map.has_key?(thinker, :desc) do %>
|
|
<span class="tdesc"><%= thinker.desc %></span><br>
|
|
<% end %>
|
|
</figcaption>
|
|
</figure>
|
|
<% end %>
|
|
<% end %>
|
|
<% end %>
|
|
"""
|
|
end
|
|
|
|
def affiliate(assigns) do
|
|
~H"""
|
|
<% current_theme = Theme.list(:current) %>
|
|
<!-- @NOTE if using default theme and experiencing janky sizing, make sure to remove SVGwidth and height attributes in source image -->
|
|
<!-- @NOTE if using default theme and SVG unresponsive to CSS color changes, make sure to remove fill and stroke SVG path attributes -->
|
|
<% rel_proj_root = "../../.." %>
|
|
<%= raw File.read!(Path.expand(rel_proj_root <> "/priv/static/images/themes/" <> current_theme <> "/icons/" <> @icon <> ".svg", __DIR__)) %>
|
|
"""
|
|
end
|
|
|
|
def html_foot(assigns) do
|
|
# @TODO do HEEx loop on @badge_collection
|
|
~H"""
|
|
<footer>
|
|
<% # @TODO add list of badges here or an anchor element with attribute set to a badges route %>
|
|
</footer>
|
|
"""
|
|
end
|
|
end
|