#!/usr/bin/env python3
import os
import re
class PageMethods:
def __init__(self, path):
self.path = path
def resource(self, resource):
return os.path.relpath(resource, self.path)
def header(self, title, menu_hl=None, nodiv=False, black_bg=False):
bodystyle = " style=\"background: #000; color: #fff;\"" if black_bg else ""
r = """
""" + title + """ | M-Labs
"""
def item(target, title, highlight):
nonlocal r
if menu_hl is not None and menu_hl == highlight:
r += "
↘ " + title + "\n"
else:
r += "
↘ " + title + "\n"
def subitem(target, title):
nonlocal r
r += "
" + title + "\n"
item("artiq/index.html", "ARTIQ", "artiq")
subitem("artiq/index.html", "Overview")
subitem("artiq/sinara.html", "Sinara hardware")
subitem("artiq/resources.html", "Resources")
item("migen/index.html", "Migen", "migen")
item("smoltcp.html", "smoltcp", "smoltcp")
item("solvespace/index.html", "SolveSpace", "solvespace")
item("ionpak.html", "ionpak", "ionpak")
item("about.html", "About", "about")
subitem("about.html", "Company")
subitem("office.html", "Office")
r += """
"""
if not nodiv:
r += ""
return r
def footer(self, nodiv=False):
d = "" if nodiv else "
\n"
return d + """
"""
def get_globals(self):
return {
"header": self.header,
"footer": self.footer,
"resource": self.resource
}
def process(path, name_in, name_out):
fullname = os.path.join(path, name_in)
print("processing", fullname)
with open(fullname, "r") as infile:
indata = infile.read()
pm = PageMethods(path)
outdata = ""
# FIXME: this is just a buggy quick hack
splits = re.split("({{{[^}]+}}})", indata)
for split in splits:
if split and split[:3] == "{{{":
outdata += eval(split[3:-3], pm.get_globals())
else:
outdata += split
with open(os.path.join(path, name_out), "w") as outfile:
outfile.write(outdata)
def main():
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith(".page"):
process(root, file, file[:-5] + ".html")
if __name__ == "__main__":
main()