forked from mirrors/homebox
Initial commit
This commit is contained in:
commit
29f583e936
135 changed files with 18463 additions and 0 deletions
62
backend/pkgs/mailer/templates.go
Normal file
62
backend/pkgs/mailer/templates.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
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())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue