Files
estus-shots/internal/server/template_data.go
2025-10-15 11:14:56 +02:00

85 lines
2.1 KiB
Go

package server
// 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 {
Label string
Items []MenuItem
}
// MenuItem represents a single menu item.
type MenuItem struct {
Label string
URL string
IsDivider bool
}
// DefaultMenuBar returns the standard menu configuration.
func DefaultMenuBar() PageData {
return PageData{
ShowClock: true,
MenuGroups: []MenuGroup{
{
Label: "Game",
Items: []MenuItem{
{Label: "Home", URL: "/"},
{Label: "Sessions", URL: "/sessions"},
{Label: "Statistics", URL: "/statistics"},
{IsDivider: true},
{Label: "Exit", URL: "#!"},
},
},
{
Label: "Manage",
Items: []MenuItem{
{Label: "Players", URL: "/players"},
{Label: "Games", URL: "/games"},
{Label: "Bosses", URL: "/bosses"},
{Label: "Drinks", URL: "/drinks"},
},
},
{
Label: "Help",
Items: []MenuItem{
{Label: "Documentation", URL: "#!"},
{Label: "About", URL: "#!"},
},
},
},
}
}
// AdminMenuBar returns a menu configuration with admin options.
func AdminMenuBar() PageData {
data := DefaultMenuBar()
data.MenuGroups = append(data.MenuGroups, MenuGroup{
Label: "Admin",
Items: []MenuItem{
{Label: "Users", URL: "/admin/users"},
{Label: "Settings", URL: "/admin/settings"},
{Label: "Logs", URL: "/admin/logs"},
},
})
return data
}