templates: add version func

Fixes #316
This commit is contained in:
Reto Brunner 2020-05-02 14:06:02 +02:00 committed by Drew DeVault
parent 434eaa19a1
commit 6bd6690d80
3 changed files with 19 additions and 0 deletions

View file

@ -19,6 +19,7 @@ import (
"git.sr.ht/~sircmpwn/aerc/commands/terminal" "git.sr.ht/~sircmpwn/aerc/commands/terminal"
"git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/config"
"git.sr.ht/~sircmpwn/aerc/lib" "git.sr.ht/~sircmpwn/aerc/lib"
"git.sr.ht/~sircmpwn/aerc/lib/templates"
libui "git.sr.ht/~sircmpwn/aerc/lib/ui" libui "git.sr.ht/~sircmpwn/aerc/lib/ui"
"git.sr.ht/~sircmpwn/aerc/widgets" "git.sr.ht/~sircmpwn/aerc/widgets"
) )
@ -179,6 +180,9 @@ func main() {
as.OnMailto = aerc.Mailto as.OnMailto = aerc.Mailto
} }
// set the aerc version so that we can use it in the template funcs
templates.SetVersion(Version)
close(initDone) close(initDone)
for !ui.ShouldExit() { for !ui.ShouldExit() {

View file

@ -125,6 +125,13 @@ aerc provides the following additional functions:
{{dateFormat .Date "Mon Jan 2 15:04:05 -0700 MST 2006"}} {{dateFormat .Date "Mon Jan 2 15:04:05 -0700 MST 2006"}}
``` ```
*version*
Returns the version of aerc, which can be useful for things like X-Mailer.
```
X-Mailer: aerc {{version}}
```
*Function chaining* *Function chaining*
All of the template functions can be chained together if needed. All of the template functions can be chained together if needed.

View file

@ -16,6 +16,13 @@ import (
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
) )
var version string
//SetVersion initializes the aerc version displayed in template functions
func SetVersion(v string) {
version = v
}
type TemplateData struct { type TemplateData struct {
To []*mail.Address To []*mail.Address
Cc []*mail.Address Cc []*mail.Address
@ -168,6 +175,7 @@ var templateFuncs = template.FuncMap{
"dateFormat": time.Time.Format, "dateFormat": time.Time.Format,
"toLocal": toLocal, "toLocal": toLocal,
"exec": cmd, "exec": cmd,
"version": func() string { return version },
} }
func findTemplate(templateName string, templateDirs []string) (string, error) { func findTemplate(templateName string, templateDirs []string) (string, error) {