Tweak scss-docs shortcode
This commit is contained in:
parent
69afafe811
commit
94c46cc4f8
1 changed files with 22 additions and 17 deletions
|
|
@ -5,29 +5,34 @@
|
|||
comments in the docs.
|
||||
|
||||
Optional parameters:
|
||||
strip-default: Remove the ` !default` flag from variable assignments - default: `true`
|
||||
* strip-default: Remove the ` !default` flag from variable assignments - default: `true`
|
||||
*/ -}}
|
||||
|
||||
{{- $name := .Get "name" -}}
|
||||
{{- $file := .Get "file" -}}
|
||||
{{- $strip_default := .Get "strip-default" | default "true" -}}
|
||||
|
||||
{{- $start := printf "// scss-docs-start %s\n" $name -}}
|
||||
{{- $end := printf "\n// scss-docs-end %s" $name -}}
|
||||
{{- $regex := printf "%s(.|\n)*%s" $start $end -}}
|
||||
{{- /* If any parameters are missing, print an error and exit */ -}}
|
||||
{{- if or (not $name) (not $file) -}}
|
||||
{{- errorf "Missing required parameters! Got: name=%q file=%q! (called in %q)" $name $file $.Page.Path -}}
|
||||
{{- else -}}
|
||||
{{- $start := printf "// scss-docs-start %s\n" $name -}}
|
||||
{{- $end := printf "\n// scss-docs-end %s" $name -}}
|
||||
{{- $regex := printf "%s(.|\n)*%s" $start $end -}}
|
||||
|
||||
{{- $css := readFile $file -}}
|
||||
{{- $match := findRE $regex $css 1 -}}
|
||||
{{- $css := readFile $file -}}
|
||||
{{- $match := findRE $regex $css 1 -}}
|
||||
|
||||
{{- if (eq (len $match) 0) -}}
|
||||
{{- errorf "Got no matches for %q in %q! (called in %q)" $name $file $.Page.Path -}}
|
||||
{{- if (eq (len $match) 0) -}}
|
||||
{{- errorf "Got no matches for name=%q in file=%q! (called in %q)" $name $file $.Page.Path -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $remove_start := replace (index $match 0) $start "" -}}
|
||||
{{- $result := replace $remove_start $end "" -}}
|
||||
|
||||
{{- if (ne $strip_default "false") -}}
|
||||
{{- $result = replace $result " !default" "" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- highlight $result "scss" "" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $remove_start := replace (index $match 0) $start "" -}}
|
||||
{{- $result := replace $remove_start $end "" -}}
|
||||
|
||||
{{- if (ne $strip_default "false") -}}
|
||||
{{- $result = replace $result " !default" "" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- highlight $result "scss" "" -}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue