feat(postcard): header, logo, footer and padding in the system and minimal layouts
- system.htm: the header partial (logo or site name) above the card and the copyright footer below it; its text wrapper ends with the footer - brand CSS: the system layout's content cell keeps WinterCMS's 35px side padding (the 35px 0 override is gone) - minimal.htm: the logo above the message when logoUrl is set - TestMailPartialsSmoke/built_in_layouts covers the three layouts and the inlined brand colour on the button in each - 35-06 Task 3 (G-35-8)
This commit is contained in:
@@ -176,8 +176,8 @@ Markdown drops raw HTML, so a call in a body does not insert the partial's HTML
|
||||
| Layout alias | Full name | Renders |
|
||||
|--------------|-----------|---------|
|
||||
| `default` | `postcard::mail.layouts.default` | WinterCMS's default layout (`wrapper layout-default`): the `header` partial with the logo or the site name, the message in the `inner-body` card, and the `footer` partial with `© <year> <site name>`. Used when a template names no layout. |
|
||||
| `system` | `postcard::mail.layouts.system` | WinterCMS's system layout: the message in a centred table, followed by a note that the message is automatic. |
|
||||
| `minimal` | `postcard::mail.layouts.minimal` | The message directly in the page body. |
|
||||
| `system` | `postcard::mail.layouts.system` | WinterCMS's system layout (`wrapper layout-system`): the same header and footer as `default`, the message in the padded card followed by a `subcopy` note that the message is automatic. Its text wrapper ends with that note and the footer's text section. |
|
||||
| `minimal` | `postcard::mail.layouts.minimal` | The message directly in the page body, with the logo (`img.logo`, the site name as its alternative text) in a paragraph above it when `logoUrl` is set. |
|
||||
|
||||
A template selects one with `layout = "system"`. A plugin's own alias of the same name wins, except `default`, which plugins cannot redefine. Every built-in layout has the `{{ .brandCss }}{{ .css }}` style block.
|
||||
|
||||
@@ -193,7 +193,7 @@ A layout opts out with WinterCMS's option name, `disable_auto_inline_css`:
|
||||
|
||||
An opted-out layout keeps its style block as rendered. When the inliner fails on a message, the message is sent with its style block only and a warning keyed by the layout is logged at most once a minute.
|
||||
|
||||
Both wrappers of every layout get these keys: `Content`, `Subject`, `css`, `brandCss`, `logoUrl` (see [Branding](#branding)), `siteName` (the Branding's site name, else the display name of `mail.from`, else empty) and `year` (the current year). The default layout calls the header only when `logoUrl` or `siteName` is set, and builds the footer line from `year` and `siteName`, `© 2026 Acme`, or `© 2026` without a name. Its text wrapper is the message, a blank line and the footer's text section.
|
||||
Both wrappers of every layout get these keys: `Content`, `Subject`, `css`, `brandCss`, `logoUrl` (see [Branding](#branding)), `siteName` (the Branding's site name, else the display name of `mail.from`, else empty) and `year` (the current year). The default and system layouts call the header only when `logoUrl` or `siteName` is set, and builds the footer line from `year` and `siteName`, `© 2026 Acme`, or `© 2026` without a name. Its text wrapper is the message, a blank line and the footer's text section.
|
||||
|
||||
| Partial | Arguments | Renders |
|
||||
|---------|-----------|---------|
|
||||
@@ -263,7 +263,7 @@ Layouts have two CSS slots, `{{ .brandCss }}` and `{{ .css }}`, a logo slot, `{{
|
||||
|
||||
`mail.css` fills `{{ .css }}` in both cases, after the brand CSS, with a layout's own CSS before it.
|
||||
|
||||
The compiled CSS styles the page, links, headings, paragraphs and tables, and the classes of the built-in layouts and partials (`button button-primary`, `panel`, `table`, `subcopy`, `layout-system` and others), so the colours also apply in a plugin's layout that has the style block and no brand classes of its own. A colour must be a six-digit hexadecimal colour such as `#2da7c7`; `postcard.CompileBrandCSS` refuses anything else with an error naming the column. If a stored colour is invalid at send time, a warning is logged and `mail.brandCss` is used.
|
||||
The compiled CSS styles the page, links, headings, paragraphs and tables, and the classes of the built-in layouts and partials (`button button-primary`, `panel`, `table`, `subcopy`, `header`, `footer`, the `logo` image and others), so the colours also apply in a plugin's layout that has the style block and no brand classes of its own. A colour must be a six-digit hexadecimal colour such as `#2da7c7`; `postcard.CompileBrandCSS` refuses anything else with an error naming the column. If a stored colour is invalid at send time, a warning is logged and `mail.brandCss` is used.
|
||||
|
||||
| Column | `postcard.Brand` field | Default |
|
||||
|--------|------------------------|---------|
|
||||
|
||||
@@ -116,9 +116,6 @@ img.logo {
|
||||
.content-cell {
|
||||
padding: 35px;
|
||||
}
|
||||
.wrapper.layout-system .content-cell {
|
||||
padding: 35px 0;
|
||||
}
|
||||
/* Subcopy */
|
||||
.subcopy {
|
||||
border-top: 1px solid {{ .TableBorderColor }};
|
||||
|
||||
@@ -9,6 +9,7 @@ name = "Minimal"
|
||||
<style type="text/css">{{ .brandCss }}{{ .css }}</style>
|
||||
</head>
|
||||
<body>
|
||||
{{ .Content }}
|
||||
{{ if .logoUrl }}<p><img src="{{ .logoUrl }}" class="logo" alt="{{ .siteName }}" /></p>
|
||||
{{ end }}{{ .Content }}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -5,6 +5,8 @@ name = "System layout"
|
||||
|
||||
---
|
||||
This is an automatic message. Please do not reply to it.
|
||||
|
||||
{{ $copy := printf "© %v" .year }}{{ with .siteName }}{{ $copy = printf "%s %s" $copy . }}{{ end }}{{ partial "footer" "body" $copy }}
|
||||
==
|
||||
<!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">
|
||||
@@ -15,6 +17,7 @@ This is an automatic message. Please do not reply to it.
|
||||
</head>
|
||||
<body>
|
||||
<table class="wrapper layout-system" width="100%" cellpadding="0" cellspacing="0">
|
||||
{{ if or .logoUrl .siteName }}{{ partial "header" "logo" .logoUrl "body" .siteName }}{{ end }}
|
||||
<tr>
|
||||
<td align="center">
|
||||
<table class="content" width="100%" cellpadding="0" cellspacing="0">
|
||||
@@ -33,6 +36,7 @@ This is an automatic message. Please do not reply to it.
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
{{ $copy := printf "© %v" .year }}{{ with .siteName }}{{ $copy = printf "%s %s" $copy . }}{{ end }}{{ partial "footer" "body" $copy }}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -360,21 +360,55 @@ func TestMailPartialsSmoke(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("built_in_layouts", func(t *testing.T) {
|
||||
m, drv := partialsMailer(t, Options{CSS: "p{color:red}", BrandCSS: ".brand{color:blue}"}, nil)
|
||||
const logo = "https://cdn.example.com/u/logo.png"
|
||||
header := "<td class=\"header\">\n<img src=\"" + logo + "\" class=\"logo\" alt=\"Acme Mail\"/>"
|
||||
|
||||
// The system layout with a logo: the header above the card, the
|
||||
// card with the subcopy, the footer below, and the content cell's
|
||||
// side padding.
|
||||
m, drv := partialsMailer(t, Options{CSS: "p{color:red}"}, &Overrides{Brand: &Brand{LogoURL: logo, SiteName: "Acme Mail"}})
|
||||
msg := sendTemplate(t, m, drv, "acme.blog::mail.auto", nil)
|
||||
html := unstyled(msg.HTML)
|
||||
for _, want := range []string{
|
||||
// mail.css is inlined onto the paragraph.
|
||||
`class="wrapper layout-system"`, `<p style="color:red">Done.</p>`,
|
||||
`class="wrapper layout-system"`, header, "<p>Done.</p>",
|
||||
`<table class="subcopy"`, "<strong>This is an automatic message. Please do not reply to it.</strong>",
|
||||
`<table class="footer"`, "<p>" + copyright() + " Acme Mail</p>",
|
||||
} {
|
||||
if !strings.Contains(msg.HTML, want) {
|
||||
t.Errorf("system layout: HTML lacks %q:\n%s", want, msg.HTML)
|
||||
if !strings.Contains(html, want) {
|
||||
t.Errorf("system layout: HTML lacks %q:\n%s", want, html)
|
||||
}
|
||||
}
|
||||
if msg.Text != "Done.\n\n\n---\nThis is an automatic message. Please do not reply to it." {
|
||||
if h, card, foot := strings.Index(html, `class="header"`), strings.Index(html, `class="inner-body"`), strings.Index(html, `class="footer"`); h > card || card > foot {
|
||||
t.Errorf("system layout: header %d, card %d, footer %d are out of order", h, card, foot)
|
||||
}
|
||||
// mail.css is inlined onto the paragraph, after the brand CSS.
|
||||
if !regexp.MustCompile(`<p style="[^"]*;color:red[;"][^>]*>Done\.</p>`).MatchString(msg.HTML) {
|
||||
t.Errorf("system layout: mail.css is not inlined:\n%s", msg.HTML)
|
||||
}
|
||||
if !strings.Contains(msg.HTML, `<td class="content-cell" style="padding:35px">`) || strings.Contains(msg.HTML, "padding:35px 0") {
|
||||
t.Errorf("system layout: the content cell lost its side padding:\n%s", msg.HTML)
|
||||
}
|
||||
if msg.Text != "Done.\n\n\n---\nThis is an automatic message. Please do not reply to it.\n\n-------------------\n"+copyright()+" Acme Mail" {
|
||||
t.Errorf("system layout: text = %q", msg.Text)
|
||||
}
|
||||
|
||||
// Without a logo the header shows the site name.
|
||||
m, drv = partialsMailer(t, Options{}, &Overrides{Brand: &Brand{SiteName: "Acme Mail"}})
|
||||
if html := unstyled(sendTemplate(t, m, drv, "acme.blog::mail.auto", nil).HTML); !strings.Contains(html, "<td class=\"header\">\n<span>Acme Mail</span>") || strings.Contains(html, "<img") {
|
||||
t.Errorf("system layout without a logo:\n%s", html)
|
||||
}
|
||||
|
||||
// The minimal layout shows the logo above the message.
|
||||
m, drv = partialsMailer(t, Options{CSS: "p{color:red}"}, &Overrides{Brand: &Brand{LogoURL: logo, SiteName: "Acme Mail"}})
|
||||
msg = sendTemplate(t, m, drv, "acme.blog::mail.bare", nil)
|
||||
if html := unstyled(msg.HTML); !strings.Contains(html, "<p><img src=\""+logo+"\" class=\"logo\" alt=\"Acme Mail\"/></p>\n<p>Done.</p>") || strings.Contains(html, "layout-system") {
|
||||
t.Errorf("minimal layout with a logo: HTML = %q", html)
|
||||
}
|
||||
if msg.Text != "Done." {
|
||||
t.Errorf("minimal layout: text = %q", msg.Text)
|
||||
}
|
||||
// Without a logo its body holds only the message.
|
||||
m, drv = partialsMailer(t, Options{CSS: "p{color:red}"}, nil)
|
||||
msg = sendTemplate(t, m, drv, "acme.blog::mail.bare", nil)
|
||||
if !strings.Contains(msg.HTML, "<body>\n<p style=\"color:red\">Done.</p>\n\n\n</body>") || strings.Contains(msg.HTML, "content-body") || strings.Contains(msg.HTML, "layout-system") {
|
||||
t.Errorf("minimal layout: HTML = %q", msg.HTML)
|
||||
@@ -387,12 +421,32 @@ func TestMailPartialsSmoke(t *testing.T) {
|
||||
t.Errorf("minimal layout: text = %q", msg.Text)
|
||||
}
|
||||
|
||||
// Every built-in layout styles the button with the brand colour.
|
||||
button := "{{ partial \"button\" \"url\" \"https://example.com\" \"body\" \"Go\" }}\n"
|
||||
buttons := fstest.MapFS{
|
||||
"views/mail/d.htm": {Data: []byte("subject = \"D\"\n==\n" + button)},
|
||||
"views/mail/s.htm": {Data: []byte("subject = \"S\"\nlayout = \"system\"\n==\n" + button)},
|
||||
"views/mail/m.htm": {Data: []byte("subject = \"M\"\nlayout = \"minimal\"\n==\n" + button)},
|
||||
}
|
||||
cat := NewCatalog()
|
||||
if err := cat.Register("acme.shop", buttons, []string{"acme.shop::mail.d", "acme.shop::mail.s", "acme.shop::mail.m"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
drvB := NewMemoryDriver()
|
||||
mb := NewMailer(cat, drvB, Options{Overrides: fakeOverrides{ov: Overrides{Brand: &Brand{ButtonPrimaryBg: "#445566"}}}})
|
||||
for _, name := range []string{"acme.shop::mail.d", "acme.shop::mail.s", "acme.shop::mail.m"} {
|
||||
msg := sendTemplate(t, mb, drvB, name, nil)
|
||||
if style := buttonStyle(t, msg.HTML); !strings.Contains(unstyled(msg.HTML), `class="button button-primary"`) || !strings.Contains(style, "background-color:#445566") {
|
||||
t.Errorf("%s: button style %q", name, style)
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin's own alias named system wins over the built-in one.
|
||||
fsys := fstest.MapFS{
|
||||
"views/mail/auto.htm": {Data: []byte("subject = \"Auto\"\nlayout = \"system\"\n==\nDone.\n")},
|
||||
"views/mail/layouts/system.htm": {Data: []byte("name = \"Mine\"\n==\n{{ .Content }}\n==\n<div class=\"mine\">{{ .Content }}</div>\n")},
|
||||
}
|
||||
cat := NewCatalog()
|
||||
cat = NewCatalog()
|
||||
if err := cat.Register("acme.shop", fsys, []string{"acme.shop::mail.auto"}, map[string]string{"system": "acme.shop::mail.layouts.system"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user