Init
This commit is contained in:
84
internal/server/template_data.go
Normal file
84
internal/server/template_data.go
Normal file
@@ -0,0 +1,84 @@
|
||||
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: "File",
|
||||
Items: []MenuItem{
|
||||
{Label: "New", URL: "#!"},
|
||||
{Label: "Open", URL: "#!"},
|
||||
{Label: "Save", URL: "#!"},
|
||||
{Label: "Save As", URL: "#!"},
|
||||
{IsDivider: true},
|
||||
{Label: "Exit", URL: "#!"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Label: "Edit",
|
||||
Items: []MenuItem{
|
||||
{Label: "Cut", URL: "#!"},
|
||||
{Label: "Copy", URL: "#!"},
|
||||
{Label: "Paste", URL: "#!"},
|
||||
},
|
||||
},
|
||||
{
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user