{{- /*
  Usage: `css-vars-docs file="file/_location.scss"`

  Find all CSS Variables and print them in the docs.
*/ -}}

{{- $file := .Get "file" -}}
{{- $strip_default := .Get "strip-default" | default "true" -}}

{{- $regex := printf "(--#{\\$variable-prefix}[^,|)|:]*)" -}}

{{- $css := readFile $file -}}
{{- $match := (findRE $regex $css) | uniq | sort -}}

{{- if (eq (len $match) 0) -}}
  {{- errorf "Got no matches for %q in %q! (called in %q)" $file $.Page.Path -}}
{{- end -}}

{{- $result := delimit $match "\n" -}}

{{- if (ne $strip_default "false") -}}
  {{- $result = replace $result "#{$variable-prefix}" "cui-" -}}
{{- end -}}

{{- highlight $result "scss" "" -}}
