diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 756a1a9..539efc3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -316,6 +316,28 @@ It means, if you want to create a button, the best solution is to create a case {{safe "" }} ``` +When the action is an invite code, use this kind of code: + +```html +{{ if $action.InviteCode }} +
+ + + + +
+ + + + +
+ {{ $action.InviteCode }} +
+
+
+{{ end }} +``` + ## Outro Injection The following will inject the outro text (string or array) into the e-mail: diff --git a/README.md b/README.md index a9353de..259f04f 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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) @@ -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 diff --git a/default.go b/default.go index 003148d..323fc3a 100644 --- a/default.go +++ b/default.go @@ -234,7 +234,10 @@ func (dt *Default) HTMLTemplate() string { /* Invite Code ------------------------------ */ .invite-code { display: inline-block; - padding: 20px 36px 16px 36px; + padding-top: 20px; + padding-right: 36px; + padding-bottom: 16px; + padding-left: 36px; border-radius: 3px; font-family: Consolas, monaco, monospace; font-size: 28px; @@ -377,40 +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 "" }} - {{safe ""}} - - - - -
-
- {{ if $action.InviteCode }} - {{ $action.InviteCode }} - {{ end }} - {{ if $action.Button.Text }} - - {{ $action.Button.Text }} - - {{ end }} -
-
- {{safe "" }} + {{safe "" }} + {{safe ""}} + + + + +
+
+ {{ if $action.Button.Text }} + + {{ $action.Button.Text }} + + {{end}} + {{ if $action.InviteCode }} + {{ $action.InviteCode }} + {{end}} +
+
+ {{safe "" }} {{ end }} {{ end }} {{ end }} @@ -435,12 +457,14 @@ func (dt *Default) HTMLTemplate() string { {{ range $action := . }} + {{if $action.Button.Text}} + {{ end }} {{ end }}

{{$.Hermes.Product.TroubleText | replace "{ACTION}" $action.Button.Text}}

{{ $action.Button.Link }}

diff --git a/examples/default/default.invite_code.html b/examples/default/default.invite_code.html new file mode 100644 index 0000000..6b06842 --- /dev/null +++ b/examples/default/default.invite_code.html @@ -0,0 +1,161 @@ + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/examples/default/default.invite_code.txt b/examples/default/default.invite_code.txt new file mode 100644 index 0000000..3ffd46d --- /dev/null +++ b/examples/default/default.invite_code.txt @@ -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. \ No newline at end of file diff --git a/examples/default/default.receipt.html b/examples/default/default.receipt.html index 1f2cc41..a07df81 100644 --- a/examples/default/default.receipt.html +++ b/examples/default/default.receipt.html @@ -128,35 +128,41 @@

Hi Jon Sn - - - - -
- + + + + + + + + +
+ +
+ @@ -175,12 +181,14 @@

Hi Jon Sn + +

If you’re having trouble with the button 'Go to Dashboard', copy and paste the URL below into your web browser.

https://hermes-example.com/dashboard

diff --git a/examples/default/default.reset.html b/examples/default/default.reset.html index e4f3e93..f7ee77e 100644 --- a/examples/default/default.reset.html +++ b/examples/default/default.reset.html @@ -70,35 +70,41 @@

Hi Jon Sn - - - - -
- + + + + + + + + +
+ +
+ @@ -123,12 +129,14 @@

Hi Jon Sn + +

If you’re having trouble with the button 'Reset your password', copy and paste the URL below into your web browser.

https://hermes-example.com/reset-password?token=d9729feb74992cc3482b350163a1a010

diff --git a/examples/default/default.welcome.html b/examples/default/default.welcome.html index dbafd02..15fc274 100644 --- a/examples/default/default.welcome.html +++ b/examples/default/default.welcome.html @@ -85,35 +85,41 @@

Hi Jon Sn - - - - -
- + + + + + + + + +
+ +
+ @@ -138,12 +144,14 @@

Hi Jon Sn + +

If you’re having trouble with the button 'Confirm your account', copy and paste the URL below into your web browser.

https://hermes-example.com/confirm?token=d9729feb74992cc3482b350163a1a010

diff --git a/examples/flat/flat.invite_code.html b/examples/flat/flat.invite_code.html new file mode 100644 index 0000000..d557ad2 --- /dev/null +++ b/examples/flat/flat.invite_code.html @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/flat/flat.invite_code.txt b/examples/flat/flat.invite_code.txt new file mode 100644 index 0000000..3ffd46d --- /dev/null +++ b/examples/flat/flat.invite_code.txt @@ -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. \ No newline at end of file diff --git a/examples/flat/flat.receipt.html b/examples/flat/flat.receipt.html index a602276..d05aa32 100644 --- a/examples/flat/flat.receipt.html +++ b/examples/flat/flat.receipt.html @@ -121,6 +121,7 @@

Hi Jon Sn

You can check the status of your order and more in your dashboard:

-
- - + + @@ -167,6 +173,7 @@

Hi Jon Sn + +

If you’re having trouble with the button 'Go to Dashboard', copy and paste the URL below into your web browser.

@@ -174,6 +181,7 @@

Hi Jon Sn

diff --git a/examples/flat/flat.reset.html b/examples/flat/flat.reset.html index f0f64a2..e6dc621 100644 --- a/examples/flat/flat.reset.html +++ b/examples/flat/flat.reset.html @@ -63,6 +63,7 @@

Hi Jon Sn

Click the button below to reset your password:

-
- - + + @@ -115,6 +121,7 @@

Hi Jon Sn + +

If you’re having trouble with the button 'Reset your password', copy and paste the URL below into your web browser.

@@ -122,6 +129,7 @@

Hi Jon Sn

diff --git a/examples/flat/flat.welcome.html b/examples/flat/flat.welcome.html index a6a762c..988dbfb 100644 --- a/examples/flat/flat.welcome.html +++ b/examples/flat/flat.welcome.html @@ -78,6 +78,7 @@

Hi Jon Sn

To get started with Hermes, please click here:

-
- - + + @@ -130,6 +136,7 @@

Hi Jon Sn + +

If you’re having trouble with the button 'Confirm your account', copy and paste the URL below into your web browser.

@@ -137,6 +144,7 @@

Hi Jon Sn

diff --git a/examples/invite_code.go b/examples/invite_code.go new file mode 100644 index 0000000..fb39caf --- /dev/null +++ b/examples/invite_code.go @@ -0,0 +1,32 @@ +package main + +import ( + "github.com/matcornic/hermes/v2" +) + +type inviteCode struct { +} + +func (w *inviteCode) Name() string { + return "invite_code" +} + +func (w *inviteCode) 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.", + }, + Actions: []hermes.Action{ + { + Instructions: "Please copy your invite code:", + InviteCode: "123456", + }, + }, + Outros: []string{ + "Need help, or have questions? Just reply to this email, we'd love to help.", + }, + }, + } +} diff --git a/examples/main.go b/examples/main.go index edd3054..dcf8761 100644 --- a/examples/main.go +++ b/examples/main.go @@ -33,6 +33,7 @@ func main() { new(reset), new(receipt), new(maintenance), + new(inviteCode), } themes := []hermes.Theme{ diff --git a/flat.go b/flat.go index 1e4949b..13992a6 100644 --- a/flat.go +++ b/flat.go @@ -240,7 +240,10 @@ func (dt *Flat) HTMLTemplate() string { /* Invite Code ------------------------------ */ .invite-code { display: inline-block; - padding: 20px 36px 16px 36px; + padding-top: 20px; + padding-right: 36px; + padding-bottom: 16px; + padding-left: 36px; border-radius: 3px; font-family: Consolas, monaco, monospace; font-size: 28px; @@ -376,6 +379,7 @@ func (dt *Flat) HTMLTemplate() string { {{ range $action := . }}

{{ $action.Instructions }}

{{safe "" }} {{safe ""}}
- {{ if $action.InviteCode }} - {{ $action.InviteCode }} - {{ end }} {{ if $action.Button.Text }} {{ $action.Button.Text }} - {{ end }} + {{end}} + {{ if $action.InviteCode }} + {{ $action.InviteCode }} + {{end}}
- {{safe ""}} - {{ end }} + {{safe "" }} + {{ end }} {{ end }} {{ end }} @@ -433,6 +455,7 @@ func (dt *Flat) HTMLTemplate() string { {{ range $action := . }} + {{if $action.Button.Text}} {{ end }} + {{ end }}

{{$.Hermes.Product.TroubleText | replace "{ACTION}" $action.Button.Text}}

@@ -440,6 +463,7 @@ func (dt *Flat) HTMLTemplate() string {
{{ end }} diff --git a/hermes_test.go b/hermes_test.go index 303b7a6..6197ce6 100644 --- a/hermes_test.go +++ b/hermes_test.go @@ -250,6 +250,44 @@ func (ed *WithSignatureDifferentThanDefault) assertPlainTextContent(t *testing.T assert.Contains(t, r, "Best regards", "Should have greeting with Dear") } +type WithInviteCode struct { + theme Theme +} + +func (ed *WithInviteCode) getExample() (Hermes, Email) { + h := Hermes{ + Theme: ed.theme, + Product: Product{ + Name: "Hermes", + Link: "http://hermes.com", + }, + DisableCSSInlining: true, + } + + email := Email{ + Body{ + Name: "Jon Snow", + Actions: []Action{ + { + Instructions: "Here is your invite code:", + InviteCode: "123456", + }, + }, + }, + } + return h, email +} + +func (ed *WithInviteCode) assertHTMLContent(t *testing.T, r string) { + assert.Contains(t, r, "Here is your invite code", "Should contains the instruction") + assert.Contains(t, r, "123456", "Should contain the short code") +} + +func (ed *WithInviteCode) assertPlainTextContent(t *testing.T, r string) { + assert.Contains(t, r, "Here is your invite code", "Should contains the instruction") + assert.Contains(t, r, "123456", "Should contain the short code") +} + type WithFreeMarkdownContent struct { theme Theme } @@ -380,6 +418,12 @@ func TestThemeWithFreeMarkdownContent(t *testing.T) { } } +func TestThemeWithInviteCode(t *testing.T) { + for _, theme := range testedThemes { + checkExample(t, &WithInviteCode{theme}) + } +} + func checkExample(t *testing.T, ex Example) { // Given an example h, email := ex.getExample()