mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-13 02:24:22 +02:00
Lots of docs tweaks for openscad-docsgen v2
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
DISPMD=0
|
||||
GEN_ARGS=()
|
||||
FILES=()
|
||||
for opt in "$@" ; do
|
||||
case "$opt" in
|
||||
-f ) GEN_ARGS+=(-f) ;;
|
||||
-d ) DISPMD=1 ;;
|
||||
-* ) echo "Unknown option $opt" >&2; exit 1 ;;
|
||||
* ) FILES+=("$opt") ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if (( ${#FILES[@]} == 0 )); then
|
||||
FILES=(Shapes2d Shapes3d Transforms Distributors Mutators Attachments Paths FractalTree)
|
||||
fi
|
||||
|
||||
# Try to cd to the BOSL2.wiki directory if run from the BOSL2 root
|
||||
if [[ "$(basename "$PWD")" != "BOSL2.wiki" ]]; then
|
||||
if ! cd BOSL2.wiki; then
|
||||
echo "BOSL2.wiki directory not found, try running from the BOSL2 or BOSL2/BOSL2.wiki directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f tmp_*.scad
|
||||
for base in "${FILES[@]}"; do
|
||||
base="$(basename "$base" .md)"
|
||||
mkdir -p images/tutorials
|
||||
rm -f "images/tutorials/${base}"_*.png "images/tutorials/${base}"_*.gif
|
||||
echo "${base}.md"
|
||||
../scripts/tutorial_gen.py "../tutorials/${base}.md" -o "Tutorial-${base}.md" "${GEN_ARGS[@]}" -I images/tutorials/ || exit 1
|
||||
if (( DISPMD )); then
|
||||
open -a Typora "Tutorial-${base}.md"
|
||||
fi
|
||||
done
|
||||
|
||||
|
@@ -1,133 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
import os.path
|
||||
import argparse
|
||||
|
||||
from openscad_docsgen.imagemanager import ImageManager
|
||||
|
||||
|
||||
imgmgr = ImageManager()
|
||||
|
||||
|
||||
def img_started(req):
|
||||
print(" {}... ".format(os.path.basename(req.image_file)), end='')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def img_completed(req):
|
||||
if req.success:
|
||||
if req.status == "SKIP":
|
||||
print()
|
||||
else:
|
||||
print(req.status)
|
||||
sys.stdout.flush()
|
||||
return
|
||||
out = "\n\n"
|
||||
for line in req.echos:
|
||||
out += line + "\n"
|
||||
for line in req.warnings:
|
||||
out += line + "\n"
|
||||
for line in req.errors:
|
||||
out += line + "\n"
|
||||
out += "//////////////////////////////////////////////////////////////////////\n"
|
||||
out += "// LibFile: {} Line: {} Image: {}\n".format(
|
||||
req.src_file, req.src_line, os.path.basename(req.image_file)
|
||||
)
|
||||
out += "//////////////////////////////////////////////////////////////////////\n"
|
||||
for line in req.script_lines:
|
||||
out += line + "\n"
|
||||
out += "//////////////////////////////////////////////////////////////////////\n"
|
||||
print(out, file=sys.stderr)
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
def processFile(infile, outfile=None, imgroot=""):
|
||||
if imgroot and not imgroot.endswith('/'):
|
||||
imgroot += "/"
|
||||
fileroot = os.path.splitext(os.path.basename(infile))[0]
|
||||
|
||||
outdata = []
|
||||
with open(infile, "r") as f:
|
||||
script = ["include <BOSL2/std.scad>"]
|
||||
extyp = ""
|
||||
in_script = False
|
||||
imgnum = 0
|
||||
show_script = True
|
||||
linenum = -1
|
||||
for line in f.readlines():
|
||||
linenum += 1
|
||||
line = line.rstrip("\n")
|
||||
if line.startswith("```openscad"):
|
||||
in_script = True;
|
||||
if "-" in line:
|
||||
extyp = line.split("-")[1]
|
||||
else:
|
||||
extyp = ""
|
||||
show_script = "ImgOnly" not in extyp
|
||||
script = ["include <BOSL2/std.scad>"]
|
||||
imgnum = imgnum + 1
|
||||
elif in_script:
|
||||
if line == "```":
|
||||
in_script = False
|
||||
fext = "png"
|
||||
if any(x in extyp for x in ("Anim", "Spin")):
|
||||
fext = "gif"
|
||||
imgfile = os.path.join(imgroot, "{}_{}.{}".format(fileroot, imgnum, fext))
|
||||
imgmgr.new_request(
|
||||
fileroot+".md", linenum,
|
||||
imgfile, script, extyp,
|
||||
starting_cb=img_started,
|
||||
completion_cb=img_completed
|
||||
)
|
||||
if show_script:
|
||||
outdata.append("```openscad")
|
||||
outdata.extend(script)
|
||||
outdata.append("```")
|
||||
outdata.append("".format(imgnum, imgfile))
|
||||
show_script = True
|
||||
extyp = ""
|
||||
else:
|
||||
script.append(line)
|
||||
else:
|
||||
outdata.append(line)
|
||||
|
||||
if outfile == None:
|
||||
f = sys.stdout
|
||||
else:
|
||||
f = open(outfile, "w")
|
||||
|
||||
for line in outdata:
|
||||
print(line, file=f)
|
||||
|
||||
if outfile:
|
||||
f.close()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(prog='docs_gen')
|
||||
parser.add_argument('-I', '--imgroot', default="",
|
||||
help='The directory to put generated images in.')
|
||||
parser.add_argument('-o', '--outfile',
|
||||
help='Output file, if different from infile.')
|
||||
parser.add_argument('infile', help='Input filename.')
|
||||
args = parser.parse_args()
|
||||
|
||||
processFile(
|
||||
args.infile,
|
||||
outfile=args.outfile,
|
||||
imgroot=args.imgroot
|
||||
)
|
||||
imgmgr.process_requests()
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
# vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
Reference in New Issue
Block a user