# Contributing Thanks so much for wanting to help! We really appreciate it. * Have an idea for a new feature? * Want to add a new built-in theme? Excellent! You've come to the right place. 1. If you find a bug or wish to suggest a new feature, please create an issue first 2. Make sure your code & comment conventions are in-line with the project's style (execute gometalinter as in [.travis.yml](.travis.yml) file) 3. Make your commits and PRs as tiny as possible - one feature or bugfix at a time 4. Write detailed commit messages, in-line with the project's commit naming conventions ## Theming Instructions 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) > 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 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 ```go type MyCustomTheme struct{} func (dt *MyCustomTheme) Name() string { return "mycustomthem" } func (dt *MyCustomTheme) HTMLTemplate() string { // Get the template from a file (if you want to be able to change the template live without retstarting your application) // Or write the template by returning pure string here (if you want embbeded template and do not bother with external dependencies) return "" } func (dt *MyCustomTheme) PlainTextTemplate() string { // Get the template from a file (if you want to be able to change the template live without retstarting your application) // Or write the template by returning pure string here (if you want embbeded template and do not bother with external dependencies) return "" } h := hermes.Hermes{ Theme: new(MyCustomTheme) // Set your fresh new theme here Product: hermes.Product{ Name: "Hermes", Link: "https://example-hermes.com/", }, } // ... // Continue with the rest as usual, create your email and generate the content. // ... ``` 3. That's it. ### Creating a Built-In 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 3. Copy content of [default.go](default.go) file in new file and make any necessary changes 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! # Injection Snippets ## Product Branding Injection The following will inject either the product logo or name into the template. ```html {{ if .Hermes.Product.Logo }} {{ else }} {{ .Hermes.Product.Name }} {{ end }} ``` It's a good idea to add the following CSS declaration to set `max-height: 50px` for the logo: ```css .email-logo { max-height: 50px; } ``` ## Title Injection The following will inject the e-mail title (Hi John Appleseed,) or a custom title provided by the user: ```html
{{ $line }}
{{ end }} {{ end }} {{ end }} ``` ## Dictionary Injection The following will inject a `
|
{{ $action.Instructions }}
{{$.Hermes.Product.TroubleText | replace "{ACTION}" $action.Button.Text}} |
{{ end }}
{{ $line }}
{{ end }} {{ end }} {{ end }} ``` ## Signature Injection The following will inject the signature phrase (e.g. Yours truly) along with the product name into the e-mail: ```html {{.Email.Body.Signature}},