package server
import "html/template"
// This file defines the data structures and helper functions for the template system.
//
// The template system uses Go's html/template package to provide:
// - Dynamic menu bars that can be customized per page
// - Template inheritance via layout.html
// - Type-safe data passing via structs
//
// To create a new page with a custom menu:
// 1. Create a PageData struct with your menu configuration
// 2. Call s.renderTemplate(w, status, "yourpage.html", data)
// 3. In yourpage.html, use {{template "layout" .}} and define content blocks
//
// See TEMPLATE_GUIDE.md for detailed examples and usage patterns.
// PageData holds the data passed to page templates.
type PageData struct {
Title string
MenuGroups []MenuGroup
ShowClock bool
}
// MenuGroup represents a dropdown menu in the navbar.
type MenuGroup struct {
LabelHTML template.HTML
Items []MenuItem
}
// MenuItem represents a single menu item.
type MenuItem struct {
LabelHTML template.HTML
URL string
IsDivider bool
}
// DefaultMenuBar returns the standard menu configuration.
func DefaultMenuBar() PageData {
return PageData{
ShowClock: true,
MenuGroups: []MenuGroup{
{
LabelHTML: template.HTML(`File`),
Items: []MenuItem{
{LabelHTML: template.HTML(`New`), URL: "#!"},
{LabelHTML: template.HTML(`Open`), URL: "#!"},
{LabelHTML: template.HTML(`Save`), URL: "#!"},
{LabelHTML: template.HTML(`Save As`), URL: "#!"},
{IsDivider: true},
{LabelHTML: template.HTML(`Exit`), URL: "#!"},
},
},
{
LabelHTML: template.HTML(`Edit`),
Items: []MenuItem{
{LabelHTML: template.HTML(`Cut`), URL: "#!"},
{LabelHTML: template.HTML(`Copy`), URL: "#!"},
{LabelHTML: template.HTML(`Paste`), URL: "#!"},
},
},
{
LabelHTML: template.HTML(`Help`),
Items: []MenuItem{
{LabelHTML: template.HTML(`Documentation`), URL: "#!"},
{LabelHTML: template.HTML(`About`), URL: "#!"},
},
},
},
}
}
// AdminMenuBar returns a menu configuration with admin options.
func AdminMenuBar() PageData {
data := DefaultMenuBar()
data.MenuGroups = append(data.MenuGroups, MenuGroup{
LabelHTML: template.HTML(`Admin`),
Items: []MenuItem{
{LabelHTML: template.HTML(`Users`), URL: "/admin/users"},
{LabelHTML: template.HTML(`Settings`), URL: "/admin/settings"},
{LabelHTML: template.HTML(`Logs`), URL: "/admin/logs"},
},
})
return data
}