diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7512d1a..dead767 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,12 +20,15 @@ This file contains instructions on adding themes to Mailgen: * [Creating a Built-In Theme](#creating-a-built-in-theme) > We use Golang templates under the hood to inject the e-mail body into themes. +> - [Official guide](https://golang.org/pkg/text/template/) +> - [Tutorial](https://astaxie.gitbooks.io/build-web-application-with-golang/en/07.4.html) +> - [Hugo guide](https://gohugo.io/templates/go-templates/) ### 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): -1. Create a new struct implementing `Theme` interface ([hermes.go](hermes.go)). An real-life example is in [default.go](default.go) +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 ```go @@ -70,11 +73,11 @@ If you want to create a new **built-in** Mailgen 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 3. Copy content of [default.go](default.go) file in new file and make any necessary changes -6. Scroll down to the [injection snippets](#injection-snippets) and copy and paste each code snippet into the relevant area of your template markup -7. Test the theme by running the `examples/*.js` scripts (insert your theme name in each script) and observing the template output in `preview.html` -8. Take a screenshot of your theme portraying each example and place it in `screenshots/{theme}/{example}.png` -9. Add the theme name, credit, and screenshots to the `README.md` file's [Supported Themes](README.md#supported-themes) section (copy one of the existing themes' markup and modify it accordingly) -7. Submit a pull request with your changes and we'll let you know if anything's missing! +4. Scroll down to the [injection snippets](#injection-snippets) and copy and paste each code snippet into the relevant area of your template markup +5. Test the theme by adding the theme to slice of tested themes (see [hermes_test.go](hermes_test.go)). A set of tests will be run to check that your theme follows features of Hermes. +6. Create examples in new folder for your theme in `examples` folder and run `go run *.go`. It will generate the different `html` and `plaintext` emails for your different examples. Follow the same examples as default theme (3 examples: Welcome, Reset and Receipt) +7. Add the theme name, credit, and screenshots to the `README.md` file's [Supported Themes](README.md#supported-themes) section (copy one of the existing themes' markup and modify it accordingly) +8. Submit a pull request with your changes and we'll let you know if anything's missing! Thanks again for your contribution! @@ -85,12 +88,12 @@ Thanks again for your contribution! The following will inject either the product logo or name into the template. ```html - - <% if (locals.product.logo) { %> - - <% } else { %> - <%- product.name %> - <% } %> + + {{ if .Hermes.Product.Logo }} + + {{ else }} + {{ .Hermes.Product.Name }} + {{ end }} ``` @@ -107,7 +110,7 @@ It's a good idea to add the following CSS declaration to set `max-height: 50px` The following will inject the e-mail title (Hi John Appleseed,) or a custom title provided by the user: ```html -<%- title %> +
<%- introItem %>
- <% }) -%> -<% } %> +{{ with .Email.Body.Intros }} + {{ if gt (len .) 0 }} + {{ range $line := . }} +{{ $line }}
+ {{ end }} + {{ end }} +{{ end }} ``` ## Dictionary Injection @@ -127,15 +132,16 @@ The following will inject the intro text (string or array) into the e-mail: The following will inject a `
- width="<%= table.columns.customWidth[column] %>"
- <% } %>
- <% if(locals.table.columns && locals.table.columns.customAlignment && locals.table.columns.customAlignment[column]) { %>
- style="text-align:<%= table.columns.customAlignment[column] %>"
- <% } %>
- >
- <%- column.charAt(0).toUpperCase() + column.slice(1) %> - |
- <% } %>
- ||||
---|---|---|---|---|
- style="text-align:<%= table.columns.customAlignment[column] %>"
- <% } %>
- >
- <%- table.data[i][column] %>
+{{ with .Email.Body.Table }}
+{{ $data := .Data }}
+{{ $columns := .Columns }}
+ {{ if gt (len $data) 0 }}
+
|
<%- actionItem.instructions %>
- - <%- actionItem.button.text %> - - <% }) -%> -<% } %> +{{ with .Email.Body.Actions }} + {{ if gt (len .) 0 }} + {{ range $action := . }} +{{ $action.Instructions }}
++ + | +
+ If you’re having trouble with the button '{{ $action.Button.Text }}', copy and paste the URL below into your web browser. + + |
+ {{ end }}
+
<%- outroItem %>
- <% }) -%> -<% } %> +{{ with .Email.Body.Outros }} + {{ if gt (len .) 0 }} + {{ range $line := . }} +{{ $line }}
+ {{ end }} + {{ end }} +{{ end }} ``` ## Signature Injection @@ -277,9 +313,9 @@ The following will inject the outro text (string or array) into the e-mail: The following will inject the signature phrase (e.g. Yours truly) along with the product name into the e-mail: ```html -<%- signature %>, -
- {{.Email.Body.Signature}},
-
- {{.Hermes.Product.Name}}
-
+ {{.Email.Body.Signature}},
+
+ {{.Hermes.Product.Name}}
+