Skip to content
Permalink
Browse files

Merge pull request matcornic#8 from fridolin-koch/master

Customisation of 'Trouble Text'
  • Loading branch information...
matcornic committed May 17, 2017
2 parents 8fb17c0 + 8ab2355 commit 6604b0a15906653e29793175d148d950a8a68482
Showing with 28 additions and 12 deletions.
  1. +3 −3 CONTRIBUTING.md
  2. +15 −1 README.md
  3. +1 −1 default.go
  4. +8 −6 hermes.go
  5. +1 −1 hermes_test.go
@@ -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 }}
<table class="body-sub">
<tbody><tr>
{{ range $action := . }}
<td>
<p class="sub">If you’re having trouble with the button '{{ $action.Button.Text }}', copy and paste the URL below into your web browser.</p>
<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>
{{ end }}
@@ -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",
@@ -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
TroubleText: "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.
@@ -346,7 +346,7 @@ func (dt *Default) HTMLTemplate() string {
{{ range $action := . }}
<tr>
<td>
<p class="sub">If you’re having trouble with the button '{{ $action.Button.Text }}', copy and paste the URL below into your web browser.</p>
<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>
@@ -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 '{ACTION}', 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 '{ACTION}', copy and paste the URL below into your web browser.",
},
}
// Merge the given hermes engine configuration with default one
@@ -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 &#39;Confirm your account&#39;, 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")

0 comments on commit 6604b0a

Please sign in to comment.
You can’t perform that action at this time.