1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00
miniflux-v2/internal/ui/view/view.go
Julien Voisin 798bc4cd2d
refactor(static): use a simple struct instead of two slices to store assets data and checksums
- Use a simple struct instead of two slices to store the data and the checksums
  of resources
- Remove a superfluous call to Sprintf
- Factorise presence check and data retrieval in some maps
- Size the maps when possible
2025-08-05 19:35:27 -07:00

50 lines
1.6 KiB
Go

// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package view // import "miniflux.app/v2/internal/ui/view"
import (
"net/http"
"miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/http/request"
"miniflux.app/v2/internal/template"
"miniflux.app/v2/internal/ui/session"
"miniflux.app/v2/internal/ui/static"
)
// View wraps template argument building.
type View struct {
tpl *template.Engine
r *http.Request
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+".html", v.params)
}
// New returns a new view with default parameters.
func New(tpl *template.Engine, r *http.Request, sess *session.Session) *View {
theme := request.UserTheme(r)
return &View{tpl, r, map[string]interface{}{
"menu": "",
"csrf": request.CSRF(r),
"flashMessage": sess.FlashMessage(request.FlashMessage(r)),
"flashErrorMessage": sess.FlashErrorMessage(request.FlashErrorMessage(r)),
"theme": theme,
"language": request.UserLanguage(r),
"theme_checksum": static.StylesheetBundles[theme].Checksum,
"app_js_checksum": static.JavascriptBundles["app"].Checksum,
"sw_js_checksum": static.JavascriptBundles["service-worker"].Checksum,
"webauthn_js_checksum": static.JavascriptBundles["webauthn"].Checksum,
"webAuthnEnabled": config.Opts.WebAuthn(),
}}
}