From 280b1d8197b03d35592b969822ea74de54f06f10 Mon Sep 17 00:00:00 2001 From: Andreas Deininger Date: Fri, 10 Mar 2023 15:08:35 +0100 Subject: [PATCH] Tabpane shortcodes: improved reporting of warnings and errors --- layouts/shortcodes/blocks/lead.html | 2 +- layouts/shortcodes/imgproc.html | 28 ++++++++++++++-------------- layouts/shortcodes/tab.html | 13 ++++++++----- layouts/shortcodes/tabpane.html | 12 ++++++------ 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/layouts/shortcodes/blocks/lead.html b/layouts/shortcodes/blocks/lead.html index 6c12d62037..5afe34c647 100644 --- a/layouts/shortcodes/blocks/lead.html +++ b/layouts/shortcodes/blocks/lead.html @@ -2,7 +2,7 @@ {{ $height := .Get "height" | default "auto" -}} {{ with .Get "height" -}} {{ if not ( or ( eq . "auto" ) ( eq . "min" ) ( eq . "med" ) ( eq . "max" ) ( eq . "full" ) ) -}} - {{ errorf "shortcode 'lead': parameter height is '%s', must be one of 'auto', 'min', 'med', 'max' or 'full'." . -}} + {{ errorf "shortcode 'lead': parameter height is %q, must be one of 'auto', 'min', 'med', 'max' or 'full'." . -}} {{ end -}} {{ end -}} diff --git a/layouts/shortcodes/imgproc.html b/layouts/shortcodes/imgproc.html index 6c5a211f90..318f0f2404 100644 --- a/layouts/shortcodes/imgproc.html +++ b/layouts/shortcodes/imgproc.html @@ -1,17 +1,17 @@ -{{ $original := .Page.Resources.GetMatch (printf "**%s*" (.Get 0)) }} -{{ $command := .Get 1 }} -{{ $options := .Get 2 }} -{{ if eq $command "Fit"}} -{{ .Scratch.Set "image" ($original.Fit $options) }} -{{ else if eq $command "Resize"}} -{{ .Scratch.Set "image" ($original.Resize $options) }} -{{ else if eq $command "Fill"}} -{{ .Scratch.Set "image" ($original.Fill $options) }} -{{ else if eq $command "Crop"}} -{{ .Scratch.Set "image" ($original.Crop $options) }} -{{ else }} -{{ errorf "Invalid image processing command: Must be one of Fit, Fill, Crop or Resize."}} -{{ end }} +{{ $original := .Page.Resources.GetMatch (printf "**%s*" (.Get 0)) -}} +{{ $command := .Get 1 -}} +{{ $options := .Get 2 -}} +{{ if eq $command "Fit" -}} +{{ .Scratch.Set "image" ($original.Fit $options) -}} +{{ else if eq $command "Resize" -}} +{{ .Scratch.Set "image" ($original.Resize $options) -}} +{{ else if eq $command "Fill" -}} +{{ .Scratch.Set "image" ($original.Fill $options) -}} +{{ else if eq $command "Crop" -}} +{{ .Scratch.Set "image" ($original.Crop $options) -}} +{{ else -}} +{{ errorf "Invalid image processing command %q: must be one of Fit, Fill, Crop or Resize." $command -}} +{{ end -}} {{ $image := .Scratch.Get "image" }}
diff --git a/layouts/shortcodes/tab.html b/layouts/shortcodes/tab.html index 8ec7e09d5e..d13e0338e3 100644 --- a/layouts/shortcodes/tab.html +++ b/layouts/shortcodes/tab.html @@ -1,8 +1,11 @@ {{- /* Make sure that we are enclosed within a tabpane shortcode block */ -}} + {{ with $.Parent -}} -{{ if ne $.Parent.Name "tabpane" -}} - {{ errorf "shortcode 'tab' must be used within a 'tabpane' block" -}} + {{ if ne $.Parent.Name "tabpane" -}} + {{ errorf "Found shortcode %q enclosed inside a %q block, must be enclosed inside a %q block. Error position: %s" $.Name $.Parent.Name "tabpane" $.Position -}} {{ end -}} +{{ else -}} + {{ errorf "shortcode %q must be enclosed inside a %q block, but no parent block was found. Error position: %s" $.Name "tabpane" $.Position -}} {{ end -}} {{ $header := "Tab" -}} @@ -23,19 +26,19 @@ {{ end -}} {{ with $.Get "text" -}} {{ if ne ( printf "%T" . ) "bool" -}} - {{ errorf "shortcode tab: parameter 'text' must be either true or false" -}} + {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "text" (printf "%T" .) $.Position -}} {{ end -}} {{ $tab = merge $tab (dict "text" ($.Get "text")) -}} {{ end -}} {{ with $.Get "right" -}} {{ if ne ( printf "%T" . ) "bool" -}} - {{ errorf "shortcode tab: parameter 'right' must be either true or false" -}} + {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "right" (printf "%T" .) $.Position -}} {{ end -}} {{ $tab = merge $tab (dict "rightpush" ($.Get "right")) -}} {{ end -}} {{ with $.Get "disabled" -}} {{ if ne ( printf "%T" . ) "bool" -}} - {{ errorf "shortcode tab: parameter 'disabled' must be either true or false" -}} + {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "disabled" (printf "%T" .) $.Position -}} {{ end -}} {{ $tab = merge $tab (dict "disabled" ($.Get "disabled")) -}} {{ end -}} diff --git a/layouts/shortcodes/tabpane.html b/layouts/shortcodes/tabpane.html index d22a59a193..c553383db0 100644 --- a/layouts/shortcodes/tabpane.html +++ b/layouts/shortcodes/tabpane.html @@ -1,25 +1,25 @@ {{/* Check parameter types */ -}} {{ with .Get "langEqualsHeader" -}} - {{ if ne ( printf "%T" . ) "bool" -}} - {{ errorf "shortcode tabpane: parameter 'langEqualsHeader' must be either true or false" -}} + {{ if ne ( printf "%T" . ) "bool" -}} + {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "langEqualsHeader" (printf "%T" .) $.Position -}} {{ end -}} {{ end -}} {{ with .Get "text" -}} {{ if ne ( printf "%T" . ) "bool" -}} - {{ errorf "shortcode tabpane: parameter 'text' must be either true or false" -}} + {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "text" (printf "%T" .) $.Position -}} {{ end -}} {{ end -}} {{ with .Get "persistLang" -}} {{ if ne ( printf "%T" . ) "bool" -}} - {{ errorf "shortcode tabpane: parameter 'persistLang' must be either true or false" -}} + {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "persistLang" (printf "%T" .) $.Position -}} {{ end -}} {{ end -}} {{ with .Get "right" -}} {{ if ne ( printf "%T" . ) "bool" -}} - {{ errorf "shortcode tabpane: parameter 'right' must be either true or false" -}} + {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "right" (printf "%T" .) $.Position -}} {{ end -}} {{ end -}} @@ -101,7 +101,7 @@ {{ if $duplicate -}} - {{ warnf "Tabpane on page '%s': duplicate language '%s' detected, disabling persistance of language to avoid multiple tab display." .Page.RelPermalink $duplicateLang -}} + {{ warnf "Shortcode %q: duplicate language %q detected, disabling persistance of language to avoid multiple tab display. Position: %s" $.Name $duplicateLang $.Position -}} {{ end -}} {{ $duplicate = false -}} {{ $langs = slice -}}