-
Notifications
You must be signed in to change notification settings - Fork 22
/
bookshop_partial.html
42 lines (37 loc) · 1.46 KB
/
bookshop_partial.html
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
{{/*
Renders a Bookshop partial
Expects a slice:
[
<string>, # Partial name
<_> # Partial props
]
Or a <string>: # Component name
*/}}
{{- $partial_name := false -}}
{{- $partial_props := false -}}
{{- if reflect.IsSlice . -}}
{{- if eq (len .) 2 -}}
{{- if eq (printf "%T" (index . 0)) "string" -}}
{{- $partial_name = index . 0 -}}
{{- $partial_props = index . 1 -}}
{{- else -}}
{{- $err := printf "Expected the first argument to be a string of the partial name. Received %+v" (index . 0) -}}
{{- partial "_bookshop/errors/bad_bookshop_tag" $err -}}
{{- end -}}
{{- else -}}
{{- $err := printf "Expected a slice of length 2, was given %d" (len .) -}}
{{- partial "_bookshop/errors/bad_bookshop_tag" $err -}}
{{- end -}}
{{- else if eq (printf "%T" .) "string" -}}
{{- $partial_name = . -}}
{{- $partial_props = true -}}
{{- else if . -}}
{{- $err := printf "bookshop_partial tag expected a slice or string. Was given the %T: %+v" . . -}}
{{- partial "_bookshop/errors/bad_bookshop_tag" $err -}}
{{- else -}}
{{- $err := printf "bookshop_partial tag expected a slice or string. Was provided with no arguments" -}}
{{- partial "_bookshop/errors/bad_bookshop_tag" $err -}}
{{- end -}}
{{- if and $partial_name $partial_props -}}
{{- partial "_bookshop/helpers/partial" (slice $partial_name $partial_props) -}}
{{- end -}}