add EditMode enum to adapter, basic CMS list
This commit is contained in:
parent
8e8fd65f92
commit
3f04afa16e
6 changed files with 46 additions and 3 deletions
|
@ -1,8 +1,16 @@
|
||||||
package archetype
|
package archetype
|
||||||
|
|
||||||
|
type EditMode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
EditModeLiteralTextArea EditMode = iota
|
||||||
|
EditModeEscapedContentEditable
|
||||||
|
)
|
||||||
|
|
||||||
type Adapter interface {
|
type Adapter interface {
|
||||||
Init(cfg *Config)
|
Init(cfg *Config)
|
||||||
Name() string
|
Name() string
|
||||||
|
EditMode() EditMode
|
||||||
GetConfig(key string) (interface{}, error)
|
GetConfig(key string) (interface{}, error)
|
||||||
SetConfig(key string, value interface{}) error
|
SetConfig(key string, value interface{}) error
|
||||||
ListPages() map[string]string
|
ListPages() map[string]string
|
||||||
|
|
|
@ -27,6 +27,10 @@ func (self *EurekaAdapter) Name() string {
|
||||||
return "eureka"
|
return "eureka"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *EurekaAdapter) EditMode() EditMode {
|
||||||
|
return EditModeLiteralTextArea
|
||||||
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) GetConfig(key string) (interface{}, error) {
|
func (self *EurekaAdapter) GetConfig(key string) (interface{}, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
17
lfo/middleware.go
Normal file
17
lfo/middleware.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package lfo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
core "nilfm.cc/git/nirvash/archetype"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WithAdapter(next http.Handler, adapter core.Adapter) http.Handler {
|
||||||
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
*req = *req.WithContext(context.WithValue(req.Context(), "adapter", adapter))
|
||||||
|
next.ServeHTTP(w, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
return http.HandlerFunc(handlerFunc)
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
core "nilfm.cc/git/nirvash/archetype"
|
core "nilfm.cc/git/nirvash/archetype"
|
||||||
|
shell "nilfm.cc/git/nirvash/lfo"
|
||||||
"nilfm.cc/git/quartzgun/indentalUserDB"
|
"nilfm.cc/git/quartzgun/indentalUserDB"
|
||||||
"nilfm.cc/git/quartzgun/middleware"
|
"nilfm.cc/git/quartzgun/middleware"
|
||||||
"nilfm.cc/git/quartzgun/renderer"
|
"nilfm.cc/git/quartzgun/renderer"
|
||||||
|
@ -38,10 +39,11 @@ func main() {
|
||||||
rtr.Post("/login", middleware.Authorize("/", udb, "/login?tryagain=1"))
|
rtr.Post("/login", middleware.Authorize("/", udb, "/login?tryagain=1"))
|
||||||
|
|
||||||
rtr.Get("/", middleware.Protected(
|
rtr.Get("/", middleware.Protected(
|
||||||
|
shell.WithAdapter(
|
||||||
renderer.Template(
|
renderer.Template(
|
||||||
"templates/cms_list.html",
|
"templates/cms_list.html",
|
||||||
"templates/header.html",
|
"templates/header.html",
|
||||||
"templates/footer.html"), http.MethodGet, udb, "/login"))
|
"templates/footer.html"), cfg.Adapter), http.MethodGet, udb, "/login"))
|
||||||
|
|
||||||
http.ListenAndServe(":8080", rtr)
|
http.ListenAndServe(":8080", rtr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
{{ $pages := ((.Context).Value "adapter").ListPages }}
|
||||||
|
|
||||||
{{ template "header" .}}
|
{{ template "header" .}}
|
||||||
<h1>It works!</h1>
|
<div class="page-list">
|
||||||
|
<a class="new-page-button" href="/new/">New Page</a>
|
||||||
|
<ul>
|
||||||
|
{{ range $slug, $title := $pages }}
|
||||||
|
<li><a href="/edit/{{$slug}}">{{$title}}</a></li>
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="static-files-list">
|
||||||
|
</div>
|
||||||
{{ template "footer" .}}
|
{{ template "footer" .}}
|
|
@ -5,7 +5,7 @@
|
||||||
<meta charset='utf-8'>
|
<meta charset='utf-8'>
|
||||||
<meta name='description' content='Nirvash CMS'/>
|
<meta name='description' content='Nirvash CMS'/>
|
||||||
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||||
<title>Nirvash — Test</title>
|
<title>Nirvash — CMS</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in a new issue