package main import ( "context" "github.com/a-h/templ" "git.dev.alexdunmow.com/block/core/blocks" "git.dev.alexdunmow.com/block/core/templates" ) // wrap adapts a templ-returning render function to templates.TemplateFunc. func wrap(f func(ctx context.Context, doc map[string]any) templ.Component) templates.TemplateFunc { return func(ctx context.Context, doc map[string]any) templates.HTMLComponent { return f(ctx, doc) } } // Register is the plugin entry point that wires Coffee's system template, // page templates, blocks, overrides, and email wrapper. func Register(tr templates.TemplateRegistry, br blocks.BlockRegistry) error { // 1. System template ---------------------------------------------------- tr.RegisterSystemTemplate(templates.SystemTemplateMeta{ Key: "coffee", Title: "Coffee", Description: "Warm, hand-crafted theme for cafes, bakeries, and slow-craft makers", }) // 2. Page templates ----------------------------------------------------- if err := tr.RegisterPageTemplate("coffee", templates.PageTemplateMeta{ Key: "default", Title: "Default", Description: "Header + main + footer with warm paper background", Slots: []string{"header", "main", "footer"}, }, wrap(RenderCoffee)); err != nil { return err } if err := tr.RegisterPageTemplate("coffee", templates.PageTemplateMeta{ Key: "landing", Title: "Landing", Description: "Hero pour + featured menu, big imagery", Slots: []string{"hero", "menu", "story", "cta", "footer"}, }, wrap(RenderCoffeeLanding)); err != nil { return err } if err := tr.RegisterPageTemplate("coffee", templates.PageTemplateMeta{ Key: "article", Title: "Article", Description: "Narrow narrative column for journal / recipes", Slots: []string{"header", "main", "footer"}, }, wrap(RenderCoffeeArticle)); err != nil { return err } if err := tr.RegisterPageTemplate("coffee", templates.PageTemplateMeta{ Key: "full-width", Title: "Full Width", Description: "Edge-to-edge gallery / interior shots", Slots: []string{"header", "main", "footer"}, }, wrap(RenderCoffeeFullWidth)); err != nil { return err } // 3. Schemas — MUST be loaded BEFORE br.Register -------------------------- if err := br.LoadSchemasFromFS(Schemas()); err != nil { return err } // 4. Theme-specific blocks (registered unqualified; addressed as coffee:) br.Register(MenuBoardBlockMeta, MenuBoardBlock) br.Register(HoursStripBlockMeta, HoursStripBlock) br.Register(LocationCardBlockMeta, LocationCardBlock) br.Register(FeaturedPourBlockMeta, FeaturedPourBlock) br.Register(FooterBlockMeta, FooterBlock) br.Register(DoodleDividerBlockMeta, DoodleDividerBlock) // 5. Built-in block overrides — only active when Coffee is the system template br.RegisterTemplateOverride("coffee", "heading", CoffeeHeadingBlock) br.RegisterTemplateOverride("coffee", "text", CoffeeTextBlock) br.RegisterTemplateOverride("coffee", "button", CoffeeButtonBlock) br.RegisterTemplateOverride("coffee", "image", CoffeeImageBlock) // 6. Email wrapper ------------------------------------------------------ tr.RegisterEmailWrapper("coffee", CoffeeEmailWrapper) return nil }