berrypod/lib/berrypod_web/plugs/load_theme.ex
jamey 5b41f3fedf extract site_name and site_description from theme settings into standalone settings
site_name and site_description are shop identity, not theme concerns.
They now live in the Settings table as first-class settings with their
own assigns (@site_name, @site_description) piped through hooks and
plugs. The setup wizard writes site_name on account creation, and the
theme editor reads/writes via Settings.put_setting. Removed the
"configure your shop" checklist item since currency/country aren't
built yet. Also adds shop name field to setup wizard step 1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 14:52:31 +00:00

42 lines
1.2 KiB
Elixir

defmodule BerrypodWeb.Plugs.LoadTheme do
@moduledoc """
Plug that loads theme settings and generated CSS for public shop pages.
This plug:
1. Checks the ETS cache for pre-generated CSS
2. Falls back to generating CSS from theme settings on cache miss
3. Assigns both `theme_settings` and `generated_css` to the connection
The generated CSS contains only the active theme values (not all variants),
making it much smaller than the full theme-layer2-attributes.css file used
by the theme editor for live preview switching.
"""
import Plug.Conn
alias Berrypod.Settings
alias Berrypod.Theme.{CSSGenerator, CSSCache}
def init(opts), do: opts
def call(conn, _opts) do
{theme_settings, generated_css} =
case CSSCache.get() do
{:ok, css} ->
{Settings.get_theme_settings(), css}
:miss ->
settings = Settings.get_theme_settings()
css = CSSGenerator.generate(settings, &BerrypodWeb.Endpoint.static_path/1)
CSSCache.put(css)
{settings, css}
end
conn
|> assign(:theme_settings, theme_settings)
|> assign(:site_name, Settings.site_name())
|> assign(:site_description, Settings.site_description())
|> assign(:generated_css, generated_css)
end
end