Documentation
¶
Overview ¶
Package theme resolves, lists and loads goblog themes. A theme is a directory with templates/ (and optionally static/). Built-in themes ship in the image under themes/; themes installed from the directory live in a separate, persisted root so a Docker bind mount can keep them across redeploys without hiding the built-ins.
Index ¶
- Constants
- Variables
- func Dir(name string) (string, bool)
- func FuncMap() template.FuncMap
- func InstalledRoot() string
- func IsBuiltin(name string) bool
- func List() []string
- func Load(name string, funcMap template.FuncMap) (*template.Template, string, error)
- func Screenshot(name string) (string, bool)
- func StaticHandler(active func() string) gin.HandlerFunc
- func ValidName(name string) bool
- func ValidateFiles(files map[string][]byte) error
Constants ¶
const DefaultName = "default"
DefaultName is the theme every other theme is layered on.
const MaxTemplateBytes = 256 << 10
MaxTemplateBytes caps one template file before it is parsed. The parser recurses once per nested {{if}}/{{with}}/{{range}}, so an unbounded file can exhaust the stack (a fatal error, not a panic); goblog's largest real template is under 32 KiB.
Variables ¶
var ( BuiltinRoot = "themes" )
BuiltinRoot holds the themes compiled into the image (and, on bare metal, whatever the operator drops there). SharedDir holds the templates every theme gets. Both are package variables so tests can point them at temp dirs.
Functions ¶
func Dir ¶
Dir returns the directory of a theme — the built-in one first, then the installed one — and whether it exists. A directory counts only when it has a templates/ subdirectory.
func InstalledRoot ¶
func InstalledRoot() string
InstalledRoot is where the theme installer writes: $THEMES_INSTALLED_DIR, or themes/installed (under the data directory when one is set). Read on every call so tests can change it.
func IsBuiltin ¶
IsBuiltin reports whether name resolves to the built-in root. Dir looks there first, so a theme is built-in exactly when Dir lands there — even if an installed copy of the same name exists underneath.
func List ¶
func List() []string
List returns every theme name from both roots, sorted. "default" is always listed: it is the baseline every other theme is layered on, and Load requires it (a missing or broken default is a startup error).
func Load ¶
Load builds the template set for name. Anything wrong with the named theme (unknown, unparsable) is logged and default is loaded instead; only a broken shared/default set is an error, because nothing can render without it.
func Screenshot ¶
Screenshot returns the path of a theme's preview image — screenshot.png or screenshot.jpg beside its templates/, the same file the directory requires of a published theme — and whether it has one.
func StaticHandler ¶
func StaticHandler(active func() string) gin.HandlerFunc
StaticHandler serves /theme/* from the active theme's static/ directory, falling back to default's so an override-only theme still gets the base CSS. The path is cleaned as an absolute path first so ".." cannot climb out of static/.
func ValidateFiles ¶
ValidateFiles checks a theme's files as the installer and the directory see them (paths relative to the theme root, e.g. "templates/home.html"): there must be at least one template, each templates/*.html must parse on top of the shared and default sets, and every {{ template }} they reference must exist somewhere in that set. Files in subdirectories of templates/ are not loaded by Load and are ignored here too.
Types ¶
This section is empty.