@ -14,7 +14,7 @@ Excellent! You've come to the right place.
 | 
			
		||||
 | 
			
		||||
## Theming Instructions
 | 
			
		||||
 | 
			
		||||
This file contains instructions on adding themes to Mailgen:
 | 
			
		||||
This file contains instructions on adding themes to Hermes:
 | 
			
		||||
 | 
			
		||||
* [Using a Custom Theme](#using-a-custom-theme)
 | 
			
		||||
* [Creating a Built-In Theme](#creating-a-built-in-theme)
 | 
			
		||||
@ -26,7 +26,7 @@ This file contains instructions on adding themes to Mailgen:
 | 
			
		||||
 | 
			
		||||
### Using a Custom Theme
 | 
			
		||||
 | 
			
		||||
If you want to supply your own **custom theme** for Hermes to use (but don't want it included with Mailgen):
 | 
			
		||||
If you want to supply your own **custom theme** for Hermes to use (but don't want it included with Hermes):
 | 
			
		||||
 | 
			
		||||
1. Create a new struct implementing `Theme` interface ([hermes.go](hermes.go)). A real-life example is in [default.go](default.go)
 | 
			
		||||
2. Supply your new theme at hermes creation
 | 
			
		||||
@ -68,7 +68,7 @@ h := hermes.Hermes{
 | 
			
		||||
 | 
			
		||||
### Creating a Built-In Theme
 | 
			
		||||
 | 
			
		||||
If you want to create a new **built-in** Mailgen theme:
 | 
			
		||||
If you want to create a new **built-in** Hermes theme:
 | 
			
		||||
 | 
			
		||||
1. Fork the repository to your GitHub account and clone it to your computer
 | 
			
		||||
2. Create a new Go file named after your new theme
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										25
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								README.md
									
									
									
									
									
								
							@ -5,12 +5,12 @@
 | 
			
		||||
[](https://codecov.io/github/matcornic/hermes/)
 | 
			
		||||
[](https://godoc.org/github.com/matcornic/hermes)
 | 
			
		||||
 | 
			
		||||
Hermes is the Go port of the great [mailgen](https://github.com/eladnava/mailgen) engine for Node.js. Check their work, it's awesome !
 | 
			
		||||
It's a package that generates clean, responsive HTML e-mails for sending transactional e-mails (welcome e-mail, reset password e-mails, receipt e-mails and so on).
 | 
			
		||||
Hermes is the Go port of the great [mailgen](https://github.com/eladnava/mailgen) engine for Node.js. Check their work, it's awesome!
 | 
			
		||||
It's a package that generates clean, responsive HTML e-mails for sending transactional e-mails (welcome e-mails, reset password e-mails, receipt e-mails and so on).
 | 
			
		||||
 | 
			
		||||
# Demo
 | 
			
		||||
 | 
			
		||||
<img src="https://raw.github.com/matcornic/hermes/master/screens/default/welcome.png" height="400" /> <img src="https://raw.github.com/matcornic/hermes/master/screens/default/reset.png" height="400" /> <img src="https://raw.github.com/matcornic/hermes/master/screens/default/receipt.png" height="400" />
 | 
			
		||||
<img src="screens/default/welcome.png" height="400" /> <img src="screens/default/reset.png" height="400" /> <img src="screens/default/receipt.png" height="400" />
 | 
			
		||||
 | 
			
		||||
# Usage
 | 
			
		||||
 | 
			
		||||
@ -31,8 +31,8 @@ h := hermes.Hermes{
 | 
			
		||||
        // Appears in header & footer of e-mails
 | 
			
		||||
        Name: "Hermes",
 | 
			
		||||
        Link: "https://example-hermes.com/",
 | 
			
		||||
        //Option product logo
 | 
			
		||||
        //Logo: "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png",
 | 
			
		||||
        // Option product logo
 | 
			
		||||
        // Logo: "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png",
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
@ -62,7 +62,7 @@ email := hermes.Email{
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Generate an HTML email with the provided contents(for modern clients)
 | 
			
		||||
// Generate an HTML email with the provided contents (for modern clients)
 | 
			
		||||
emailBody, err := h.GenerateHTML(email)
 | 
			
		||||
if err != nil {
 | 
			
		||||
    panic(err) // Tip: Handle error with something else than a panic ;)
 | 
			
		||||
@ -74,7 +74,7 @@ if err != nil {
 | 
			
		||||
    panic(err) // Tip: Handle error with something else than a panic ;)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Optionnaly, preview the generated HTML e-mail by writing it to a local file
 | 
			
		||||
// Optionally, preview the generated HTML e-mail by writing it to a local file
 | 
			
		||||
err = ioutil.WriteFile("preview.html", []byte(emailBody), 0644)
 | 
			
		||||
if err != nil {
 | 
			
		||||
    panic(err) // Tip: Handle error with something else than a panic ;)
 | 
			
		||||
@ -83,7 +83,7 @@ if err != nil {
 | 
			
		||||
 | 
			
		||||
This code would output the following HTML template:
 | 
			
		||||
 | 
			
		||||
<img src="https://raw.github.com/matcornic/hermes/master/screens/demo.png" height="400" />
 | 
			
		||||
<img src="screens/demo.png" height="400" />
 | 
			
		||||
 | 
			
		||||
> Theme templates will be embedded in your application binary. If you want to use external templates (for configuration), use your own theme by implementing `hermes.Theme` interface with code searching for your files.
 | 
			
		||||
 | 
			
		||||
@ -113,7 +113,7 @@ The following open-source themes are bundled with this package:
 | 
			
		||||
 | 
			
		||||
* `default` by [Postmark Transactional Email Templates](https://github.com/wildbit/postmark-templates)
 | 
			
		||||
 | 
			
		||||
<img src="https://raw.github.com/matcornic/hermes/master/screens/default/welcome.png" height="200" /> <img src="https://raw.github.com/matcornic/hermes/master/screens/default/reset.png" height="200" /> <img src="https://raw.github.com/matcornic/hermes/master/screens/default/receipt.png" height="200" />
 | 
			
		||||
<img src="screens/default/welcome.png" height="200" /> <img src="screens/default/reset.png" height="200" /> <img src="screens/default/receipt.png" height="200" />
 | 
			
		||||
 | 
			
		||||
## RTL Support
 | 
			
		||||
 | 
			
		||||
@ -129,13 +129,13 @@ h := hermes.Hermes {
 | 
			
		||||
 | 
			
		||||
## Language Customizations
 | 
			
		||||
 | 
			
		||||
To customize the e-mail greeting (Hi) or signature (Yours truly), supply custom strings within the e-mail `Body`:
 | 
			
		||||
To customize the e-mail's greeting ("Hi") or signature ("Yours truly"), supply custom strings within the e-mail's `Body`:
 | 
			
		||||
 | 
			
		||||
```go
 | 
			
		||||
email := hermes.Email{
 | 
			
		||||
    Body: hermes.Body{
 | 
			
		||||
        Greeting: "Dear",
 | 
			
		||||
        Signature: "Sincerly",
 | 
			
		||||
        Signature: "Sincerely",
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
@ -146,7 +146,7 @@ To use a custom title string rather than a greeting/name introduction, provide i
 | 
			
		||||
email := hermes.Email{
 | 
			
		||||
    Body: hermes.Body{
 | 
			
		||||
        // Title will override `Name`
 | 
			
		||||
        Title: "Welcome to Mailgen",
 | 
			
		||||
        Title: "Welcome to Hermes",
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
@ -176,7 +176,6 @@ Hermes supports injecting custom elements such as dictionaries, tables and actio
 | 
			
		||||
 | 
			
		||||
To inject an action button in to the e-mail, supply the `Actions` object as follows:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
```go
 | 
			
		||||
email := hermes.Email{
 | 
			
		||||
    Body: hermes.Body{
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										218
									
								
								default.go
									
									
									
									
									
								
							
							
						
						
									
										218
									
								
								default.go
									
									
									
									
									
								
							@ -227,6 +227,7 @@ func (dt *Default) HTMLTemplate() string {
 | 
			
		||||
                </a>
 | 
			
		||||
            </td>
 | 
			
		||||
          </tr>
 | 
			
		||||
 | 
			
		||||
          <!-- Email Body -->
 | 
			
		||||
          <tr>
 | 
			
		||||
            <td class="email-body" width="100%">
 | 
			
		||||
@ -235,121 +236,124 @@ func (dt *Default) HTMLTemplate() string {
 | 
			
		||||
                <tr>
 | 
			
		||||
                  <td class="content-cell">
 | 
			
		||||
                    <h1>{{if .Email.Body.Title }}{{ .Email.Body.Title }}{{ else }}{{ .Email.Body.Greeting }} {{ .Email.Body.Name }},{{ end }}</h1>
 | 
			
		||||
					{{ with .Email.Body.Intros }}
 | 
			
		||||
					{{ if gt (len .) 0 }}
 | 
			
		||||
					{{ range $line := . }}
 | 
			
		||||
					<p>{{ $line }}</p>
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					{{ end }}
 | 
			
		||||
                    {{ with .Email.Body.Intros }}
 | 
			
		||||
                      {{ if gt (len .) 0 }}
 | 
			
		||||
                        {{ range $line := . }}
 | 
			
		||||
                          <p>{{ $line }}</p>
 | 
			
		||||
                        {{ end }}
 | 
			
		||||
                      {{ end }}
 | 
			
		||||
                    {{ end }}
 | 
			
		||||
 | 
			
		||||
					{{ with .Email.Body.Dictionary }} 
 | 
			
		||||
					{{ if gt (len .) 0 }}
 | 
			
		||||
					<dl class="body-dictionary">
 | 
			
		||||
					{{ range $entry := . }}
 | 
			
		||||
						<dt>{{ $entry.Key }}:</dt>
 | 
			
		||||
                        <dd>{{ $entry.Value }}</dd>
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					 </dl>
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					{{ end }}
 | 
			
		||||
                    {{ with .Email.Body.Dictionary }} 
 | 
			
		||||
                      {{ if gt (len .) 0 }}
 | 
			
		||||
                        <dl class="body-dictionary">
 | 
			
		||||
                          {{ range $entry := . }}
 | 
			
		||||
                            <dt>{{ $entry.Key }}:</dt>
 | 
			
		||||
                            <dd>{{ $entry.Value }}</dd>
 | 
			
		||||
                          {{ end }}
 | 
			
		||||
                        </dl>
 | 
			
		||||
                      {{ end }}
 | 
			
		||||
                    {{ end }}
 | 
			
		||||
 | 
			
		||||
					<!-- Table -->
 | 
			
		||||
					{{ with .Email.Body.Table }}
 | 
			
		||||
					{{ $data := .Data }}
 | 
			
		||||
					{{ $columns := .Columns }}
 | 
			
		||||
					{{ if gt (len $data) 0 }}
 | 
			
		||||
					<table class="data-wrapper" width="100%" cellpadding="0" cellspacing="0">
 | 
			
		||||
                      <tr>
 | 
			
		||||
                        <td colspan="2">
 | 
			
		||||
                          <table class="data-table" width="100%" cellpadding="0" cellspacing="0">
 | 
			
		||||
                    <!-- Table -->
 | 
			
		||||
                    {{ with .Email.Body.Table }}
 | 
			
		||||
                      {{ $data := .Data }}
 | 
			
		||||
                      {{ $columns := .Columns }}
 | 
			
		||||
                      {{ if gt (len $data) 0 }}
 | 
			
		||||
                        <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>
 | 
			
		||||
                                  {{ $col := index $data 0 }}
 | 
			
		||||
                                  {{ range $entry := $col }}
 | 
			
		||||
                                    <th
 | 
			
		||||
                                      {{ with $columns }}
 | 
			
		||||
                                        {{ $width := index .CustomWidth $entry.Key }}
 | 
			
		||||
                                        {{ with $width }}
 | 
			
		||||
                                          width="{{ . }}"
 | 
			
		||||
                                        {{ end }}
 | 
			
		||||
                                        {{ $align := index .CustomAlignement $entry.Key }}
 | 
			
		||||
                                        {{ with $align }}
 | 
			
		||||
                                          style="text-align:{{ . }}"
 | 
			
		||||
                                        {{ end }}
 | 
			
		||||
                                      {{ end }}
 | 
			
		||||
                                    >
 | 
			
		||||
                                      <p>{{ $entry.Key }}</p>
 | 
			
		||||
                                    </th>
 | 
			
		||||
                                  {{ end }}
 | 
			
		||||
                                </tr>
 | 
			
		||||
                                {{ range $row := $data }}
 | 
			
		||||
                                  <tr>
 | 
			
		||||
                                    {{ range $cell := $row }}
 | 
			
		||||
                                      <td
 | 
			
		||||
                                        {{ with $columns }}
 | 
			
		||||
                                          {{ $align := index .CustomAlignement $cell.Key }}
 | 
			
		||||
                                          {{ with $align }}
 | 
			
		||||
                                            style="text-align:{{ . }}"
 | 
			
		||||
                                          {{ end }}
 | 
			
		||||
                                        {{ end }}
 | 
			
		||||
                                      >
 | 
			
		||||
                                        {{ $cell.Value }}
 | 
			
		||||
                                      </td>
 | 
			
		||||
                                    {{ end }}
 | 
			
		||||
                                  </tr>
 | 
			
		||||
                                {{ end }}
 | 
			
		||||
                              </table>
 | 
			
		||||
                            </td>
 | 
			
		||||
                          </tr>
 | 
			
		||||
                        </table>
 | 
			
		||||
                      {{ end }}
 | 
			
		||||
                    {{ end }}
 | 
			
		||||
 | 
			
		||||
                    <!-- Action -->
 | 
			
		||||
                    {{ with .Email.Body.Actions }}
 | 
			
		||||
                      {{ if gt (len .) 0 }}
 | 
			
		||||
                        {{ range $action := . }}
 | 
			
		||||
                          <p>{{ $action.Instructions }}</p>
 | 
			
		||||
                          <table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
 | 
			
		||||
                            <tr>
 | 
			
		||||
								{{ $col := index $data 0 }}
 | 
			
		||||
								{{ range $entry := $col }}
 | 
			
		||||
                                <th
 | 
			
		||||
									{{ with $columns }}
 | 
			
		||||
										{{ $width := index .CustomWidth $entry.Key }}
 | 
			
		||||
										{{ with $width }}
 | 
			
		||||
										width="{{ . }}"
 | 
			
		||||
										{{ end }}
 | 
			
		||||
										{{ $align := index .CustomAlignement $entry.Key }}
 | 
			
		||||
										{{ with $align }}
 | 
			
		||||
										style="text-align:{{ . }}"
 | 
			
		||||
										{{ end }}
 | 
			
		||||
									{{ end }}
 | 
			
		||||
								>
 | 
			
		||||
                                  <p>{{ $entry.Key }}</p>
 | 
			
		||||
                                </th>
 | 
			
		||||
                              	{{ end }}
 | 
			
		||||
                              <td align="center">
 | 
			
		||||
                                <div>
 | 
			
		||||
                                  <a href="{{ $action.Button.Link }}" class="button" style="background-color: {{ $action.Button.Color }}" target="_blank">
 | 
			
		||||
                                    {{ $action.Button.Text }}
 | 
			
		||||
                                  </a>
 | 
			
		||||
                                </div>
 | 
			
		||||
                              </td>
 | 
			
		||||
                            </tr>
 | 
			
		||||
							{{ range $row := $data }}
 | 
			
		||||
                            <tr>
 | 
			
		||||
                              {{ range $cell := $row }}
 | 
			
		||||
                                <td
 | 
			
		||||
									{{ with $columns }}
 | 
			
		||||
										{{ $align := index .CustomAlignement $cell.Key }}
 | 
			
		||||
										{{ with $align }}
 | 
			
		||||
										style="text-align:{{ . }}"
 | 
			
		||||
										{{ end }}
 | 
			
		||||
									{{ end }}
 | 
			
		||||
								>
 | 
			
		||||
                                {{ $cell.Value }}
 | 
			
		||||
                                </td>
 | 
			
		||||
                              {{ end }}
 | 
			
		||||
                            </tr>
 | 
			
		||||
                            {{ end }}
 | 
			
		||||
                          </table>
 | 
			
		||||
                        </td>
 | 
			
		||||
                      </tr>
 | 
			
		||||
                    </table>
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					{{ end }}
 | 
			
		||||
                        {{ end }}
 | 
			
		||||
                      {{ end }}
 | 
			
		||||
                    {{ end }}
 | 
			
		||||
 | 
			
		||||
					<!-- Action -->
 | 
			
		||||
					{{ with .Email.Body.Actions }}
 | 
			
		||||
					{{ if gt (len .) 0 }}
 | 
			
		||||
					{{ range $action := . }}
 | 
			
		||||
					<p>{{ $action.Instructions }}</p>
 | 
			
		||||
					<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="background-color: {{ $action.Button.Color }}" target="_blank">{{ $action.Button.Text }}</a>
 | 
			
		||||
							</div>
 | 
			
		||||
							</td>
 | 
			
		||||
						</tr>
 | 
			
		||||
                    </table>
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					{{ end }}
 | 
			
		||||
                    {{ with .Email.Body.Outros }} 
 | 
			
		||||
                      {{ if gt (len .) 0 }}
 | 
			
		||||
                        {{ range $line := . }}
 | 
			
		||||
                          <p>{{ $line }}</p>
 | 
			
		||||
                        {{ end }}
 | 
			
		||||
                      {{ end }}
 | 
			
		||||
                    {{ end }}
 | 
			
		||||
 | 
			
		||||
					{{ with .Email.Body.Outros }} 
 | 
			
		||||
					{{ if gt (len .) 0 }}
 | 
			
		||||
					{{ range $line := . }}
 | 
			
		||||
					<p>{{ $line }}</p>
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					{{ end }}
 | 
			
		||||
					{{ end }}
 | 
			
		||||
                    <p>
 | 
			
		||||
                      {{.Email.Body.Signature}},
 | 
			
		||||
                      <br />
 | 
			
		||||
                      {{.Hermes.Product.Name}}
 | 
			
		||||
                    </p>
 | 
			
		||||
 | 
			
		||||
          <p>
 | 
			
		||||
            {{.Email.Body.Signature}},
 | 
			
		||||
            <br>
 | 
			
		||||
            {{.Hermes.Product.Name}}
 | 
			
		||||
          </p>
 | 
			
		||||
 | 
			
		||||
					{{ 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"><a href="{{ $action.Button.Link }}">{{ $action.Button.Link }}</a></p>
 | 
			
		||||
                      </td>
 | 
			
		||||
					  {{ end }}
 | 
			
		||||
					  </tr>
 | 
			
		||||
					  </tbody>
 | 
			
		||||
					</table>
 | 
			
		||||
					{{ end }}
 | 
			
		||||
                    {{ 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"><a href="{{ $action.Button.Link }}">{{ $action.Button.Link }}</a></p>
 | 
			
		||||
                              </td>
 | 
			
		||||
                            {{ end }}
 | 
			
		||||
                          </tr>
 | 
			
		||||
                        </tbody>
 | 
			
		||||
                      </table>
 | 
			
		||||
                    {{ end }}
 | 
			
		||||
                  </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
              </table>
 | 
			
		||||
 | 
			
		||||
@ -124,7 +124,7 @@ func setDefaultHermesValues(h *Hermes) error {
 | 
			
		||||
			Copyright: "Copyright © 2017 Hermes. All rights reserved.",
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	// Merge the given hermes engine coniguration with default one
 | 
			
		||||
	// Merge the given hermes engine configuration with default one
 | 
			
		||||
	// Default one overrides all zero values
 | 
			
		||||
	err := mergo.Merge(h, defaultHermes)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user