tab.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. {{- /* Make sure that we are enclosed within a tabpane shortcode block */ -}}
  2. {{ with $.Parent -}}
  3. {{ if ne $.Parent.Name "tabpane" -}}
  4. {{ errorf "Found shortcode %q enclosed inside a %q block, must be enclosed inside a %q block. Error position: %s" $.Name $.Parent.Name "tabpane" $.Position -}}
  5. {{ end -}}
  6. {{ else -}}
  7. {{ errorf "shortcode %q must be enclosed inside a %q block, but no parent block was found. Error position: %s" $.Name "tabpane" $.Position -}}
  8. {{ end -}}
  9. {{ $header := "Tab" -}}
  10. {{ if and (not .IsNamedParams) (.Get 0) -}}
  11. {{ $header = (.Get 0) -}}
  12. {{ else -}}
  13. {{/* Prefill header if not given as named or unnamed parameter */ -}}
  14. {{ $header = .Get "header" | default (printf "Tab %v" .Ordinal) -}}
  15. {{ end -}}
  16. {{/* store all tab info in dict tab */ -}}
  17. {{ $tab := dict "header" $header -}}
  18. {{ with $.Get "lang" -}}
  19. {{ $tab = merge $tab (dict "language" .) -}}
  20. {{ end -}}
  21. {{ with $.Get "highlight" -}}
  22. {{ $tab = merge $tab (dict "highlight" .) -}}
  23. {{ end -}}
  24. {{ with $.Get "text" -}}
  25. {{ if ne ( printf "%T" . ) "bool" -}}
  26. {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "text" (printf "%T" .) $.Position -}}
  27. {{ end -}}
  28. {{ $tab = merge $tab (dict "text" .) -}}
  29. {{ end -}}
  30. {{ with $.Get "right" -}}
  31. {{ if ne ( printf "%T" . ) "bool" -}}
  32. {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "right" (printf "%T" .) $.Position -}}
  33. {{ end -}}
  34. {{ $tab = merge $tab (dict "rightpush" .) -}}
  35. {{ end -}}
  36. {{ with $.Get "disabled" -}}
  37. {{ if ne ( printf "%T" . ) "bool" -}}
  38. {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "disabled" (printf "%T" .) $.Position -}}
  39. {{ end -}}
  40. {{ $tab = merge $tab (dict "disabled" .) -}}
  41. {{ end -}}
  42. {{ with $.Inner -}}
  43. {{/* Trim any leading and trailing newlines from .Inner, this avoids
  44. spurious lines during syntax highlighting */ -}}
  45. {{ $tab = merge $tab (dict "content" .) -}}
  46. {{ end -}}
  47. {{/* add dict tab to parent's scratchpad */ -}}
  48. {{ with .Parent -}}
  49. {{ $.Parent.Scratch.SetInMap "tabs" (printf "%02v" $.Ordinal) $tab -}}
  50. {{ end -}}