Refactor renderer and templates
authorr <r@freesoftwareextremist.com>
Tue, 14 Jan 2020 16:57:16 +0000 (16:57 +0000)
committerr <r@freesoftwareextremist.com>
Tue, 14 Jan 2020 16:57:16 +0000 (16:57 +0000)
27 files changed:
mastodon/status.go
renderer/model.go
renderer/renderer.go
service/auth.go
service/logging.go
service/service.go
service/transport.go
templates/about.tmpl
templates/emoji.tmpl
templates/error.tmpl
templates/followers.tmpl
templates/following.tmpl
templates/header.tmpl
templates/homepage.tmpl [deleted file]
templates/likedby.tmpl
templates/navigation.tmpl
templates/notification.tmpl
templates/postform.tmpl
templates/retweetedby.tmpl
templates/search.tmpl
templates/settings.tmpl
templates/signin.tmpl
templates/status.tmpl
templates/thread.tmpl
templates/timeline.tmpl
templates/user.tmpl
templates/userlist.tmpl

index e6e247f6a6b32e055311d71611442b8df85686d7..d6a93302c1528c83019c5fd3e555d1b73579a4a9 100644 (file)
@@ -54,10 +54,7 @@ type Status struct {
        ShowReplies     bool                   `json:"show_replies"`
        ReplyMap        map[string][]ReplyInfo `json:"reply_map"`
        ReplyNumber     int                    `json:"reply_number"`
-       ThreadInNewTab  bool                   `json:"thread_in_new_tab"`
-       MaskNSFW        bool                   `json:"mask_nsfw"`
        RetweetedByID   string                 `json:"retweeted_by_id"`
-       DarkMode        bool                   `json:"dark_mode"`
 }
 
 // Context hold information for mastodon context.
index 64b99461ac048a2401a7e79a9a1ddbbbfc17cdf9..cc0a6ce3f3158b1dabdf6ec704adf05f0fa47514 100644 (file)
@@ -5,12 +5,17 @@ import (
        "mastodon"
 )
 
+type Context struct {
+       MaskNSFW       bool
+       FluorideMode   bool
+       ThreadInNewTab bool
+       DarkMode       bool
+}
+
 type HeaderData struct {
        Title             string
        NotificationCount int
        CustomCSS         string
-       FluorideMode      bool
-       DarkMode          bool
 }
 
 type NavbarData struct {
index 42bffad40398909f51a56968a338214f52961572..4d2c74df5eebefbc3ded548113addc883bd53bf5 100644 (file)
@@ -1,7 +1,6 @@
 package renderer
 
 import (
-       "context"
        "io"
        "strconv"
        "strings"
@@ -44,22 +43,26 @@ var (
        }
 )
 
+type TemplateData struct {
+       Data interface{}
+       Ctx  *Context
+}
+
 type Renderer interface {
-       RenderErrorPage(ctx context.Context, writer io.Writer, data *ErrorData)
-       RenderHomePage(ctx context.Context, writer io.Writer, data *HomePageData) (err error)
-       RenderSigninPage(ctx context.Context, writer io.Writer, data *SigninData) (err error)
-       RenderTimelinePage(ctx context.Context, writer io.Writer, data *TimelineData) (err error)
-       RenderThreadPage(ctx context.Context, writer io.Writer, data *ThreadData) (err error)
-       RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationData) (err error)
-       RenderUserPage(ctx context.Context, writer io.Writer, data *UserData) (err error)
-       RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutData) (err error)
-       RenderEmojiPage(ctx context.Context, writer io.Writer, data *EmojiData) (err error)
-       RenderLikedByPage(ctx context.Context, writer io.Writer, data *LikedByData) (err error)
-       RenderRetweetedByPage(ctx context.Context, writer io.Writer, data *RetweetedByData) (err error)
-       RenderFollowingPage(ctx context.Context, writer io.Writer, data *FollowingData) (err error)
-       RenderFollowersPage(ctx context.Context, writer io.Writer, data *FollowersData) (err error)
-       RenderSearchPage(ctx context.Context, writer io.Writer, data *SearchData) (err error)
-       RenderSettingsPage(ctx context.Context, writer io.Writer, data *SettingsData) (err error)
+       RenderSigninPage(ctx *Context, writer io.Writer, data *SigninData) (err error)
+       RenderErrorPage(ctx *Context, writer io.Writer, data *ErrorData)
+       RenderTimelinePage(ctx *Context, writer io.Writer, data *TimelineData) (err error)
+       RenderThreadPage(ctx *Context, writer io.Writer, data *ThreadData) (err error)
+       RenderNotificationPage(ctx *Context, writer io.Writer, data *NotificationData) (err error)
+       RenderUserPage(ctx *Context, writer io.Writer, data *UserData) (err error)
+       RenderAboutPage(ctx *Context, writer io.Writer, data *AboutData) (err error)
+       RenderEmojiPage(ctx *Context, writer io.Writer, data *EmojiData) (err error)
+       RenderLikedByPage(ctx *Context, writer io.Writer, data *LikedByData) (err error)
+       RenderRetweetedByPage(ctx *Context, writer io.Writer, data *RetweetedByData) (err error)
+       RenderFollowingPage(ctx *Context, writer io.Writer, data *FollowingData) (err error)
+       RenderFollowersPage(ctx *Context, writer io.Writer, data *FollowersData) (err error)
+       RenderSearchPage(ctx *Context, writer io.Writer, data *SearchData) (err error)
+       RenderSettingsPage(ctx *Context, writer io.Writer, data *SettingsData) (err error)
 }
 
 type renderer struct {
@@ -76,6 +79,7 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
                "FormatTimeRFC3339":       FormatTimeRFC3339,
                "FormatTimeRFC822":        FormatTimeRFC822,
                "GetIcon":                 GetIcon,
+               "WithContext":             WithContext,
        }).ParseGlob(templateGlobPattern)
        if err != nil {
                return
@@ -85,65 +89,61 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
        }, nil
 }
 
-func (r *renderer) RenderErrorPage(ctx context.Context, writer io.Writer, errorData *ErrorData) {
-       r.template.ExecuteTemplate(writer, "error.tmpl", errorData)
-       return
-}
-
-func (r *renderer) RenderHomePage(ctx context.Context, writer io.Writer, homePageData *HomePageData) (err error) {
-       return r.template.ExecuteTemplate(writer, "homepage.tmpl", homePageData)
+func (r *renderer) RenderSigninPage(ctx *Context, writer io.Writer, signinData *SigninData) (err error) {
+       return r.template.ExecuteTemplate(writer, "signin.tmpl", WithContext(signinData, ctx))
 }
 
-func (r *renderer) RenderSigninPage(ctx context.Context, writer io.Writer, signinData *SigninData) (err error) {
-       return r.template.ExecuteTemplate(writer, "signin.tmpl", signinData)
+func (r *renderer) RenderErrorPage(ctx *Context, writer io.Writer, errorData *ErrorData) {
+       r.template.ExecuteTemplate(writer, "error.tmpl", WithContext(errorData, ctx))
+       return
 }
 
-func (r *renderer) RenderTimelinePage(ctx context.Context, writer io.Writer, data *TimelineData) (err error) {
-       return r.template.ExecuteTemplate(writer, "timeline.tmpl", data)
+func (r *renderer) RenderTimelinePage(ctx *Context, writer io.Writer, data *TimelineData) (err error) {
+       return r.template.ExecuteTemplate(writer, "timeline.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderThreadPage(ctx context.Context, writer io.Writer, data *ThreadData) (err error) {
-       return r.template.ExecuteTemplate(writer, "thread.tmpl", data)
+func (r *renderer) RenderThreadPage(ctx *Context, writer io.Writer, data *ThreadData) (err error) {
+       return r.template.ExecuteTemplate(writer, "thread.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationData) (err error) {
-       return r.template.ExecuteTemplate(writer, "notification.tmpl", data)
+func (r *renderer) RenderNotificationPage(ctx *Context, writer io.Writer, data *NotificationData) (err error) {
+       return r.template.ExecuteTemplate(writer, "notification.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderUserPage(ctx context.Context, writer io.Writer, data *UserData) (err error) {
-       return r.template.ExecuteTemplate(writer, "user.tmpl", data)
+func (r *renderer) RenderUserPage(ctx *Context, writer io.Writer, data *UserData) (err error) {
+       return r.template.ExecuteTemplate(writer, "user.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutData) (err error) {
-       return r.template.ExecuteTemplate(writer, "about.tmpl", data)
+func (r *renderer) RenderAboutPage(ctx *Context, writer io.Writer, data *AboutData) (err error) {
+       return r.template.ExecuteTemplate(writer, "about.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderEmojiPage(ctx context.Context, writer io.Writer, data *EmojiData) (err error) {
-       return r.template.ExecuteTemplate(writer, "emoji.tmpl", data)
+func (r *renderer) RenderEmojiPage(ctx *Context, writer io.Writer, data *EmojiData) (err error) {
+       return r.template.ExecuteTemplate(writer, "emoji.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderLikedByPage(ctx context.Context, writer io.Writer, data *LikedByData) (err error) {
-       return r.template.ExecuteTemplate(writer, "likedby.tmpl", data)
+func (r *renderer) RenderLikedByPage(ctx *Context, writer io.Writer, data *LikedByData) (err error) {
+       return r.template.ExecuteTemplate(writer, "likedby.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderRetweetedByPage(ctx context.Context, writer io.Writer, data *RetweetedByData) (err error) {
-       return r.template.ExecuteTemplate(writer, "retweetedby.tmpl", data)
+func (r *renderer) RenderRetweetedByPage(ctx *Context, writer io.Writer, data *RetweetedByData) (err error) {
+       return r.template.ExecuteTemplate(writer, "retweetedby.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderFollowingPage(ctx context.Context, writer io.Writer, data *FollowingData) (err error) {
-       return r.template.ExecuteTemplate(writer, "following.tmpl", data)
+func (r *renderer) RenderFollowingPage(ctx *Context, writer io.Writer, data *FollowingData) (err error) {
+       return r.template.ExecuteTemplate(writer, "following.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderFollowersPage(ctx context.Context, writer io.Writer, data *FollowersData) (err error) {
-       return r.template.ExecuteTemplate(writer, "followers.tmpl", data)
+func (r *renderer) RenderFollowersPage(ctx *Context, writer io.Writer, data *FollowersData) (err error) {
+       return r.template.ExecuteTemplate(writer, "followers.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderSearchPage(ctx context.Context, writer io.Writer, data *SearchData) (err error) {
-       return r.template.ExecuteTemplate(writer, "search.tmpl", data)
+func (r *renderer) RenderSearchPage(ctx *Context, writer io.Writer, data *SearchData) (err error) {
+       return r.template.ExecuteTemplate(writer, "search.tmpl", WithContext(data, ctx))
 }
 
-func (r *renderer) RenderSettingsPage(ctx context.Context, writer io.Writer, data *SettingsData) (err error) {
-       return r.template.ExecuteTemplate(writer, "settings.tmpl", data)
+func (r *renderer) RenderSettingsPage(ctx *Context, writer io.Writer, data *SettingsData) (err error) {
+       return r.template.ExecuteTemplate(writer, "settings.tmpl", WithContext(data, ctx))
 }
 
 func EmojiFilter(content string, emojis []mastodon.Emoji) string {
@@ -222,3 +222,7 @@ func GetIcon(name string, darkMode bool) (icon string) {
        icon, _ = icons[name]
        return
 }
+
+func WithContext(data interface{}, ctx *Context) TemplateData {
+       return TemplateData{data, ctx}
+}
index 2f637175f9f464b2ea33b61025120f2f9eb7c99c..e5173836082678b2aafcc6ac5837187489d1a79f 100644 (file)
@@ -73,12 +73,9 @@ func (s *authService) GetUserToken(ctx context.Context, sessionID string, c *mod
        return
 }
 
-func (s *authService) ServeHomePage(ctx context.Context, client io.Writer) (err error) {
-       return s.Service.ServeHomePage(ctx, client)
-}
-
-func (s *authService) ServeErrorPage(ctx context.Context, client io.Writer, err error) {
-       s.Service.ServeErrorPage(ctx, client, err)
+func (s *authService) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error) {
+       c, _ = s.getClient(ctx)
+       s.Service.ServeErrorPage(ctx, client, c, err)
 }
 
 func (s *authService) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
index 27c038d4ee26f5c7b53e26af18e3e5d0fe80f2bc..cafd8155a926cf9f409728e35f8f4d200130898b 100644 (file)
@@ -37,20 +37,12 @@ func (s *loggingService) GetUserToken(ctx context.Context, sessionID string, c *
        return s.Service.GetUserToken(ctx, sessionID, c, code)
 }
 
-func (s *loggingService) ServeHomePage(ctx context.Context, client io.Writer) (err error) {
-       defer func(begin time.Time) {
-               s.logger.Printf("method=%v, took=%v, err=%v\n",
-                       "ServeHomePage", time.Since(begin), err)
-       }(time.Now())
-       return s.Service.ServeHomePage(ctx, client)
-}
-
-func (s *loggingService) ServeErrorPage(ctx context.Context, client io.Writer, err error) {
+func (s *loggingService) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error) {
        defer func(begin time.Time) {
                s.logger.Printf("method=%v, err=%v, took=%v\n",
                        "ServeErrorPage", err, time.Since(begin))
        }(time.Now())
-       s.Service.ServeErrorPage(ctx, client, err)
+       s.Service.ServeErrorPage(ctx, client, c, err)
 }
 
 func (s *loggingService) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
index b3c21038f614fab9257a8879e4462f0971e479c2..0c01dce7d2868c0bae2fc71de38b90d96a56ddbb 100644 (file)
@@ -26,10 +26,9 @@ var (
 )
 
 type Service interface {
-       ServeHomePage(ctx context.Context, client io.Writer) (err error)
        GetAuthUrl(ctx context.Context, instance string) (url string, sessionID string, err error)
        GetUserToken(ctx context.Context, sessionID string, c *model.Client, token string) (accessToken string, err error)
-       ServeErrorPage(ctx context.Context, client io.Writer, err error)
+       ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error)
        ServeSigninPage(ctx context.Context, client io.Writer) (err error)
        ServeTimelinePage(ctx context.Context, client io.Writer, c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error)
        ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error)
@@ -79,6 +78,15 @@ func NewService(clientName string, clientScope string, clientWebsite string,
        }
 }
 
+func getRendererContext(s model.Settings) *renderer.Context {
+       return &renderer.Context{
+               MaskNSFW:       s.MaskNSFW,
+               ThreadInNewTab: s.ThreadInNewTab,
+               FluorideMode:   s.FluorideMode,
+               DarkMode:       s.DarkMode,
+       }
+}
+
 func (svc *service) GetAuthUrl(ctx context.Context, instance string) (
        redirectUrl string, sessionID string, err error) {
        var instanceURL string
@@ -202,20 +210,7 @@ func (svc *service) GetUserToken(ctx context.Context, sessionID string, c *model
        return res.AccessToken, nil
 }
 
-func (svc *service) ServeHomePage(ctx context.Context, client io.Writer) (err error) {
-       commonData, err := svc.getCommonData(ctx, client, nil, "home")
-       if err != nil {
-               return
-       }
-
-       data := &renderer.HomePageData{
-               CommonData: commonData,
-       }
-
-       return svc.renderer.RenderHomePage(ctx, client, data)
-}
-
-func (svc *service) ServeErrorPage(ctx context.Context, client io.Writer, err error) {
+func (svc *service) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error) {
        var errStr string
        if err != nil {
                errStr = err.Error()
@@ -231,7 +226,15 @@ func (svc *service) ServeErrorPage(ctx context.Context, client io.Writer, err er
                Error:      errStr,
        }
 
-       svc.renderer.RenderErrorPage(ctx, client, data)
+       var s model.Settings
+       if c != nil {
+               s = c.Session.Settings
+       } else {
+               s = *model.NewSettings()
+       }
+       rCtx := getRendererContext(s)
+
+       svc.renderer.RenderErrorPage(rCtx, client, data)
 }
 
 func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
@@ -244,7 +247,8 @@ func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err
                CommonData: commonData,
        }
 
-       return svc.renderer.RenderSigninPage(ctx, client, data)
+       rCtx := getRendererContext(*model.NewSettings())
+       return svc.renderer.RenderSigninPage(rCtx, client, data)
 }
 
 func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
@@ -279,14 +283,8 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
        }
 
        for i := range statuses {
-               statuses[i].ThreadInNewTab = c.Session.Settings.ThreadInNewTab
-               statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW
-               statuses[i].DarkMode = c.Session.Settings.DarkMode
                if statuses[i].Reblog != nil {
                        statuses[i].Reblog.RetweetedByID = statuses[i].ID
-                       statuses[i].Reblog.ThreadInNewTab = c.Session.Settings.ThreadInNewTab
-                       statuses[i].Reblog.MaskNSFW = c.Session.Settings.MaskNSFW
-                       statuses[i].Reblog.DarkMode = c.Session.Settings.DarkMode
                }
        }
 
@@ -319,7 +317,6 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
        postContext := model.PostContext{
                DefaultVisibility: c.Session.Settings.DefaultVisibility,
                Formats:           svc.postFormats,
-               DarkMode:          c.Session.Settings.DarkMode,
        }
 
        commonData, err := svc.getCommonData(ctx, client, c, timelineType+" timeline ")
@@ -337,8 +334,9 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
                PostContext: postContext,
                CommonData:  commonData,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderTimelinePage(ctx, client, data)
+       err = svc.renderer.RenderTimelinePage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -404,8 +402,6 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *mo
        for i := range statuses {
                statuses[i].ShowReplies = true
                statuses[i].ReplyMap = replyMap
-               statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW
-               statuses[i].DarkMode = c.Session.Settings.DarkMode
                addToReplyMap(replyMap, statuses[i].InReplyToID, statuses[i].ID, i+1)
        }
 
@@ -420,8 +416,9 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *mo
                ReplyMap:    replyMap,
                CommonData:  commonData,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderThreadPage(ctx, client, data)
+       err = svc.renderer.RenderThreadPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -448,8 +445,6 @@ func (svc *service) ServeNotificationPage(ctx context.Context, client io.Writer,
        for i := range notifications {
                if notifications[i].Status != nil {
                        notifications[i].Status.CreatedAt = notifications[i].CreatedAt
-                       notifications[i].Status.MaskNSFW = c.Session.Settings.MaskNSFW
-                       notifications[i].Status.DarkMode = c.Session.Settings.DarkMode
                        switch notifications[i].Type {
                        case "reblog", "favourite":
                                notifications[i].Status.HideAccountInfo = true
@@ -482,9 +477,10 @@ func (svc *service) ServeNotificationPage(ctx context.Context, client io.Writer,
                HasNext:       hasNext,
                NextLink:      nextLink,
                CommonData:    commonData,
-               DarkMode:      c.Session.Settings.DarkMode,
        }
-       err = svc.renderer.RenderNotificationPage(ctx, client, data)
+       rCtx := getRendererContext(c.Session.Settings)
+
+       err = svc.renderer.RenderNotificationPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -512,15 +508,6 @@ func (svc *service) ServeUserPage(ctx context.Context, client io.Writer, c *mode
                return
        }
 
-       for i := range statuses {
-               statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW
-               statuses[i].DarkMode = c.Session.Settings.DarkMode
-               if statuses[i].Reblog != nil {
-                       statuses[i].Reblog.MaskNSFW = c.Session.Settings.MaskNSFW
-                       statuses[i].Reblog.DarkMode = c.Session.Settings.DarkMode
-               }
-       }
-
        if len(pg.MaxID) > 0 {
                hasNext = true
                nextLink = "/user/" + id + "?max_id=" + pg.MaxID
@@ -537,10 +524,10 @@ func (svc *service) ServeUserPage(ctx context.Context, client io.Writer, c *mode
                HasNext:    hasNext,
                NextLink:   nextLink,
                CommonData: commonData,
-               DarkMode:   c.Session.Settings.DarkMode,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderUserPage(ctx, client, data)
+       err = svc.renderer.RenderUserPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -557,7 +544,9 @@ func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *mod
        data := &renderer.AboutData{
                CommonData: commonData,
        }
-       err = svc.renderer.RenderAboutPage(ctx, client, data)
+       rCtx := getRendererContext(c.Session.Settings)
+
+       err = svc.renderer.RenderAboutPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -580,8 +569,9 @@ func (svc *service) ServeEmojiPage(ctx context.Context, client io.Writer, c *mod
                Emojis:     emojis,
                CommonData: commonData,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderEmojiPage(ctx, client, data)
+       err = svc.renderer.RenderEmojiPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -604,8 +594,9 @@ func (svc *service) ServeLikedByPage(ctx context.Context, client io.Writer, c *m
                CommonData: commonData,
                Users:      likers,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderLikedByPage(ctx, client, data)
+       err = svc.renderer.RenderLikedByPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -628,8 +619,9 @@ func (svc *service) ServeRetweetedByPage(ctx context.Context, client io.Writer,
                CommonData: commonData,
                Users:      retweeters,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderRetweetedByPage(ctx, client, data)
+       err = svc.renderer.RenderRetweetedByPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -668,8 +660,9 @@ func (svc *service) ServeFollowingPage(ctx context.Context, client io.Writer, c
                HasNext:    hasNext,
                NextLink:   nextLink,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderFollowingPage(ctx, client, data)
+       err = svc.renderer.RenderFollowingPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -708,8 +701,9 @@ func (svc *service) ServeFollowersPage(ctx context.Context, client io.Writer, c
                HasNext:    hasNext,
                NextLink:   nextLink,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderFollowersPage(ctx, client, data)
+       err = svc.renderer.RenderFollowersPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -731,11 +725,6 @@ func (svc *service) ServeSearchPage(ctx context.Context, client io.Writer, c *mo
                hasNext = len(results.Accounts) == 20
        case "statuses":
                hasNext = len(results.Statuses) == 20
-               for i := range results.Statuses {
-                       results.Statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW
-                       results.Statuses[i].DarkMode = c.Session.Settings.DarkMode
-               }
-
        }
 
        if hasNext {
@@ -761,8 +750,9 @@ func (svc *service) ServeSearchPage(ctx context.Context, client io.Writer, c *mo
                HasNext:    hasNext,
                NextLink:   nextLink,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderSearchPage(ctx, client, data)
+       err = svc.renderer.RenderSearchPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -780,8 +770,9 @@ func (svc *service) ServeSettingsPage(ctx context.Context, client io.Writer, c *
                CommonData: commonData,
                Settings:   &c.Session.Settings,
        }
+       rCtx := getRendererContext(c.Session.Settings)
 
-       err = svc.renderer.RenderSettingsPage(ctx, client, data)
+       err = svc.renderer.RenderSettingsPage(rCtx, client, data)
        if err != nil {
                return
        }
@@ -837,8 +828,6 @@ func (svc *service) getCommonData(ctx context.Context, client io.Writer, c *mode
                }
 
                data.HeaderData.NotificationCount = notificationCount
-               data.HeaderData.FluorideMode = c.Session.Settings.FluorideMode
-               data.HeaderData.DarkMode = c.Session.Settings.DarkMode
        }
 
        return
index 0072f9571375912caf0b384c089afffb49c0cca7..8cca4f518991e3abdc78bb6f687d49132e817c49 100644 (file)
@@ -41,7 +41,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
        r.HandleFunc("/signin", func(w http.ResponseWriter, req *http.Request) {
                err := s.ServeSigninPage(ctx, w)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -50,7 +50,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
                instance := req.FormValue("instance")
                url, sessionID, err := s.GetAuthUrl(ctx, instance)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -69,7 +69,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
                token := req.URL.Query().Get("code")
                _, err := s.GetUserToken(ctx, "", nil, token)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -92,7 +92,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeTimelinePage(ctx, w, nil, timelineType, maxID, sinceID, minID)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -103,7 +103,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
                reply := req.URL.Query().Get("reply")
                err := s.ServeThreadPage(ctx, w, nil, id, len(reply) > 1)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -114,7 +114,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeLikedByPage(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -125,7 +125,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeRetweetedByPage(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -139,7 +139,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeFollowingPage(ctx, w, nil, id, maxID, minID)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -153,7 +153,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeFollowersPage(ctx, w, nil, id, maxID, minID)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -165,7 +165,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                _, err := s.Like(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -184,7 +184,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                _, err := s.UnLike(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -203,7 +203,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                _, err := s.Retweet(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -222,7 +222,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                _, err := s.UnRetweet(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -239,13 +239,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
                id, _ := mux.Vars(req)["id"]
                count, err := s.Like(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
                err = serveJson(w, count)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodPost)
@@ -255,13 +255,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
                id, _ := mux.Vars(req)["id"]
                count, err := s.UnLike(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
                err = serveJson(w, count)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodPost)
@@ -271,13 +271,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
                id, _ := mux.Vars(req)["id"]
                count, err := s.Retweet(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
                err = serveJson(w, count)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodPost)
@@ -287,13 +287,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
                id, _ := mux.Vars(req)["id"]
                count, err := s.UnRetweet(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
                err = serveJson(w, count)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodPost)
@@ -303,7 +303,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := req.ParseMultipartForm(4 << 20)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -317,7 +317,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                id, err := s.PostTweet(ctx, w, nil, content, replyToID, format, visibility, isNSFW, files)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -337,7 +337,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeNotificationPage(ctx, w, nil, maxID, minID)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -351,7 +351,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeUserPage(ctx, w, nil, id, maxID, minID)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -363,7 +363,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.Follow(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -378,7 +378,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.UnFollow(ctx, w, nil, id)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
@@ -391,7 +391,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeAboutPage(ctx, w, nil)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -401,7 +401,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeEmojiPage(ctx, w, nil)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -418,14 +418,14 @@ func NewHandler(s Service, staticDir string) http.Handler {
                if len(offsetStr) > 1 {
                        offset, err = strconv.Atoi(offsetStr)
                        if err != nil {
-                               s.ServeErrorPage(ctx, w, err)
+                               s.ServeErrorPage(ctx, w, nil, err)
                                return
                        }
                }
 
                err = s.ServeSearchPage(ctx, w, nil, q, qType, offset)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -435,7 +435,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
 
                err := s.ServeSettingsPage(ctx, w, nil)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
        }).Methods(http.MethodGet)
@@ -455,12 +455,12 @@ func NewHandler(s Service, staticDir string) http.Handler {
                        ThreadInNewTab:    threadInNewTab,
                        MaskNSFW:          maskNSFW,
                        FluorideMode:      fluorideMode,
-                       DarkMode:      darkMode,
+                       DarkMode:          darkMode,
                }
 
                err := s.SaveSettings(ctx, w, nil, settings)
                if err != nil {
-                       s.ServeErrorPage(ctx, w, err)
+                       s.ServeErrorPage(ctx, w, nil, err)
                        return
                }
 
index 60bb5f60b4c149494fdcfbde03900652b6f05370..b3c9a494134924ca467e9263f002c41dd8a4f884 100644 (file)
@@ -1,5 +1,6 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> About </div>
 
 <div>
@@ -15,4 +16,5 @@
 </div>
 
 {{template "footer.tmpl"}}
+{{end}}
 
index aba47262ceb665120cf6abac96676d510a30d36c..2066afaba1259134b84cc270300c37f9878217db 100644 (file)
@@ -1,5 +1,6 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Emojis </div>
 
 <div class="emoji-list-container">
@@ -12,5 +13,4 @@
 </div>
 
 {{template "footer.tmpl"}}
-
-
+{{end}}
index 2049665209d1bad220ed754e43287d14e756a0f0..0d6115a91b3583c1c348e5a6892114d47d39ebdc 100644 (file)
@@ -1,9 +1,12 @@
-{{template "header.tmpl" .HeaderData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
 <div class="page-title"> Error </div>
+
 <div class="error-text"> {{.Error}} </div>
 <div>
-<a href="/timeline/home">Home</a>
-<a href="/signin">Sign In</a>
+       <a href="/timeline/home">Home</a>
+       <a href="/signin">Sign In</a>
 </div>
-{{template "footer.tmpl"}}
 
+{{template "footer.tmpl"}}
+{{end}}
index 1c4e9eb381e18e4087d3411b6f23b9dc3496f361..8102b26908eb429d518e6d139e929a4aec55b698 100644 (file)
@@ -1,8 +1,9 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Followers </div>
 
-{{template "userlist.tmpl" .Users}}
+{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
 <div class="pagination">
        {{if .HasNext}}
                <a href="{{.NextLink}}">next</a>
@@ -10,3 +11,4 @@
 </div>
 
 {{template "footer.tmpl"}}
+{{end}}
index b1d8499b8d9e6d300257c5ba1eeb9e943512e7ba..43a60dce959111433aa8f66d434be32fad706c6d 100644 (file)
@@ -1,8 +1,9 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Following </div>
 
-{{template "userlist.tmpl" .Users}}
+{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
 <div class="pagination">
        {{if .HasNext}}
                <a href="{{.NextLink}}">next</a>
@@ -10,3 +11,4 @@
 </div>
 
 {{template "footer.tmpl"}}
+{{end}}
index 10afe8aba5808905e37aa31a697c9568920a164b..571008aefae6507fa9d481a825b9ded23bac5b68 100644 (file)
@@ -1,3 +1,4 @@
+{{with .Data}}
 <!DOCTYPE html>
 <html lang="en">
 <head>
@@ -8,8 +9,9 @@
        {{if .CustomCSS}}
        <link rel="stylesheet" href="{{.CustomCSS}}">
        {{end}}
-       {{if .FluorideMode}}
+       {{if $.Ctx.FluorideMode}}
        <script src="/static/fluoride.js"></script>
        {{end}}
 </head>
-<body {{if .DarkMode}}class="dark"{{end}}>
+<body {{if $.Ctx.DarkMode}}class="dark"{{end}}>
+{{end}}
diff --git a/templates/homepage.tmpl b/templates/homepage.tmpl
deleted file mode 100644 (file)
index 5e8e8a0..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-{{template "header.tmpl" .HeaderData}}
-<div class="page-title"> Home </div>
-<a href="/signin"> Signin </a>
-{{template "footer.tmpl"}}
index 72855e01b5be5b14ccc0680b5542ef90b885da8e..00857c17a5125e379c4a0107d168c303b8ebea1e 100644 (file)
@@ -1,7 +1,9 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Liked By </div>
 
-{{template "userlist.tmpl" .Users}}
+{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
 
 {{template "footer.tmpl"}}
+{{end}}
index fe834761decbb01908fab03b09de192648ce1a3b..e2547ea3cc09ff3fb007d9c4e0345920a2be6599 100644 (file)
@@ -1,3 +1,4 @@
+{{with .Data}}
 <div class="user-info">
        <div class="user-info-img-container">
                <a class="img-link" href="/timeline/home" title="home">
@@ -25,3 +26,4 @@
                </div>
        </div>
 </div>
+{{end}}
index 79d6d908920bd7e03e0e1d3fb62e693b16c5aaa1..86134ac62ea0eb53fc824bd18c14b8142381e973 100644 (file)
@@ -1,5 +1,6 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Notifications </div>
 
 {{range .Notifications}}
@@ -14,7 +15,7 @@
                <div>
                        <div class="notification-info-text">
                                <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
-                               <img class="icon" src="{{GetIcon "user-plus" .DarkMode}}" alt="followed" />
+                               <img class="icon" src="{{GetIcon "user-plus" $.Ctx.DarkMode}}" alt="followed" />
                                <span> followed you </span>
                        </div>
                        <div class="notification-follow-uname">
@@ -24,7 +25,7 @@
        </div>
 
        {{else if eq .Type "mention"}}
-       {{template "status" .Status}}
+       {{template "status" (WithContext .Status $.Ctx)}}
 
        {{else if eq .Type "reblog"}}
        <div class="notification-retweet-container">
                <div>
                        <div class="notification-info-text">
                                <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
-                               <img class="icon" src="{{GetIcon "retweeted" .DarkMode}}" alt="retweeted" />
+                               <img class="icon" src="{{GetIcon "retweeted" $.Ctx.DarkMode}}" alt="retweeted" />
                                <span> retweeted your post </span>
                        </div>
-                       {{template "status" .Status}}
+                       {{template "status" (WithContext .Status $.Ctx)}}
                </div>
        </div>
 
                <div>
                        <div class="notification-info-text">
                                <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
-                               <img class="icon" src="{{GetIcon "liked" .DarkMode}}" alt="liked" />
+                               <img class="icon" src="{{GetIcon "liked" $.Ctx.DarkMode}}" alt="liked" />
                                <span> liked your post </span>
                        </div>
-                       {{template "status" .Status}}
+                       {{template "status" (WithContext .Status $.Ctx)}}
                </div>
        </div>
        {{end}}
@@ -68,4 +69,6 @@
                <a href="{{.NextLink}}">next</a>
        {{end}}
 </div>
+
 {{template "footer.tmpl"}}
+{{end}}
index ff70eaf5db442ffd29ad062515ba5b69b94881c6..0b83d2cd7766a82f6e2e5a32ed0530aa5908f43c 100644 (file)
@@ -1,3 +1,4 @@
+{{with .Data}}
 <form class="post-form" action="/post" method="POST" enctype="multipart/form-data">
        {{if .ReplyContext}}
        <input type="hidden" name="reply_to_id" value="{{.ReplyContext.InReplyToID}}" />
@@ -6,7 +7,7 @@
        <label for="post-content" class="post-form-title"> New post </label>
        {{end}}
        <a class="post-form-emoji-link" href="/emojis" target="_blank" title="emoji reference">
-               <img class="icon post-emoji" src="{{GetIcon "smile-o" .DarkMode}}" alt="emojis" />
+               <img class="icon post-emoji" src="{{GetIcon "smile-o" $.Ctx.DarkMode}}" alt="emojis" />
        </a>
        <div class="post-form-content-container">
                <textarea id="post-content" name="content" class="post-content" cols="50" rows="5">{{if .ReplyContext}}{{.ReplyContext.ReplyContent}}{{end}}</textarea>
@@ -42,4 +43,5 @@
        </div>
        <button type="submit"> Post </button>
 </form>
+{{end}}
 
index 2d9c5390e6bf5b6aececc1911ec0c98ffec2b54f..ce0d3374478aeee2927c0505e37d43421eddb9c2 100644 (file)
@@ -1,7 +1,9 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Retweeted By </div>
 
-{{template "userlist.tmpl" .Users}}
+{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
 
 {{template "footer.tmpl"}}
+{{end}}
index de80facb6918b66f8c49fdb413f38733bea0ef37..b4cd74422093263478d7c62ff4a4af3d3d35894c 100644 (file)
@@ -1,5 +1,6 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Search </div>
 
 <div>
 
 {{if eq .Type "statuses"}}
 {{range .Statuses}}
-{{template "status.tmpl" .}}
+{{template "status.tmpl" (WithContext . $.Ctx)}}
 {{end}}
 
 {{end}}
 {{if eq .Type "accounts"}}
-{{template "userlist.tmpl" .Users}}
+{{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
 {{end}}
 
 <div class="pagination">
@@ -34,4 +35,6 @@
                <a href="{{.NextLink}}">next</a>
        {{end}}
 </div>
+
 {{template "footer.tmpl"}}
+{{end}}
index 06e2a9a56d8fcf409869d66b7fdddc04d573611a..a32a1b041a9894f573c7b90521c652d4ba6639fa 100644 (file)
@@ -1,5 +1,6 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Settings </div>
 
 <form id="settings-form" action="/settings" method="POST">
@@ -36,3 +37,4 @@
 </form>
 
 {{template "footer.tmpl"}}
+{{end}}
index 5dd03f6e616d36e22be53dab08ed43ec1bf33968..a1999486fd489ad047abea9d383ecf4f70ba17d1 100644 (file)
@@ -1,4 +1,5 @@
-{{template "header.tmpl" .HeaderData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
 <div class="page-title"> Signin </div>
 
 <form class="signin-form" action="/signin" method="post">
@@ -8,3 +9,4 @@
 </form>
 
 {{template "footer.tmpl"}}
+{{end}}
index 91d666d3a418f45e4237e22c7e75a7b284439123..09c13547e6b96ff4940bec46c1bfe7987218051a 100644 (file)
@@ -1,3 +1,4 @@
+{{with .Data}}
 <div id="status-{{.ID}}" class="status-container-container">
        {{if .Reblog}}
        <div class="retweet-info">
@@ -5,12 +6,13 @@
                        <img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="avatar" />
                </a>
                <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>  
-               <img class="icon" src="{{GetIcon "retweeted" .DarkMode}}" alt="retweeted" />
+               <img class="icon" src="{{GetIcon "retweeted" $.Ctx.DarkMode}}" alt="retweeted" />
                retweeted
        </div>
-       {{template "status" .Reblog}}
+       {{template "status" (WithContext .Reblog $.Ctx)}}
        {{else}}
-       {{block "status" .}}
+       {{block "status" (WithContext . $.Ctx)}}
+       {{with $s := .Data}}
        <div class="status-container status-{{.ID}}" data-id="{{.ID}}">
                {{if not .HideAccountInfo}}
                <div class="status-profile-img-container">
                                </a>
                                <a class="status-visibility">
                                        {{if eq .Visibility "public"}}
-                                       <img class="icon" src="{{GetIcon "globe" .DarkMode}}" alt="Public" title="Public" />
+                                       <img class="icon" src="{{GetIcon "globe" $.Ctx.DarkMode}}" alt="Public" title="Public" />
                                        {{else if eq .Visibility "unlisted"}}
-                                       <img class="icon" src="{{GetIcon "unlock-alt" .DarkMode}}" alt="Unlisted" title="Unlisted" />
+                                       <img class="icon" src="{{GetIcon "unlock-alt" $.Ctx.DarkMode}}" alt="Unlisted" title="Unlisted" />
                                        {{else if eq .Visibility "private"}}
-                                       <img class="icon" src="{{GetIcon "lock" .DarkMode}}" alt="Private" title="Private" />
+                                       <img class="icon" src="{{GetIcon "lock" $.Ctx.DarkMode}}" alt="Private" title="Private" />
                                        {{else if eq .Visibility "direct"}}
-                                       <img class="icon" src="{{GetIcon "envelope" .DarkMode}}" alt="Direct" title="Direct" />
+                                       <img class="icon" src="{{GetIcon "envelope" $.Ctx.DarkMode}}" alt="Direct" title="Direct" />
                                        {{end}}
                                </a>
                                <a class="remote-link" href="{{.URL}}" target="_blank" title="source">
-                                       <img class="icon" src="{{GetIcon "link" .DarkMode}}" alt="source" />
+                                       <img class="icon" src="{{GetIcon "link" $.Ctx.DarkMode}}" alt="source" />
                                </a>
                        </div>
                        {{end}}
@@ -46,7 +48,7 @@
                                {{if .InReplyToID}}
                                <div class="status-reply-to">
                                        <a class="status-reply-to-link" href="{{if not .ShowReplies}}/thread/{{.InReplyToID}}{{end}}#status-{{.InReplyToID}}"> 
-                                               <img class="icon" src="{{GetIcon "mail-forward" .DarkMode}}" alt="reply to" /> reply to {{.Pleroma.InReplyToAccountAcct}} 
+                                               <img class="icon" src="{{GetIcon "mail-forward" $.Ctx.DarkMode}}" alt="reply to" /> reply to {{.Pleroma.InReplyToAccountAcct}} 
                                        </a>
                                </div>
                                {{if index .ReplyMap .ID}} <span class="status-reply-info-divider"> - </span> {{end}}
@@ -66,7 +68,7 @@
                        {{if eq .Type "image"}}
                        <a class="img-link" href="{{.URL}}" target="_blank">
                                <img class="status-image" src="{{.URL}}" alt="status-image" />
-                               {{if (and $.MaskNSFW $.Sensitive)}}
+                               {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
                                <div class="status-nsfw-overlay"></div>
                                {{end}}
                        </a>
@@ -81,7 +83,7 @@
                                        <source src="{{.URL}}">
                                        <p> Your browser doesn't support HTML5 video </p>
                                </video>
-                               {{if (and $.MaskNSFW $.Sensitive)}}
+                               {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
                                <div class="status-nsfw-overlay"></div>
                                {{end}}
                        </div>
                        <div class="status-action-container"> 
                                <div class="status-action">
                                        <a class="status-you" href="/thread/{{.ID}}?reply=true#status-{{.ID}}" title="reply"> 
-                                               <img class="icon" src="{{GetIcon "reply" .DarkMode}}" alt="reply" />
+                                               <img class="icon" src="{{GetIcon "reply" $.Ctx.DarkMode}}" alt="reply" />
                                        </a>
-                                       <a class="status-reply-count" href="/thread/{{.ID}}#status-{{.ID}}" {{if .ThreadInNewTab}}target="_blank"{{end}}>
+                                       <a class="status-reply-count" href="/thread/{{.ID}}#status-{{.ID}}" {{if $.Ctx.ThreadInNewTab}}target="_blank"{{end}}>
                                                {{DisplayInteractionCount .RepliesCount}}
                                        </a>
                                </div>
                                <div class="status-action">
                                        {{if or (eq .Visibility "private") (eq .Visibility "direct")}}
                                        <a class="status-retweet" title="this status cannot be retweeted"> 
-                                               <img class="icon" src="{{GetIcon "retweet" .DarkMode}}" alt="retweet" />
+                                               <img class="icon" src="{{GetIcon "retweet" $.Ctx.DarkMode}}" alt="retweet" />
                                        </a>
                                        {{else}}
                                        {{if .Reblogged}}
                                        <form class="status-retweet" data-action="unretweet" action="/unretweet/{{.ID}}" method="post">
                                                <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" />
-                                               <input type="image" src="{{GetIcon "retweeted" .DarkMode}}" alt="undo retweet" class="icon" title="undo retweet">
+                                               <input type="image" src="{{GetIcon "retweeted" $.Ctx.DarkMode}}" alt="undo retweet" class="icon" title="undo retweet">
                                        </form>
                                        {{else}}
                                        <form class="status-retweet" data-action="retweet" action="/retweet/{{.ID}}" method="post">
                                                <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" />
-                                               <input type="image" src="{{GetIcon "retweet" .DarkMode}}" alt="retweet" class="icon" title="retweet">
+                                               <input type="image" src="{{GetIcon "retweet" $.Ctx.DarkMode}}" alt="retweet" class="icon" title="retweet">
                                        </form>
                                        {{end}}
                                        {{end}}
                                        {{if .Favourited}}
                                        <form class="status-like" data-action="unlike" action="/unlike/{{.ID}}" method="post">
                                                <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" />
-                                               <input type="image" src="{{GetIcon "liked" .DarkMode}}" alt="unlike" class="icon" title="unlike">
+                                               <input type="image" src="{{GetIcon "liked" $.Ctx.DarkMode}}" alt="unlike" class="icon" title="unlike">
                                        </form>
                                        {{else}}
                                        <form class="status-like" data-action="like" action="/like/{{.ID}}" method="post">
                                                <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" />
-                                               <input type="image" src="{{GetIcon "star-o" .DarkMode}}" alt="like" class="icon" title="like">
+                                               <input type="image" src="{{GetIcon "star-o" $.Ctx.DarkMode}}" alt="like" class="icon" title="like">
                                        </form>
                                        {{end}}
                                        <a class="status-like-count" href="/likedby/{{.ID}}" title="click to see the the list"> 
                                        </a>
                                </div>
                                <div class="status-action">
-                                       <a class="status-time" href="{{if not .ShowReplies}}/thread/{{.ID}}{{end}}#status-{{.ID}}" {{if .ThreadInNewTab}}target="_blank"{{end}}> 
+                                       <a class="status-time" href="{{if not .ShowReplies}}/thread/{{.ID}}{{end}}#status-{{.ID}}" {{if $.Ctx.ThreadInNewTab}}target="_blank"{{end}}> 
                                                <time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{FormatTimeRFC822 .CreatedAt}}"> {{TimeSince .CreatedAt}} </time> 
                                        </a>
                                </div>
        </div>
        {{end}}
        {{end}}
+       {{end}}
 </div>
+{{end}}
index 7ec0e94a6e5b7e949854c04b55c9ff6146608654..2927ee4b04ae975d34a02d4faae8af1eee816845 100644 (file)
@@ -1,14 +1,16 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with $s := .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> Thread </div>
 
 {{range .Statuses}}
 
-{{template "status.tmpl" .}}
-{{if $.PostContext.ReplyContext}}{{if eq .ID $.PostContext.ReplyContext.InReplyToID}}
-{{template "postform.tmpl" $.PostContext}}
+{{template "status.tmpl" (WithContext . $.Ctx)}}
+{{if $s.PostContext.ReplyContext}}{{if eq .ID $s.PostContext.ReplyContext.InReplyToID}}
+{{template "postform.tmpl" (WithContext $s.PostContext $.Ctx)}}
 {{end}}{{end}}
 
 {{end}}
 
 {{template "footer.tmpl"}}
+{{end}}
index b6885010706b06f76ab6d4fbe3cba5728dfbb2af..aa951fc815fe58b637e2f33217835ff24f4cd149 100644 (file)
@@ -1,12 +1,12 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> {{.Title}} </div>
 
-
-{{template "postform.tmpl" .PostContext}}
+{{template "postform.tmpl" (WithContext .PostContext $.Ctx)}}
 
 {{range .Statuses}}
-{{template "status.tmpl" .}}
+{{template "status.tmpl" (WithContext . $.Ctx)}}
 {{end}}
 
 <div class="pagination">
@@ -17,4 +17,6 @@
                <a href="{{.NextLink}}">next</a>
        {{end}}
 </div>
+
 {{template "footer.tmpl"}}
+{{end}}
index 60536bb361bd335e6563c19723ee9e53f073b744..bbbce329e4844ccec383ace1dae7f6a8ea698b1a 100644 (file)
@@ -1,5 +1,6 @@
-{{template "header.tmpl" .HeaderData}}
-{{template "navigation.tmpl" .NavbarData}}
+{{with .Data}}
+{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
+{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
 <div class="page-title"> User </div>
 
 <div class="user-info-container">
@@ -14,7 +15,7 @@
                        <span class="status-dname"> {{EmojiFilter .User.DisplayName .User.Emojis}} </span>  
                        <span class="status-uname"> {{.User.Acct}} </span>
                        <a class="remote-link" href="{{.User.URL}}" target="_blank" title="remote profile">
-                               <img class="icon" src="{{GetIcon "link" .DarkMode}}" alt="link" />
+                               <img class="icon" src="{{GetIcon "link" $.Ctx.DarkMode}}" alt="link" />
                        </a>
                </div>
                <div>
@@ -48,7 +49,7 @@
 </div>
 
 {{range .Statuses}}
-{{template "status.tmpl" .}}
+{{template "status.tmpl" (WithContext . $.Ctx)}}
 {{end}}
 
 <div class="pagination">
@@ -58,4 +59,4 @@
 </div>
 
 {{template "footer.tmpl"}}
-
+{{end}}
index d52e67d8ddf136decd3461dd2fd7e60e7ba279e1..83fa1df534619df5dbda9751b1fa03a26027e92b 100644 (file)
@@ -1,3 +1,4 @@
+{{with .Data}}
 <div class="user-list-container">
        {{range .}}
        <div class="user-list-item">
@@ -15,3 +16,4 @@
        </div>
        {{end}}
 </div>
+{{end}}