simple page edit screen
This commit is contained in:
parent
3f04afa16e
commit
358d4fb2af
5 changed files with 54 additions and 17 deletions
|
@ -15,3 +15,14 @@ func WithAdapter(next http.Handler, adapter core.Adapter) http.Handler {
|
||||||
return http.HandlerFunc(handlerFunc)
|
return http.HandlerFunc(handlerFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithEditModes(next http.Handler) http.Handler {
|
||||||
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
*req = *req.WithContext(context.WithValue(req.Context(), "edit-modes", map[string]core.EditMode{
|
||||||
|
"Literal": core.EditModeLiteralTextArea,
|
||||||
|
"Escaped": core.EditModeEscapedContentEditable,
|
||||||
|
}))
|
||||||
|
next.ServeHTTP(w, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
return http.HandlerFunc(handlerFunc)
|
||||||
|
}
|
||||||
|
|
|
@ -45,5 +45,12 @@ func main() {
|
||||||
"templates/header.html",
|
"templates/header.html",
|
||||||
"templates/footer.html"), cfg.Adapter), http.MethodGet, udb, "/login"))
|
"templates/footer.html"), cfg.Adapter), http.MethodGet, udb, "/login"))
|
||||||
|
|
||||||
|
rtr.Get(`/edit/(?P<Slug>\S+)`, middleware.Protected(
|
||||||
|
shell.WithAdapter(
|
||||||
|
renderer.Template(
|
||||||
|
"templates/cms_edit.html",
|
||||||
|
"templates/header.html",
|
||||||
|
"templates/footer.html"), cfg.Adapter), http.MethodGet, udb, "/login"))
|
||||||
|
|
||||||
http.ListenAndServe(":8080", rtr)
|
http.ListenAndServe(":8080", rtr)
|
||||||
}
|
}
|
||||||
|
|
19
templates/cms_edit.html
Normal file
19
templates/cms_edit.html
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{{ $slug := ((.Context).Value "params").Slug }}
|
||||||
|
{{ $page := ((.Context).Value "adapter").GetPage $slug }}
|
||||||
|
{{ $editMode := ((.Context).Value "adapter").EditMode }}
|
||||||
|
{{ $editModes := (.Context).Value "edit-modes" }}
|
||||||
|
|
||||||
|
{{ template "header" . }}
|
||||||
|
|
||||||
|
<form method="POST" action="/save/{{$slug}}">
|
||||||
|
<textarea name="title">{{($page).Title}}</textarea>
|
||||||
|
<span>last edited {{($page).Edited}}</span>
|
||||||
|
{{ if eq $editMode 0 }}
|
||||||
|
<textarea name="content">{{($page).Content}}</textarea>
|
||||||
|
{{ else }}
|
||||||
|
<div contenteditable>{{($page).Content}}</div>
|
||||||
|
{{ end }}
|
||||||
|
<input type="submit" value="Save"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{{ template "footer" . }}
|
Loading…
Reference in a new issue