themes-coffee/menu_board.go
Alex Dunmow 11c6c8c63e initial: theme plugin coffee
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/coffee.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:11:22 +08:00

83 lines
1.8 KiB
Go

package main
import (
"bytes"
"context"
"git.dev.alexdunmow.com/block/core/blocks"
)
// MenuBoardBlockMeta defines metadata for the menu_board block.
var MenuBoardBlockMeta = blocks.BlockMeta{
Key: "menu_board",
Title: "Menu Board",
Description: "Kraft-paper menu with sections of items (espresso, filter, pastry, ...)",
Source: "coffee",
}
// MenuBoardBlock renders a sectioned menu card.
// Content shape:
//
// {
// "title": "Menu",
// "sections": [
// {"name": "Espresso", "items": [
// {"name": "Flat White", "price": "5.50", "note": "...", "allergens": "..."}
// ]}
// ]
// }
func MenuBoardBlock(ctx context.Context, content map[string]any) string {
title := getString(content, "title")
if title == "" {
title = "Menu"
}
rawSections := getSlice(content, "sections")
var sections []MenuSection
for _, s := range rawSections {
rawItems := getSlice(s, "items")
var items []MenuItem
for _, it := range rawItems {
items = append(items, MenuItem{
Name: getString(it, "name"),
Price: getString(it, "price"),
Note: getString(it, "note"),
Allergens: getString(it, "allergens"),
})
}
sections = append(sections, MenuSection{
Name: getString(s, "name"),
Items: items,
})
}
data := MenuBoardData{
Title: title,
Sections: sections,
}
var buf bytes.Buffer
_ = menuBoardComponent(data).Render(ctx, &buf)
return buf.String()
}
// MenuBoardData contains data for the menu board component.
type MenuBoardData struct {
Title string
Sections []MenuSection
}
// MenuSection groups a list of items under a heading.
type MenuSection struct {
Name string
Items []MenuItem
}
// MenuItem represents a single menu line.
type MenuItem struct {
Name string
Price string
Note string
Allergens string
}