all repos — nirvash @ 2833ba2574621e736f6e37c897224eb22c1f175f

modular CMS using the quartzgun library

standardize templates a bit, add strong types to build options
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmKtbeQACgkQO3+8IhRO
Y5iX9g//XxLuhMUQEFicmJ2otjjNrcyY6oFFfCrcmnbPyB5kjRRcRIuB6/5kes2f
wJjLv/C1Jy9l1Pmj7CayH8SXhg0c61gKmHQSPo/IriwymViA4gJFufX6MPf9uMsX
d3aepE2rwzT90SgEHLlm8JWNI8JRVqM9KY9m07XQ/05WpokAvduwWmT5zXzs3mOX
BM5emDK7srP5JGjU54raP2iIjE/trADiY+f5uVm/7RAn5vxyPESPsDxOgkV93KlW
TohHLiASoUoDQqajmCbxAzBNqNlNC3nJE+wT4hHRdVooEdbGN9b/iItrpYZJ9XNU
bHnlxtF7jDs+dPDFzvM/k9AfqNXo65MIPtXHVlnHC5dEz0gtm+LR57Iw9EgnprTi
yR8Ph9oq+KneHTAzk5qtmk2TD2+YSDt5REFXGDmyqQsphTWDAczOfqipjXkavPn2
K0eWLtzRKfdRMjQNjTOgz+u4gSk8Z9QQsNH6+KInttK09Qt5OAhEq+9av4sZQV2q
ZuxvEwKxw62NfJzNUz0x3y4pTG1uz4MK6fgE0OvJyc7xpfqSuQcdfyiX0ZhwyC0m
WkqYQ2IC5kOQ43Aqd8OAg9DsBrtFI2L2jN0pJ7LwZbuOb8HJ7Zk1yPNTbNBiZ4u9
E4hQ0DjvLqyyy5CDu+sjoyarais8FiJ6D/Eu2RfMj9E1TrCXovA=
=0hA7
-----END PGP SIGNATURE-----
commit

2833ba2574621e736f6e37c897224eb22c1f175f

parent

ae1606081f172a78242f998f427e5b5a87a55368

M archetype/adapter.goarchetype/adapter.go

@@ -21,11 +21,13 @@ Name string

Type string } +type BuildOption ConfigOption + type Adapter interface { Init(cfg *Config) Name() string EditableSlugs() bool - BuildOptions() []string + BuildOptions() []BuildOption GetConfig() map[ConfigOption]string SetConfig(map[ConfigOption]string) error ListPages() map[string]string

@@ -35,5 +37,5 @@ FormattingHelp() string

CreatePage(slug, title, content string) error SavePage(oldSlug, newSlug, title, content string) error DeletePage(slug string) error - Build(buildOptions map[string][]string) BuildStatus + Build(buildOptions map[BuildOption]string) BuildStatus }
M archetype/eureka.goarchetype/eureka.go

@@ -40,8 +40,21 @@ func (self *EurekaAdapter) EditableSlugs() bool {

return false } -func (self *EurekaAdapter) BuildOptions() []string { - return []string{"twtxt"} +func (self *EurekaAdapter) BuildOptions() []BuildOption { + return []BuildOption{ + BuildOption{ + Name: "twtxt", + Type: "string", + }, + BuildOption{ + Name: "remove newest twtxt", + Type: "bool", + }, + BuildOption{ + Name: "clear thumbnail cache", + Type: "bool", + }, + } } func (self *EurekaAdapter) GetConfig() map[ConfigOption]string {

@@ -249,8 +262,11 @@ }

return os.Remove(filepath.Join(self.Root, "inc", slug)) } -func (self *EurekaAdapter) Build(buildOptions map[string][]string) BuildStatus { - twtxt := strings.Join(buildOptions["twtxt"], " ") +func (self *EurekaAdapter) Build(buildOptions map[BuildOption]string) BuildStatus { + twtxt := buildOptions[BuildOption{ + Name: "twtxt", + Type: "string", + }] cmdArgs := []string{} if twtxt != "" { cmdArgs = append(cmdArgs, "-t")
M lfo/middleware.golfo/middleware.go

@@ -55,7 +55,7 @@

return http.HandlerFunc(handlerFunc) } -func FormMapToAdapterConfig(next http.Handler, adapter core.Adapter) http.Handler { +func FormMapToAdapterConfig(next http.Handler) http.Handler { handlerFunc := func(w http.ResponseWriter, req *http.Request) { cfg := make(map[core.ConfigOption]string) for k, arr := range req.PostForm {

@@ -69,6 +69,26 @@ Type: optType,

}] = v } *req = *req.WithContext(context.WithValue(req.Context(), "config", cfg)) + next.ServeHTTP(w, req) + } + + return http.HandlerFunc(handlerFunc) +} + +func FormMapToBuildOptions(next http.Handler) http.Handler { + handlerFunc := func(w http.ResponseWriter, req *http.Request) { + options := make(map[core.BuildOption]string) + for k, arr := range req.PostForm { + v := strings.Join(arr, "") + optNameAndType := strings.Split(k, ":") + optName := optNameAndType[0] + optType := optNameAndType[1] + options[core.BuildOption{ + Name: optName, + Type: optType, + }] = v + } + *req = *req.WithContext(context.WithValue(req.Context(), "build-options", options)) next.ServeHTTP(w, req) }
M nirvash.gonirvash.go

@@ -148,12 +148,13 @@ `/build-run`,

Defend( Protected( SanitizeFormMap( - WithAdapter( - renderer.Template( - pathConcat(templateRoot, "build_run.html"), - pathConcat(templateRoot, "header.html"), - pathConcat(templateRoot, "footer.html")), - cfg.Adapter)), + FormMapToBuildOptions( + WithAdapter( + renderer.Template( + pathConcat(templateRoot, "build_run.html"), + pathConcat(templateRoot, "header.html"), + pathConcat(templateRoot, "footer.html")), + cfg.Adapter))), http.MethodGet, udb, "/login"),

@@ -201,8 +202,7 @@ renderer.Template(

pathConcat(templateRoot, "config_set.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), - cfg.Adapter), - cfg.Adapter)), + cfg.Adapter))), http.MethodGet, udb, "/login"),
M templates/build.htmltemplates/build.html

@@ -7,16 +7,35 @@ <h2>Build</h2>

<form class="build" method="POST" action="/build-run"> <input hidden type="text" name="csrfToken" value="{{$csrfToken}}"/> +{{ if $buildOpts }} <details><summary>Build Options</summary> -{{ if $buildOpts }} - {{ range $optName := $buildOpts }} - <label>{{$optName}} <input type="text" name="{{$optName}}"/></label> + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "bool" }} + <label>{{($opt).Name}} <input type="checkbox" name="{{($opt).Name}}:{{($opt).Type}}"/></label><br/> + {{ end }} + {{ end }} + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "int" }} + <label>{{($opt).Name}} <input type="number" step="1" name="{{($opt).Name}}:{{($opt).Type}}"/></label><br/> + {{ end }} + {{ end }} + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "float" }} + <label>{{($opt).Name}} <input type="number" step="0.00000001" name="{{($opt).Name}}:{{($opt).Type}}"/></label><br/> + {{ end }} + {{ end }} + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "string" }} + <label>{{($opt).Name}} <input type="text" name="{{($opt).Name}}:{{($opt).Type}}"/></label><br/> + {{ end }} {{ end }} -{{ else }} -<span>There are no build options for this adapter.</span> -{{ end }} + {{ range $opt := $buildOpts }} + {{ if eq ($opt).Type "multilinestring" }} + <label>{{($opt).Name}} <textarea name="{{($opt).Name}}:{{($opt).Type}}"></textarea></label><br/> + {{ end }} + {{ end }} </details> - +{{ end }} <input type="submit" value="Build"/> </form>
M templates/build_run.htmltemplates/build_run.html

@@ -1,14 +1,18 @@

-{{ $buildOpts := .PostForm }} +{{ $buildOpts := (.Context).Value "build-options" }} {{ $status := ((.Context).Value "adapter").Build $buildOpts }} {{ template "header" . }} {{ if ne ($status).Success true }} + <h2>Build Error</h2> <span class="adapter-error"><pre>{{($status).Message}}</pre></span> + {{ else }} + <h2>Build Successful</h2> <span class="adapter-success"><pre>{{($status).Message}}</pre></span> + {{ end }} {{ template "footer" . }}
M templates/cms_create.htmltemplates/cms_create.html

@@ -6,11 +6,15 @@

{{ template "header" . }} {{ if $createErr }} + <h2>Page Creation Error</h2> - <span class="adapter-error">There was an error creating the page: {{ ($createErr).Error }}</span> + <span class="adapter-error">{{ ($createErr).Error }}</span> + {{ else }} + <h2>Page Created</h2> <span class="adapter-success">Page '{{ $title }}' created successfully</span> + {{ end }} {{ template "footer" . }}
M templates/cms_edit.htmltemplates/cms_edit.html

@@ -7,9 +7,10 @@

{{ template "header" . }} {{ if ($page).Error }} - <h2>Page Error</h2> - + + <h2>Page Error</h2> <span class="adapter-error">{{($page).Error}}</span> + {{ else }} <h2>Edit Page</h2>
M templates/cms_save.htmltemplates/cms_save.html

@@ -7,11 +7,15 @@

{{ template "header" . }} {{ if $saveErr }} + <h2>Page Save Error</h2> - <span class="adapter-error">There was an error saving the page: {{ ($saveErr).Error }}</span> + <span class="adapter-error">{{ ($saveErr).Error }}</span> + {{ else }} + <h2>Page Saved</h2> <span class="adapter-success">Page '{{ $title }}' saved successfully</span> + {{ end }} {{ template "footer" . }}
M templates/config.htmltemplates/config.html

@@ -8,6 +8,11 @@

<form class="configurator" method="POST" action="/config-set"> <input hidden type="text" name="csrfToken" value="{{$csrfToken}}"/> {{ range $opt, $val := $config }} + {{ if eq ($opt).Type "bool" }} + <label>{{($opt).Name}} <input type="checkbox" name="{{($opt).Name}}:{{($opt).Type}}" checked="{{$val}}"/></label><br/> + {{ end }} + {{ end }} + {{ range $opt, $val := $config }} {{ if eq ($opt).Type "int" }} <label>{{($opt).Name}} <input type="number" step="1" name="{{($opt).Name}}:{{($opt).Type}}" value="{{$val}}"/></label><br/> {{ end }}
M templates/config_set.htmltemplates/config_set.html

@@ -4,11 +4,15 @@

{{ template "header" . }} {{ if $cfgError }} + <h2>Configuration Error</h2> <span class="adapter-error">{{($cfgError).Error}}</span> + {{ else }} + <h2>Configuration Saved</h2> <span class="adapter-success">The adapter configuration has been saved</span> + {{ end }} {{ template "footer" . }}
M templates/delete.htmltemplates/delete.html

@@ -4,11 +4,15 @@

{{ template "header" . }} {{ if $deleteErr }} + <h2>Deletion Error</h2> - <span class="adapter-error">There was an error deleting the page: {{ ($deleteErr).Error }}</span> + <span class="adapter-error">{{ ($deleteErr).Error }}</span> + {{ else }} + <h2>Page Deleted</h2> <span class="adapter-success">Page at '{{ $slug }}' was deleted</span> + {{ end }} {{ template "footer" . }}
M templates/file_delete.htmltemplates/file_delete.html

@@ -4,11 +4,15 @@

{{ template "header" . }} {{ if $deleteErr }} + <h2>File Deletion Error</h2> - <span class="adapter-error">There was an error deleting the file: {{ ($deleteErr).Error }}</span> + <span class="adapter-error">{{ ($deleteErr).Error }}</span> + {{ else }} + <h2>File Deleted</h2> - <span class="adapter-success">Static file '{{ $slug }}' was deleted</span> + <span class="adapter-success">'{{ $slug }}' was deleted successfully</span> + {{ end }} {{ template "footer" . }}
M templates/file_list.htmltemplates/file_list.html

@@ -5,9 +5,10 @@ {{ template "header" .}}

{{ if ($fileList).Error }} + <h2>File Listing Error</h2> +<span class="adapter-error">{{($fileList).Error}}</span> -<span class="adapter-error">{{($fileList).Error}}</span> {{ else }} <h2>Files: {{($fileList).Root}}</h2>
M templates/file_mkdir.htmltemplates/file_mkdir.html

@@ -1,8 +1,16 @@

{{ $slug := ((.Context).Value "params").Slug }} +{{ $fileData := ((.Context).Value "file-manager").GetFileData $slug }} {{ $csrfToken := (.Context).Value "csrfToken" }} {{ template "header" . }} +{{ if ($fileData).Error }} + +<h2>Error</h2> +<span class="adapter-error">{{($fileData).Error}}</span> + +{{ else }} + <h2>Directory Creation</h2> <form class="mkdir" method="POST" action="/mkdir-process/{{$slug}}">

@@ -14,5 +22,7 @@ <input required type="text" name="dirname" id="dirname-input"/>

<input type="submit" value="Create"/> </form> + +{{ end }} {{ template "footer" . }}
M templates/file_mkdir_process.htmltemplates/file_mkdir_process.html

@@ -5,11 +5,15 @@

{{ template "header" . }} {{ if $mkdirError }} - <h2>Directory Creation Error</h2> - <span class="adapter-error">{{($mkdirError).Error}}</span> + +<h2>Directory Creation Error</h2> +<span class="adapter-error">{{($mkdirError).Error}}</span> + {{ else }} - <h2>Directory Created</h2> - <span class="adapter-success">The directory has been created successfully</span> + +<h2>Directory Created</h2> +<span class="adapter-success">The directory has been created successfully</span> + {{ end }} {{ template "footer" . }}
M templates/file_move.htmltemplates/file_move.html

@@ -15,10 +15,10 @@

{{ else if ($fileData).Error }} <h2>File Listing Error</h2> - <span class="adapter-error">{{($fileData).Error}}</span> {{ else }} + <h2>Moving {{($fileData).Name}}: {{($fileList).Root}}</h2> <form class="move-rename-file" method="POST" action="/file-move-process/{{($fileData).Path}}">
M templates/file_move_process.htmltemplates/file_move_process.html

@@ -8,13 +8,11 @@

{{ if $moveError }} <h2>File Move/Rename Error</h2> - <span class="adapter-error">{{$moveError}}</span> {{ else }} <h2>File Move/Rename Success</h2> - <span class="adapter-success">File moved from /{{$slug}} to {{$dest}}{{$name}} </span> {{ end }}
M templates/file_upload.htmltemplates/file_upload.html

@@ -5,12 +5,11 @@

{{ template "header" . }} {{ if ($fileData).Error }} -<h2>Error</h2> +<h2>Filesystem Error</h2> <span class="adapter-error">{{($fileData).Error}}</span> {{ else }} - <h2>File Upload</h2> <form class="uploader" enctype="multipart/form-data" method="POST" action="/upload-process/{{$slug}}">
M templates/file_upload_process.htmltemplates/file_upload_process.html

@@ -4,11 +4,15 @@

{{ template "header" . }} {{ if $uploadError }} - <h2>Upload Error</h2> - <span class="adapter-error">{{($uploadError).Error}}</span> + +<h2>Upload Error</h2> +<span class="adapter-error">{{($uploadError).Error}}</span> + {{ else }} - <h2>Upload Successful</h2> - <span class="adapter-success">The file has been uploaded successfuly</span> + +<h2>Upload Successful</h2> +<span class="adapter-success">The file has been uploaded successfuly</span> + {{ end }} {{ template "footer" . }}