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

Rely on a hermes fork to pass custom template functions #1148

Merged
merged 1 commit into from
Jan 4, 2018
Merged
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
13 changes: 12 additions & 1 deletion pkg/workers/mails/mail_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ package mails
import (
"bytes"
"fmt"
"strings"
"sync"
"text/template"

"github.com/cozy/cozy-stack/pkg/i18n"
"github.com/matcornic/hermes"
"github.com/cozy/hermes"
)

// TODO: avoid having a lock by init-ing hermes instances after loading
// locales.
var hermeses map[string]hermes.Hermes
var hermesesMu sync.Mutex

var templateFuncsMap = map[string]interface{}{
"splitList": func(sep, orig string) []string {
return strings.Split(orig, sep)
},
"replace": func(old, new, src string) string {
return strings.Replace(src, old, new, -1)
},
}

func getHermes(locale string) hermes.Hermes {
hermesesMu.Lock()
defer hermesesMu.Unlock()
Expand All @@ -31,6 +41,7 @@ func getHermes(locale string) hermes.Hermes {
Copyright: "",
TroubleText: i18n.Translate("Mail Trouble Text", locale),
},
TemplateFuncsMap: templateFuncsMap,
}
}
}
Expand Down