aboutsummaryrefslogtreecommitdiff
path: root/themes/hugo-pt2021/layouts
diff options
context:
space:
mode:
Diffstat (limited to 'themes/hugo-pt2021/layouts')
-rw-r--r--themes/hugo-pt2021/layouts/shortcodes/table.html299
1 files changed, 171 insertions, 128 deletions
diff --git a/themes/hugo-pt2021/layouts/shortcodes/table.html b/themes/hugo-pt2021/layouts/shortcodes/table.html
index 7fa30cc..707b469 100644
--- a/themes/hugo-pt2021/layouts/shortcodes/table.html
+++ b/themes/hugo-pt2021/layouts/shortcodes/table.html
@@ -120,13 +120,20 @@ you can override the `class` attribute for individual cells.
*/}}
{{/* get config from site params (default to bulma) */}}
-{{- $config := default (dict "data_prefix" "" "table_base_css" "table" "cell_align_left" "has-text-left" "cell_align_center" "has-text-centered" "cell_align_justified" "has-text-justified" "cell_align_right" "has-text-right") $.Site.Params.table_shortcode -}}
+{{- $config := default (dict "data_prefix" "" "table_base_css" "table" "cell_align_left" "has-text-left" "cell_align_center" "has-text-centered" "cell_align_justify" "has-text-justified" "cell_align_right" "has-text-right") $.Site.Params.table_shortcode -}}
{{/* get data prefix */}}
{{- $dp := $config.data_prefix | safeHTMLAttr -}}
{{/* get table data */}}
-{{- $table := (index .Site.Data.tables (.Get 0) (.Get 1)) -}}
+{{- $table := (dict) -}}
+{{- if .Get 1 -}}
+ {{/* get table data from site data */}}
+ {{- $table = (index .Site.Data.tables (.Get 0) (.Get 1)) -}}
+{{- else -}}
+ {{/* get table data from page params */}}
+ {{- $table = (index $.Page.Params "tables" (.Get 0)) -}}
+{{- end -}}
<table
{{/* emit table ID */}}
@@ -148,167 +155,203 @@ you can override the `class` attribute for individual cells.
<thead>
<tr>
{{- range $x, $col := $table.cols -}}
- {{/* set default css */}}
- {{- $css := "" -}}
-
- {{/* get alignment */}}
- {{- $align := default "" $col.align -}}
- {{- if eq $align "left" -}}
- {{- $css = $config.cell_align_left -}}
- {{- else if eq $align "center" -}}
- {{- $css = $config.cell_align_center -}}
- {{- else if eq $align "justified" -}}
- {{- $css = $config.cell_align_justified -}}
- {{- else if eq $align "right" -}}
- {{- $css = $config.cell_align_right -}}
- {{- end -}}
+ {{- $is_map := reflect.IsMap $col -}}
+
+ {{- if $is_map -}}
+ {{/* col is a map, reference keys */}}
+
+ {{/* set default css */}}
+ {{- $css := "" -}}
+
+ {{/* get alignment */}}
+ {{- $align := default "" $col.align -}}
+ {{- if eq $align "left" -}}
+ {{- $css = $config.cell_align_left -}}
+ {{- else if eq $align "center" -}}
+ {{- $css = $config.cell_align_center -}}
+ {{- else if eq $align "justified" -}}
+ {{- $css = $config.cell_align_justify -}}
+ {{- else if eq $align "right" -}}
+ {{- $css = $config.cell_align_right -}}
+ {{- end -}}
- <th
- {{if $css}} class='{{- $css -}}'{{- end}}
- title='{{- default $col.name $col.tip -}}'
- aria-label='{{- default $col.name $col.tip -}}'
- data-{{- $dp -}}th_x='{{- $x -}}'
- data-{{- $dp -}}='{{- $col.id -}}'
- >
- {{- $col.name -}}
- </th>
+ <th
+ {{if $css}} class='{{- $css -}}'{{- end}}
+ title='{{- default $col.name $col.tip -}}'
+ aria-label='{{- default $col.name $col.tip -}}'
+ data-{{- $dp -}}th_x='{{- $x -}}'
+ data-{{- $dp -}}id='{{- $col.id -}}'
+ >
+ {{- $col.name -}}
+ </th>
+ {{- else -}}
+ {{/* col is a string */}}
+ <th
+ title='{{- $col -}}'
+ aria-label='{{- $col -}}'
+ data-{{- $dp -}}th_x='{{- $x -}}'
+ data-{{- $dp -}}id='{{- $x -}}'
+ >
+ {{- $col -}}
+ </th>
+ {{- end -}}
{{- end -}}
</tr>
</thead>
{{- if $table.rows -}}
<tbody>
+ {{/* is the first column a map? */}}
+ {{- $first_col_is_map := reflect.IsMap (index $table.cols 0) -}}
+
{{/* render rows */}}
{{- range $y, $row := $table.rows -}}
- <tr
- {{/* emit row ID */}}
- {{- if $row._id -}}
- id='{{- $row._id -}}'
- {{- end -}}
-
- {{- if $row._tip -}}
- {{/* emit row tooltip */}}
- title='{{- $row._tip -}}'
- aria-label='{{- $row._tip -}}'
- {{- end -}}
+ {{- if $first_col_is_map -}}
+ <tr
+ {{/* emit row ID */}}
+ {{- if $row._id -}}
+ id='{{- $row._id -}}'
+ {{- end -}}
- {{- if $row._css -}}
- {{/* emit row css */}}
- class='{{- $row._css -}}'
- {{- end -}}
+ {{- if $row._tip -}}
+ {{/* emit row tooltip */}}
+ title='{{- $row._tip -}}'
+ aria-label='{{- $row._tip -}}'
+ {{- end -}}
- {{/* row position */}}
- data-{{- $dp -}}tr_y='{{- $y -}}'
- >
- {{- range $x, $col := $table.cols -}}
- {{/* get cell */}}
- {{- $cell := index $row $col.id -}}
- {{- $is_map := reflect.IsMap $cell -}}
-
- {{/* get cell value */}}
- {{- $val := "" -}}
- {{- if $is_map -}}
- {{- $val = index $cell "val" -}}
- {{- else -}}
- {{- $val = $cell -}}
+ {{- if $row._css -}}
+ {{/* emit row css */}}
+ class='{{- $row._css -}}'
{{- end -}}
- {{/* get cell ID */}}
- {{- $cell_id := "" -}}
- {{- if $is_map -}}
- {{- if index $cell "id" -}}
- {{- $cell_id = $cell.id -}}
+ {{/* row position */}}
+ data-{{- $dp -}}tr_y='{{- $y -}}'
+ >
+ {{- range $x, $col := $table.cols -}}
+ {{/* get cell */}}
+ {{- $cell := index $row $col.id -}}
+ {{- $is_map := reflect.IsMap $cell -}}
+
+ {{/* get cell value */}}
+ {{- $val := "" -}}
+ {{- if $is_map -}}
+ {{- $val = index $cell "val" -}}
+ {{- else -}}
+ {{- $val = $cell -}}
{{- end -}}
- {{- end -}}
- {{/* get cell tip */}}
- {{- $tip := (default $col.name $col.tip) -}}
- {{- if $is_map -}}
- {{- if index $cell "tip" -}}
- {{- $tip = index $cell "tip" -}}
+ {{/* get cell ID */}}
+ {{- $cell_id := "" -}}
+ {{- if $is_map -}}
+ {{- if index $cell "id" -}}
+ {{- $cell_id = $cell.id -}}
+ {{- end -}}
{{- end -}}
- {{- end -}}
- {{/* get cell alignment */}}
- {{- $align := $col.align -}}
- {{- if and $is_map -}}
- {{- if (index $cell "align") -}}
- {{- $align = index $cell "align" -}}
+ {{/* get cell tip */}}
+ {{- $tip := (default $col.name $col.tip) -}}
+ {{- if $is_map -}}
+ {{- if index $cell "tip" -}}
+ {{- $tip = index $cell "tip" -}}
+ {{- end -}}
{{- end -}}
- {{- end -}}
- {{/* get default cell css */}}
- {{- $css := "" -}}
- {{- if eq $align "left" -}}
- {{- $css = $config.cell_align_left -}}
- {{- else if eq $align "center" -}}
- {{- $css = $config.cell_align_center -}}
- {{- else if eq $align "justified" -}}
- {{- $css = $config.cell_align_justified -}}
- {{- else if eq $align "right" -}}
- {{- $css = $config.cell_align_right -}}
- {{- end -}}
+ {{/* get cell alignment */}}
+ {{- $align := $col.align -}}
+ {{- if and $is_map -}}
+ {{- if (index $cell "align") -}}
+ {{- $align = index $cell "align" -}}
+ {{- end -}}
+ {{- end -}}
- {{/* get cell css override */}}
- {{- if $is_map -}}
- {{- if index $cell "css" -}}
- {{- $css = $cell.css -}}
+ {{/* get default cell css */}}
+ {{- $css := "" -}}
+ {{- if eq $align "left" -}}
+ {{- $css = $config.cell_align_left -}}
+ {{- else if eq $align "center" -}}
+ {{- $css = $config.cell_align_center -}}
+ {{- else if eq $align "justified" -}}
+ {{- $css = $config.cell_align_justify -}}
+ {{- else if eq $align "right" -}}
+ {{- $css = $config.cell_align_right -}}
{{- end -}}
- {{- end -}}
- {{/* get colspan */}}
- {{- $colspan := 1 -}}
- {{- if $is_map -}}
- {{- if index $cell "colspan" -}}
- {{- $colspan = $cell.colspan -}}
+ {{/* get cell css override */}}
+ {{- if $is_map -}}
+ {{- if index $cell "css" -}}
+ {{- $css = $cell.css -}}
+ {{- end -}}
{{- end -}}
- {{- end -}}
- {{/* get rowspan */}}
- {{- $rowspan := 1 -}}
- {{- if $is_map -}}
- {{- if index $cell "rowspan" -}}
- {{- $rowspan = $cell.rowspan -}}
+ {{/* get colspan */}}
+ {{- $colspan := 1 -}}
+ {{- if $is_map -}}
+ {{- if index $cell "colspan" -}}
+ {{- $colspan = $cell.colspan -}}
+ {{- end -}}
{{- end -}}
- {{- end -}}
- {{/* emit cell */}}
- <td
- {{/* emit cell ID */}}
- {{- if $cell_id -}}
- id='{{- $cell_id -}}'
+ {{/* get rowspan */}}
+ {{- $rowspan := 1 -}}
+ {{- if $is_map -}}
+ {{- if index $cell "rowspan" -}}
+ {{- $rowspan = $cell.rowspan -}}
+ {{- end -}}
{{- end -}}
- title='{{- $tip -}}'
- aria-label='{{- $tip -}}'
- class='{{- $css -}}'
+ {{/* emit cell */}}
+ <td
+ {{/* emit cell ID */}}
+ {{- if $cell_id -}}
+ id='{{- $cell_id -}}'
+ {{- end -}}
- data-{{- $dp -}}td_x='{{- $x -}}'
- data-{{- $dp -}}col_id='{{- $col.id -}}'
+ title='{{- $tip -}}'
+ aria-label='{{- $tip -}}'
+ class='{{- $css -}}'
- {{- if gt $colspan 1 -}}
- colspan='{{- $colspan -}}'
- {{- end -}}
+ data-{{- $dp -}}td_x='{{- $x -}}'
+ data-{{- $dp -}}col_id='{{- $col.id -}}'
- {{- if gt $rowspan 1 -}}
- rowspan='{{- $rowspan -}}'
- {{- end -}}
- >
- {{- if $is_map -}}
- {{- if $cell.html -}}
- {{/* render as raw HTML */}}
- {{- $val | safeHTML -}}
+ {{- if gt $colspan 1 -}}
+ colspan='{{- $colspan -}}'
+ {{- end -}}
+
+ {{- if gt $rowspan 1 -}}
+ rowspan='{{- $rowspan -}}'
+ {{- end -}}
+ >
+ {{- if $is_map -}}
+ {{- if $cell.html -}}
+ {{/* render as raw HTML */}}
+ {{- $val | safeHTML -}}
+ {{- else -}}
+ {{/* render as markup */}}
+ {{- $val | $.Page.RenderString -}}
+ {{- end -}}
{{- else -}}
{{/* render as markup */}}
{{- $val | $.Page.RenderString -}}
{{- end -}}
- {{- else -}}
- {{/* render as markup */}}
- {{- $val | $.Page.RenderString -}}
- {{- end -}}
- </td>
- {{- end -}}
- </tr>
+ </td>
+ {{- end -}}
+ </tr>
+ {{- else -}}
+ {{/* first column is string, rows are arrays of values */}}
+ <tr
+ {{/* row position */}}
+ data-{{- $dp -}}tr_y='{{- $y -}}'
+ >
+ {{- range $x, $col := $table.cols -}}
+ <td
+ title='{{- $col -}}'
+ aria-label='{{- $col -}}'
+ >
+ {{- index $row $x -}}
+ </td>
+ {{- end -}}
+ </tr>
+ {{- end -}}
{{- end -}}
</tbody>
{{- end -}}