mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-01 04:55:40 +00:00
bd321af29f
* new PR tasks * add homebox to know words * formatting * bump deps * generate db models * ts errors * drop id * fix accessor * drop unused time field * change CI * add expected error * add type check * resolve serveral type errors * hoise in CI
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package mailer
|
|
|
|
import (
|
|
"bytes"
|
|
_ "embed"
|
|
"html/template"
|
|
)
|
|
|
|
//go:embed templates/welcome.html
|
|
var templatesWelcome string
|
|
|
|
type TemplateDefaults struct {
|
|
CompanyName string
|
|
CompanyAddress string
|
|
CompanyURL string
|
|
ActivateAccountURL string
|
|
UnsubscribeURL string
|
|
}
|
|
|
|
type TemplateProps struct {
|
|
Defaults TemplateDefaults
|
|
Data map[string]string
|
|
}
|
|
|
|
func (tp *TemplateProps) Set(key, value string) {
|
|
tp.Data[key] = value
|
|
}
|
|
|
|
func DefaultTemplateData() TemplateProps {
|
|
return TemplateProps{
|
|
Defaults: TemplateDefaults{
|
|
CompanyName: "Haybytes.com",
|
|
CompanyAddress: "123 Main St, Anytown, CA 12345",
|
|
CompanyURL: "https://haybytes.com",
|
|
ActivateAccountURL: "https://google.com",
|
|
UnsubscribeURL: "https://google.com",
|
|
},
|
|
Data: make(map[string]string),
|
|
}
|
|
}
|
|
|
|
func render(tpl string, data TemplateProps) (string, error) {
|
|
tmpl, err := template.New("name").Parse(tpl)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
var tplBuffer bytes.Buffer
|
|
|
|
err = tmpl.Execute(&tplBuffer, data)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return tplBuffer.String(), nil
|
|
}
|
|
|
|
func RenderWelcome() (string, error) {
|
|
return render(templatesWelcome, DefaultTemplateData())
|
|
}
|