Created
January 15, 2019 14:15
-
-
Save raghavkarol/c779009fa93ae8d130e9d97682183ab8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
set -u | |
# ---------------------------------------------------------- | |
# Helpers | |
function html() { | |
contents="none" | |
case $1 in | |
ok) | |
contents="<div class='content'><img src=$2></div>" | |
;; | |
error) | |
shift | |
contents="<div class='error'>$*</div>" | |
;; | |
esac | |
cat <<EOF | |
<html> | |
<style> | |
* { | |
font-family: courier; | |
} | |
body { | |
margin: 0; | |
} | |
.error { | |
font-size: 32px; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
width: 100vw; | |
height: 100vh; | |
background: pink | |
} | |
</style> | |
<body> | |
${contents} | |
</body> | |
</html> | |
EOF | |
} | |
# ---------------------------------------------------------- | |
# Main | |
readonly dot_file=$1 | |
readonly svg_file=${dot_file/%.dot/.svg} | |
readonly out=$2 | |
readonly error=`mktemp` | |
rm -f $out | |
trap "{ rm -f $error; }" EXIT | |
exec > $out | |
exec 2> $error | |
dot -Nfontname=courier -Efontname=courier -Tsvg -o $svg_file $dot_file | |
if [[ $? != 0 || -s $error ]] | |
then | |
html error $(cat $error) | |
exit 1 | |
fi | |
echo $svg_file | |
html ok $svg_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment