theme

package
v0.0.0-...-a606fa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package theme resolves the active theme for a tenant page render.

Per gocodealone-multisite SPEC.md:

C11: Theming — default theme bundled with host for sites lacking own
     template; per-site theme is expected.
V23: bundle's `multisite.yaml.theme` → first try tenant theme record;
     on miss + `use_host_default=true` → host default theme; on miss +
     `use_host_default=false` → 503 (config error, ⊥ silent fallback).

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("theme not found")

ErrNotFound — same semantic as store.ErrNotFound to keep callers indifferent to source.

View Source
var ErrThemeMissingNoFallback = errors.New("theme missing and use_host_default=false (V23)")

ErrThemeMissingNoFallback is returned when the requested theme is not found AND `use_host_default` is false (V23: hard 503 — never silent fallback).

Functions

This section is empty.

Types

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

MemoryStore is an in-memory Store for tests + local dev.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Get

func (m *MemoryStore) Get(_ context.Context, tenantID, themeID int64) (*Theme, error)

func (*MemoryStore) GetHostDefault

func (m *MemoryStore) GetHostDefault(_ context.Context) (*Theme, error)

func (*MemoryStore) Put

func (m *MemoryStore) Put(t *Theme)

Put inserts/updates a theme.

type Spec

type Spec struct {
	ID             int64 // theme id; 0 means "default" name lookup
	UseHostDefault bool
}

Spec is the resolver input — comes from multisite.yaml.theme block.

type Store

type Store interface {
	// Get fetches a theme by id, scoped to the tenant. tenant_id mismatch
	// → ErrNotFound (V12 multi-tenancy guard).
	Get(ctx context.Context, tenantID, themeID int64) (*Theme, error)
	// GetHostDefault returns the bundled host-default theme.
	GetHostDefault(ctx context.Context) (*Theme, error)
}

Store provides theme lookup by id + by-tenant-default + host-default.

type Theme

type Theme struct {
	ID                  int64
	TenantID            int64 // 0 = host default
	Name                string
	TemplateArchivePath string
	IsDefault           bool
}

Theme is the persistent representation of a renderable theme.

Production wires a postgres-backed Store; the in-memory implementation here suits tests + local dev. TenantID == 0 means a host-default theme (shared across tenants).

func Resolve

func Resolve(ctx context.Context, s Store, tenantID int64, spec Spec) (*Theme, error)

Resolve returns the theme to render with, following the V23 ladder:

  1. spec.ID → store.Get → return
  2. miss + spec.UseHostDefault=true → store.GetHostDefault → return
  3. miss + spec.UseHostDefault=false → ErrThemeMissingNoFallback

Calls Get with tenantID; the tenant-scoping guard lives in the Store impl.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL