Skip to content

Commit

Permalink
Tabpane shortcodes: improved reporting of warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
deining committed Mar 10, 2023
1 parent 1d192e3 commit 280b1d8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion layouts/shortcodes/blocks/lead.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

Expand Down
28 changes: 14 additions & 14 deletions layouts/shortcodes/imgproc.html
Original file line number Diff line number Diff line change
@@ -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" }}
<figure class="card rounded p-2 td-post-card mb-4 mt-4" style="max-width: {{ add $image.Width 10 }}px">
<img class="card-img-top" src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}">
Expand Down
13 changes: 8 additions & 5 deletions layouts/shortcodes/tab.html
Original file line number Diff line number Diff line change
@@ -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" -}}
Expand All @@ -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 -}}
Expand Down
12 changes: 6 additions & 6 deletions layouts/shortcodes/tabpane.html
Original file line number Diff line number Diff line change
@@ -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 -}}

Expand Down Expand Up @@ -101,7 +101,7 @@
</ul>

{{ 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 -}}
Expand Down

0 comments on commit 280b1d8

Please sign in to comment.