aboutsummaryrefslogtreecommitdiff
path: root/template.go
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-10 17:36:21 +0100
committerSimon Ser <contact@emersion.fr>2019-12-10 17:36:21 +0100
commit3748b4413e6962654162625a3e57ade91defb71b (patch)
tree29e9eabe6122dd5ba06c3df50863b748e0e01566 /template.go
parentedf738f23d96efdd2c96146d430301a3128cb8e9 (diff)
downloadalps-3748b4413e6962654162625a3e57ade91defb71b.tar.gz
alps-3748b4413e6962654162625a3e57ade91defb71b.zip
Introduce GlobalRenderData and RenderData
GlobalRenderData contains some global metadata that can be obtained from any template. RenderData is a base type for template data. It contains a Global field with global metadata and an Extra field for plugins.
Diffstat (limited to 'template.go')
-rw-r--r--template.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/template.go b/template.go
index 110c433..2ebcbc0 100644
--- a/template.go
+++ b/template.go
@@ -13,6 +13,38 @@ import (
const themesDir = "public/themes"
+// GlobalRenderData contains data available in all templates.
+type GlobalRenderData struct {
+ LoggedIn bool
+
+ // if logged in
+ Username string
+ // TODO: list of mailboxes
+
+ Extra map[string]interface{}
+}
+
+// RenderData is the base type for templates. It should be extended with new
+// template-specific fields.
+type RenderData struct {
+ Global GlobalRenderData
+ Extra map[string]interface{}
+}
+
+func NewRenderData(ctx *context) *RenderData {
+ global := GlobalRenderData{Extra: make(map[string]interface{})}
+
+ if ctx.session != nil {
+ global.LoggedIn = true
+ global.Username = ctx.session.username
+ }
+
+ return &RenderData{
+ Global: global,
+ Extra: make(map[string]interface{}),
+ }
+}
+
type renderer struct {
base *template.Template
themes map[string]*template.Template