1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-04-29 13:53:10 +00:00
Timur Ismagilov a4cc67cd74
Migrate from log to slog #109 (#255)
* Migrate httpd.go

* Migrate history and main

* Migrate hypview

* Migrate interwiki

* Migrate misc

* Migrate utils

* Migrate backlinks

* Migrate categories

* Reformat some imports

* Migrate hyphae

* Migrate migration

* Reformat more imports

* Migrate user

* Migrate shroom

* Migrate viewutil

* Migrate web

* Migrate others

* Migrate main

* Wording concerns
2024-09-07 23:55:39 +03:00

41 lines
781 B
Go

package viewutil
import (
"html/template"
"io"
"net/http"
"github.com/bouncepaw/mycorrhiza/internal/user"
"github.com/bouncepaw/mycorrhiza/l18n"
)
// Meta is a bundle of common stuffs used by views, templates.
type Meta struct {
Lc *l18n.Localizer
U *user.User
W io.Writer
Addr string
// New template additions
HeadElements []template.HTML
BodyAttributes map[string]string
}
// MetaFrom makes a Meta from the given data. You are meant to further modify it.
func MetaFrom(w http.ResponseWriter, rq *http.Request) Meta {
return Meta{
Lc: l18n.FromRequest(rq),
U: user.FromRequest(rq),
W: w,
Addr: rq.URL.Path,
}
}
func (m Meta) Locale() string {
return m.Lc.Locale
}
func (m Meta) LocaleIsRussian() bool {
return m.Locale() == "ru"
}