mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-06 12:19:47 +00:00
Added Figure tag to LeafNodes
This commit is contained in:
parent
f51bc36ab9
commit
feb58dc20c
1 changed files with 45 additions and 1 deletions
|
@ -95,9 +95,12 @@ class ImageProcessing(object):
|
||||||
def process_examples(self, imgroot, force=False):
|
def process_examples(self, imgroot, force=False):
|
||||||
self.imgroot = imgroot
|
self.imgroot = imgroot
|
||||||
self.force = force
|
self.force = force
|
||||||
|
self.hashes = {}
|
||||||
with dbm.gnu.open("examples_hashes.gdbm", "c") as db:
|
with dbm.gnu.open("examples_hashes.gdbm", "c") as db:
|
||||||
for libfile, imgfile, code, extype in self.examples:
|
for libfile, imgfile, code, extype in self.examples:
|
||||||
self.gen_example_image(db, libfile, imgfile, code, extype)
|
self.gen_example_image(db, libfile, imgfile, code, extype)
|
||||||
|
for key, hash in self.hashes.items():
|
||||||
|
db[key] = hash
|
||||||
|
|
||||||
def gen_example_image(self, db, libfile, imgfile, code, extype):
|
def gen_example_image(self, db, libfile, imgfile, code, extype):
|
||||||
OPENSCAD = "/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD"
|
OPENSCAD = "/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD"
|
||||||
|
@ -282,7 +285,7 @@ class ImageProcessing(object):
|
||||||
print(" UPDATED IMAGE\n")
|
print(" UPDATED IMAGE\n")
|
||||||
os.unlink(targimgfile)
|
os.unlink(targimgfile)
|
||||||
os.rename(newimgfile, targimgfile)
|
os.rename(newimgfile, targimgfile)
|
||||||
db[key] = hash
|
self.hashes[key] = hash
|
||||||
|
|
||||||
|
|
||||||
imgprc = ImageProcessing()
|
imgprc = ImageProcessing()
|
||||||
|
@ -298,6 +301,7 @@ class LeafNode(object):
|
||||||
self.arguments = []
|
self.arguments = []
|
||||||
self.anchors = []
|
self.anchors = []
|
||||||
self.side_effects = []
|
self.side_effects = []
|
||||||
|
self.figures = []
|
||||||
self.examples = []
|
self.examples = []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -312,12 +316,16 @@ class LeafNode(object):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def add_figure(self, title, code, figtype):
|
||||||
|
self.figures.append((title, code, figtype))
|
||||||
|
|
||||||
def add_example(self, title, code, extype):
|
def add_example(self, title, code, extype):
|
||||||
self.examples.append((title, code, extype))
|
self.examples.append((title, code, extype))
|
||||||
|
|
||||||
def parse_lines(self, lines, prefix):
|
def parse_lines(self, lines, prefix):
|
||||||
blankcnt = 0
|
blankcnt = 0
|
||||||
expat = re.compile(r"^(Examples?)(\(([^\)]*)\))?: *(.*)$")
|
expat = re.compile(r"^(Examples?)(\(([^\)]*)\))?: *(.*)$")
|
||||||
|
figpat = re.compile(r"^(Figures?)(\(([^\)]*)\))?: *(.*)$")
|
||||||
while lines:
|
while lines:
|
||||||
if prefix and not lines[0].startswith(prefix.strip()):
|
if prefix and not lines[0].startswith(prefix.strip()):
|
||||||
break
|
break
|
||||||
|
@ -398,6 +406,19 @@ class LeafNode(object):
|
||||||
else:
|
else:
|
||||||
for line in block:
|
for line in block:
|
||||||
self.add_example(title="", code=[line], extype=extype)
|
self.add_example(title="", code=[line], extype=extype)
|
||||||
|
m = figpat.match(line)
|
||||||
|
if m: # Figure(TYPE):
|
||||||
|
plural = m.group(1) == "Figures"
|
||||||
|
figtype = m.group(3)
|
||||||
|
title = m.group(4)
|
||||||
|
lines, block = get_comment_block(lines, prefix)
|
||||||
|
if not figtype:
|
||||||
|
figtype = "3D"
|
||||||
|
if not plural:
|
||||||
|
self.add_figure(title, block, figtype)
|
||||||
|
else:
|
||||||
|
for line in block:
|
||||||
|
self.add_figure("", [line], figtype)
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def gen_md(self, fileroot, imgroot):
|
def gen_md(self, fileroot, imgroot):
|
||||||
|
@ -421,6 +442,29 @@ class LeafNode(object):
|
||||||
for line in self.description:
|
for line in self.description:
|
||||||
out.append(mkdn_esc(line))
|
out.append(mkdn_esc(line))
|
||||||
out.append("")
|
out.append("")
|
||||||
|
fignum = 0
|
||||||
|
for title, excode, extype in self.figures:
|
||||||
|
fignum += 1
|
||||||
|
extitle = "**Figure {0}**:".format(fignum)
|
||||||
|
if title:
|
||||||
|
extitle += " " + mkdn_esc(title)
|
||||||
|
san_name = re.sub(r"[^A-Za-z0-9_]", "", self.name)
|
||||||
|
imgfile = "{}_{}.{}".format(
|
||||||
|
san_name,
|
||||||
|
("fig%d" % fignum),
|
||||||
|
"gif" if "Spin" in extype else "png"
|
||||||
|
)
|
||||||
|
imgprc.add_image(fileroot+".scad", imgfile, excode, extype)
|
||||||
|
out.append(extitle)
|
||||||
|
out.append(
|
||||||
|
"![{0} Figure {1}]({2}{3})".format(
|
||||||
|
mkdn_esc(self.name),
|
||||||
|
fignum,
|
||||||
|
imgroot,
|
||||||
|
imgfile
|
||||||
|
)
|
||||||
|
)
|
||||||
|
out.append("")
|
||||||
if self.arguments:
|
if self.arguments:
|
||||||
out.append("Argument | What it does")
|
out.append("Argument | What it does")
|
||||||
out.append("--------------- | ------------------------------")
|
out.append("--------------- | ------------------------------")
|
||||||
|
|
Loading…
Reference in a new issue