Refactor html templates
This commit entirely refactors the use of html templates. Instead of inheriting from a shared template, we insert the results into a base template.
This commit is contained in:
parent
6ede99d7c6
commit
d235ee4e5c
59 changed files with 869 additions and 777 deletions
|
|
@ -17,32 +17,8 @@ import (
|
|||
//
|
||||
// Each asset group should be registered as a parameter to the 'go:generate' line.
|
||||
type Assets struct {
|
||||
Scripts string // <script> tags inserted by the asset
|
||||
Styles string // <link> tags inserted by the asset
|
||||
Scripts template.HTML // <script> tags inserted by the asset
|
||||
Styles template.HTML // <link> tags inserted by the asset
|
||||
}
|
||||
|
||||
//go:generate node build.mjs Default User Admin
|
||||
|
||||
// MustParse parses a new template from the given source
|
||||
// and calls [RegisterAssoc] on it.
|
||||
func (assets *Assets) MustParse(t *template.Template, value string) *template.Template {
|
||||
t = template.Must(t.Parse(value))
|
||||
assets.RegisterAssoc(t)
|
||||
return t
|
||||
}
|
||||
|
||||
// MustParseShared is like [MustParse], but creates a new SharedTemplate instead
|
||||
func (assets *Assets) MustParseShared(name string, value string) *template.Template {
|
||||
return assets.MustParse(NewSharedTemplate(name), value)
|
||||
}
|
||||
|
||||
// RegisterAssoc registers two new associated templates with t.
|
||||
//
|
||||
// The template "scripts" will render all script tags required.
|
||||
// The template "styles" will render all style tags required.
|
||||
//
|
||||
// If either template already exists, it will be overwritten.
|
||||
func (assets *Assets) RegisterAssoc(t *template.Template) {
|
||||
t.New("scripts").Parse(assets.Scripts)
|
||||
t.New("styles").Parse(assets.Styles)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
package assets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
//go:embed "templates/*.html"
|
||||
var templates embed.FS
|
||||
|
||||
var (
|
||||
shared *template.Template = template.Must(template.ParseFS(templates, "templates/*.html"))
|
||||
)
|
||||
|
||||
// NewSharedTemplate creates a new template with the given name.
|
||||
// It will be able to make use of shared templates as well as functions.
|
||||
func NewSharedTemplate(name string) *template.Template {
|
||||
new := template.New(name)
|
||||
for _, template := range shared.Templates() {
|
||||
new.AddParseTree(template.Tree.Name, template.Tree.Copy())
|
||||
}
|
||||
return new
|
||||
}
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
<div class="pure-u-1-1">
|
||||
<h2 id="structs">Structs</h2>
|
||||
</div>
|
||||
|
||||
{{ range $name, $comp := .Components }}
|
||||
<div class="pure-u-1-1" id="{{ $name }}">
|
||||
<div class="padding">
|
||||
<div class="overflow">
|
||||
<table class="pure-table pure-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3">
|
||||
{{ $name }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .Groups }}
|
||||
<tr>
|
||||
<td>
|
||||
Implements
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<code><a href="#{{.}}">{{ . }}</a></code><br />
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $comp := .CFields }}
|
||||
<tr>
|
||||
<td>Component Pointer</td>
|
||||
<td>
|
||||
<code>{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code><a href="#{{ $comp }}">{{ $comp }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $comp := .DCFields }}
|
||||
<tr>
|
||||
<td>Component Pointer</td>
|
||||
<td>
|
||||
<code>Dependencies/{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code><a href="#{{ $comp }}">{{ $comp }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $iface := .IFields }}
|
||||
<tr>
|
||||
<td>Interface Slice</td>
|
||||
<td>
|
||||
<code>{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code><a href="#{{ $iface }}">[]{{ $iface }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $iface := .DIFields }}
|
||||
<tr>
|
||||
<td>Interface Slice</td>
|
||||
<td>
|
||||
<code>Dependencies/{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code><a href="#{{ $iface }}">[]{{ $iface }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $sig := $comp.Methods }}
|
||||
<tr>
|
||||
<td>
|
||||
Method
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ $sig }}</code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<div class="pure-u-1-1">
|
||||
<h2 id="interfaces">Interfaces</h2>
|
||||
</div>
|
||||
|
||||
{{ range $name, $group := .Groups }}
|
||||
<div class="pure-u-1-1" id="{{ $name }}">
|
||||
<div class="padding">
|
||||
|
||||
<div class="overflow">
|
||||
<table class="pure-table pure-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3">
|
||||
{{ $name }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range $name, $sig := $group.Methods }}
|
||||
<tr>
|
||||
<td>
|
||||
Method
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ $sig }}</code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $group.Components }}
|
||||
<tr>
|
||||
<td>
|
||||
Implemented By
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<code><a href="#{{.}}">{{ . }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>{{ block "title" . }}WissKI Distillery{{ end }}</title>
|
||||
{{ block "styles" . }}styles{{ end }}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{ .BaseContext.DoInitCheck }}
|
||||
<nav class="pure-menu pure-menu-horizontal">
|
||||
<ul class="pure-menu-list" role="menubar">
|
||||
{{ range .BaseContext.Menu }}
|
||||
<li class="pure-menu-item{{ if .Active }} pure-menu-selected{{ end }}">
|
||||
<a href="{{ .Path }}" class="pure-menu-link">{{ .Title }}</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</nav>
|
||||
<nav class="breadcrumbs" role="navigation" aria-label="Breadcrumbs">
|
||||
{{ range .BaseContext.Crumbs }}
|
||||
<a class="{{ if .Active }}active{{ end }}" href="{{ .Path }}">{{ .Title }}</a>
|
||||
{{ end }}
|
||||
</nav>
|
||||
|
||||
<header>
|
||||
<h1 id="top">{{ template "title" . }}</h1>
|
||||
{{ if .BaseContext.Actions }}
|
||||
<div class="pure-button-group" role="group" aria-label="Actions">
|
||||
{{ range .BaseContext.Actions }}
|
||||
<a href="{{ .Path }}" class="pure-button{{ if eq .Priority -1 }} pure-button-small{{end}}">{{ .Title }}</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</header>
|
||||
<main>
|
||||
<div class="pure-g">
|
||||
{{ block "content" . }}content{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
{{ block "@custom/footer" .BaseContext }}
|
||||
<div style="z-index:10000;position:fixed;top:0;left:0;width:100vh;height:100vw;background:red;text-align:center;padding:10vh 10vw;font-size:xx-large;font-weight:bold">
|
||||
<code>.Templating.Template()</code> not called
|
||||
</div>
|
||||
{{ end }}
|
||||
</footer>
|
||||
|
||||
|
||||
{{ block "scripts" . }}scripts{{ end }}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
{{ template "_base.html" . }}
|
||||
{{ define "title" }}{{ block "form/title" . }}Form{{ end }}{{ end }}
|
||||
|
||||
{{ define "content" }}
|
||||
<div class="pure-u-1">
|
||||
{{ block "form/extra" . }}<!-- no extra -->{{ end }}
|
||||
|
||||
<form class="pure-form pure-form-aligned" method="POST">
|
||||
<fieldset>
|
||||
<legend>{{ template "form/title" . }}</legend>
|
||||
|
||||
{{ block "form/message" . }}
|
||||
{{ $E := .Error }}
|
||||
{{ if not (eq $E "") }}
|
||||
<div class="pure-form-group">
|
||||
<p class="error-message">
|
||||
{{ $E }}
|
||||
</p>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ block "form/inside" . }}<!-- no inside -->{{ end }}
|
||||
{{ .Form }}
|
||||
<input type="submit" value="{{ block "form/button" .}}Submit{{ end }}" class="pure-button">
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue