// 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/static" ) // view wraps template argument building. type view struct { tpl *template.Engine r *http.Request params map[string]any } // Set adds a new template argument. func (v *view) Set(param string, value any) *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) *view { webSession := request.WebSession(r) flashSuccessMessage, flashErrorMessage := webSession.ConsumeMessages() v := newView(tpl, r) v.params["csrf"] = webSession.CSRF() v.params["flashSuccessMessage"] = flashSuccessMessage v.params["flashErrorMessage"] = flashErrorMessage return v } // NewPublic returns a view for public pages, without the CSRF token or flash messages. func NewPublic(tpl *template.Engine, r *http.Request) *view { return newView(tpl, r) } func newView(tpl *template.Engine, r *http.Request) *view { webSession := request.WebSession(r) theme := webSession.Theme() return &view{tpl, r, map[string]any{ "menu": "", "theme": theme, "language": webSession.Language(), "theme_checksum": static.StylesheetBundles[theme+".css"].Checksum, "app_js_checksum": static.JavascriptBundles["app.js"].Checksum, "sw_js_checksum": static.JavascriptBundles["service-worker.js"].Checksum, "webAuthnEnabled": config.Opts.WebAuthn(), }} }