hermes/examples/main.go

71 lines
1.3 KiB
Go
Raw Normal View History

2017-03-26 17:11:30 +00:00
package main
import (
2017-03-28 16:16:20 +00:00
"fmt"
2017-03-26 17:11:30 +00:00
"github.com/matcornic/hermes"
"io/ioutil"
"os"
2017-03-26 17:11:30 +00:00
)
2017-03-28 16:41:38 +00:00
type example interface {
2017-03-28 16:16:20 +00:00
Email() hermes.Email
Name() string
}
2017-03-26 17:11:30 +00:00
func main() {
2017-03-26 17:11:30 +00:00
h := hermes.Hermes{
Product: hermes.Product{
Name: "Hermes",
2017-03-28 16:16:20 +00:00
Link: "https://example-hermes.com/",
Logo: "http://www.duchess-france.org/wp-content/uploads/2016/01/gopher.png",
2017-03-26 17:11:30 +00:00
},
}
2017-03-28 16:41:38 +00:00
examples := []example{
2017-03-28 16:57:33 +00:00
new(welcome),
new(reset),
new(receipt),
new(maintenance),
}
themes := []hermes.Theme{
new(hermes.Default),
new(hermes.Flat),
2017-03-26 17:11:30 +00:00
}
for _, theme := range themes {
h.Theme = theme
for _, e := range examples {
generateEmails(h, e.Email(), e.Name())
}
2017-03-28 16:16:20 +00:00
}
}
func generateEmails(h hermes.Hermes, email hermes.Email, example string) {
// Generate the HTML template and save it
res, err := h.GenerateHTML(email)
2017-03-26 17:11:30 +00:00
if err != nil {
panic(err)
}
err = os.MkdirAll(h.Theme.Name(), 0744)
if err != nil {
panic(err)
}
err = ioutil.WriteFile(fmt.Sprintf("%v/%v.%v.html", h.Theme.Name(), h.Theme.Name(), example), []byte(res), 0644)
2017-03-26 17:11:30 +00:00
if err != nil {
panic(err)
}
2017-03-28 16:16:20 +00:00
// Generate the plaintext template and save it
res, err = h.GeneratePlainText(email)
2017-03-26 17:11:30 +00:00
if err != nil {
panic(err)
}
err = ioutil.WriteFile(fmt.Sprintf("%v/%v.%v.txt", h.Theme.Name(), h.Theme.Name(), example), []byte(res), 0644)
2017-03-26 17:11:30 +00:00
if err != nil {
panic(err)
}
}