From 44be3778410a55d7aa5f6951118d4c70de9cc0ad Mon Sep 17 00:00:00 2001 From: Frido Koch Date: Sat, 13 May 2017 13:43:57 +0200 Subject: [PATCH 1/3] Possibility to customise 'Action Trouble Text' --- default.go | 2 +- hermes.go | 14 ++++++++------ hermes_test.go | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/default.go b/default.go index 19d5f83..bf0d5c9 100644 --- a/default.go +++ b/default.go @@ -346,7 +346,7 @@ func (dt *Default) HTMLTemplate() string { {{ range $action := . }} -

If you’re having trouble with the button '{{ $action.Button.Text }}', copy and paste the URL below into your web browser.

+

{{printf $.Hermes.Product.TroubleText $action.Button.Text}}

{{ $action.Button.Link }}

diff --git a/hermes.go b/hermes.go index 374ca20..d17da81 100644 --- a/hermes.go +++ b/hermes.go @@ -33,10 +33,11 @@ const TDRightToLeft TextDirection = "rtl" // Product represents your company product (brand) // Appears in header & footer of e-mails type Product struct { - Name string - Link string // e.g. https://matcornic.github.io - Logo string // e.g. https://matcornic.github.io/img/logo.png - Copyright string // Copyright © 2017 Hermes. All rights reserved. + Name string + Link string // e.g. https://matcornic.github.io + Logo string // e.g. https://matcornic.github.io/img/logo.png + Copyright string // Copyright © 2017 Hermes. All rights reserved. + TroubleText string // TroubleText is the sentence at the end of the email for users having trouble with the button (default to `If you’re having trouble with the button %s, copy and paste the URL below into your web browser.`) } // Email is the email containing a body @@ -120,8 +121,9 @@ func setDefaultHermesValues(h *Hermes) error { Theme: new(Default), TextDirection: defaultTextDirection, Product: Product{ - Name: "Hermes", - Copyright: "Copyright © 2017 Hermes. All rights reserved.", + Name: "Hermes", + Copyright: "Copyright © 2017 Hermes. All rights reserved.", + TroubleText: "If you’re having trouble with the button '%s', copy and paste the URL below into your web browser.", }, } // Merge the given hermes engine configuration with default one diff --git a/hermes_test.go b/hermes_test.go index 47bc131..87d3ef9 100644 --- a/hermes_test.go +++ b/hermes_test.go @@ -102,7 +102,7 @@ func (ed *SimpleExample) assertHTMLContent(t *testing.T, r string) { assert.Contains(t, r, "http://hermes-link.com", "Product: Should find the link of the product in email") assert.Contains(t, r, "Copyright © Hermes-Test", "Product: Should find the Copyright of the product in email") assert.Contains(t, r, "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png", "Product: Should find the logo of the product in email") - + assert.Contains(t, r, "If you’re having trouble with the button 'Confirm your account', copy and paste the URL below into your web browser.", "Product: Should find the trouble text in email") // Assert on email body assert.Contains(t, r, "Hi Jon Snow", "Name: Should find the name of the person") assert.Contains(t, r, "Welcome to Hermes", "Intro: Should have intro") From 27e2a1a02c23350a4f0f4fd3a0f438486cfe564d Mon Sep 17 00:00:00 2001 From: Frido Koch Date: Sun, 14 May 2017 11:52:11 +0200 Subject: [PATCH 2/3] Use fixed placeholder rather then printf --- CONTRIBUTING.md | 6 +++--- README.md | 14 ++++++++++++++ default.go | 2 +- hermes.go | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 81e1d47..66b66e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -276,15 +276,15 @@ The following will inject the action link (or button) into the e-mail: {{ end }} ``` -A good practice is to describe action in footer in case of problem when displaying button and CSS +A good practice is to describe action in footer in case of problem when displaying button and CSS. The text for the description is provided through the `TroubleText` field of the `Product` struct. The text may contain a placeholder `{ACTION}` which is expected to be replaced with the text of the button. The default value of `TroubleText` is `If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.` ```html -{{ with .Email.Body.Actions }} +{{ with .Email.Body.Actions }} {{ range $action := . }} {{ end }} diff --git a/README.md b/README.md index 5742bba..003cc15 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,20 @@ h := hermes.Hermes{ } ``` +To use a custom fallback text at the end of the email, change the `TroubleText` field of the `hermes.Product` struct. The default value is `If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.`. The `{ACTION}` placeholder will be replaced with the corresponding text of the supplied action button: + +```go +// Configure hermes by setting a theme and your product info +h := hermes.Hermes{ + // Optional Theme + // Theme: new(Default) + Product: hermes.Product{ + // Custom trouble text + Copyright: "If the {ACTION}-button is not working for you, just copy and paste the URL below into your web browser." + }, +} +``` + ## Elements Hermes supports injecting custom elements such as dictionaries, tables and action buttons into e-mails. diff --git a/default.go b/default.go index bf0d5c9..c632288 100644 --- a/default.go +++ b/default.go @@ -346,7 +346,7 @@ func (dt *Default) HTMLTemplate() string { {{ range $action := . }} diff --git a/hermes.go b/hermes.go index d17da81..d76d5f2 100644 --- a/hermes.go +++ b/hermes.go @@ -37,7 +37,7 @@ type Product struct { Link string // e.g. https://matcornic.github.io Logo string // e.g. https://matcornic.github.io/img/logo.png Copyright string // Copyright © 2017 Hermes. All rights reserved. - TroubleText string // TroubleText is the sentence at the end of the email for users having trouble with the button (default to `If you’re having trouble with the button %s, copy and paste the URL below into your web browser.`) + TroubleText string // TroubleText is the sentence at the end of the email for users having trouble with the button (default to `If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.`) } // Email is the email containing a body @@ -123,7 +123,7 @@ func setDefaultHermesValues(h *Hermes) error { Product: Product{ Name: "Hermes", Copyright: "Copyright © 2017 Hermes. All rights reserved.", - TroubleText: "If you’re having trouble with the button '%s', copy and paste the URL below into your web browser.", + TroubleText: "If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.", }, } // Merge the given hermes engine configuration with default one From 8ab23550253f56220f3bed7f6cd01d0b65a6d5f9 Mon Sep 17 00:00:00 2001 From: Frido Koch Date: Wed, 17 May 2017 10:46:27 +0200 Subject: [PATCH 3/3] Fixed README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 003cc15..79d0acd 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ To customize the `Copyright`, override it when initializing `Hermes` within your // Configure hermes by setting a theme and your product info h := hermes.Hermes{ // Optional Theme - // Theme: new(Default) + // Theme: new(Default) Product: hermes.Product{ // Appears in header & footer of e-mails Name: "Hermes", @@ -177,7 +177,7 @@ h := hermes.Hermes{ // Theme: new(Default) Product: hermes.Product{ // Custom trouble text - Copyright: "If the {ACTION}-button is not working for you, just copy and paste the URL below into your web browser." + TroubleText: "If the {ACTION}-button is not working for you, just copy and paste the URL below into your web browser." }, } ```
-

If you’re having trouble with the button '{{ $action.Button.Text }}', copy and paste the URL below into your web browser.

+

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

{{ $action.Button.Link }}

-

{{printf $.Hermes.Product.TroubleText $action.Button.Text}}

+

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

{{ $action.Button.Link }}