Skip to content

Commit

Permalink
Merge pull request #62 from matcornic/mack-master
Browse files Browse the repository at this point in the history
Mack master
  • Loading branch information
matcornic authored Jan 29, 2020
2 parents 9f477cc + 38cd82e commit b496815
Show file tree
Hide file tree
Showing 18 changed files with 745 additions and 141 deletions.
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,28 @@ It means, if you want to create a button, the best solution is to create a case
{{safe "<![endif]-->" }}
```

When the action is an invite code, use this kind of code:

```html
{{ if $action.InviteCode }}
<div style="margin-top:30px;margin-bottom:30px">
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table align="center" cellpadding="0" cellspacing="0" style="padding:0;text-align:center">
<tr>
<td style="display:inline-block;border-radius:3px;font-family:Consolas, monaco, monospace;font-size:28px;text-align:center;letter-spacing:8px;color:#555;background-color:#eee;padding:20px">
{{ $action.InviteCode }}
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
{{ end }}
```

## Outro Injection

The following will inject the outro text (string or array) into the e-mail:
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ First install the package:
go get -u github.com/matcornic/hermes/v2
```

> Starting from release *v2.0.0*, Hermes uses [Go modules](https://github.com/golang/go/wiki/Modules). The latest version of Hermes requires Go 1.11 with gomodules enabled.
> Starting from release *v2.0.0*, Hermes uses [Go modules](https://github.com/golang/go/wiki/Modules). The latest version of Hermes requires at least Go 1.11 with gomodules enabled.
> You can still use an Hermes release compatible with prior Go versions by using *v1.2.0* release
Then, start using the package by importing and configuring it:
Expand Down Expand Up @@ -113,7 +113,8 @@ Copyright © 2017 Hermes. All rights reserved.
## More Examples

* [Welcome](examples/welcome.go)
* [Welcome with button](examples/welcome.go)
* [Welcome with invite code](examples/invite_code.go)
* [Receipt](examples/receipt.go)
* [Password Reset](examples/reset.go)
* [Maintenance](examples/maintenance.go)
Expand Down Expand Up @@ -258,6 +259,21 @@ email := hermes.Email{
}
```

Alternatively, instead of having a button, an action can be an invite code as follows:

```go
email := hermes.Email{
Body: hermes.Body{
Actions: []hermes.Action{
{
Instructions: "To get started with Hermes, please use the invite code:",
InviteCode: "123456",
},
},
},
}
```

To inject multiple action buttons in to the e-mail, supply another struct in Actions slice `Action`.

### Table
Expand Down
107 changes: 78 additions & 29 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ func (dt *Default) HTMLTemplate() string {
font-size: 15px;
line-height: 18px;
}
/* Invite Code ------------------------------ */
.invite-code {
display: inline-block;
padding-top: 20px;
padding-right: 36px;
padding-bottom: 16px;
padding-left: 36px;
border-radius: 3px;
font-family: Consolas, monaco, monospace;
font-size: 28px;
text-align: center;
letter-spacing: 8px;
color: #555;
background-color: #eee;
}
/* Buttons ------------------------------ */
.button {
display: inline-block;
Expand Down Expand Up @@ -365,35 +380,59 @@ func (dt *Default) HTMLTemplate() string {
{{ $length := len $action.Button.Text }}
{{ $width := add (mul $length 9) 20 }}
{{if (lt $width 200)}}{{$width = 200}}{{else if (gt $width 570)}}{{$width = 570}}{{else}}{{end}}
{{safe "<!--[if mso]>" }}
<div style="margin: 30px auto;v-text-anchor:middle;text-align:center">
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w="urn:schemas-microsoft-com:office:word"
href="{{ $action.Button.Link }}"
style="height:45px;v-text-anchor:middle;width:{{$width}}px;background-color:{{ if $action.Button.Color }}{{ $action.Button.Color }}{{ else }}#3869D4{{ end }};"
arcsize="10%"
{{ if $action.Button.Color }}strokecolor="{{ $action.Button.Color }}" fillcolor="{{ $action.Button.Color }}"{{ else }}strokecolor="#3869D4" fillcolor="#3869D4"{{ end }}
>
<w:anchorlock/>
<center style="color: {{ if $action.Button.TextColor }}{{ $action.Button.TextColor }}{{else}}#FFFFFF{{ end }};font-size: 15px;text-align: center;font-family:sans-serif;font-weight:bold;">
{{ $action.Button.Text }}
</center>
</v:roundrect>
</div>
{{safe "<![endif]-->" }}
{{safe "<!--[if !mso]><!-- -->"}}
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<div>
<a href="{{ $action.Button.Link }}" class="button" style="{{ with $action.Button.Color }}background-color: {{ . }};{{ end }} {{ with $action.Button.TextColor }}color: {{ . }};{{ end }} width: {{$width}}px;" target="_blank">
{{safe "<!--[if mso]>" }}
{{ if $action.Button.Text }}
<div style="margin: 30px auto;v-text-anchor:middle;text-align:center">
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w="urn:schemas-microsoft-com:office:word"
href="{{ $action.Button.Link }}"
style="height:45px;v-text-anchor:middle;width:{{$width}}px;background-color:{{ if $action.Button.Color }}{{ $action.Button.Color }}{{ else }}#3869D4{{ end }};"
arcsize="10%"
{{ if $action.Button.Color }}strokecolor="{{ $action.Button.Color }}" fillcolor="{{ $action.Button.Color }}"{{ else }}strokecolor="#3869D4" fillcolor="#3869D4"{{ end }}
>
<w:anchorlock/>
<center style="color: {{ if $action.Button.TextColor }}{{ $action.Button.TextColor }}{{else}}#FFFFFF{{ end }};font-size: 15px;text-align: center;font-family:sans-serif;font-weight:bold;">
{{ $action.Button.Text }}
</a>
</div>
</td>
</tr>
</table>
{{safe "<![endif]-->" }}
</center>
</v:roundrect>
</div>
{{ end }}
{{ if $action.InviteCode }}
<div style="margin-top:30px;margin-bottom:30px">
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table align="center" cellpadding="0" cellspacing="0" style="padding:0;text-align:center">
<tr>
<td style="display:inline-block;border-radius:3px;font-family:Consolas, monaco, monospace;font-size:28px;text-align:center;letter-spacing:8px;color:#555;background-color:#eee;padding:20px">
{{ $action.InviteCode }}
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
{{ end }}
{{safe "<![endif]-->" }}
{{safe "<!--[if !mso]><!-- -->"}}
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<div>
{{ if $action.Button.Text }}
<a href="{{ $action.Button.Link }}" class="button" style="{{ with $action.Button.Color }}background-color: {{ . }};{{ end }} {{ with $action.Button.TextColor }}color: {{ . }};{{ end }} width: {{$width}}px;" target="_blank">
{{ $action.Button.Text }}
</a>
{{end}}
{{ if $action.InviteCode }}
<span class="invite-code">{{ $action.InviteCode }}</span>
{{end}}
</div>
</td>
</tr>
</table>
{{safe "<![endif]-->" }}
{{ end }}
{{ end }}
{{ end }}
Expand All @@ -418,12 +457,14 @@ func (dt *Default) HTMLTemplate() string {
<table class="body-sub">
<tbody>
{{ range $action := . }}
{{if $action.Button.Text}}
<tr>
<td>
<p class="sub">{{$.Hermes.Product.TroubleText | replace "{ACTION}" $action.Button.Text}}</p>
<p class="sub"><a href="{{ $action.Button.Link }}">{{ $action.Button.Link }}</a></p>
</td>
</tr>
{{ end }}
{{ end }}
</tbody>
</table>
Expand Down Expand Up @@ -499,7 +540,15 @@ func (dt *Default) PlainTextTemplate() string {
{{ end }}
{{ with .Email.Body.Actions }}
{{ range $action := . }}
<p>{{ $action.Instructions }} {{ $action.Button.Link }}</p>
<p>
{{ $action.Instructions }}
{{ if $action.InviteCode }}
{{ $action.InviteCode }}
{{ end }}
{{ if $action.Button.Link }}
{{ $action.Button.Link }}
{{ end }}
</p>
{{ end }}
{{ end }}
{{ end }}
Expand Down
161 changes: 161 additions & 0 deletions examples/default/default.invite_code.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<!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">*:not(br):not(tr):not(html) {
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif !important;
-webkit-box-sizing: border-box !important;
box-sizing: border-box !important
}cite:before {
content: "\2014 \0020" !important
}@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" style="height:100%;margin:0;line-height:1.4;background-color:#F2F4F6;color:#74787E;-webkit-text-size-adjust:none;width:100%">
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0" style="width:100%;margin:0;padding:0;background-color:#F2F4F6">
<tbody><tr>
<td class="content" style="color:#74787E;font-size:15px;line-height:18px;align:center;padding:0">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0" style="width:100%;margin:0;padding:0">

<tbody><tr>
<td class="email-masthead" style="color:#74787E;font-size:15px;line-height:18px;padding:25px 0;text-align:center">
<a class="email-masthead_name" href="https://example-hermes.com/" target="_blank" style="font-size:16px;font-weight:bold;color:#2F3133;text-decoration:none;text-shadow:0 1px 0 white">

<img src="https://github.com/matcornic/hermes/blob/master/examples/gopher.png?raw=true" class="email-logo" style="max-height:50px"/>

</a>
</td>
</tr>


<tr>
<td class="email-body" width="100%" style="color:#74787E;font-size:15px;line-height:18px;width:100%;margin:0;padding:0;border-top:1px solid #EDEFF2;border-bottom:1px solid #EDEFF2;background-color:#FFF">
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0" style="width:570px;margin:0 auto;padding:0">

<tbody><tr>
<td class="content-cell" style="color:#74787E;font-size:15px;line-height:18px;padding:35px">
<h1 style="margin-top:0;color:#2F3133;font-size:19px;font-weight:bold">Hi Jon Snow,</h1>



<p style="margin-top:0;color:#74787E;font-size:16px;line-height:1.5em">Welcome to Hermes! We&#39;re very excited to have you on board.</p>


















<p style="margin-top:0;color:#74787E;font-size:16px;line-height:1.5em">Please copy your invite code:</p>



<!--[if mso]>
<div style="margin-top:30px;margin-bottom:30px">
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table align="center" cellpadding="0" cellspacing="0" style="padding:0;text-align:center">
<tr>
<td style="display:inline-block;border-radius:3px;font-family:Consolas, monaco, monospace;font-size:28px;text-align:center;letter-spacing:8px;color:#555;background-color:#eee;padding:20px">
123456
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<![endif]-->
<!--[if !mso]><!-- -->
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0" style="width:100%;margin:30px auto;padding:0;text-align:center">
<tbody><tr>
<td align="center" style="padding:10px 5px;color:#74787E;font-size:15px;line-height:18px">
<div>


<span class="invite-code" style="display:inline-block;padding-top:20px;padding-right:36px;padding-bottom:16px;padding-left:36px;border-radius:3px;font-family:Consolas, monaco, monospace;font-size:28px;text-align:center;letter-spacing:8px;color:#555;background-color:#eee">123456</span>

</div>
</td>
</tr>
</tbody></table>
<!--[endif]---->








<p style="margin-top:0;color:#74787E;font-size:16px;line-height:1.5em">Need help, or have questions? Just reply to this email, we&#39;d love to help.</p>




<p style="margin-top:0;color:#74787E;font-size:16px;line-height:1.5em">
Yours truly,
<br/>
Hermes
</p>



<table class="body-sub" style="width:100%;margin-top:25px;padding-top:25px;border-top:1px solid #EDEFF2;table-layout:fixed">
<tbody>



</tbody>
</table>


</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td style="padding:10px 5px;color:#74787E;font-size:15px;line-height:18px">
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0" style="width:570px;margin:0 auto;padding:0;text-align:center">
<tbody><tr>
<td class="content-cell" style="color:#74787E;font-size:15px;line-height:18px;padding:35px">
<p class="sub center" style="margin-top:0;line-height:1.5em;color:#AEAEAE;font-size:12px;text-align:center">
Copyright © 2020 Hermes. All rights reserved.
</p>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>


</body></html>
14 changes: 14 additions & 0 deletions examples/default/default.invite_code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
------------
Hi Jon Snow,
------------

Welcome to Hermes! We're very excited to have you on board.

Please copy your invite code: 123456

Need help, or have questions? Just reply to this email, we'd love to help.

Yours truly,
Hermes - https://example-hermes.com/

Copyright © 2020 Hermes. All rights reserved.
Loading

0 comments on commit b496815

Please sign in to comment.