mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-05-21 06:44:06 +00:00
Categories, views: Give the card view its own file, make title a block
This commit is contained in:
parent
cbf416d7bb
commit
686c329615
@ -1,38 +0,0 @@
|
|||||||
{{define "category x"}}Category {{. | beautifulName}}{{end}}
|
|
||||||
{{define "category list heading"}}Category list{{end}}
|
|
||||||
|
|
||||||
{{define "category card"}}
|
|
||||||
{{$hyphaName := .HyphaName}}
|
|
||||||
{{$givenPermission := .GivenPermissionToModify}}
|
|
||||||
<aside class="layout-card categories-card">
|
|
||||||
<h2 class="layout-card__title">{{block `categories` .}}Categories{{end}}</h2>
|
|
||||||
<ul class="categories-card__entries">
|
|
||||||
{{range .Categories}}
|
|
||||||
<li class="categories-card__entry">
|
|
||||||
<a class="categories-card__link" href="/category/{{.}}">{{beautifulName .}}</a>
|
|
||||||
<form method="POST" action="/remove-from-category" class="categories-card__remove-form">
|
|
||||||
<input type="hidden" name="cat" value="{{.}}">
|
|
||||||
<input type="hidden" name="hypha" value="{{$hyphaName}}">
|
|
||||||
<input type="hidden" name="redirect-to" value="/hypha/{{$hyphaName}}">
|
|
||||||
{{if $givenPermission}}
|
|
||||||
<input type="submit" value="x" class="btn categories-card__btn"
|
|
||||||
title="{{block `remove from category title` .}}Remove the hypha from this category{{end}}">
|
|
||||||
{{end}}
|
|
||||||
</form>
|
|
||||||
</li>
|
|
||||||
{{end}}
|
|
||||||
{{if .GivenPermissionToModify}}
|
|
||||||
<li class="categories-card__entry categories-card__add-to-cat">
|
|
||||||
<form method="POST" action="/add-to-category" class="categories-card__add-form">
|
|
||||||
<input type="text" name="cat" id="_cat-name"
|
|
||||||
placeholder="{{block `placeholder` .}}Category name...{{end}}">
|
|
||||||
<input type="hidden" name="hypha" value="{{$hyphaName}}">
|
|
||||||
<input type="hidden" name="redirect-to" value="/hypha/{{$hyphaName}}">
|
|
||||||
<input type="submit" class="btn categories-card__btn" value="+"
|
|
||||||
title="{{block `add to category title` .}}Add the hypha to this category{{end}}">
|
|
||||||
</form>
|
|
||||||
</li>
|
|
||||||
{{end}}
|
|
||||||
</ul>
|
|
||||||
</aside>
|
|
||||||
{{end}}
|
|
35
categories/view_card.html
Normal file
35
categories/view_card.html
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{{define "category card"}}
|
||||||
|
{{$hyphaName := .HyphaName}}
|
||||||
|
{{$givenPermission := .GivenPermissionToModify}}
|
||||||
|
<aside class="layout-card categories-card">
|
||||||
|
<h2 class="layout-card__title">{{block `categories` .}}Categories{{end}}</h2>
|
||||||
|
<ul class="categories-card__entries">
|
||||||
|
{{range .Categories}}
|
||||||
|
<li class="categories-card__entry">
|
||||||
|
<a class="categories-card__link" href="/category/{{.}}">{{beautifulName .}}</a>
|
||||||
|
<form method="POST" action="/remove-from-category" class="categories-card__remove-form">
|
||||||
|
<input type="hidden" name="cat" value="{{.}}">
|
||||||
|
<input type="hidden" name="hypha" value="{{$hyphaName}}">
|
||||||
|
<input type="hidden" name="redirect-to" value="/hypha/{{$hyphaName}}">
|
||||||
|
{{if $givenPermission}}
|
||||||
|
<input type="submit" value="x" class="btn categories-card__btn"
|
||||||
|
title="{{block `remove from category title` .}}Remove the hypha from this category{{end}}">
|
||||||
|
{{end}}
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
{{if .GivenPermissionToModify}}
|
||||||
|
<li class="categories-card__entry categories-card__add-to-cat">
|
||||||
|
<form method="POST" action="/add-to-category" class="categories-card__add-form">
|
||||||
|
<input type="text" name="cat" id="_cat-name"
|
||||||
|
placeholder="{{block `placeholder` .}}Category name...{{end}}">
|
||||||
|
<input type="hidden" name="hypha" value="{{$hyphaName}}">
|
||||||
|
<input type="hidden" name="redirect-to" value="/hypha/{{$hyphaName}}">
|
||||||
|
<input type="submit" class="btn categories-card__btn" value="+"
|
||||||
|
title="{{block `add to category title` .}}Add the hypha to this category{{end}}">
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
</aside>
|
||||||
|
{{end}}
|
@ -1,6 +1,7 @@
|
|||||||
|
{{define "title"}}Category list{{end}}
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
<main class="main-width category-list">
|
<main class="main-width category-list">
|
||||||
<h1>{{block `category list heading` .}}Category list{{end}}</h1>
|
<h1>{{template "title"}}</h1>
|
||||||
{{if len .Categories}}
|
{{if len .Categories}}
|
||||||
<ul class="category-list__entries">
|
<ul class="category-list__entries">
|
||||||
{{range .Categories}}
|
{{range .Categories}}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
{{define "title"}}Category {{.CatName | beautifulName}}{{end}}
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
{{$catName := .CatName}}
|
{{$catName := .CatName}}
|
||||||
<main class="main-width category">
|
<main class="main-width category">
|
||||||
|
@ -3,7 +3,6 @@ package categories
|
|||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
@ -29,24 +28,19 @@ var (
|
|||||||
fs embed.FS
|
fs embed.FS
|
||||||
m = template.Must
|
m = template.Must
|
||||||
baseEn, baseRu *template.Template
|
baseEn, baseRu *template.Template
|
||||||
viewListChain, viewPageChain viewutil.Chain
|
viewListChain, viewPageChain, viewCardChain viewutil.Chain
|
||||||
categoryTemplatesEn *template.Template
|
|
||||||
categoryTemplatesRu *template.Template
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func prepareViews() {
|
func prepareViews() {
|
||||||
categoryTemplatesEn = template.Must(template.
|
|
||||||
New("category").
|
|
||||||
Funcs(
|
|
||||||
template.FuncMap{
|
|
||||||
"beautifulName": util.BeautifulName,
|
|
||||||
}).
|
|
||||||
ParseFS(fs, "categories.html"))
|
|
||||||
categoryTemplatesRu = template.Must(template.Must(categoryTemplatesEn.Clone()).Parse(categoriesRu))
|
|
||||||
|
|
||||||
baseEn = m(viewutil.BaseEn.Clone())
|
baseEn = m(viewutil.BaseEn.Clone())
|
||||||
baseRu = m(viewutil.BaseRu.Clone())
|
baseRu = m(viewutil.BaseRu.Clone())
|
||||||
|
|
||||||
|
viewCardChain = viewutil.
|
||||||
|
En(
|
||||||
|
m(m(baseEn.Clone()).ParseFS(fs, "view_card.html"))).
|
||||||
|
Ru(
|
||||||
|
m(m(m(baseRu.Clone()).ParseFS(fs, "view_card.html")).Parse(categoriesRu)))
|
||||||
viewListChain = viewutil.
|
viewListChain = viewutil.
|
||||||
En(
|
En(
|
||||||
m(m(baseEn.Clone()).ParseFS(fs, "view_list.html"))).
|
m(m(baseEn.Clone()).ParseFS(fs, "view_list.html"))).
|
||||||
@ -59,35 +53,15 @@ func prepareViews() {
|
|||||||
m(m(m(baseRu.Clone()).ParseFS(fs, "view_page.html")).Parse(categoriesRu)))
|
m(m(m(baseRu.Clone()).ParseFS(fs, "view_page.html")).Parse(categoriesRu)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func localizedCatTemplates(meta viewutil.Meta) *template.Template {
|
type cardData struct {
|
||||||
if meta.Lc.Locale == "ru" {
|
HyphaName string
|
||||||
return categoryTemplatesRu
|
Categories []string
|
||||||
}
|
GivenPermissionToModify bool
|
||||||
return categoryTemplatesEn
|
|
||||||
}
|
|
||||||
|
|
||||||
func localizedCatTemplateAsString(meta viewutil.Meta, name string, datum ...interface{}) string {
|
|
||||||
var buf strings.Builder
|
|
||||||
var err error
|
|
||||||
if len(datum) == 1 {
|
|
||||||
err = localizedCatTemplates(meta).ExecuteTemplate(&buf, name, datum[0])
|
|
||||||
} else {
|
|
||||||
err = localizedCatTemplates(meta).ExecuteTemplate(&buf, name, nil)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return buf.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CategoryCard(meta viewutil.Meta, hyphaName string) string {
|
func CategoryCard(meta viewutil.Meta, hyphaName string) string {
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
err := localizedCatTemplates(meta).ExecuteTemplate(&buf, "category card", struct {
|
err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{
|
||||||
HyphaName string
|
|
||||||
Categories []string
|
|
||||||
GivenPermissionToModify bool
|
|
||||||
}{
|
|
||||||
hyphaName,
|
hyphaName,
|
||||||
WithHypha(hyphaName),
|
WithHypha(hyphaName),
|
||||||
meta.U.CanProceed("add-to-category"),
|
meta.U.CanProceed("add-to-category"),
|
||||||
@ -109,7 +83,6 @@ func categoryPage(meta viewutil.Meta, catName string) {
|
|||||||
if err := viewPageChain.Get(meta).ExecuteTemplate(meta.W, "page", pageData{
|
if err := viewPageChain.Get(meta).ExecuteTemplate(meta.W, "page", pageData{
|
||||||
BaseData: viewutil.BaseData{
|
BaseData: viewutil.BaseData{
|
||||||
Meta: meta,
|
Meta: meta,
|
||||||
Title: localizedCatTemplateAsString(meta, "category x", catName),
|
|
||||||
HeaderLinks: cfg.HeaderLinks,
|
HeaderLinks: cfg.HeaderLinks,
|
||||||
CommonScripts: cfg.CommonScripts,
|
CommonScripts: cfg.CommonScripts,
|
||||||
},
|
},
|
||||||
@ -130,7 +103,6 @@ func categoryList(meta viewutil.Meta) {
|
|||||||
if err := viewListChain.Get(meta).ExecuteTemplate(meta.W, "page", listData{
|
if err := viewListChain.Get(meta).ExecuteTemplate(meta.W, "page", listData{
|
||||||
BaseData: viewutil.BaseData{
|
BaseData: viewutil.BaseData{
|
||||||
Meta: meta,
|
Meta: meta,
|
||||||
Title: localizedCatTemplateAsString(meta, "category list heading"),
|
|
||||||
HeaderLinks: cfg.HeaderLinks,
|
HeaderLinks: cfg.HeaderLinks,
|
||||||
CommonScripts: cfg.CommonScripts,
|
CommonScripts: cfg.CommonScripts,
|
||||||
},
|
},
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{{.Title}}</title>
|
<title>{{block "title" .}}{{end}}</title>
|
||||||
<link rel="shortcut icon" href="/static/favicon.ico">
|
<link rel="shortcut icon" href="/static/favicon.ico">
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
<script src="/static/shortcuts.js"></script>
|
<script src="/static/shortcuts.js"></script>
|
||||||
|
@ -52,15 +52,18 @@ func localizedBaseWithWeirdBody(meta Meta) *template.Template {
|
|||||||
}
|
}
|
||||||
return BaseEn
|
return BaseEn
|
||||||
}()
|
}()
|
||||||
return m(m(t.Clone()).Parse(`{{define "body"}}{{.Body}}{{end}}`))
|
return m(m(t.Clone()).Parse(`
|
||||||
|
{{define "body"}}{{.Body}}{{end}}
|
||||||
|
{{define "title"}}{{.Title}}{{end}}
|
||||||
|
`))
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseData struct {
|
type BaseData struct {
|
||||||
Meta Meta
|
Meta Meta
|
||||||
Title string
|
|
||||||
HeadElements []string
|
HeadElements []string
|
||||||
HeaderLinks []cfg.HeaderLink
|
HeaderLinks []cfg.HeaderLink
|
||||||
CommonScripts []string
|
CommonScripts []string
|
||||||
|
Title string // TODO: remove
|
||||||
Body string // TODO: remove
|
Body string // TODO: remove
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user