2018-04-30 01:35:04 +02:00
|
|
|
// 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.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package view // import "miniflux.app/ui/view"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/http/context"
|
|
|
|
"miniflux.app/template"
|
|
|
|
"miniflux.app/ui/session"
|
|
|
|
"miniflux.app/ui/static"
|
2018-04-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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{})}
|
2018-07-22 21:24:46 +02:00
|
|
|
theme := ctx.UserTheme()
|
2018-04-30 01:35:04 +02:00
|
|
|
b.params["menu"] = ""
|
|
|
|
b.params["csrf"] = ctx.CSRF()
|
|
|
|
b.params["flashMessage"] = sess.FlashMessage()
|
|
|
|
b.params["flashErrorMessage"] = sess.FlashErrorMessage()
|
2018-07-22 21:24:46 +02:00
|
|
|
b.params["theme"] = theme
|
|
|
|
b.params["theme_checksum"] = static.StylesheetsChecksums[theme]
|
|
|
|
b.params["app_js_checksum"] = static.JavascriptsChecksums["app"]
|
|
|
|
b.params["sw_js_checksum"] = static.JavascriptsChecksums["sw"]
|
2018-04-30 01:35:04 +02:00
|
|
|
return b
|
|
|
|
}
|