Compare commits

...
3 Commits
Author SHA1 Message Date
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
terminar d3e900389f Add Renderer.ExecuteNamed for rendering a non-base named block
Needed by yasta's SSE system-status stream, which re-renders just its
own fragment block on every tick instead of the full page.
2026-08-29 00:46:28 +02:00
terminar e712ce14fa Correct README sync instructions (root merge, not subtree --prefix) 2026-08-29 00:28:22 +02:00
4 changed files with 55 additions and 17 deletions

No files matched your search

+28 -15
View File
@@ -9,30 +9,43 @@ see `layout.go` for the API (`PageHeader`, `NavItem`, `NewRenderer`,
## Source of truth
This repo is the **source of truth** for the shared layout. It is mirrored
into the other two meta-repos as `yak-webui-template` and
`yamase-webui-template`, each of which pulls this repo in via `git
subtree` so layout/CSS changes can be synchronized without duplicating
design work. Make layout changes *here first*, then push them out — never
edit the mirrored copies directly.
This repo is the **source of truth** for the shared layout. `yak/yak-webui-template`
and `yamase/yamase-webui-template` are git-history mirrors of it (each repo's
root mirrors this repo's root — not a subdirectory — created via `git merge
--allow-unrelated-histories`, so the histories are related and can be
re-merged incrementally). Each mirror has exactly one intentional local
difference: its `go.mod` `module` line, which names that repo's own import
path instead of this one. Make layout changes *here first*, tag a new
version, then pull the change into each mirror — never edit the mirrored
copies directly.
### Pushing a change out to the mirrors
### Pulling a change into a mirror
From inside `yak` or `yamase` (which already have this repo added as a
subtree remote — see below):
From inside `yak-webui-template` or `yamase-webui-template` (each already
has a `source` remote pointing back here):
```sh
git subtree pull --prefix=yak-webui-template webui-template-origin main --squash
# resolve/verify, then:
git fetch source main
git merge source/main
# resolve the go.mod conflict: keep the mirror's own module line, take
# everything else from source
git checkout --ours go.mod # if go.mod conflicted
git add go.mod
git commit
go test ./...
git push origin main
```
### One-time subtree setup (already done for yak/yamase, kept here for
reference/re-setup)
### One-time mirror setup (already done, kept here for reference/re-setup)
```sh
git remote add webui-template-origin https://teruna.dev/yetano/yetano-webui-template.git
git subtree add --prefix=yak-webui-template webui-template-origin main --squash
git init -b main
git remote add source git@teruna.dev:yetano/yetano-webui-template.git
git fetch source main
git merge --allow-unrelated-histories -m "Initial mirror of yetano-webui-template" source/main
go mod edit -module teruna.dev/<org>/<org>-webui-template
git remote add origin git@teruna.dev:<org>/<org>-webui-template.git
git push -u origin main
```
## What's shared vs. what stays per-project
+9 -1
View File
@@ -53,6 +53,7 @@ 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>
@@ -92,11 +93,18 @@ func NewRenderer(pagesFS fs.FS, pageDir string, pageNames []string, pageSuffix s
// Page renders the full page (layout + content) for the given page name.
func (r *Renderer) Page(w io.Writer, page string, data any) error {
return r.ExecuteNamed(w, page, "base", data)
}
// ExecuteNamed renders the named block (not necessarily "base") from
// page's parsed template set -- e.g. an SSE handler re-rendering just a
// page's own fragment block on every tick instead of the full page.
func (r *Renderer) ExecuteNamed(w io.Writer, page, name string, data any) error {
t, ok := r.pages[page]
if !ok {
return fmt.Errorf("layout: unknown page %q", page)
}
return t.ExecuteTemplate(w, "base", data)
return t.ExecuteTemplate(w, name, data)
}
// StaticHandler serves the shared vendored static assets
+17 -1
View File
@@ -11,7 +11,8 @@ import (
func testPagesFS() fstest.MapFS {
return fstest.MapFS{
"pages/dashboard.html.tmpl": &fstest.MapFile{Data: []byte(
`{{define "content"}}<p>hello {{.Title}}</p>{{end}}`,
`{{define "content"}}<p>hello {{.Title}}</p>{{end}}` +
`{{define "fragment"}}<p>fragment {{.Title}}</p>{{end}}`,
)},
}
}
@@ -53,6 +54,21 @@ func TestNewRendererAndPage(t *testing.T) {
}
}
func TestExecuteNamed(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
if err := r.ExecuteNamed(&buf, "dashboard", "fragment", PageHeader{Title: "Dashboard"}); err != nil {
t.Fatalf("ExecuteNamed: %v", err)
}
if got, want := buf.String(), "<p>fragment Dashboard</p>"; got != want {
t.Errorf("ExecuteNamed rendered %q, want %q", got, want)
}
}
func TestPageUnknown(t *testing.T) {
r, err := NewRenderer(testPagesFS(), "pages", []string{"dashboard"}, ".html.tmpl", testFuncs())
if err != nil {
+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}}