mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Use vanilla HTTP handlers (refactoring)
This commit is contained in:
parent
1eba1730d1
commit
f49b42f70f
121 changed files with 4339 additions and 3369 deletions
39
ui/view/view.go
Normal file
39
ui/view/view.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue