Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Aug 5, 2024
1 parent 3d5707c commit 0bf2dfa
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 75 deletions.
100 changes: 55 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,68 @@ This is especially helpful when you are writing HTMX.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Hello, world!</title>
<script src="https://unpkg.com/htmx.org@2.0.1" integrity="sha384-QWGpdj554B4ETpJJC9z+ZHJcA/i59TyjxEPXiiUgN2WmTyV5OEZWCD6gQhgkdpB/" crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx-ext-response-targets@2.0.0/response-targets.js"></script>

<style>
#error {
background: lightcoral; font-weight: bold; padding: .25rem; border-radius: .25rem;
}
#error:empty {
display: none;
}
</style>
<meta charset="UTF-8"/>
<title>Hello, world!</title>
<script src="https://unpkg.com/htmx.org@2.0.1"
integrity="sha384-QWGpdj554B4ETpJJC9z+ZHJcA/i59TyjxEPXiiUgN2WmTyV5OEZWCD6gQhgkdpB/"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx-ext-response-targets@2.0.0/response-targets.js"></script>

<style>
#error {
background: lightcoral;
font-weight: bold;
padding: .25rem;
border-radius: .25rem;
}
#error:empty {
display: none;
}
</style>

</head>
<body hx-ext="response-targets">
<table>
<thead>
<tr><th>Fruit</th><th>Count</th></tr>
</thead>
<tbody>
<thead>
<tr>
<th>Fruit</th>
<th>Count</th>
</tr>
</thead>
<tbody>

{{- range . -}}
{{- block "fruit row" . -}}
<tr>
<td>{{ .Fruit }}</td>
<td hx-get="/fruits/{{.Fruit}}/edit" hx-include="this" hx-swap="outerHTML" hx-target="closest tr">{{ .Count }}
<input type="hidden" name="count" value="{{.Count}}">
</td>
</tr>
{{- end -}}
{{- end -}}


{{- range . -}}
{{- block "fruit row" . -}}
{{- define "GET /fruits/{fruit}/edit" -}}
<tr>
<td>{{ .Fruit }}</td>
<td hx-get="/fruits/{{.Fruit}}/edit" hx-include="this" hx-swap="outerHTML" hx-target="closest tr">{{ .Count }}
<input type="hidden" name="count" value="{{.Count}}">
</td>
</tr>
<td>{{ .PathValue "fruit" }}</td>
<td>
<form hx-patch="/fruits/{{.PathValue " fruit
"}}" hx-target-error="#error">
<input aria-label="Count" type="number" name="count" value="{{ .FormValue " count" }}" step="1" min="0">
<input type="submit" value="Update">
</form>
<p id="error"></p>
</td>
</tr>
{{- end -}}
{{- end -}}


{{- define "GET /fruits/{fruit}/edit" -}}
<tr>
<td>{{ .PathValue "fruit" }}</td>
<td>
<form hx-patch="/fruits/{{.PathValue "fruit"}}" hx-target-error="#error">
<input aria-label="Count" type="number" name="count" value="{{ .FormValue "count" }}" step="1" min="0">
<input type="submit" value="Update">
</form>
<p id="error"></p>
</td>
</tr>
{{- end -}}

{{- define "PATCH /fruits/{fruit} EditRow(response, request, fruit)" }}
{{template "fruit row" .}}
{{ end -}}

</tbody>

{{- define "PATCH /fruits/{fruit} EditRow(response, request, fruit)" }}
{{template "fruit row" .}}
{{ end -}}

</tbody>
</table>
</body>
</html>
Expand Down
68 changes: 39 additions & 29 deletions cmd/example/form.gohtml
Original file line number Diff line number Diff line change
@@ -1,55 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta charset="UTF-8"/>
<title>Hello, world!</title>
<script src="https://unpkg.com/htmx.org@2.0.1" integrity="sha384-QWGpdj554B4ETpJJC9z+ZHJcA/i59TyjxEPXiiUgN2WmTyV5OEZWCD6gQhgkdpB/" crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx.org@2.0.1"
integrity="sha384-QWGpdj554B4ETpJJC9z+ZHJcA/i59TyjxEPXiiUgN2WmTyV5OEZWCD6gQhgkdpB/"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx-ext-response-targets@2.0.0/response-targets.js"></script>

<style>
#error {
background: lightcoral; font-weight: bold; padding: .25rem; border-radius: .25rem;
}
#error:empty {
display: none;
}
#error {
background: lightcoral;
font-weight: bold;
padding: .25rem;
border-radius: .25rem;
}

#error:empty {
display: none;
}
</style>

</head>
<body hx-ext="response-targets">
<table>
<thead>
<tr><th>Fruit</th><th>Count</th></tr>
<tr>
<th>Fruit</th>
<th>Count</th>
</tr>
</thead>
<tbody>

{{- range . -}}
{{- block "fruit row" . -}}
<tr>
<td>{{ .Fruit }}</td>
<td hx-get="/fruits/{{.Fruit}}/edit" hx-include="this" hx-swap="outerHTML" hx-target="closest tr">{{ .Count }}
<input type="hidden" name="count" value="{{.Count}}">
</td>
</tr>
{{- end -}}
{{- range . -}}
{{- block "fruit row" . -}}
<tr>
<td>{{ .Fruit }}</td>
<td hx-get="/fruits/{{.Fruit}}/edit" hx-include="this" hx-swap="outerHTML" hx-target="closest tr">{{ .Count }}
<input type="hidden" name="count" value="{{.Count}}">
</td>
</tr>
{{- end -}}
{{- end -}}


{{- define "GET /fruits/{fruit}/edit" -}}
<tr>
<td>{{ .PathValue "fruit" }}</td>
<td>
<form hx-patch="/fruits/{{.PathValue "fruit"}}" hx-target-error="#error">
<input aria-label="Count" type="number" name="count" value="{{ .FormValue "count" }}" step="1" min="0">
<input type="submit" value="Update">
</form>
<p id="error"></p>
</td>
</tr>
<tr>
<td>{{ .PathValue "fruit" }}</td>
<td>
<form hx-patch="/fruits/{{.PathValue " fruit
"}}" hx-target-error="#error">
<input aria-label="Count" type="number" name="count" value="{{ .FormValue " count" }}" step="1" min="0">
<input type="submit" value="Update">
</form>
<p id="error"></p>
</td>
</tr>
{{- end -}}

{{- define "PATCH /fruits/{fruit} EditRow(response, request, fruit)" }}
{{template "fruit row" .}}
{{template "fruit row" .}}
{{ end -}}

</tbody>
Expand Down
1 change: 0 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ func (def EndpointDefinition) pathParams() ([]string, error) {
}
}
return result, nil

}

var templateNameMux = regexp.MustCompile(`^(?P<Pattern>(?P<Method>([A-Z]+\s+)?)(?P<Host>([^/])*)(?P<Path>(/(\S)*)))(?P<Handler>.*)$`)
Expand Down

0 comments on commit 0bf2dfa

Please sign in to comment.