Skip to content

Commit

Permalink
Remove the hack for .File that was added to debugprint partial #test
Browse files Browse the repository at this point in the history
Full discussion here:
https://discourse.gohugo.io/t/how-to-specify-a-function-call-instead-of-field-reference-in-a-partial/9219

This hack is not needed (probably after the Page Bundle release
v0.32), tested on Hugo v0.35-DEV.
  • Loading branch information
kaushalmodi committed Jan 23, 2018
1 parent 03cf11b commit 9574360
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion test/site/themes/bare_min/layouts/_default/single.html
Expand Up @@ -93,7 +93,7 @@ <h3 id="resource-debug">Resources (Debug)</h3>
{{ partial "debugprint.html" . }}
{{ end }}
<h3 id="file-debug">File Object (Debug)</h3>
{{ partial "debugprint.html" (slice "File" .) }}
{{ partial "debugprint.html" .File }}
</div>

{{ end }}
38 changes: 17 additions & 21 deletions test/site/themes/bare_min/layouts/partials/debugprint.html
Expand Up @@ -3,7 +3,8 @@
{{/* partial "debugprint.html" .Params */}}
{{/* partial "debugprint.html" .Site */}}
{{/* partial "debugprint.html" .GitInfo */}}
{{/* partial "debugprint.html" (slice "File" .) */}}
{{/* partial "debugprint.html" .Resources */}}
{{/* partial "debugprint.html" .File */}}
-->
{{ $value := . }}
{{ $type := (printf "%T" $value) }}
Expand All @@ -20,7 +21,8 @@
{{ $typeIsOutputFormat := (eq "output.Format" $type) }}
{{ $typeIsResource := (findRE "^\\*resource" $type) }}
{{ $typeIsPage := (findRE "^\\*hugolib\\.Page" $type) }}
{{ $typeIsSpecial := (or $typeIsSiteInfo $typeIsGitInfo $typeIsOutputFormat $typeIsResource $typeIsPage) }}
{{ $typeIsFileInfo := (eq "*hugolib.fileInfo" $type) }}
{{ $typeIsSpecial := (or $typeIsSiteInfo $typeIsGitInfo $typeIsOutputFormat $typeIsResource $typeIsPage $typeIsFileInfo) }}

{{ if $typeIsBool }}
{{ printf "<span class=\"debugprint\"><span class=\"%#v\">%#v</span></span>" $value $value | safeHTML }}
Expand All @@ -31,25 +33,8 @@
{{ else if (or $typeIsTime $typeIsInterface) }}
{{ printf "%s" $value | safeHTML }}
{{ else if $typeIsSlice }}
{{ if eq 2 (len $value) }}
{{ $slice_elem_0 := (index $value 0) }}
{{ $slice_elem_1 := (index $value 1) }}
<!-- Special treatment for File object
Go templates limitation: https://discourse.gohugo.io/t/how-to-specify-a-function-call-instead-of-field-reference-in-a-partial/9219 -->
{{ if (and (eq "*hugolib.PageOutput" (printf "%T" $slice_elem_1)) (eq "File" $slice_elem_0)) }}
{{ with $slice_elem_1 }} <!-- This carries the .Page scope -->
{{ $fileVars := (dict "UniqueID" .File.UniqueID "BaseFileName" .File.BaseFileName "TranslationBaseName" .File.TranslationBaseName "Lang" .File.Lang "Section" .File.Section "LogicalName" .File.LogicalName "Dir" .File.Dir "Ext" .File.Ext "Path" .File.Path) }}
{{ partial "debugprint.html" $fileVars }} <!-- Recursive call FTW! -->
{{ end }}
{{ else }}
{{ range $value }}
{{ partial "debugprint.html" . }} <!-- Recursive call FTW! -->
{{ end }}
{{ end }}
{{ else }}
{{ range $value }}
{{ partial "debugprint.html" . }} <!-- Recursive call FTW! -->
{{ end }}
{{ range $value }}
{{ partial "debugprint.html" . }} <!-- Recursive call FTW! -->
{{ end }}
{{ else if $typeIsMap }}
{{ if (gt (len $value) 0) }}
Expand Down Expand Up @@ -132,6 +117,17 @@
{{ end }}
</table>
<hr>
{{ else if $typeIsFileInfo }}
{{ $FileInfoVarNames := (slice "UniqueID" "BaseFileName" "TranslationBaseName" "Lang" "Section" "LogicalName" "Dir" "Ext" "Path") }}
{{ $FileInfoVarSymbols := (slice .UniqueID .BaseFileName .TranslationBaseName .Lang .Section .LogicalName .Dir .Ext .Path ) }}
<table>
<tr><th class="key">FileInfo Variable</th><th class="value">Value</th></tr>
{{ range $idx, $elem := $FileInfoVarNames }}
{{ printf "<tr><td class=\"key\">%s</td><td class=\"value\">" $elem | safeHTML }}
{{ partial "debugprint.html" (index $FileInfoVarSymbols $idx) }} <!-- Recursive call FTW! -->
{{ printf "</td></tr>" | safeHTML }}
{{ end }}
</table>
{{ else }}
{{ printf "%#v" $value | safeHTML }}
{{ end }}
Expand Down

0 comments on commit 9574360

Please sign in to comment.