WraithWeb.Theme behaviour (Wraith v0.1.0)

View Source

What a theme is: a layout (the HEEx templates and the structural CSS for a kind of site — editorial, list, grid, magazine, minimal, journal) plus tokens (fonts, palette, radius, measure) inlined as CSS variables, plus a Google Fonts URL. Eighteen themes ship from six layouts, so the type and colour change completely while a layout's templates are written once.

defmodule WraithWeb.Themes.Broadsheet do
  use WraithWeb.Theme,
    name: "broadsheet",
    label: "Broadsheet",
    description: "Black on white, newspaper serif, a big first story.",
    layout: WraithWeb.Themes.Layouts.Editorial,
    fonts: "https://fonts.googleapis.com/css2?family=Playfair+Display:wght@500;700&family=Source+Serif+4&display=swap",
    tokens: %{"--heading" => "'Playfair Display', serif", "--body" => "'Source Serif 4', serif", "--paper" => "#fff", …}
end

A layout module (WraithWeb.Theme.Layout) embeds templates/{layout,index, post,listing}.html.heex and gets tag, author, search from its listing, and subscribe/member from WraithWeb.Themes.Shared. Tokens every layout reads (priv/static/themes/base.css sets fallbacks): --heading, --body, --mono, --paper, --paper-2, --rule, --ink, --ink-2, --ink-3, --accent, --radius, --measure, --scheme (light | dark).

Summary

Types

info()

@type info() :: %{
  name: String.t(),
  label: String.t(),
  description: String.t(),
  layout: module(),
  layout_name: String.t(),
  css: [String.t()],
  fonts: String.t() | nil,
  tokens: %{required(String.t()) => String.t()},
  swatch: [String.t()]
}

Callbacks

author(map)

@callback author(map()) :: Phoenix.LiveView.Rendered.t()

index(map)

@callback index(map()) :: Phoenix.LiveView.Rendered.t()

info()

@callback info() :: info()

layout(map)

@callback layout(map()) :: Phoenix.LiveView.Rendered.t()

member(map)

@callback member(map()) :: Phoenix.LiveView.Rendered.t()

post(map)

@callback post(map()) :: Phoenix.LiveView.Rendered.t()

search(map)

@callback search(map()) :: Phoenix.LiveView.Rendered.t()

subscribe(map)

@callback subscribe(map()) :: Phoenix.LiveView.Rendered.t()

tag(map)

@callback tag(map()) :: Phoenix.LiveView.Rendered.t()

Functions

pages()