-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.gohtml
84 lines (74 loc) · 2.31 KB
/
index.gohtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
{{block "head" "example"}}
<head>
<meta charset='UTF-8'/>
<title>{{.}}</title>
<script src='https://unpkg.com/[email protected]/dist/htmx.min.js' integrity='sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq' crossorigin='anonymous'></script>
<script src='https://unpkg.com/[email protected]/response-targets.js'></script>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css'>
</head>
{{end}}
<body hx-ext='response-targets'>
<main class='container'>
<table>
<thead>
<tr>
<th>Fruit</th>
<th>Count</th>
</tr>
</thead>
<tbody hx-target="closest tr" hx-swap="outerHTML">
{{- define "view-row" -}}
<tr>
<td>{{ .Name }}</td>
<td id="count" hx-get='/fruits/{{.ID}}/edit'>{{ .Value }}</td>
</tr>
{{- end -}}
{{range .}}
{{template "view-row" .}}
{{end}}
{{define "edit-row" -}}
<tr>
<td>{{ .Row.Name }}</td>
<td>
<form hx-patch='/fruits/{{.Row.ID}}'>
{{block "count" . -}}
<input aria-label='Count' type='number' name='count' value='{{ .Row.Value }}' step='1' min='0'>
{{- end}}
<input type='submit' value='Update'>
<pre>{{.}}</pre>
</form>
<p id='error'>{{.Error}}</p>
</td>
</tr>
{{- end}}
{{- define "GET /{$} List(ctx)" -}}
{{template "index.gohtml" .}}
{{- end -}}
{{- define "GET /fruits/{id}/edit GetFormEditRow(id)" -}}
{{template "edit-row" .}}
{{- end -}}
{{- define "PATCH /fruits/{id} SubmitFormEditRow(id, form)" }}
{{- if .Error -}}
{{template "edit-row" .}}
{{- else -}}
{{template "view-row" .Row}}
{{- end -}}
{{ end -}}
</tbody>
</table>
</main>
</body>
</html>
{{- define "GET /help" -}}
<!DOCTYPE html>
<html lang='us-en'>
{{template "head" "Help"}}
<body>
<main class='container'>
Hello, help!
</main>
</body>
</html>
{{- end -}}