From 693423fa30557060f7f5bcc9370a708114c6d4fa Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Mon, 13 Nov 2017 13:13:40 -0500 Subject: [PATCH] Hugo partials can be called recursively! --- .../bare_min/layouts/_default/baseof.html | 4 +- .../bare_min/layouts/_default/single.html | 2 +- .../bare_min/layouts/partials/debugprint.html | 167 ++++++------------ 3 files changed, 53 insertions(+), 120 deletions(-) diff --git a/test/site/themes/bare_min/layouts/_default/baseof.html b/test/site/themes/bare_min/layouts/_default/baseof.html index 44af554..5274d1b 100644 --- a/test/site/themes/bare_min/layouts/_default/baseof.html +++ b/test/site/themes/bare_min/layouts/_default/baseof.html @@ -47,10 +47,10 @@ .debugprint td.value { font-family: monospace; } - .debugprint td.value.true { + .debugprint td.value .true { color: green; } - .debugprint td.value.false { + .debugprint td.value .false { color: red; } /* Hide Type columns in debugprint */ diff --git a/test/site/themes/bare_min/layouts/_default/single.html b/test/site/themes/bare_min/layouts/_default/single.html index fb2cb07..074e1f0 100644 --- a/test/site/themes/bare_min/layouts/_default/single.html +++ b/test/site/themes/bare_min/layouts/_default/single.html @@ -72,7 +72,7 @@ {{ .Content }}
-

Page Params (Debug)

+

Page Params (Debug)

{{ partial "debugprint.html" .Params }} diff --git a/test/site/themes/bare_min/layouts/partials/debugprint.html b/test/site/themes/bare_min/layouts/partials/debugprint.html index 819c167..d252464 100644 --- a/test/site/themes/bare_min/layouts/partials/debugprint.html +++ b/test/site/themes/bare_min/layouts/partials/debugprint.html @@ -1,129 +1,62 @@ - -{{ $value0 := . }} -{{ $type0 := (printf "%T" $value0) }} -{{ $type0IsBool := (eq "bool" $type0) }} -{{ $type0IsString := (eq "string" $type0) }} -{{ $type0IsTime := (eq "time.Time" $type0) }} -{{ $type0IsArray := (findRE "^[[][]]" $type0 1 | len | eq 1) }} -{{ $type0IsStringArray := (findRE "^[[][]]string" $type0 1 | len | eq 1) }} -{{ $type0IsInterfaceArray := (findRE "^[[][]]interface" $type0 1 | len | eq 1) }} -{{ $type0IsMap := (findRE "^map[[].+[]]" $type0 1 | len | eq 1) }} +{{ $value := . }} +{{ $type := (printf "%T" $value) }} +{{ $typeIsBool := (eq "bool" $type) }} +{{ $typeIsString := (eq "string" $type) }} +{{ $typeIsTime := (eq "time.Time" $type) }} +{{ $typeIsArray := (findRE "^[[][]]" $type 1 | len | eq 1) }} +{{ $typeIsStringArray := (findRE "^[[][]]string" $type 1 | len | eq 1) }} +{{ $typeIsInterfaceArray := (findRE "^[[][]]interface" $type 1 | len | eq 1) }} +{{ $typeIsMap := (findRE "^map[[].+[]]" $type 1 | len | eq 1) }} - - {{ if $type0IsBool }} - {{ if $value0 }} - {{ printf "" $type0 $value0 | safeHTML }} +
+ {{ if $typeIsBool }} + {{ if $value }} + {{ printf "%#v" $value | safeHTML }} {{ else }} - {{ printf "
" $type0 $value0 | safeHTML }} + {{ printf "%#v" $value | safeHTML }} {{ end }} - {{ else if $type0IsString }} - {{ printf "" $type0 $value0 | safeHTML }} - {{ else if $type0IsTime }} - - {{ if ne ($value0.Format "2006-01-02") "0001-01-01" }} - {{ printf "" $type0 $value0 | safeHTML }} - {{ end }} - {{ else if $type0IsArray }} - {{ printf "" | safeHTML }} - {{ else if $type0IsMap }} - - {{ range $key1, $value1 := $value0 }} - {{ $type1 := (printf "%T" $value1) }} - {{ $type1IsBool := (eq "bool" $type1) }} - {{ $type1IsString := (eq "string" $type1) }} - {{ $type1IsTime := (eq "time.Time" $type1) }} - {{ $type1IsArray := (findRE "^[[][]]" $type1 1 | len | eq 1) }} - {{ $type1IsStringArray := (findRE "^[[][]]string" $type1 1 | len | eq 1) }} - {{ $type1IsInterfaceArray := (findRE "^[[][]]interface" $type1 1 | len | eq 1) }} - {{ $type1IsMap := (findRE "^map[[].+[]]" $type1 1 | len | eq 1) }} - - {{ if $type1IsBool }} - {{ if $value1 }} - {{ printf "" $key1 $type1 $value1 | safeHTML }} - {{ else }} - {{ printf "" $key1 $type1 $value1 | safeHTML }} - {{ end }} - {{ else if $type1IsString }} - {{ printf "" $key1 $type1 $value1 | safeHTML }} - {{ else if $type1IsTime }} - {{ if ne ($value1.Format "2006-01-02") "0001-01-01" }} - {{ printf "" $key1 $type1 $value1 | safeHTML }} - {{ end }} - {{ else if $type1IsArray }} - {{ printf "" $key1 $value1 | safeHTML */}} - {{/* end */}} -
%s%s
%s%s
%s%s
%s%s
%s" $type0 | safeHTML }} - {{ range $value0 }} - {{ if $type0IsStringArray }} + {{ else if (or $typeIsString $typeIsTime) }} + {{ printf "%s" $value | safeHTML }} + {{ else if $typeIsArray }} + {{ range $value }} + {{ if $typeIsStringArray }} - {{ printf "\"%s\"" . }} - {{ else if $type0IsInterfaceArray }} - {{ printf "%s" . }} + {{ printf "\"%s\"" . | safeHTML }} + {{ else if $typeIsInterfaceArray }} + {{ printf "%s" . | safeHTML }} {{ else }} - {{ printf "%#v" . }} + {{ printf "%#v" . | safeHTML }} {{ end }} {{ end }} - {{ printf "
KeyTypeValue
%s%s%#v
%s%s%#v
%s%s%s
%s%s%s
%s%s" $key1 $type1 | safeHTML }} - {{ range $value1 }} - {{ if $type1IsStringArray }} - {{ printf "\"%s\"" . }} - {{ else if $type1IsInterfaceArray }} - {{ printf "%s" . }} - {{ else }} - {{ printf "%#v" . }} + {{ else if $typeIsMap }} + + + {{ range $key1, $value1 := $value }} + {{ $type1 := (printf "%T" $value1) }} + {{ $type1IsTime := (eq "time.Time" $type1) }} + {{ if $type1IsTime }} + + {{ if (ne "0001-01-01" ($value1.Format "2006-01-02")) }} + {{ printf "" | safeHTML }} {{ end }} + {{ else }} + {{ printf "" | safeHTML }} {{ end }} - {{ printf "" | safeHTML }} - {{ else if $type1IsMap }} - {{ printf "" | safeHTML }} - {{ else }} - {{ printf "" $key1 $type1 $value1 | safeHTML }} {{ end }} - {{ end }} +
KeyTypeValue
%s%s" $key1 $type1 | safeHTML }} + {{ partial "debugprint.html" $value1 }} + {{ printf "
%s%s" $key1 $type1 | safeHTML }} + {{ partial "debugprint.html" $value1 }} + {{ printf "
%s%s" $key1 $type1 | safeHTML }} - - - {{ range $key2, $value2 := $value1 }} - {{ $type2 := (printf "%T" $value2) }} - {{ $type2IsBool := (eq "bool" $type2) }} - {{ $type2IsString := (eq "string" $type2) }} - {{ $type2IsTime := (eq "time.Time" $type2) }} - {{ $type2IsArray := (findRE "^[[][]]" $type2 1 | len | eq 1) }} - {{ $type2IsStringArray := (findRE "^[[][]]string" $type2 1 | len | eq 1) }} - {{ $type2IsInterfaceArray := (findRE "^[[][]]interface" $type2 1 | len | eq 1) }} - {{ $type2IsMap := (findRE "^map[[].+[]]" $type2 1 | len | eq 1) }} - - {{ if $type2IsBool }} - {{ if $value2 }} - {{ printf "" $key2 $type2 $value2 | safeHTML }} - {{ else }} - {{ printf "" $key2 $type2 $value2 | safeHTML }} - {{ end }} - {{ else if $type2IsString }} - {{ printf "" $key2 $type2 $value2 | safeHTML }} - {{ else if $type2IsTime }} - {{ if ne ($value2.Format "2006-01-02") "0001-01-01" }} - {{ printf "" $key2 $type2 $value2 | safeHTML }} - {{ end }} - {{ else if $type2IsArray }} - {{ printf "" | safeHTML }} - {{ else }} - {{ printf "" $key2 $type2 $value2 | safeHTML }} - {{ end }} - {{ end }} -
KeyTypeValue
%s%s%#v
%s%s%#v
%s%s%s
%s%s%s
%s%s" $key2 $type2 | safeHTML }} - {{ range $value2 }} - {{ if $type2IsStringArray }} - {{ printf "\"%s\"" . }} - {{ else if $type2IsInterfaceArray }} - {{ printf "%s" . }} - {{ else }} - {{ printf "%#v" . }} - {{ end }} - {{ end }} - {{ printf "
%s%s%#v
- {{ printf "
%s%s%#v
+ {{ else }} + {{ printf "%#v" . | safeHTML }} {{ end }} - - {{/* range $key1, $value1 := . */}} - {{/* printf "
%#v%#v
+ + + + +{{/* range $key1, $value1 := . */}} +{{/* printf "%#v%#v" $key1 $value1 | safeHTML */}} +{{/* end */}} +