Add examples

This commit is contained in:
matcornic
2017-03-28 18:16:20 +02:00
parent 076d2b46d6
commit 0b783aebf0
20 changed files with 1437 additions and 208 deletions

BIN
examples/.DS_Store vendored

Binary file not shown.

View File

@ -1,49 +0,0 @@
Hi Jon Snow,
<br />
<br />
Welcome to Hermes! We&#39;re very excited to have you on board.<br />
<br />
Firstname: Jon<br />
Lastname: Snow<br />
Birthday: 01/01/283<br />
<br />
To get started with Hermes, please click here:
<br />
<a href="https://hermes-example.com/confirm?token=d9729feb74992cc3482b350163a1a010">https://hermes-example.com/confirm?token=d9729feb74992cc3482b350163a1a010</a>
<br />
<br />
Need help, or have questions? Just reply to this email, we&#39;d love to help.
<br />
<br />
Yours truly,
<br />
Hermes
<br />
<br />
Copyright © 2017 Hermes. All rights reserved.

View File

@ -0,0 +1,422 @@
<!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 name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css" rel="stylesheet" media="all">
*:not(br):not(tr):not(html) {
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
width: 100% !important;
height: 100%;
margin: 0;
line-height: 1.4;
background-color: #F2F4F6;
color: #74787E;
-webkit-text-size-adjust: none;
}
a {
color: #3869D4;
}
.email-wrapper {
width: 100%;
margin: 0;
padding: 0;
background-color: #F2F4F6;
}
.email-content {
width: 100%;
margin: 0;
padding: 0;
}
.email-masthead {
padding: 25px 0;
text-align: center;
}
.email-masthead_logo {
max-width: 400px;
border: 0;
}
.email-masthead_name {
font-size: 16px;
font-weight: bold;
color: #2F3133;
text-decoration: none;
text-shadow: 0 1px 0 white;
}
.email-logo {
max-height: 50px;
}
.email-body {
width: 100%;
margin: 0;
padding: 0;
border-top: 1px solid #EDEFF2;
border-bottom: 1px solid #EDEFF2;
background-color: #FFF;
}
.email-body_inner {
width: 570px;
margin: 0 auto;
padding: 0;
}
.email-footer {
width: 570px;
margin: 0 auto;
padding: 0;
text-align: center;
}
.email-footer p {
color: #AEAEAE;
}
.body-action {
width: 100%;
margin: 30px auto;
padding: 0;
text-align: center;
}
.body-dictionary {
width: 100%;
overflow: hidden;
margin: 20px auto 10px;
padding: 0;
}
.body-dictionary dd {
margin: 0 0 10px 0;
}
.body-dictionary dt {
clear: both;
color: #000;
font-weight: bold;
}
.body-dictionary dd {
margin-left: 0;
margin-bottom: 10px;
}
.body-sub {
margin-top: 25px;
padding-top: 25px;
border-top: 1px solid #EDEFF2;
}
.content-cell {
padding: 35px;
}
.align-right {
text-align: right;
}
h1 {
margin-top: 0;
color: #2F3133;
font-size: 19px;
font-weight: bold;
}
h2 {
margin-top: 0;
color: #2F3133;
font-size: 16px;
font-weight: bold;
}
h3 {
margin-top: 0;
color: #2F3133;
font-size: 14px;
font-weight: bold;
}
p {
margin-top: 0;
color: #74787E;
font-size: 16px;
line-height: 1.5em;
}
p.sub {
font-size: 12px;
}
p.center {
text-align: center;
}
.data-wrapper {
width: 100%;
margin: 0;
padding: 35px 0;
}
.data-table {
width: 100%;
margin: 0;
}
.data-table th {
text-align: left;
padding: 0px 5px;
padding-bottom: 8px;
border-bottom: 1px solid #EDEFF2;
}
.data-table th p {
margin: 0;
color: #9BA2AB;
font-size: 12px;
}
.data-table td {
padding: 10px 5px;
color: #74787E;
font-size: 15px;
line-height: 18px;
}
.button {
display: inline-block;
width: 200px;
background-color: #3869D4;
border-radius: 3px;
color: #ffffff;
font-size: 15px;
line-height: 45px;
text-align: center;
text-decoration: none;
-webkit-text-size-adjust: none;
mso-hide: all;
}
@media only screen and (max-width: 600px) {
.email-body_inner,
.email-footer {
width: 100% !important;
}
}
@media only screen and (max-width: 500px) {
.button {
width: 100% !important;
}
}
</style>
</head>
<body dir="ltr">
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="email-masthead">
<a class="email-masthead_name" href="https://example-hermes.com/" target="_blank">
<img src="http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png" class="email-logo" />
</a>
</td>
</tr>
<tr>
<td class="email-body" width="100%">
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell">
<h1>Hi Jon Snow,</h1>
<p>Your order has been processed successfully.</p>
<table class="data-wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<table class="data-table" width="100%" cellpadding="0" cellspacing="0">
<tr>
<th
width="20%"
>
<p>Item</p>
</th>
<th
>
<p>Description</p>
</th>
<th
width="15%"
style="text-align:right"
>
<p>Price</p>
</th>
</tr>
<tr>
<td
>
Node.js
</td>
<td
>
Event-driven I/O server-side JavaScript environment based on V8
</td>
<td
style="text-align:right"
>
$10.99
</td>
</tr>
<tr>
<td
>
Mailgen
</td>
<td
>
Programmatically create beautiful e-mails using plain old JavaScript.
</td>
<td
style="text-align:right"
>
$1.99
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>You can check the status of your order and more in your dashboard:</p>
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<div>
<a href="https://hermes-example.com/dashboard" class="button" style="background-color: " target="_blank">Go to Dashboard</a>
</div>
</td>
</tr>
</table>
<p>
Yours truly,
<br>
Hermes
</p>
<table class="body-sub">
<tbody><tr>
<td>
<p class="sub">If youre having trouble with the button 'Go to Dashboard', copy and paste the URL below into your web browser.</p>
<p class="sub"><a href="https://hermes-example.com/dashboard">https://hermes-example.com/dashboard</a></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell">
<p class="sub center">
Copyright © 2017 Hermes. All rights reserved.
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,12 @@
Hi Jon Snow,
Your order has been processed successfully.
You can check the status of your order and more in your dashboard:
https://hermes-example.com/dashboard
Yours truly,
Hermes
Copyright © 2017 Hermes. All rights reserved.

View File

@ -0,0 +1,309 @@
<!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 name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css" rel="stylesheet" media="all">
*:not(br):not(tr):not(html) {
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
width: 100% !important;
height: 100%;
margin: 0;
line-height: 1.4;
background-color: #F2F4F6;
color: #74787E;
-webkit-text-size-adjust: none;
}
a {
color: #3869D4;
}
.email-wrapper {
width: 100%;
margin: 0;
padding: 0;
background-color: #F2F4F6;
}
.email-content {
width: 100%;
margin: 0;
padding: 0;
}
.email-masthead {
padding: 25px 0;
text-align: center;
}
.email-masthead_logo {
max-width: 400px;
border: 0;
}
.email-masthead_name {
font-size: 16px;
font-weight: bold;
color: #2F3133;
text-decoration: none;
text-shadow: 0 1px 0 white;
}
.email-logo {
max-height: 50px;
}
.email-body {
width: 100%;
margin: 0;
padding: 0;
border-top: 1px solid #EDEFF2;
border-bottom: 1px solid #EDEFF2;
background-color: #FFF;
}
.email-body_inner {
width: 570px;
margin: 0 auto;
padding: 0;
}
.email-footer {
width: 570px;
margin: 0 auto;
padding: 0;
text-align: center;
}
.email-footer p {
color: #AEAEAE;
}
.body-action {
width: 100%;
margin: 30px auto;
padding: 0;
text-align: center;
}
.body-dictionary {
width: 100%;
overflow: hidden;
margin: 20px auto 10px;
padding: 0;
}
.body-dictionary dd {
margin: 0 0 10px 0;
}
.body-dictionary dt {
clear: both;
color: #000;
font-weight: bold;
}
.body-dictionary dd {
margin-left: 0;
margin-bottom: 10px;
}
.body-sub {
margin-top: 25px;
padding-top: 25px;
border-top: 1px solid #EDEFF2;
}
.content-cell {
padding: 35px;
}
.align-right {
text-align: right;
}
h1 {
margin-top: 0;
color: #2F3133;
font-size: 19px;
font-weight: bold;
}
h2 {
margin-top: 0;
color: #2F3133;
font-size: 16px;
font-weight: bold;
}
h3 {
margin-top: 0;
color: #2F3133;
font-size: 14px;
font-weight: bold;
}
p {
margin-top: 0;
color: #74787E;
font-size: 16px;
line-height: 1.5em;
}
p.sub {
font-size: 12px;
}
p.center {
text-align: center;
}
.data-wrapper {
width: 100%;
margin: 0;
padding: 35px 0;
}
.data-table {
width: 100%;
margin: 0;
}
.data-table th {
text-align: left;
padding: 0px 5px;
padding-bottom: 8px;
border-bottom: 1px solid #EDEFF2;
}
.data-table th p {
margin: 0;
color: #9BA2AB;
font-size: 12px;
}
.data-table td {
padding: 10px 5px;
color: #74787E;
font-size: 15px;
line-height: 18px;
}
.button {
display: inline-block;
width: 200px;
background-color: #3869D4;
border-radius: 3px;
color: #ffffff;
font-size: 15px;
line-height: 45px;
text-align: center;
text-decoration: none;
-webkit-text-size-adjust: none;
mso-hide: all;
}
@media only screen and (max-width: 600px) {
.email-body_inner,
.email-footer {
width: 100% !important;
}
}
@media only screen and (max-width: 500px) {
.button {
width: 100% !important;
}
}
</style>
</head>
<body dir="ltr">
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="email-masthead">
<a class="email-masthead_name" href="https://example-hermes.com/" target="_blank">
<img src="http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png" class="email-logo" />
</a>
</td>
</tr>
<tr>
<td class="email-body" width="100%">
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell">
<h1>Hi Jon Snow,</h1>
<p>You have received this email because a password reset request for Hermes account was received.</p>
<p>Click the button below to reset your password:</p>
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<div>
<a href="https://hermes-example.com/reset-password?token=d9729feb74992cc3482b350163a1a010" class="button" style="background-color: #DC4D2F" target="_blank">Reset your password</a>
</div>
</td>
</tr>
</table>
<p>If you did not request a password reset, no further action is required on your part.</p>
<p>
Thanks,
<br>
Hermes
</p>
<table class="body-sub">
<tbody><tr>
<td>
<p class="sub">If youre having trouble with the button 'Reset your password', copy and paste the URL below into your web browser.</p>
<p class="sub"><a href="https://hermes-example.com/reset-password?token=d9729feb74992cc3482b350163a1a010">https://hermes-example.com/reset-password?token=d9729feb74992cc3482b350163a1a010</a></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell">
<p class="sub center">
Copyright © 2017 Hermes. All rights reserved.
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,13 @@
Hi Jon Snow,
You have received this email because a password reset request for Hermes account was received.
Click the button below to reset your password:
https://hermes-example.com/reset-password?token=d9729feb74992cc3482b350163a1a010
If you did not request a password reset, no further action is required on your part.
Thanks,
Hermes
Copyright © 2017 Hermes. All rights reserved.

View File

@ -206,9 +206,9 @@
<tr>
<td class="email-masthead">
<a class="email-masthead_name" href="http://hermes.com" target="_blank">
<a class="email-masthead_name" href="https://example-hermes.com/" target="_blank">
Hermes
<img src="http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png" class="email-logo" />
</a>
</td>
@ -221,28 +221,26 @@
<tr>
<td class="content-cell">
<h1>Hi Jon Snow,</h1>
<p>Welcome to Hermes! We&#39;re very excited to have you on board.</p>
<dl class="body-dictionary">
<dt>Firstname:</dt>
<dd>Jon</dd>
<dt>Lastname:</dt>
<dd>Snow</dd>
<dt>Birthday:</dt>
<dd>01/01/283</dd>
</dl>
<p>To get started with Hermes, please click here:</p>
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
@ -256,12 +254,15 @@
</table>
<p>Need help, or have questions? Just reply to this email, we&#39;d love to help.</p>
<p>
Yours truly,

View File

@ -0,0 +1,13 @@
Hi Jon Snow,
Welcome to Hermes! We&#39;re very excited to have you on board.
To get started with Hermes, please click here:
https://hermes-example.com/confirm?token=d9729feb74992cc3482b350163a1a010
Need help, or have questions? Just reply to this email, we&#39;d love to help.
Yours truly,
Hermes
Copyright © 2017 Hermes. All rights reserved.

View File

@ -1,66 +1,55 @@
package main
import (
"bytes"
"fmt"
"github.com/matcornic/hermes"
"io/ioutil"
)
type Example interface {
Email() hermes.Email
Name() string
}
func main() {
h := hermes.Hermes{
Product: hermes.Product{
Name: "Hermes",
Link: "http://hermes.com",
Link: "https://example-hermes.com/",
Logo: "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png",
},
}
email := hermes.Email{
Body: hermes.Body{
Name: "Jon Snow",
Intros: []string{
"Welcome to Hermes! We're very excited to have you on board.",
},
Dictionary: []hermes.Entry{
{Key: "Firstname", Value: "Jon"},
{Key: "Lastname", Value: "Snow"},
{Key: "Birthday", Value: "01/01/283"},
},
Actions: []hermes.Action{
{
Instructions: "To get started with Hermes, please click here:",
Button: hermes.Button{
Color: "#22BC66",
Text: "Confirm your account",
Link: "https://hermes-example.com/confirm?token=d9729feb74992cc3482b350163a1a010",
},
},
},
Outros: []string{
"Need help, or have questions? Just reply to this email, we'd love to help.",
},
},
examples := []Example{
new(Welcome),
new(Reset),
new(Receipt),
}
// Generate the HTML template
stream, err := h.GenerateHTML(email)
if err != nil {
panic(err)
for _, e := range examples {
generateEmails(h, e.Email(), e.Name())
}
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(stream)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("default.plaintext.html", buf.Bytes(), 0644)
stream, err = h.GeneratePlainText(email)
if err != nil {
panic(err)
}
buf = new(bytes.Buffer)
_, err = buf.ReadFrom(stream)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("default.html", buf.Bytes(), 0644)
}
func generateEmails(h hermes.Hermes, email hermes.Email, example string) {
// Generate the HTML template and save it
res, err := h.GenerateHTML(email)
if err != nil {
panic(err)
}
err = ioutil.WriteFile(fmt.Sprintf("%v.%v.html", h.Theme.Name(), example), []byte(res), 0644)
if err != nil {
panic(err)
}
// Generate the plaintext template and save it
res, err = h.GeneratePlainText(email)
if err != nil {
panic(err)
}
err = ioutil.WriteFile(fmt.Sprintf("%v.%v.txt", h.Theme.Name(), example), []byte(res), 0644)
if err != nil {
panic(err)
}
}

View File

@ -0,0 +1,55 @@
package main
import (
"github.com/matcornic/hermes"
)
type Receipt struct {
}
func (r *Receipt) Name() string {
return "receipt"
}
func (r *Receipt) Email() hermes.Email {
return hermes.Email{
Body: hermes.Body{
Name: "Jon Snow",
Intros: []string{
"Your order has been processed successfully.",
},
Table: hermes.Table{
Data: [][]hermes.Entry{
{
{Key: "Item", Value: "Node.js"},
{Key: "Description", Value: "Event-driven I/O server-side JavaScript environment based on V8"},
{Key: "Price", Value: "$10.99"},
},
{
{Key: "Item", Value: "Mailgen"},
{Key: "Description", Value: "Programmatically create beautiful e-mails using plain old JavaScript."},
{Key: "Price", Value: "$1.99"},
},
},
Columns: hermes.Columns{
CustomWidth: map[string]string{
"Item": "20%",
"Price": "15%",
},
CustomAlignement: map[string]string{
"Price": "right",
},
},
},
Actions: []hermes.Action{
{
Instructions: "You can check the status of your order and more in your dashboard:",
Button: hermes.Button{
Text: "Go to Dashboard",
Link: "https://hermes-example.com/dashboard",
},
},
},
},
}
}

37
examples/default/reset.go Normal file
View File

@ -0,0 +1,37 @@
package main
import (
"github.com/matcornic/hermes"
)
type Reset struct {
}
func (r *Reset) Name() string {
return "reset"
}
func (r *Reset) Email() hermes.Email {
return hermes.Email{
Body: hermes.Body{
Name: "Jon Snow",
Intros: []string{
"You have received this email because a password reset request for Hermes account was received.",
},
Actions: []hermes.Action{
{
Instructions: "Click the button below to reset your password:",
Button: hermes.Button{
Color: "#DC4D2F",
Text: "Reset your password",
Link: "https://hermes-example.com/reset-password?token=d9729feb74992cc3482b350163a1a010",
},
},
},
Outros: []string{
"If you did not request a password reset, no further action is required on your part.",
},
Signature: "Thanks",
},
}
}

View File

@ -0,0 +1,41 @@
package main
import (
"github.com/matcornic/hermes"
)
type Welcome struct {
}
func (w *Welcome) Name() string {
return "welcome"
}
func (w *Welcome) Email() hermes.Email {
return hermes.Email{
Body: hermes.Body{
Name: "Jon Snow",
Intros: []string{
"Welcome to Hermes! We're very excited to have you on board.",
},
Dictionary: []hermes.Entry{
{Key: "Firstname", Value: "Jon"},
{Key: "Lastname", Value: "Snow"},
{Key: "Birthday", Value: "01/01/283"},
},
Actions: []hermes.Action{
{
Instructions: "To get started with Hermes, please click here:",
Button: hermes.Button{
Color: "#22BC66",
Text: "Confirm your account",
Link: "https://hermes-example.com/confirm?token=d9729feb74992cc3482b350163a1a010",
},
},
},
Outros: []string{
"Need help, or have questions? Just reply to this email, we'd love to help.",
},
},
}
}