Motif No. 1, copyright © 2010 Douglas Cuthbertson
Build Table Template
{{- define "buildTable" -}}
<!-- Table data is always a map -->
{{- $table := . -}}
{{- $haveHead := false -}}
{{- $haveBody := false -}}
{{- $captionValue := "" -}}
{{- $colGroupValue := "" -}}
{{- $bodyValue := "" -}}
{{- $headValue := "" -}}
{{- $footValue := "" -}}
<!-- collect all the keys in the map -->
{{- range $key, $val := $table -}}
{{- if eq $key "body" -}}
{{- if $haveBody -}}
{{- $haveBody = $haveBody | append $val -}}
{{- else -}}
{{- $haveBody = true -}}
{{- $bodyValue = $val}}
{{- end -}}
{{- else if eq $key "caption" -}}
{{- $captionValue = $val -}}
{{- else if eq $key "colgroup" -}}
{{- $colGroupValue = $val -}}
{{- else if eq $key "head" -}}
{{- $haveHead = true -}}
{{- $headValue = $val -}}
{{- else if ne $key "foot" -}}
{{- if $haveBody -}}
{{- $bodyValue = $bodyValue | append $val -}}
{{- else -}}
{{- $haveBody = true -}}
{{- $bodyValue = $val}}
{{- end -}}
{{- else -}}<!-- key is foot -->
{{- $footValue = $val -}}
{{- end -}}
{{- end -}}
{{- if ne $captionValue "" -}}
<caption>{{- $captionValue -}}</caption>
{{- end -}}
{{- if ne $colGroupValue "" -}}
<colgroup>
{{- template "createColgroup" $colGroupValue -}}
</colgroup>
{{- end -}}
{{- if ne $headValue "" -}}
<thead>
{{- template "createRowsHead" $headValue -}}
</thead>
{{- end -}}
{{- if ne $bodyValue "" -}}
<tbody>
{{- template "createRows" $bodyValue -}}
</tbody>
{{- end -}}
{{- if ne $footValue "" -}}
<tfoot>
{{- template "createRows" $footValue -}}
</tfoot>
{{- end -}}
{{- end -}}