scss-docs.html 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. {{- /*
  2. Usage: `scss-docs name="name" file="file/_location.scss"`
  3. Prints everything between `// scss-docs-start "name"` and `// scss-docs-end "name"`
  4. comments in the docs.
  5. Optional parameters:
  6. strip-default: Remove the ` !default` flag from variable assignments - default: `true`
  7. */ -}}
  8. {{- $name := .Get "name" -}}
  9. {{- $file := .Get "file" -}}
  10. {{- $strip_default := .Get "strip-default" | default "true" -}}
  11. {{- $start := printf "// scss-docs-start %s\n" $name -}}
  12. {{- $end := printf "// scss-docs-end %s" $name -}}
  13. {{- $regex := printf "%s(.|\n)*%s" $start $end -}}
  14. {{- $css := readFile $file -}}
  15. {{- $match := findRE $regex $css 1 -}}
  16. {{- if (eq (len $match) 0) -}}
  17. {{- errorf "Got no matches for %q in %q! (called in %q)" $name $file $.Page.Path -}}
  18. {{- end -}}
  19. {{- $remove_start := replace (index $match 0) $start "" -}}
  20. {{- $result := replace $remove_start $end "" -}}
  21. {{- if (ne $strip_default "false") -}}
  22. {{- $result = replace $result " !default" "" -}}
  23. {{- end -}}
  24. {{- highlight $result "scss" "" -}}