{{- $basePath := .Site.Params.docs.basePath -}} {{- $file := .Get "path" | default "" -}} {{- if hasPrefix $file "./" -}} {{- $file = path.Clean $file -}} {{- else -}} {{- $file = path.Join $basePath (path.Clean $file) -}} {{- end -}} {{- $extension := strings.TrimLeft "." (path.Ext $file) }} {{- $lang := .Get "lang" | default $extension -}} {{- $id := printf "file-collapse-%d" .Ordinal -}} {{ with .Get "id" }} {{ $id = . }} {{ end }} {{ $supportedFlags := slice "true" "false" -}} {{ $showParam := "true" -}} {{ $show := true -}} {{ with .Get "show" }}{{ $showParam = . }}{{ end -}} {{ if in $supportedFlags $showParam -}} {{ if eq $showParam "true" }}{{ $show = true }}{{ else }}{{ $show = false }}{{ end -}} {{ else -}} {{ errorf "Invalid value for param 'show': %s" $showParam -}} {{ end -}} {{ $fullParam := "true" -}} {{ $full := true -}} {{ with .Get "full" }}{{ $fullParam = . }}{{ end -}} {{ if in $supportedFlags $fullParam -}} {{ if eq $fullParam "true" }}{{ $full = true }}{{ else }}{{ $full = false }}{{ end -}} {{ else -}} {{ errorf "Invalid value for param 'full': %s" $fullParam -}} {{ end -}} {{- $class := .Get "class" | default "" -}} {{- /* If any parameters are missing, print an error and exit */ -}} {{- if not $file -}} {{- errorf "%s: %q: Missing required parameters! Got: path=%q!" .Position .Name $file -}} {{- else -}} {{- /* Force-check if the file exists */ -}} {{ $tmp := os.Stat $file }} {{- $content := readFile $file -}}
{{- highlight (trim $content "\r\n") $lang "" -}}
{{- end -}}