From 790970fabb7897e27354dab8ff7fd430d0138fd6 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Thu, 14 Mar 2024 11:42:24 -0700 Subject: [PATCH 1/7] Add tomlToTable equivalent of yamlToTable --- layouts/shortcodes/tomlToTable.html | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 layouts/shortcodes/tomlToTable.html diff --git a/layouts/shortcodes/tomlToTable.html b/layouts/shortcodes/tomlToTable.html new file mode 100644 index 00000000..63002df7 --- /dev/null +++ b/layouts/shortcodes/tomlToTable.html @@ -0,0 +1,68 @@ +{{/* + +doc: Render TOML to an HTML table. + +{{< tomlToTable >}} + +[[row]] +type = 'header' + +[[row.column]] +body = 'Project' + +[[row.column]] +body = 'Available Packages' + +[[row.column]] +body = 'Download location' + +[[row]] + +[[row.column]] +body = 'NumPy' + +[[row.column]] +body = '''Official *source code* (all platforms) and *binaries* for
+**Windows**, **Linux**, and **Mac OS X**''' + +[[row.column]] +body = '[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)' + +[[row]] + +[[row.column]] +body = 'SciPy' + +[[row.column]] +body = '''Official *source code* (all platforms) and *binaries* for
+**Windows**, **Linux**, and **Mac OS X**''' + +[[row.column]] +align = 'right' +body = '''[SciPy release page](https://github.com/scipy/scipy/releases) (sources)
+[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)''' + +{{< /tomlToTable >}} + +*/}} + +{{ $arg := .Get 0 }} +{{ $data := .Inner | transform.Unmarshal }} + +{{ with $data }} + + {{ range $row := .row }} + + {{ $el := "td" }} + {{ if (eq $row.type "header") }} + {{ $el = "th" }} + {{ end }} + {{ range $col := .column }} + {{ printf "<%s" $el | safeHTML }} colspan="{{ $col.colspan }}" rowspan="{{ $col.rowspan }}" {{ printf ">" | safeHTML }} + {{ $col.body | markdownify }} + {{ printf "" $el | safeHTML }} + {{ end }} + + {{ end }} +
+{{ end }} From 1f7dec84d9a0c4ec29edb7f42d13754d8b2e116c Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Thu, 14 Mar 2024 14:49:43 -0700 Subject: [PATCH 2/7] Add legend to figure using tomlToTable --- layouts/shortcodes/figure.html | 35 +++++++++++++++++++++++++++-- layouts/shortcodes/tomlToTable.html | 12 ++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index f071ce07..744e868d 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -14,7 +14,36 @@ A figure is an image with a caption. Figures may also include a tile, legend, and/or attribution. ''' legend = ''' -**TODO: use tomltotable (https://github.com/scientific-python/scientific-python-hugo-theme/pull/548)** +{{< tomlToTable >}} + +[[row]] +type = 'header' + +[[row.column]] +body = 'Project' + +[[row.column]] +body = 'Available Packages' + +[[row]] + +[[row.column]] +body = 'NumPy' + +[[row.column]] +body = '''Official *source code* (all platforms) and *binaries* for
+**Windows**, **Linux**, and **Mac OS X**''' + +[[row]] + +[[row.column]] +body = 'SciPy' + +[[row.column]] +body = '''Official *source code* (all platforms) and *binaries* for
+**Windows**, **Linux**, and **Mac OS X**''' + +{{< /tomlToTable >}} This paragraph is also part of the legend. ''' @@ -59,7 +88,9 @@ {{- with $figure.legend }}
-{{ . | markdownify -}} +{{- with (trim . "\n") }} + {{ . | safeHTML }} +{{- end }}
{{- end }} diff --git a/layouts/shortcodes/tomlToTable.html b/layouts/shortcodes/tomlToTable.html index 63002df7..2118e17c 100644 --- a/layouts/shortcodes/tomlToTable.html +++ b/layouts/shortcodes/tomlToTable.html @@ -50,12 +50,16 @@ {{ $data := .Inner | transform.Unmarshal }} {{ with $data }} - - {{ range $row := .row }} - +
+ {{ range $i, $row := .row }} + {{if (modBool $i 2)}} + + {{else}} + + {{end}} {{ $el := "td" }} {{ if (eq $row.type "header") }} - {{ $el = "th" }} + {{ $el = "th class='head'" }} {{ end }} {{ range $col := .column }} {{ printf "<%s" $el | safeHTML }} colspan="{{ $col.colspan }}" rowspan="{{ $col.rowspan }}" {{ printf ">" | safeHTML }} From 2720b15e76e108756fe8252d704b74d239101dcf Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Fri, 15 Mar 2024 08:27:13 -0700 Subject: [PATCH 3/7] Add some options --- layouts/shortcodes/tomlToTable.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/layouts/shortcodes/tomlToTable.html b/layouts/shortcodes/tomlToTable.html index 2118e17c..ff471352 100644 --- a/layouts/shortcodes/tomlToTable.html +++ b/layouts/shortcodes/tomlToTable.html @@ -4,6 +4,12 @@ {{< tomlToTable >}} +caption = 'Table caption' +align = [ "left", "left", "right" ] +header-rows = 1 +footer-rows = 3 +stub-columns = 1 + [[row]] type = 'header' From 9fc387fb667bb2c0f8dd4e6894a1fb03687cbb1a Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Thu, 4 Apr 2024 07:55:35 -0700 Subject: [PATCH 4/7] Implement caption, widths, alignment, thead, and tbody --- assets/theme-css/styles.css | 2 +- layouts/shortcodes/tomlToTable.html | 72 ++++++++++++++++++----------- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/assets/theme-css/styles.css b/assets/theme-css/styles.css index 8c5f562c..9b92e633 100644 --- a/assets/theme-css/styles.css +++ b/assets/theme-css/styles.css @@ -168,7 +168,7 @@ a.headerlink { visibility: hidden; } -:is(h1, h2, h3, h4, h5, h6):hover > a.headerlink { +:is(h1, h2, h3, h4, h5, h6, caption):hover > a.headerlink { visibility: visible; } diff --git a/layouts/shortcodes/tomlToTable.html b/layouts/shortcodes/tomlToTable.html index ff471352..1f2b8642 100644 --- a/layouts/shortcodes/tomlToTable.html +++ b/layouts/shortcodes/tomlToTable.html @@ -5,13 +5,13 @@ {{< tomlToTable >}} caption = 'Table caption' -align = [ "left", "left", "right" ] -header-rows = 1 +align = ["left", "left", "right"] +widths = ["10%", "50%", "20%"] +headerrows = 1 footer-rows = 3 stub-columns = 1 [[row]] -type = 'header' [[row.column]] body = 'Project' @@ -44,7 +44,6 @@ **Windows**, **Linux**, and **Mac OS X**''' [[row.column]] -align = 'right' body = '''[SciPy release page](https://github.com/scipy/scipy/releases) (sources)
[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)''' @@ -52,27 +51,48 @@ */}} -{{ $arg := .Get 0 }} -{{ $data := .Inner | transform.Unmarshal }} - -{{ with $data }} -
- {{ range $i, $row := .row }} - {{if (modBool $i 2)}} - - {{else}} - - {{end}} - {{ $el := "td" }} - {{ if (eq $row.type "header") }} - {{ $el = "th class='head'" }} - {{ end }} - {{ range $col := .column }} - {{ printf "<%s" $el | safeHTML }} colspan="{{ $col.colspan }}" rowspan="{{ $col.rowspan }}" {{ printf ">" | safeHTML }} - {{ $col.body | markdownify }} - {{ printf "" $el | safeHTML }} - {{ end }} - +{{- $data := .Inner | transform.Unmarshal }} +{{- $id := printf "id%03d" $.Ordinal -}} +{{- $align := $data.align }} +{{- $numrows := $data.row | len }} +{{- $headerrows := or $data.headerrows 0 }} +{{- $header := first $headerrows $data.row }} +{{- $body := last (math.Sub $numrows $headerrows) $data.row }} + +
+ {{- with $data.caption }} + + {{- end }} + {{- with $data.widths }} + + {{- range . }} + + {{- end }} + {{ end }} + {{- if $header }} + {{- range $row_idx, $row := $header }} + {{ if (modBool $row_idx 2) }}{{- else }}{{- end }} + {{- range $col_idx, $col := .column }} + {{- $alignment := or (index $align $col_idx) "left" }} + + {{- end }} + + {{- end }} + + {{- end }} + + {{- range $row_idx, $row := $body }} + {{ if (modBool (add $row_idx $headerrows) 2) }}{{- else }}{{- end }} + {{- range $col_idx, $col := .column }} + {{- $alignment := or (index $align $col_idx) "left" }} + + {{- end }} + + {{- end }} +
{{ . }}#
+ {{ $col.body | markdownify }} +
+ {{ $col.body | markdownify }} +
-{{ end }} From b3d04ce2326d5c31b5c230c8afc529b2a12dd058 Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Thu, 4 Apr 2024 09:23:52 -0700 Subject: [PATCH 5/7] Implement width --- layouts/shortcodes/tomlToTable.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/layouts/shortcodes/tomlToTable.html b/layouts/shortcodes/tomlToTable.html index 1f2b8642..73739668 100644 --- a/layouts/shortcodes/tomlToTable.html +++ b/layouts/shortcodes/tomlToTable.html @@ -6,6 +6,7 @@ caption = 'Table caption' align = ["left", "left", "right"] +width = "80%" widths = ["10%", "50%", "20%"] headerrows = 1 footer-rows = 3 @@ -59,7 +60,7 @@ {{- $header := first $headerrows $data.row }} {{- $body := last (math.Sub $numrows $headerrows) $data.row }} - +
{{- with $data.caption }} {{- end }} From 468da7f3cfe56a46ee798ee9133a31692447d436 Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Thu, 4 Apr 2024 09:49:14 -0700 Subject: [PATCH 6/7] Simplify toml --- layouts/shortcodes/figure.html | 36 ++++++++------------ layouts/shortcodes/tomlToTable.html | 53 +++++++++++------------------ 2 files changed, 34 insertions(+), 55 deletions(-) diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index 744e868d..13e6dd89 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -17,31 +17,25 @@ {{< tomlToTable >}} [[row]] -type = 'header' - -[[row.column]] -body = 'Project' - -[[row.column]] -body = 'Available Packages' +column = [ + "Project", + "Available Packages", + "Download location" +] [[row]] - -[[row.column]] -body = 'NumPy' - -[[row.column]] -body = '''Official *source code* (all platforms) and *binaries* for
-**Windows**, **Linux**, and **Mac OS X**''' +column = [ + "NumPy", + "Official *source code* (all platforms) and *binaries* for
\n**Windows**, **Linux**, and **Mac OS X**\n", + "[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)" +] [[row]] - -[[row.column]] -body = 'SciPy' - -[[row.column]] -body = '''Official *source code* (all platforms) and *binaries* for
-**Windows**, **Linux**, and **Mac OS X**''' +column = [ + "SciPy", + "Official *source code* (all platforms) and *binaries* for
\n**Windows**, **Linux** and **Mac OS X**\n", + "[SciPy release page](https://github.com/scipy/scipy/releases) (sources)
\n[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)\n" +] {{< /tomlToTable >}} diff --git a/layouts/shortcodes/tomlToTable.html b/layouts/shortcodes/tomlToTable.html index 73739668..23460a4d 100644 --- a/layouts/shortcodes/tomlToTable.html +++ b/layouts/shortcodes/tomlToTable.html @@ -13,40 +13,25 @@ stub-columns = 1 [[row]] - -[[row.column]] -body = 'Project' - -[[row.column]] -body = 'Available Packages' - -[[row.column]] -body = 'Download location' +column = [ + "Project", + "Available Packages", + "Download location" +] [[row]] - -[[row.column]] -body = 'NumPy' - -[[row.column]] -body = '''Official *source code* (all platforms) and *binaries* for
-**Windows**, **Linux**, and **Mac OS X**''' - -[[row.column]] -body = '[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)' +column = [ + "NumPy", + "Official *source code* (all platforms) and *binaries* for
\n**Windows**, **Linux**, and **Mac OS X**\n", + "[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)" +] [[row]] - -[[row.column]] -body = 'SciPy' - -[[row.column]] -body = '''Official *source code* (all platforms) and *binaries* for
-**Windows**, **Linux**, and **Mac OS X**''' - -[[row.column]] -body = '''[SciPy release page](https://github.com/scipy/scipy/releases) (sources)
-[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)''' +column = [ + "SciPy", + "Official *source code* (all platforms) and *binaries* for
\n**Windows**, **Linux** and **Mac OS X**\n", + "[SciPy release page](https://github.com/scipy/scipy/releases) (sources)
\n[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)\n" +] {{< /tomlToTable >}} @@ -74,10 +59,10 @@ {{- if $header }}
{{- range $row_idx, $row := $header }} {{ if (modBool $row_idx 2) }}{{- else }}{{- end }} - {{- range $col_idx, $col := .column }} + {{- range $col_idx, $col := $row.column }} {{- $alignment := or (index $align $col_idx) "left" }} {{- end }} @@ -87,10 +72,10 @@ {{- range $row_idx, $row := $body }} {{ if (modBool (add $row_idx $headerrows) 2) }}{{- else }}{{- end }} - {{- range $col_idx, $col := .column }} + {{- range $col_idx, $col := $row.column }} {{- $alignment := or (index $align $col_idx) "left" }} {{- end }} From da22858c41e748145c2ee0a1769f0af710a0d87d Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Thu, 4 Apr 2024 11:00:47 -0700 Subject: [PATCH 7/7] Implement stub columns --- layouts/shortcodes/tomlToTable.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/layouts/shortcodes/tomlToTable.html b/layouts/shortcodes/tomlToTable.html index 23460a4d..bbe06808 100644 --- a/layouts/shortcodes/tomlToTable.html +++ b/layouts/shortcodes/tomlToTable.html @@ -10,7 +10,7 @@ widths = ["10%", "50%", "20%"] headerrows = 1 footer-rows = 3 -stub-columns = 1 +stubcolumns = 1 [[row]] column = [ @@ -61,7 +61,9 @@ {{ if (modBool $row_idx 2) }}{{- else }}{{- end }} {{- range $col_idx, $col := $row.column }} {{- $alignment := or (index $align $col_idx) "left" }} - {{- end }} @@ -74,9 +76,14 @@ {{ if (modBool (add $row_idx $headerrows) 2) }}{{- else }}{{- end }} {{- range $col_idx, $col := $row.column }} {{- $alignment := or (index $align $col_idx) "left" }} - + {{ cond $isStub "" "" | safeHTML }} {{- end }} {{- end }}
{{ . }}#
- {{ $col.body | markdownify }} + {{ $col | markdownify }}
- {{ $col.body | markdownify }} + {{ $col | markdownify }}
+ {{- $isStub := compare.Lt $col_idx $data.stubcolumns }} + {{- $class := cond $isStub "head stub" "head" }} + {{ $col | markdownify }}
+ {{- $isStub := compare.Lt $col_idx $data.stubcolumns }} + {{- if $isStub }} + + {{- else }} + + {{- end }} {{ $col | markdownify }} -