feat(04-03): register plugin mail layouts and publish the mailer at boot
- Map short layout names onto dotted layout files and wrap text/HTML - party.Activate publishes postcard.Mailer before Boot and names missing files - Hello plugin sends through the app-scoped mailer Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,8 +10,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ pact.HasConfig = (*Plugin)(nil)
|
||||
_ pact.HasLang = (*Plugin)(nil)
|
||||
_ pact.HasConfig = (*Plugin)(nil)
|
||||
_ pact.HasLang = (*Plugin)(nil)
|
||||
_ pact.HasMailTemplates = (*Plugin)(nil)
|
||||
)
|
||||
|
||||
//go:embed config
|
||||
@@ -20,6 +21,9 @@ var configFS embed.FS
|
||||
//go:embed lang
|
||||
var langFS embed.FS
|
||||
|
||||
//go:embed views/mail
|
||||
var mailFS embed.FS
|
||||
|
||||
// Plugin is the golem15.hello plugin.
|
||||
type Plugin struct{}
|
||||
|
||||
@@ -32,6 +36,19 @@ func (p *Plugin) Boot(*backpack.App) error { return nil }
|
||||
func (p *Plugin) ConfigFS() fs.FS { return configFS }
|
||||
func (p *Plugin) LangFS() fs.FS { return langFS }
|
||||
|
||||
func (p *Plugin) MailTemplatesFS() fs.FS { return mailFS }
|
||||
func (p *Plugin) MailTemplates() []string {
|
||||
return []string{
|
||||
"golem15.hello::mail.hello",
|
||||
"golem15.hello::mail.hello-en",
|
||||
}
|
||||
}
|
||||
func (p *Plugin) MailLayouts() map[string]string {
|
||||
return map[string]string{
|
||||
"hello": "golem15.hello::mail.layouts.hello",
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
party.Register(&Plugin{})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
subject = "Hello {{ .Name }}"
|
||||
description = "English hello greeting"
|
||||
layout = "default"
|
||||
layout = "hello"
|
||||
==
|
||||
Hello **{{ .Name }}**.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
subject = "Witaj {{ .Name }}"
|
||||
description = "Hello greeting"
|
||||
layout = "default"
|
||||
layout = "hello"
|
||||
==
|
||||
Witaj **{{ .Name }}**.
|
||||
|
||||
|
||||
14
examples/hello/plugins/base/views/mail/layouts/hello.htm
Normal file
14
examples/hello/plugins/base/views/mail/layouts/hello.htm
Normal file
@@ -0,0 +1,14 @@
|
||||
name = "Hello"
|
||||
==
|
||||
-- {{ .Content }} --
|
||||
==
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<style type="text/css">{{ .brandCss }}{{ .css }}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layout-hello">{{ .Content }}</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user