Skip to content

Commit

Permalink
Process GoAT drawing from .go source file to SVG inserted in README
Browse files Browse the repository at this point in the history
  • Loading branch information
dmullis committed Jul 13, 2022
1 parent fc9803f commit 7d97b47
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
3 changes: 3 additions & 0 deletions README.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ By default, the program writes to stdout, unless `-o outfile` is given.
- Dashed lines signaled by `:` or `=`.
- Bold lines signaled by ???.

## Data Flow
![]({{.Root}}/goat.svg)

## Examples

Here are some SVGs and the UTF-8 input they were generated from:
Expand Down
32 changes: 21 additions & 11 deletions canvas.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@

/*
Package goat formats "ASCII-art" drawings into Github-flavored Markdown.
<goat>
Internal Data Flow
Canvas{} WriteSVGBody() SVG{}
NewCanvas() .-----------------. .-------. .-------------.
ASCII-art .--. | data map[x,y]rune | | | | | Markdown
---------->| +--->| text map[x,y]rune |-->| +--->| Body string +----->
'--' | | | | | |
'-----------------' '-------' '-------------'
</goat>
<goat>
porcelain API
BuildAndWriteSVG()
.----------.
ASCII-art | | Markdown
----------------------->| +------------------------->
| |
'----------'
· · · · · · · · · · · · · · · · · · · · · · · ·
plumbing API
Canvas{}
NewCanvas() .-------------------. WriteSVGBody()
| | .-------.
ASCII-art .--. | data map[x,y]rune | | SVG{} | Markdown
---------->| +--->| text map[x,y]rune +-->| +------->
'--' | | | |
'-------------------' '-------'
</goat>
*/
package goat

Expand Down
32 changes: 15 additions & 17 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ usage () {
}

# Define colors for SVG ~foreground~ seen on Github front page.
svg_color_dark_scheme="#EDF"
svg_color_light_scheme="#014"
svg_color_dark_scheme="#EEF"
svg_color_light_scheme="#011"

TEST_ARGS=

Expand All @@ -36,32 +36,30 @@ done
#
# If the command fails due to expected changes in SVG output, rerun
# this script with "TEST_ARGS=-write" first on the command line.
# XX Better not to fail if the .txt source has changed.
# X Results are used as "golden" standard for GitHub-side regression tests --
# so arguments here must not conflict with those in "test.yml".
go test -run . -v \
-svg-color-dark-scheme ${svg_color_dark_scheme} \
-svg-color-light-scheme ${svg_color_light_scheme} \
${TEST_ARGS}

# build README.md
go run ./cmd/tmpl-expand Root="." <README.md.tmpl >README.md \
$(bash -c 'echo ./examples/{trees,overlaps,line-decorations,line-ends,dot-grids,large-nodes,small-grids,big-grids,complicated}.{txt,svg}')

go_to_markdown () {
BASENAME=$1
# input is a scan of the Go package in $CWD
go doc -all |
tee ${BASENAME}.go.doc.txt |
# XX relative path assumes $CWD is the project root dir
go run ./cmd/goatdoc -svgfilesprefix=${BASENAME} >${BASENAME}.md
}

# build API.md XX rename $(go list -f {{.Name}}).goatdoc.md ?
go_to_markdown API
# '-d' writes ./awkvars.out
cat *.go |
awk '
/[<]goat[>]/ {p = 1; next}
/[<][/]goat[>]/ {p = 0; next}
p > 0 {print}' |
tee goat.txt |
go run ./cmd/goat \
-svg-color-dark-scheme ${svg_color_dark_scheme} \
-svg-color-light-scheme ${svg_color_light_scheme} \
>goat.svg

if [ ! "$githubuser" ] # XX Is this the right test
then
# Render to HTML, for local inspection.
./markdown_to_html.sh README.md >README.html
./markdown_to_html.sh CHANGELOG.md >CHANGELOG.html
./markdown_to_html.sh API.md >API.html
fi

0 comments on commit 7d97b47

Please sign in to comment.