diff options
author | 2018-04-29 16:35:04 -0700 | |
---|---|---|
committer | 2018-04-29 16:35:04 -0700 | |
commit | f49b42f70f902d4da1e0fa4080e99164b331b716 (patch) | |
tree | c6bdd19f11d100c44b0d30344ec37038f649e988 /ui/view | |
parent | 1eba1730d1af50ed545f4fde78b22d6fb62ca11e (diff) |
Use vanilla HTTP handlers (refactoring)
Diffstat (limited to 'ui/view')
-rw-r--r-- | ui/view/view.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ui/view/view.go b/ui/view/view.go new file mode 100644 index 0000000..a1c6646 --- /dev/null +++ b/ui/view/view.go @@ -0,0 +1,39 @@ +// Copyright 2018 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package view + +import ( + "github.com/miniflux/miniflux/http/context" + "github.com/miniflux/miniflux/template" + "github.com/miniflux/miniflux/ui/session" +) + +// View wraps template argument building. +type View struct { + tpl *template.Engine + ctx *context.Context + params map[string]interface{} +} + +// Set adds a new template argument. +func (v *View) Set(param string, value interface{}) *View { + v.params[param] = value + return v +} + +// Render executes the template with arguments. +func (v *View) Render(template string) []byte { + return v.tpl.Render(template, v.ctx.UserLanguage(), v.params) +} + +// New returns a new view with default parameters. +func New(tpl *template.Engine, ctx *context.Context, sess *session.Session) *View { + b := &View{tpl, ctx, make(map[string]interface{})} + b.params["menu"] = "" + b.params["csrf"] = ctx.CSRF() + b.params["flashMessage"] = sess.FlashMessage() + b.params["flashErrorMessage"] = sess.FlashErrorMessage() + return b +} |