-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
{{- /* | ||
Usage: `scss-docs name="name" file="file/_location.scss"` | ||
|
||
Prints everything between `// scss-docs-start "name"` and `// scss-docs-end "name"` | ||
comments in the docs. | ||
Prints everything between `// scss-docs-start "name"` and `// scss-docs-end "name"` | ||
comments in the docs. | ||
|
||
Optional parameters: | ||
strip-default: Remove the ` !default` flag from variable assignments - default: `true` | ||
Optional parameters: | ||
* 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 -}} | ||
{{- end -}} | ||
{{- 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 "" -}} | ||
{{- $remove_start := replace (index $match 0) $start "" -}} | ||
{{- $result := replace $remove_start $end "" -}} | ||
|
||
{{- if (ne $strip_default "false") -}} | ||
{{- $result = replace $result " !default" "" -}} | ||
{{- end -}} | ||
{{- if (ne $strip_default "false") -}} | ||
{{- $result = replace $result " !default" "" -}} | ||
{{- end -}} | ||
|
||
{{- highlight $result "scss" "" -}} | ||
{{- highlight $result "scss" "" -}} | ||
{{- end -}} |