feat(postcard): mail partials, built-in layouts and layout and partial overrides
- pact.HasMailPartials: plugins declare <plugin>::mail.partials.<name>,
loaded from views/mail/partials/<name>.htm; HasMailTemplates is unchanged
- bodies and layouts call {{ partial "name" "key" value ... }}; a call in a
Markdown body leaves a per-render random token swapped after goldmark, so
raw HTML stays disabled for bodies
- built-in partials button, panel, table and subcopy, built-in layouts
system and minimal next to the unchanged default, reachable by alias
after a plugin's own aliases
- NewDBSource also reads customized and database-only layouts and
customized partials; a layout's CSS goes before mail.css
Plan 35-01, task 3.
This commit is contained in:
@@ -271,11 +271,14 @@ func loggerFromApp(app *backpack.App) *slog.Logger {
|
||||
return moduleLog
|
||||
}
|
||||
|
||||
// BootPlugin registers a plugin's declared mail templates and layouts.
|
||||
// Missing files and unknown layout aliases fail with the dotted name.
|
||||
// BootPlugin registers a plugin's declared mail partials (pact.HasMailPartials)
|
||||
// and its templates and layouts (pact.HasMailTemplates). Either capability is
|
||||
// optional. Missing files, duplicates, names outside the plugin's namespace
|
||||
// and unknown layout aliases fail with the dotted name.
|
||||
func BootPlugin[P interface{ ID() string }](app *backpack.App, p P) error {
|
||||
hm, ok := any(p).(pact.HasMailTemplates)
|
||||
if !ok {
|
||||
hm, hasTemplates := any(p).(pact.HasMailTemplates)
|
||||
hp, hasPartials := any(p).(pact.HasMailPartials)
|
||||
if !hasTemplates && !hasPartials {
|
||||
return nil
|
||||
}
|
||||
got, ok := app.Lookup[Mailer]()
|
||||
@@ -286,5 +289,13 @@ func BootPlugin[P interface{ ID() string }](app *backpack.App, p P) error {
|
||||
if !ok || m == nil || m.catalog == nil {
|
||||
return fmt.Errorf("postcard: mailer not published")
|
||||
}
|
||||
return m.catalog.Register(p.ID(), hm.MailTemplatesFS(), hm.MailTemplates(), hm.MailLayouts())
|
||||
if hasPartials {
|
||||
if err := m.catalog.RegisterPartials(p.ID(), hp.MailPartialsFS(), hp.MailPartials()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if hasTemplates {
|
||||
return m.catalog.Register(p.ID(), hm.MailTemplatesFS(), hm.MailTemplates(), hm.MailLayouts())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user