Skip to content

Commit

Permalink
Improve debugprint partial # test site
Browse files Browse the repository at this point in the history
- Now number types are recognized
- .Resources is recognized as a slice
- Horizontal rule is drawn automatically after printing a resource or Page type
  • Loading branch information
kaushalmodi committed Jan 20, 2018
1 parent eafe701 commit 0e8b72d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 1 addition & 4 deletions test/site/themes/bare_min/layouts/_default/single.html
Expand Up @@ -90,10 +90,7 @@ <h3 id="page-debug">Page Params (Debug)</h3>
{{ partial "debugprint.html" .Params }}
{{ with .Resources }}
<h3 id="resource-debug">Resources (Debug)</h3>
{{ range . }}
{{ partial "debugprint.html" . }}
<hr>
{{ end }}
{{ partial "debugprint.html" . }}
{{ end }}
<h3 id="file-debug">File Object (Debug)</h3>
{{ partial "debugprint.html" (slice "File" .) }}
Expand Down
7 changes: 5 additions & 2 deletions test/site/themes/bare_min/layouts/partials/debugprint.html
Expand Up @@ -8,10 +8,11 @@
{{ $value := . }}
{{ $type := (printf "%T" $value) }}
{{ $typeIsBool := (eq "bool" $type) }}
{{ $typeIsNumber := (or (eq "int" $type) (eq "int64" $type) (eq "float64" $type)) }}
{{ $typeIsString := (eq "string" $type) }}
{{ $typeIsTime := (eq "time.Time" $type) }}
{{ $typeIsInterface := (eq "interface" $type) }}
{{ $typeIsSlice := (findRE "^([[][]]|.*TaxonomyList|output\\.Formats)" $type) }} <!-- match ^[] -->
{{ $typeIsSlice := (findRE "^([[][]]|.*TaxonomyList|output\\.Formats|resource\\.Resources)" $type) }} <!-- match ^[] -->
{{ $typeIsMap := (findRE "^(map[[].+[]]|.*SiteSocial)" $type) }} <!-- match ^map[*] -->

{{ $typeIsSiteInfo := (eq "*hugolib.SiteInfo" $type) }}
Expand All @@ -23,7 +24,7 @@

{{ if $typeIsBool }}
{{ printf "<span class=\"debugprint\"><span class=\"%#v\">%#v</span></span>" $value $value | safeHTML }}
{{ else if $typeIsString }}
{{ else if (or $typeIsNumber $typeIsString) }}
<!-- Use %#v for strings so that their values always get double-quoted.
That is helpful to tell if a space char is within a string. -->
{{ printf "%#v" $value | safeHTML }}
Expand Down Expand Up @@ -118,6 +119,7 @@
{{ printf "</td></tr>" | safeHTML }}
{{ end }}
</table>
<hr>
{{ else if $typeIsPage }}
{{ $PageVarNames := (slice "ResourceType" "Kind" "Draft" "Layout" "Permalink" "RelPermalink" "Name" "Title" "Params") }}
{{ $PageVarSymbols := (slice .ResourceType .Kind .Draft .Layout .Permalink .RelPermalink .Name .Title .Params ) }}
Expand All @@ -129,6 +131,7 @@
{{ printf "</td></tr>" | safeHTML }}
{{ end }}
</table>
<hr>
{{ else }}
{{ printf "%#v" $value | safeHTML }}
{{ end }}
Expand Down

0 comments on commit 0e8b72d

Please sign in to comment.