aboutsummaryrefslogtreecommitdiffstats
path: root/modules/templates/dynamic.go
diff options
context:
space:
mode:
authorguillep2k <18600385+guillep2k@users.noreply.github.com>2019-11-07 10:34:28 -0300
committerLunny Xiao <xiaolunwen@gmail.com>2019-11-07 21:34:28 +0800
commit1f90147f3942065e2a7f564e8a3c97d23d41e6c0 (patch)
treefd5fb0bda2d84deb179bf99f9172b28f736ba9fe /modules/templates/dynamic.go
parentd5b1e6bc51f87eb1be07a4682798428bf4bbb9ce (diff)
downloadgitea-1f90147f3942065e2a7f564e8a3c97d23d41e6c0.tar.gz
gitea-1f90147f3942065e2a7f564e8a3c97d23d41e6c0.zip
Use templates for issue e-mail subject and body (#8329)
* Add template capability for issue mail subject * Remove test string * Fix trim subject length * Add comment to template and run make fmt * Add information for the template * Rename defaultMailSubject() to fallbackMailSubject() * General rewrite of the mail template code * Fix .Doer name * Use text/template for subject instead of html * Fix subject Re: prefix * Fix mail tests * Fix static templates * [skip ci] Updated translations via Crowdin * Expose db.SetMaxOpenConns and allow non MySQL dbs to set conn pool params (#8528) * Expose db.SetMaxOpenConns and allow other dbs to set their connection params * Add note about port exhaustion Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Prevent .code-view from overriding font on icon fonts (#8614) * Correct some outdated statements in the contributing guidelines (#8612) * More information for drone-cli in CONTRIBUTING.md * Increases the version of drone-cli to 1.2.0 * Adds a note for the Docker Toolbox on Windows Signed-off-by: LukBukkit <luk.bukkit@gmail.com> * Fix the url for the blog repository (now on gitea.com) Signed-off-by: LukBukkit <luk.bukkit@gmail.com> * Remove TrN due to lack of lang context * Redo templates to match previous code * Fix extra character in template * Unify PR & Issue tempaltes, fix format * Remove default subject * Add template tests * Fix template * Remove replaced function * Provide User as models.User for better consistency * Add docs * Fix doc inaccuracies, improve examples * Change mail footer to math AppName * Add test for mail subject/body template separation * Add support for code review comments * Update docs/content/doc/advanced/mail-templates-us.md Co-Authored-By: 6543 <24977596+6543@users.noreply.github.com>
Diffstat (limited to 'modules/templates/dynamic.go')
-rw-r--r--modules/templates/dynamic.go33
1 files changed, 11 insertions, 22 deletions
diff --git a/modules/templates/dynamic.go b/modules/templates/dynamic.go
index 6217f1c3b0..6153e8d027 100644
--- a/modules/templates/dynamic.go
+++ b/modules/templates/dynamic.go
@@ -11,6 +11,7 @@ import (
"io/ioutil"
"path"
"strings"
+ texttmpl "text/template"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -20,7 +21,8 @@ import (
)
var (
- templates = template.New("")
+ subjectTemplates = texttmpl.New("")
+ bodyTemplates = template.New("")
)
// HTMLRenderer implements the macaron handler for serving HTML templates.
@@ -59,9 +61,12 @@ func JSRenderer() macaron.Handler {
}
// Mailer provides the templates required for sending notification mails.
-func Mailer() *template.Template {
+func Mailer() (*texttmpl.Template, *template.Template) {
+ for _, funcs := range NewTextFuncMap() {
+ subjectTemplates.Funcs(funcs)
+ }
for _, funcs := range NewFuncMap() {
- templates.Funcs(funcs)
+ bodyTemplates.Funcs(funcs)
}
staticDir := path.Join(setting.StaticRootPath, "templates", "mail")
@@ -84,15 +89,7 @@ func Mailer() *template.Template {
continue
}
- _, err = templates.New(
- strings.TrimSuffix(
- filePath,
- ".tmpl",
- ),
- ).Parse(string(content))
- if err != nil {
- log.Warn("Failed to parse template %v", err)
- }
+ buildSubjectBodyTemplate(subjectTemplates, bodyTemplates, strings.TrimSuffix(filePath, ".tmpl"), content)
}
}
}
@@ -117,18 +114,10 @@ func Mailer() *template.Template {
continue
}
- _, err = templates.New(
- strings.TrimSuffix(
- filePath,
- ".tmpl",
- ),
- ).Parse(string(content))
- if err != nil {
- log.Warn("Failed to parse template %v", err)
- }
+ buildSubjectBodyTemplate(subjectTemplates, bodyTemplates, strings.TrimSuffix(filePath, ".tmpl"), content)
}
}
}
- return templates
+ return subjectTemplates, bodyTemplates
}