package main import ( "context" "html" "git.dev.alexdunmow.com/block/pluginsdk/blocks" "git.dev.alexdunmow.com/block/pluginsdk/plugin" "git.dev.alexdunmow.com/block/pluginsdk/templates" "git.dev.alexdunmow.com/private/quote-requests-a1a5c0/db" ) const pluginName = "quote-requests-a1a5c0" // Registration is the plugin entry registration. var Registration = plugin.PluginRegistration{ Name: pluginName, Version: "1.0.0", Register: register, HTTPHandler: newHTTPHandler, } var current plugin.CoreServices func setServices(deps plugin.CoreServices) { current = deps } func register(_ templates.TemplateRegistry, br blocks.BlockRegistry) error { br.Register(blocks.BlockMeta{Key: "quote_request_form", Title: "Quote request form"}, renderForm) br.Register(blocks.BlockMeta{Key: "recent_requests", Title: "Recent requests"}, renderRecent) return nil } func str(content map[string]any, key string) string { s, _ := content[key].(string) return html.EscapeString(s) } func renderForm(_ context.Context, content map[string]any) string { button := str(content, "button_label") if button == "" { button = "Send" } return `

` + str(content, "heading") + `

` + `
` + `` + `
` } // renderRecent lists the latest requests that visitors submitted. func renderRecent(ctx context.Context, _ map[string]any) string { dbtx, ok := current.Pool.(db.DBTX) if !ok { return "" } rows, err := db.New(dbtx).ListQuoteRequests(ctx) if err != nil { return "" } out := "" }