mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-04 18:19:54 +00:00
Create system for adding data attributes to Base body
This commit is contained in:
parent
dbaf87404b
commit
7fc48f21fc
11
auth/web.go
11
auth/web.go
@ -39,7 +39,7 @@ func handlerUserList(w http.ResponseWriter, rq *http.Request) {
|
||||
lc := l18n.FromRequest(rq)
|
||||
w.Header().Set("Content-Type", mime.TypeByExtension(".html"))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("ui.users_title"), UserList(lc))))
|
||||
w.Write([]byte(viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("ui.users_title"), UserList(lc), []string{})))
|
||||
}
|
||||
|
||||
func handlerLock(w http.ResponseWriter, rq *http.Request) {
|
||||
@ -57,6 +57,7 @@ func handlerRegister(w http.ResponseWriter, rq *http.Request) {
|
||||
viewutil.MetaFrom(w, rq),
|
||||
lc.Get("auth.register_title"),
|
||||
Register(rq),
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
return
|
||||
@ -81,6 +82,7 @@ func handlerRegister(w http.ResponseWriter, rq *http.Request) {
|
||||
err.Error(),
|
||||
lc.Get("auth.try_again"),
|
||||
),
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
return
|
||||
@ -111,7 +113,7 @@ func handlerLogout(w http.ResponseWriter, rq *http.Request) {
|
||||
}
|
||||
_, _ = io.WriteString(
|
||||
w,
|
||||
viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("auth.logout_title"), Logout(can, lc)),
|
||||
viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("auth.logout_title"), Logout(can, lc), []string{}),
|
||||
)
|
||||
} else if rq.Method == http.MethodPost {
|
||||
user.LogoutFromRequest(w, rq)
|
||||
@ -131,6 +133,7 @@ func handlerLogin(w http.ResponseWriter, rq *http.Request) {
|
||||
viewutil.MetaFrom(w, rq),
|
||||
lc.Get("auth.login_title"),
|
||||
Login(lc),
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
} else if rq.Method == http.MethodPost {
|
||||
@ -142,7 +145,7 @@ func handlerLogin(w http.ResponseWriter, rq *http.Request) {
|
||||
if err != nil {
|
||||
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
_, _ = io.WriteString(w, viewutil.Base(viewutil.MetaFrom(w, rq), err.Error(), LoginError(err.Error(), lc)))
|
||||
_, _ = io.WriteString(w, viewutil.Base(viewutil.MetaFrom(w, rq), err.Error(), LoginError(err.Error(), lc), []string{}))
|
||||
return
|
||||
}
|
||||
http.Redirect(w, rq, "/", http.StatusSeeOther)
|
||||
@ -189,6 +192,7 @@ func handlerTelegramLogin(w http.ResponseWriter, rq *http.Request) {
|
||||
err.Error(),
|
||||
lc.Get("auth.go_login"),
|
||||
),
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
return
|
||||
@ -209,6 +213,7 @@ func handlerTelegramLogin(w http.ResponseWriter, rq *http.Request) {
|
||||
err.Error(),
|
||||
lc.Get("auth.go_login"),
|
||||
),
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
return
|
||||
|
@ -125,6 +125,7 @@ func handlerAbout(w http.ResponseWriter, rq *http.Request) {
|
||||
viewutil.MetaFrom(w, rq),
|
||||
title,
|
||||
AboutHTML(lc),
|
||||
[]string{},
|
||||
))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
@ -15,7 +15,7 @@
|
||||
<script src="/static/shortcuts.js"></script>
|
||||
{{range .HeadElements}}{{.}}{{end}}
|
||||
</head>
|
||||
<body data-rrh-addr="{{if .Addr}}{{.Addr}}{{else}}{{.Meta.Addr}}{{end}}">
|
||||
<body data-rrh-addr="{{if .Addr}}{{.Addr}}{{else}}{{.Meta.Addr}}{{end}}"{{range .ExtraData}} data-rrh-{{.}}=""{{end}}>
|
||||
<header>
|
||||
<nav class="main-width top-bar">
|
||||
<ul class="top-bar__wrapper">
|
||||
|
@ -22,6 +22,7 @@ func HttpErr(meta Meta, status int, name, errMsg string) {
|
||||
name,
|
||||
meta.Lc.Get("ui.error_go_back"),
|
||||
),
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ type BaseData struct {
|
||||
Addr string
|
||||
Title string // TODO: remove
|
||||
Body string // TODO: remove
|
||||
ExtraData []string
|
||||
}
|
||||
|
||||
func (bd *BaseData) withBaseValues(meta Meta, headerLinks []HeaderLink, commonScripts []string) {
|
||||
@ -108,7 +109,7 @@ func (bd *BaseData) withBaseValues(meta Meta, headerLinks []HeaderLink, commonSc
|
||||
|
||||
// Base is a temporary wrapper around BaseEn and BaseRu, meant to facilitate the migration from qtpl.
|
||||
// TODO: get rid of this
|
||||
func Base(meta Meta, title, body string, headElements ...string) string {
|
||||
func Base(meta Meta, title, body string, extraData []string, headElements ...string) string {
|
||||
var w strings.Builder
|
||||
meta.W = &w
|
||||
t := localizedBaseWithWeirdBody(meta)
|
||||
@ -119,6 +120,7 @@ func Base(meta Meta, title, body string, headElements ...string) string {
|
||||
HeaderLinks: HeaderLinks,
|
||||
CommonScripts: cfg.CommonScripts,
|
||||
Body: body,
|
||||
ExtraData: extraData,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
@ -49,7 +49,9 @@ func handlerRemoveMedia(w http.ResponseWriter, rq *http.Request) {
|
||||
viewutil.Base(
|
||||
meta,
|
||||
fmt.Sprintf(lc.Get("ui.ask_remove_media"), util.BeautifulName(h.CanonicalName())),
|
||||
hypview.RemoveMediaAsk(rq, h.CanonicalName())))
|
||||
hypview.RemoveMediaAsk(rq, h.CanonicalName()),
|
||||
[]string{},
|
||||
))
|
||||
return
|
||||
}
|
||||
switch h := h.(type) {
|
||||
@ -175,7 +177,8 @@ func handlerEdit(w http.ResponseWriter, rq *http.Request) {
|
||||
viewutil.Base(
|
||||
meta,
|
||||
fmt.Sprintf(lc.Get("edit.title"), util.BeautifulName(hyphaName)),
|
||||
hypview.Editor(rq, hyphaName, textAreaFill, warning)))
|
||||
hypview.Editor(rq, hyphaName, textAreaFill, warning),
|
||||
[]string{}))
|
||||
}
|
||||
|
||||
// handlerUploadText uploads a new text part for the hypha.
|
||||
@ -213,7 +216,9 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
||||
textData,
|
||||
message,
|
||||
"",
|
||||
mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx)))))
|
||||
mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx))),
|
||||
[]string{},
|
||||
))
|
||||
} else {
|
||||
http.Redirect(w, rq, "/hypha/"+hyphaName, http.StatusSeeOther)
|
||||
}
|
||||
|
@ -48,7 +48,9 @@ func handlerMedia(w http.ResponseWriter, rq *http.Request) {
|
||||
viewutil.Base(
|
||||
viewutil.MetaFrom(w, rq),
|
||||
lc.Get("ui.media_title", &l18n.Replacements{"name": util.BeautifulName(hyphaName)}),
|
||||
views2.MediaMenu(rq, h, u)))
|
||||
views2.MediaMenu(rq, h, u),
|
||||
[]string{},
|
||||
))
|
||||
}
|
||||
|
||||
// handlerRevisionText sends Mycomarkup text of the hypha at the given revision. See also: handlerRevision, handlerText.
|
||||
@ -141,6 +143,7 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) {
|
||||
viewutil.MetaFrom(w, rq),
|
||||
lc.Get("ui.revision_title", &l18n.Replacements{"name": util.BeautifulName(hyphaName), "rev": revHash}),
|
||||
page,
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
}
|
||||
@ -191,6 +194,7 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
|
||||
viewutil.MetaFrom(w, rq),
|
||||
util.BeautifulName(hyphaName),
|
||||
views2.Hypha(viewutil.MetaFrom(w, rq), h, contents),
|
||||
[]string{},
|
||||
openGraph))
|
||||
case hyphae.ExistingHypha:
|
||||
fileContentsT, errT := os.ReadFile(h.TextFilePath())
|
||||
@ -206,11 +210,13 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
|
||||
contents = mycoopts.Media(h, lc) + contents
|
||||
}
|
||||
|
||||
|
||||
util.HTTP200Page(w,
|
||||
viewutil.Base(
|
||||
viewutil.MetaFrom(w, rq),
|
||||
util.BeautifulName(hyphaName),
|
||||
views2.Hypha(viewutil.MetaFrom(w, rq), h, contents),
|
||||
[]string{},
|
||||
openGraph))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user