Compare commits

..
8 Commits
Author SHA1 Message Date
terminar 8875062fc5 Prepare theming: PageHeader.Theme -> <html data-theme>, explicit dark block
Zero behavior change for every current consumer (Theme defaults to "",
which resolves to the unchanged bare :root block). Adds the seam a
future second theme slots into: its own :root[data-theme="..."] block
in static/style.css, nothing else in this module changes. See
README.md's expanded Theming section for the concrete mechanism.
2026-09-01 22:24:58 +02:00
terminar adea139888 Update migration-status table: yamocir migrated, yaais deliberately not 2026-09-01 22:11:15 +02:00
terminar ef0714e213 Extract the color palette into --yw-* custom properties (a formal theme)
Preparation for the yamocir migration: same computed colors as before,
now expressed as reusable, documented tokens instead of literals baked
into each rule. Also documents scope in README.md's new Theming
section -- this module ships exactly one theme; per-project theming
(e.g. yaais's light/dark toggle) belongs in that project, not here.
2026-09-01 21:40:28 +02:00
terminar 5d7f67b3d3 Update README: all five projects migrated, v0.1.5, versioning note 2026-09-01 17:48:08 +02:00
terminar 84a9faff29 Rename PageHeader.Name to AppName to avoid a field collision
A consuming project's own per-page data struct commonly embeds both
PageHeader and a domain type that has its own Name field (e.g. a
Kubernetes resource's name, as in yakwui's node/deployment/pod detail
pages) -- two same-depth promoted "Name" fields make html/template's
".Name" an ambiguous selector that only fails at execution time, not
at parse time.
2026-09-01 14:11:33 +02:00
terminar 1c1878cfca Add PageHeader.Lang, BodyAttrs, SidebarAttrs escape hatches
Lang: <html lang> override (defaults to "en") for a non-English UI.
BodyAttrs/SidebarAttrs: raw extra attributes spliced into <body> and
the sidebar's <nav> tag, typed template.HTMLAttr (not template.HTML --
the contextual autoescaper requires the attribute-list sentinel type
in this position or it silently drops the value). Needed by yakwui's
Alpine.js-driven collapsible mobile sidebar, which has no other way to
carry x-data state onto a common ancestor of the toggle button and the
sidebar nav.
2026-09-01 09:40:26 +02:00
terminar c99b000b1d Add PageHeader.BodyAttrs/SidebarAttrs escape hatches
Needed by yakwui's Alpine.js-based collapsible sidebar (x-data on
<body>, :class binding on the sidebar <nav>) -- the shared markup has
no generic opinion about a consumer's own client-side framework state.
2026-08-31 14:13:01 +02:00
terminar 671d9bd92d Add PageHeader.NavbarBeforeBrand for a pre-brand navbar element
Needed by yakwui's mobile sidebar-toggle button, which renders before
the brand link rather than after Subtitle.
2026-08-31 10:21:15 +02:00
7 changed files with 263 additions and 41 deletions

No files matched your search

+76 -4
View File
@@ -59,6 +59,42 @@ Stays in each consuming project: page-specific templates
(`templates/pages/*.html.tmpl`), page-content CSS (cards, tables, badges,
forms, buttons, markdown, ...), and anything else specific to that tool.
## Theming
`static/style.css`'s palette is exposed as `--yw-*` CSS custom properties
(`--yw-bg`, `--yw-text`, `--yw-chrome-bg`, `--yw-accent`, `--yw-nav-link`,
`--yw-success-*`/`--yw-danger-*`, ...) rather than baked directly into
each rule — a documented, reusable theme, not an implementation detail.
The mechanism is prepared but only one theme ("dark") is actually
defined today:
- `PageHeader.Theme` (see `layout.go`) renders as `<html data-theme="...">`.
`""` (every current consumer) omits the attribute, which resolves to
the bare `:root` block — today's exact look, unchanged.
- `static/style.css` also declares `:root[data-theme="dark"]`, byte-
identical to the bare `:root` block — `Theme: "dark"` is an explicit,
equivalent opt-in, and the template a second theme copies.
- **Adding a second theme** (e.g. "light"): add its own
`:root[data-theme="light"] { --yw-*: ...; }` block to
`static/style.css` with the same property list and new values. Nothing
else in this module changes. A consuming project opts in per-request
or per-user by setting `Theme: "light"` on the `PageHeader`s it
builds; projects that never set `Theme` are completely unaffected.
- This module does **not** read `prefers-color-scheme` or persist a
choice itself (no cookie/localStorage/JS) — that's each consuming
project's own concern (e.g. a cookie/session-backed preference,
resolved server-side into `Theme` before rendering), same as any other
`PageHeader` field.
- Don't redefine `--yw-*` globally in one consumer's own stylesheet to
get a per-project look — that silently reskins every other consumer
sharing this CSS file too. A project that genuinely needs a
self-contained different look — e.g. a light/dark toggle with its own
JS/localStorage, like `yaais` has — should own that itself rather than
pushing multi-theme complexity into this module, since `yaais` shows
that need doesn't actually require *this* module either (it's a
client-rendered SPA, not a server-rendered Go-template dashboard).
## Consuming this module
```go
@@ -76,10 +112,46 @@ module).
## Migration status
Six projects are migrated, on `v0.1.6`.
| Project | Meta-repo | Status |
|---|---|---|
| `yasta` | yetano | migrated (pilot) |
| `yasl` | yetano | not yet migrated |
| `yaiam` | yetano | not yet migrated |
| `yakwui` | yak | not yet migrated |
| `yamase-web` | yamase | not yet migrated |
| `yasl` | yetano | migrated |
| `yaiam` | yetano | migrated |
| `yakwui` | yak | migrated |
| `yamase-web` | yamase | migrated |
| `yamocir` | yetano | migrated |
`yaais` was evaluated too and deliberately NOT migrated: it's a
client-rendered SPA (static `index.html` + vanilla JS), not a
server-rendered Go-template dashboard, so this module's actual
deliverable (Go templates) doesn't apply. It adopted the same dark
palette independently in its own stylesheet instead, plus its own
light/dark toggle — see its `internal/yaais/static/style.css`.
## Versioning note
Use `v0.1.5` or later. `v0.1.3` and `v0.1.4` were force-moved to
different content after being tagged (a mistake, made while resolving a
concurrent-edit conflict during the initial rollout) and can produce a
`go.sum` checksum mismatch for anyone who fetched them beforehand. Don't
force-move an existing tag again for any future change — always cut a
new one, even for a one-line fix.
## PageHeader fields (current as of v0.1.5)
`Title`, `AppName` (lowercase product name for `<title>`/footer — not
`Name`, which collides with a domain type's own `Name` field once
embedded in the same struct, as yakwui's viewmodel types do), `Lang`
(`<html lang>`, defaults to `"en"`), `Brand`, `BrandInitial`, `Subtitle`,
`BasePath`, `NavItems`/`ActiveNav`, `Flash`/`FlashKind`, `Username`,
`LogoutPath` (a plain GET link — for a POST-form logout or any other
markup mismatch, render it yourself into `NavbarRightExtra` instead and
leave `Username`/`LogoutPath` unset), `NavbarBeforeBrand` (before the
brand link, e.g. a mobile sidebar-toggle button),
`NavbarLeftExtra`/`NavbarRightExtra` (the navbar's two groups),
`ExtraHeadHTML`/`ExtraBodyHTML`, and `BodyAttrs`/`SidebarAttrs` —
`template.HTMLAttr`, not `template.HTML` — raw extra attributes on
`<body>` and the sidebar `<nav>` for a consumer's own client-side
framework state (e.g. yakwui's Alpine.js collapsible sidebar).
+34 -2
View File
@@ -1,6 +1,7 @@
// Package layout provides the shared server-rendered web UI chrome (base
// layout, navbar, sidebar, footer) used by every Yetano/Yak/Yamase
// ops-tool admin dashboard: yasta, yasl, yaiam, yakwui, and yamase-web.
// ops-tool admin dashboard: yasta, yasl, yaiam, yakwui, yamase-web, and
// yamocir.
//
// Consumers embed PageHeader in their own per-page data struct and use
// NewRenderer to parse the shared layout templates together with their
@@ -42,7 +43,27 @@ type NavItem struct {
// username/logout group).
type PageHeader struct {
Title string
Name string // lowercase product name, e.g. "yasta"; used in <title> and the footer
// AppName is the lowercase product name, e.g. "yasta", used in
// <title> and the footer. Deliberately not "Name" -- a consuming
// project's own per-page data struct commonly embeds both PageHeader
// and a domain type that has its own Name field (e.g. a Kubernetes
// resource's name); two same-depth promoted "Name" fields make
// html/template's ".Name" an ambiguous selector that only fails at
// execution time, not at parse time.
AppName string
Lang string // <html lang="...">; "" defaults to "en"
// Theme selects which --yw-* token block static/style.css applies,
// rendered as <html data-theme="...">. "" omits the attribute, which
// resolves to the bare :root values -- today that's the only theme
// this module ships (dark), so leaving Theme unset is exactly today's
// behavior for every current consumer. Setting Theme: "dark" is
// equivalent (an explicit :root[data-theme="dark"] block exists with
// the same values) -- it's the seam a future second theme (e.g.
// "light") would slot into: add its own :root[data-theme="..."]
// block to static/style.css, nothing else in this module changes,
// and consuming projects opt in per-request/per-user by setting this
// field (see README.md's Theming section).
Theme string
Brand string // navbar brand text, e.g. "YASTA"
BrandInitial string // single-letter favicon glyph, e.g. "y"
Subtitle string
@@ -53,10 +74,21 @@ type PageHeader struct {
FlashKind string // "ok" or "error"; meaningless if Flash == ""
Username string
LogoutPath string // BasePath-relative, e.g. "/logout"; "" hides the logout link
NavbarBeforeBrand template.HTML // extra markup rendered before the brand link, e.g. a mobile sidebar toggle
NavbarLeftExtra template.HTML // extra markup rendered after Subtitle in the navbar's left group
NavbarRightExtra template.HTML // extra markup rendered after Username/Logout in the navbar's right group
ExtraHeadHTML template.HTML // extra <link>/<script> tags appended to <head>
ExtraBodyHTML template.HTML // extra <script> tags appended before </body>
// BodyAttrs/SidebarAttrs are raw extra attributes (include their own
// leading space, e.g. ` x-data="{ open: true }"`) spliced into
// <body...> and the sidebar's <nav...> tag -- an escape hatch for a
// consuming project's own client-side framework state (e.g. yakwui's
// Alpine.js collapsible sidebar), which the shared markup has no
// generic opinion about. template.HTMLAttr, not template.HTML --
// html/template's contextual autoescaper requires the attribute-list
// sentinel type in this position or it silently drops the value.
BodyAttrs template.HTMLAttr
SidebarAttrs template.HTMLAttr
}
// Renderer holds one independently parsed *template.Template per page:
+59 -1
View File
@@ -30,7 +30,7 @@ func TestNewRendererAndPage(t *testing.T) {
var buf bytes.Buffer
data := PageHeader{
Title: "Dashboard",
Name: "example",
AppName: "example",
Brand: "EXAMPLE",
BrandInitial: "e",
BasePath: "",
@@ -47,6 +47,8 @@ func TestNewRendererAndPage(t *testing.T) {
`class="nav-link active"`,
"test-build",
"<title>Dashboard · example</title>",
`<html lang="en">`,
"<body>",
} {
if !strings.Contains(out, want) {
t.Errorf("rendered output missing %q\n---\n%s", want, out)
@@ -54,6 +56,62 @@ func TestNewRendererAndPage(t *testing.T) {
}
}
func TestPageHeaderOverrides(t *testing.T) {
r, err := NewRenderer(testPagesFS(), "pages", []string{"dashboard"}, ".html.tmpl", testFuncs())
if err != nil {
t.Fatalf("NewRenderer: %v", err)
}
var buf bytes.Buffer
data := PageHeader{
Title: "Dashboard",
Lang: "de",
BodyAttrs: template.HTMLAttr(` x-data="{ open: true }"`),
SidebarAttrs: template.HTMLAttr(` :class="{ hidden: !open }"`),
}
if err := r.Page(&buf, "dashboard", data); err != nil {
t.Fatalf("Page: %v", err)
}
out := buf.String()
for _, want := range []string{
`<html lang="de">`,
`<body x-data="{ open: true }">`,
`sidebar d-md-block" :class="{ hidden: !open }">`,
} {
if !strings.Contains(out, want) {
t.Errorf("rendered output missing %q\n---\n%s", want, out)
}
}
}
func TestThemeAttribute(t *testing.T) {
r, err := NewRenderer(testPagesFS(), "pages", []string{"dashboard"}, ".html.tmpl", testFuncs())
if err != nil {
t.Fatalf("NewRenderer: %v", err)
}
cases := []struct {
name string
theme string
want string
}{
{"unset resolves to the bare :root theme", "", `<html lang="en">`},
{"explicit dark", "dark", `<html lang="en" data-theme="dark">`},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
var buf bytes.Buffer
if err := r.Page(&buf, "dashboard", PageHeader{Title: "Dashboard", Theme: c.theme}); err != nil {
t.Fatalf("Page: %v", err)
}
if out := buf.String(); !strings.Contains(out, c.want) {
t.Errorf("rendered output missing %q\n---\n%s", c.want, out)
}
})
}
}
func TestExecuteNamed(t *testing.T) {
r, err := NewRenderer(testPagesFS(), "pages", []string{"dashboard"}, ".html.tmpl", testFuncs())
if err != nil {
+88 -29
View File
@@ -1,15 +1,74 @@
/* Shared web UI chrome -- the dark-theme base layout, navbar, sidebar, and
footer used by every ops-tool dashboard built on this module (yasta,
yasl, yaiam, yakwui, yamase-web). Loaded after bootstrap.min.css.
/* Shared web UI chrome -- the base layout, navbar, sidebar, and footer
used by every ops-tool dashboard built on this module (yasta, yasl,
yaiam, yakwui, yamase-web, yamocir). Loaded after bootstrap.min.css.
Page-content styling (cards, tables, badges, forms, ...) is each
project's own concern and lives in that project's own stylesheet,
loaded alongside this one -- see PageHeader.ExtraHeadHTML. Fixed dark
theme only -- no prefers-color-scheme, no light mode. */
loaded alongside this one -- see PageHeader.ExtraHeadHTML.
The palette is exposed as --yw-* custom properties, not baked into
each rule -- a documented, reusable theme, not an implementation
detail. Exactly one theme ships today ("dark"); PageHeader.Theme
(see layout.go) renders as <html data-theme="...">, which is the seam
a second theme slots into: add its own :root[data-theme="..."] block
below with the same property list, new values -- nothing else in this
module changes, and unset Theme (every current consumer) keeps
resolving to the bare :root block, i.e. today's exact look. A project
needing a genuinely different look (not just a different accent)
should not redefine these globally -- see README.md's Theming
section. */
:root {
--bs-body-bg: #1a1d23;
--bs-body-color: #d4d8e0;
--bs-border-color: #333;
--yw-bg: #1a1d23;
--yw-text: #d4d8e0;
--yw-border: #333;
--yw-chrome-bg: #14171e;
--yw-chrome-border: #272d3a;
--yw-accent: #4fc3f7;
--yw-accent-rgb: 79, 195, 247;
--yw-nav-link: #0b82b8;
--yw-nav-link-hover-text: #c8d4e4;
--yw-subtitle: #5a7a9a;
--yw-subtitle-sep: #333c4a;
--yw-footer-text: #4a5a72;
--yw-success-bg: #192e22;
--yw-success-border: #2a5c3a;
--yw-success-text: #7ecf98;
--yw-danger-bg: #2e1820;
--yw-danger-border: #5c2a32;
--yw-danger-text: #e08090;
--bs-body-bg: var(--yw-bg);
--bs-body-color: var(--yw-text);
--bs-border-color: var(--yw-border);
}
/* Theme: "dark" -- explicit opt-in via PageHeader.Theme = "dark",
byte-identical to the bare :root block above (which is what unset
Theme resolves to). Kept in sync manually -- there are only ever a
handful of themes here, a preprocessor would be overkill. */
:root[data-theme="dark"] {
--yw-bg: #1a1d23;
--yw-text: #d4d8e0;
--yw-border: #333;
--yw-chrome-bg: #14171e;
--yw-chrome-border: #272d3a;
--yw-accent: #4fc3f7;
--yw-accent-rgb: 79, 195, 247;
--yw-nav-link: #0b82b8;
--yw-nav-link-hover-text: #c8d4e4;
--yw-subtitle: #5a7a9a;
--yw-subtitle-sep: #333c4a;
--yw-footer-text: #4a5a72;
--yw-success-bg: #192e22;
--yw-success-border: #2a5c3a;
--yw-success-text: #7ecf98;
--yw-danger-bg: #2e1820;
--yw-danger-border: #5c2a32;
--yw-danger-text: #e08090;
--bs-body-bg: var(--yw-bg);
--bs-body-color: var(--yw-text);
--bs-border-color: var(--yw-border);
}
html {
@@ -19,8 +78,8 @@ html {
/* Flex column so the footer sits right after the content when the page is
short, and grows naturally when content is long. */
body {
background: #1a1d23;
color: #d4d8e0;
background: var(--yw-bg);
color: var(--yw-text);
font-size: 0.875rem;
min-height: 100%;
display: flex;
@@ -51,71 +110,71 @@ body > .container-fluid > .row {
/* --- Navbar ------------------------------------------------ */
.navbar {
background: #14171e !important;
border-bottom: 1px solid #272d3a;
background: var(--yw-chrome-bg) !important;
border-bottom: 1px solid var(--yw-chrome-border);
padding: .6rem 1.2rem;
}
.navbar-brand {
color: #4fc3f7 !important;
color: var(--yw-accent) !important;
letter-spacing: 2.5px;
font-size: 1rem;
}
.navbar-subtitle {
color: #5a7a9a;
color: var(--yw-subtitle);
font-size: .82rem;
text-decoration: none;
}
a.navbar-subtitle:hover {
color: #4fc3f7;
color: var(--yw-accent);
}
.navbar-subtitle-sep {
color: #333c4a;
color: var(--yw-subtitle-sep);
margin: 0 .5rem;
}
/* --- Sidebar ------------------------------------------------ */
.sidebar {
background: #14171e;
border-right: 1px solid #272d3a;
background: var(--yw-chrome-bg);
border-right: 1px solid var(--yw-chrome-border);
padding-top: .5rem;
}
.sidebar .nav-link {
color: #0b82b8;
color: var(--yw-nav-link);
font-size: .85rem;
padding: .5rem 1rem;
border-radius: 0;
}
.sidebar .nav-link:hover {
background: rgba(79, 195, 247, .08);
color: #c8d4e4;
background: rgba(var(--yw-accent-rgb), .08);
color: var(--yw-nav-link-hover-text);
}
.sidebar .nav-link.active {
background: rgba(79, 195, 247, .1);
color: #4fc3f7;
background: rgba(var(--yw-accent-rgb), .1);
color: var(--yw-accent);
font-weight: 600;
border-left: 2px solid #4fc3f7;
border-left: 2px solid var(--yw-accent);
}
/* --- Alerts (flash banners) ---------------------------------------- */
.alert-success { background: #192e22; border-color: #2a5c3a; color: #7ecf98; }
.alert-danger { background: #2e1820; border-color: #5c2a32; color: #e08090; }
.alert-success { background: var(--yw-success-bg); border-color: var(--yw-success-border); color: var(--yw-success-text); }
.alert-danger { background: var(--yw-danger-bg); border-color: var(--yw-danger-border); color: var(--yw-danger-text); }
/* --- Footer ------------------------------------------------- */
.footer {
color: #4a5a72;
color: var(--yw-footer-text);
font-size: 0.8rem;
text-align: center;
padding: 0.8rem 1rem;
border-top: 1px solid #272d3a;
border-top: 1px solid var(--yw-chrome-border);
}
@media (max-width: 767.98px) {
.sidebar { border-right: none; border-bottom: 1px solid #272d3a; }
.sidebar { border-right: none; border-bottom: 1px solid var(--yw-chrome-border); }
}
+4 -4
View File
@@ -1,20 +1,20 @@
{{define "base"}}<!doctype html>
<html lang="en">
<html lang="{{if .Lang}}{{.Lang}}{{else}}en{{end}}"{{if .Theme}} data-theme="{{.Theme}}"{{end}}>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{.Title}}{{if .Name}} · {{.Name}}{{end}}</title>
<title>{{.Title}}{{if .AppName}} · {{.AppName}}{{end}}</title>
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3E%3Crect%20width='100'%20height='100'%20rx='20'%20fill='%2314171e'/%3E%3Ctext%20x='50'%20y='71'%20font-size='58'%20font-family='system-ui,sans-serif'%20font-weight='700'%20fill='%230b82b8'%20text-anchor='middle'%3E{{.BrandInitial}}%3C/text%3E%3C/svg%3E">
<link rel="stylesheet" href="{{.BasePath}}/webui-static/bootstrap.min.css">
<link rel="stylesheet" href="{{.BasePath}}/webui-static/style.css">
<script src="{{.BasePath}}/webui-static/bootstrap.bundle.min.js" defer></script>
{{.ExtraHeadHTML}}
</head>
<body>
<body{{.BodyAttrs}}>
{{template "navbar" .}}
<div class="container-fluid">
<div class="row">
<nav class="col-md-2 col-lg-2 sidebar d-md-block">
<nav class="col-md-2 col-lg-2 sidebar d-md-block"{{.SidebarAttrs}}>
{{template "sidebar" .}}
</nav>
<main class="col-md-10 col-lg-10 ms-sm-auto px-md-4 py-3">
+1 -1
View File
@@ -1,3 +1,3 @@
{{define "footer"}}
<footer class="footer">{{.Name}} web UI · {{buildInfo}}</footer>
<footer class="footer">{{.AppName}} web UI · {{buildInfo}}</footer>
{{end}}
+1
View File
@@ -2,6 +2,7 @@
<nav class="navbar navbar-dark navbar-expand">
<div class="container-fluid d-flex justify-content-between align-items-center">
<div class="d-flex align-items-center">
{{.NavbarBeforeBrand}}
<a class="navbar-brand" href="{{.BasePath}}/">{{.Brand}}</a>
{{if .Subtitle}}<span class="navbar-subtitle">{{.Subtitle}}</span>{{end}}
{{.NavbarLeftExtra}}