2018-04-29 19:35:04 -04: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 00:51:50 -04:00
|
|
|
package view // import "miniflux.app/ui/view"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
import (
|
2018-09-03 17:26:40 -04:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"miniflux.app/http/request"
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/template"
|
|
|
|
"miniflux.app/ui/session"
|
|
|
|
"miniflux.app/ui/static"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// View wraps template argument building.
|
|
|
|
type View struct {
|
|
|
|
tpl *template.Engine
|
2018-09-03 17:26:40 -04:00
|
|
|
r *http.Request
|
2018-04-29 19:35:04 -04:00
|
|
|
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 {
|
2021-02-19 00:33:29 -05:00
|
|
|
return v.tpl.Render(template+".html", request.UserLanguage(v.r), v.params)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a new view with default parameters.
|
2018-09-03 17:26:40 -04:00
|
|
|
func New(tpl *template.Engine, r *http.Request, sess *session.Session) *View {
|
|
|
|
b := &View{tpl, r, make(map[string]interface{})}
|
|
|
|
theme := request.UserTheme(r)
|
2018-04-29 19:35:04 -04:00
|
|
|
b.params["menu"] = ""
|
2018-09-03 17:26:40 -04:00
|
|
|
b.params["csrf"] = request.CSRF(r)
|
|
|
|
b.params["flashMessage"] = sess.FlashMessage(request.FlashMessage(r))
|
|
|
|
b.params["flashErrorMessage"] = sess.FlashErrorMessage(request.FlashErrorMessage(r))
|
2018-07-22 15:24:46 -04:00
|
|
|
b.params["theme"] = theme
|
2021-02-18 00:58:04 -05:00
|
|
|
b.params["theme_checksum"] = static.StylesheetBundleChecksums[theme]
|
2021-02-18 23:34:58 -05:00
|
|
|
b.params["app_js_checksum"] = static.JavascriptBundleChecksums["app"]
|
|
|
|
b.params["sw_js_checksum"] = static.JavascriptBundleChecksums["service-worker"]
|
2018-04-29 19:35:04 -04:00
|
|
|
return b
|
|
|
|
}
|