Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow markdown in Intros and Outros as an alternate to plain text #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,16 @@ 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 (ne .Email.Body.IntrosMarkdown "") }}
{{ .Email.Body.IntrosMarkdown.ToHTML }}
{{ else }}
{{ with .Email.Body.Intros }}
{{ if gt (len .) 0 }}
{{ range $line := . }}
<p>{{ $line }}</p>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ if (ne .Email.Body.FreeMarkdown "") }}
{{ .Email.Body.FreeMarkdown.ToHTML }}
Expand Down Expand Up @@ -379,17 +383,24 @@ func (dt *Default) HTMLTemplate() string {
{{ end }}

{{ end }}
{{ with .Email.Body.Outros }}
{{ if (ne .Email.Body.OutrosMarkdown "") }}
{{ .Email.Body.OutrosMarkdown.ToHTML }}
{{ else }}
{{ with .Email.Body.Outros }}
{{ if gt (len .) 0 }}
{{ range $line := . }}
<p>{{ $line }}</p>
{{ end }}
{{ end }}
{{ end }}
{{ end }}

<p>
{{.Email.Body.Signature}},
<br />
{{ if (ne .Email.Body.SignatureName "") }}
{{.Email.Body.SignatureName}}<br />
{{ end }}
{{.Hermes.Product.Name}}
</p>

Expand Down Expand Up @@ -439,9 +450,13 @@ func (dt *Default) HTMLTemplate() string {
// PlainTextTemplate returns a Golang template that will generate an plain text email.
func (dt *Default) PlainTextTemplate() string {
return `<h2>{{if .Email.Body.Title }}{{ .Email.Body.Title }}{{ else }}{{ .Email.Body.Greeting }} {{ .Email.Body.Name }},{{ end }}</h2>
{{ with .Email.Body.Intros }}
{{ range $line := . }}
<p>{{ $line }}</p>
{{ if (ne .Email.Body.IntrosMarkdown "") }}
{{ .Email.Body.IntrosMarkdown.ToHTML }}
{{ else }}
{{ with .Email.Body.Intros }}
{{ range $line := . }}
<p>{{ $line }}</p>
{{ end }}
{{ end }}
{{ end }}
{{ if (ne .Email.Body.FreeMarkdown "") }}
Expand Down Expand Up @@ -483,12 +498,23 @@ func (dt *Default) PlainTextTemplate() string {
{{ end }}
{{ end }}
{{ end }}
{{ with .Email.Body.Outros }}
{{ range $line := . }}
<p>{{ $line }}<p>
{{ if (ne .Email.Body.OutrosMarkdown "") }}
{{ .Email.Body.OutrosMarkdown.ToHTML }}
{{ else }}
{{ with .Email.Body.Outros }}
{{ range $line := . }}
<p>{{ $line }}<p>
{{ end }}
{{ end }}
{{ end }}
<p>{{.Email.Body.Signature}},<br>{{.Hermes.Product.Name}} - {{.Hermes.Product.Link}}</p>
<p>
{{.Email.Body.Signature}},
<br>
{{ if (ne .Email.Body.SignatureName "") }}
{{.Email.Body.SignatureName}}<br>
{{ end }}
{{.Hermes.Product.Name}} - {{.Hermes.Product.Link}}
</p>

<p>{{.Hermes.Product.Copyright}}</p>
`
Expand Down
44 changes: 35 additions & 9 deletions flat.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,16 @@ func (dt *Flat) 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 (ne .Email.Body.IntrosMarkdown "") }}
{{ .Email.Body.IntrosMarkdown.ToHTML }}
{{ else }}
{{ with .Email.Body.Intros }}
{{ if gt (len .) 0 }}
{{ range $line := . }}
<p>{{ $line }}</p>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ if (ne .Email.Body.FreeMarkdown "") }}
{{ .Email.Body.FreeMarkdown.ToHTML }}
Expand Down Expand Up @@ -379,17 +383,24 @@ func (dt *Flat) HTMLTemplate() string {
{{ end }}

{{ end }}
{{ with .Email.Body.Outros }}
{{ if (ne .Email.Body.OutrosMarkdown "") }}
{{ .Email.Body.OutrosMarkdown.ToHTML }}
{{ else }}
{{ with .Email.Body.Outros }}
{{ if gt (len .) 0 }}
{{ range $line := . }}
<p>{{ $line }}</p>
{{ end }}
{{ end }}
{{ end }}
{{ end }}

<p>
{{.Email.Body.Signature}},
<br />
{{ if (ne .Email.Body.SignatureName "") }}
{{.Email.Body.SignatureName}}<br />
{{ end }}
{{.Hermes.Product.Name}}
</p>

Expand Down Expand Up @@ -439,9 +450,13 @@ func (dt *Flat) HTMLTemplate() string {
// PlainTextTemplate returns a Golang template that will generate an plain text email.
func (dt *Flat) PlainTextTemplate() string {
return `<h2>{{if .Email.Body.Title }}{{ .Email.Body.Title }}{{ else }}{{ .Email.Body.Greeting }} {{ .Email.Body.Name }}{{ end }},</h2>
{{ with .Email.Body.Intros }}
{{ range $line := . }}
<p>{{ $line }}</p>
{{ if (ne .Email.Body.IntrosMarkdown "") }}
{{ .Email.Body.IntrosMarkdown.ToHTML }}
{{ else }}
{{ with .Email.Body.Intros }}
{{ range $line := . }}
<p>{{ $line }}</p>
{{ end }}
{{ end }}
{{ end }}
{{ if (ne .Email.Body.FreeMarkdown "") }}
Expand Down Expand Up @@ -483,12 +498,23 @@ func (dt *Flat) PlainTextTemplate() string {
{{ end }}
{{ end }}
{{ end }}
{{ with .Email.Body.Outros }}
{{ range $line := . }}
<p>{{ $line }}<p>
{{ if (ne .Email.Body.OutrosMarkdown "") }}
{{ .Email.Body.OutrosMarkdown.ToHTML }}
{{ else }}
{{ with .Email.Body.Outros }}
{{ range $line := . }}
<p>{{ $line }}<p>
{{ end }}
{{ end }}
{{ end }}
<p>{{.Email.Body.Signature}},<br>{{.Hermes.Product.Name}} - {{.Hermes.Product.Link}}</p>
<p>
{{.Email.Body.Signature}},
<br>
{{ if (ne .Email.Body.SignatureName "") }}
{{.Email.Body.SignatureName}}<br>
{{ end }}
{{.Hermes.Product.Name}} - {{.Hermes.Product.Link}}
</p>

<p>{{.Hermes.Product.Copyright}}</p>
`
Expand Down
23 changes: 13 additions & 10 deletions hermes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ type Markdown template.HTML

// Body is the body of the email, containing all interesting data
type Body struct {
Name string // The name of the contacted person
Intros []string // Intro sentences, first displayed in the email
Dictionary []Entry // A list of key+value (useful for displaying parameters/settings/personal info)
Table Table // Table is an table where you can put data (pricing grid, a bill, and so on)
Actions []Action // Actions are a list of actions that the user will be able to execute via a button click
Outros []string // Outro sentences, last displayed in the email
Greeting string // Greeting for the contacted person (default to 'Hi')
Signature string // Signature for the contacted person (default to 'Yours truly')
Title string // Title replaces the greeting+name when set
FreeMarkdown Markdown // Free markdown content that replaces all content other than header and footer
Name string // The name of the contacted person
Intros []string // Intro sentences, first displayed in the email
IntrosMarkdown Markdown // Intro in markdown, will override Intros
Dictionary []Entry // A list of key+value (useful for displaying parameters/settings/personal info)
Table Table // Table is an table where you can put data (pricing grid, a bill, and so on)
Actions []Action // Actions are a list of actions that the user will be able to execute via a button click
Outros []string // Outro sentences, last displayed in the email
OutrosMarkdown Markdown // Outro in markdown, will override Outros
Greeting string // Greeting for the contacted person (default to 'Hi')
Signature string // Signature for the contacted person (default to 'Yours truly')
SignatureName string // Contact person name
Title string // Title replaces the greeting+name when set
FreeMarkdown Markdown // Free markdown content that replaces all content other than header and footer
}

// ToHTML converts Markdown to HTML
Expand Down