From 9e278bdd500123e170af768395199e19b80db04d Mon Sep 17 00:00:00 2001 From: htfab Date: Mon, 6 May 2024 14:03:38 +0200 Subject: [PATCH] feat(datasheet): use mustache for doc_template --- docs/doc_header.md | 19 ------------------- docs/doc_header.md.mustache | 19 +++++++++++++++++++ docs/doc_template.md | 24 ------------------------ docs/doc_template.md.mustache | 19 +++++++++++++++++++ documentation.py | 35 ++++++++++++++++++++++++++++------- 5 files changed, 66 insertions(+), 50 deletions(-) delete mode 100644 docs/doc_header.md create mode 100644 docs/doc_header.md.mustache delete mode 100644 docs/doc_template.md create mode 100644 docs/doc_template.md.mustache diff --git a/docs/doc_header.md b/docs/doc_header.md deleted file mode 100644 index 4e2e888..0000000 --- a/docs/doc_header.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: | - ![Tiny Tapeout Logo](pics/ttlogo.png){{width=15cm}} - {name} Datasheet -subtitle: Project Repository [{repo}]({repo}) -documentclass: scrartcl -date: \today{{}} -geometry: "left=2cm,right=2cm,top=2cm,bottom=2.5cm" -fontsize: 14pt -mainfont: Latin Modern Sans -header-includes: -- \hypersetup{{colorlinks=true, - urlcolor=blue, - linkcolor=[rgb]{{0,0,0.5}}, - allbordercolors={{0 0 0}}, - pdfborderstyle={{/S/U/W 1}}}} ---- - -\pagebreak diff --git a/docs/doc_header.md.mustache b/docs/doc_header.md.mustache new file mode 100644 index 0000000..687c31d --- /dev/null +++ b/docs/doc_header.md.mustache @@ -0,0 +1,19 @@ +--- +title: | + ![Tiny Tapeout Logo](pics/ttlogo.png){width=15cm} + {{name}} Datasheet +subtitle: Project Repository [{{repo}}]({{repo}}) +documentclass: scrartcl +date: \today{} +geometry: "left=2cm,right=2cm,top=2cm,bottom=2.5cm" +fontsize: 14pt +mainfont: Latin Modern Sans +header-includes: +- \hypersetup{colorlinks=true, + urlcolor=blue, + linkcolor=[rgb]{0,0,0.5}, + allbordercolors={0 0 0}, + pdfborderstyle={/S/U/W 1} } +--- + +\pagebreak diff --git a/docs/doc_template.md b/docs/doc_template.md deleted file mode 100644 index c3270d7..0000000 --- a/docs/doc_template.md +++ /dev/null @@ -1,24 +0,0 @@ -## {title} [{mux_address}] - -* Author: {author} -* Description: {description} -* [GitHub repository](__git_url__) -* {project_type} project -* Mux address: {mux_address} -* [Extra docs](__doc_link__) -* Clock: {clock_hz} Hz - -{user_docs} - -### Pinout - -| # | Input | Output | Bidirectional | -| - | -------------- | -------------- | --------------- | -| 0 | {pinout.ui[0]} | {pinout.uo[0]} | {pinout.uio[0]} | -| 1 | {pinout.ui[1]} | {pinout.uo[1]} | {pinout.uio[1]} | -| 2 | {pinout.ui[2]} | {pinout.uo[2]} | {pinout.uio[2]} | -| 3 | {pinout.ui[3]} | {pinout.uo[3]} | {pinout.uio[3]} | -| 4 | {pinout.ui[4]} | {pinout.uo[4]} | {pinout.uio[4]} | -| 5 | {pinout.ui[5]} | {pinout.uo[5]} | {pinout.uio[5]} | -| 6 | {pinout.ui[6]} | {pinout.uo[6]} | {pinout.uio[6]} | -| 7 | {pinout.ui[7]} | {pinout.uo[7]} | {pinout.uio[7]} | diff --git a/docs/doc_template.md.mustache b/docs/doc_template.md.mustache new file mode 100644 index 0000000..adaf2c6 --- /dev/null +++ b/docs/doc_template.md.mustache @@ -0,0 +1,19 @@ +## {{title}} [{{mux_address}}] + +* Author: {{author}} +* Description: {{&description}} +* [GitHub repository]({{git_url}}) +* {{project_type}} project +* Mux address: {{mux_address}} +* [Extra docs]({{doc_link}}) +* Clock: {{clock_hz}} Hz + +{{&user_docs}} + +### Pinout + +| # | Input | Output | Bidirectional | +| ------------- | -------- | -------- | --------------- | +{{#pins}} +| {{pin_index}} | {{&ui}} | {{&uo}} | {{&uio[0]}} | +{{/pins}} diff --git a/documentation.py b/documentation.py index 5b3814d..7514299 100644 --- a/documentation.py +++ b/documentation.py @@ -4,6 +4,7 @@ import shutil import subprocess from typing import List, Optional +import chevron import frontmatter # type: ignore import git # type: ignore @@ -60,9 +61,9 @@ class Docs: return doc.content + "\n" def write_datasheet(self, markdown_file: str, pdf_file: Optional[str] = None): - doc_header = self.load_doc_template("doc_header.md") + doc_header = self.load_doc_template("doc_header.md.mustache") doc_chip_map = self.load_doc_template("../../docs/chip_map.md") - doc_template = self.load_doc_template("doc_template.md") + doc_template = self.load_doc_template("doc_template.md.mustache") doc_pinout = self.load_doc_template("PINOUT.md") doc_info = self.load_doc_template("../../tt-multiplexer/docs/INFO.md") doc_credits = self.load_doc_template("CREDITS.md") @@ -70,7 +71,13 @@ class Docs: with open(markdown_file, "w") as fh: repo = git.Repo(".") fh.write( - doc_header.format(name=self.config["name"], repo=get_first_remote(repo)) + chevron.render( + doc_header, + { + "name": self.config["name"], + "repo": get_first_remote(repo), + }, + ) ) fh.write(doc_chip_map) fh.write("# Projects\n") @@ -79,10 +86,24 @@ class Docs: for project in self.projects: yaml_data = project.get_project_docs_dict() - yaml_data["user_docs"] = rewrite_image_paths( - yaml_data["user_docs"], f"projects/{project.get_macro_name()}/docs" + yaml_data.update( + { + "user_docs": rewrite_image_paths( + yaml_data["user_docs"], + f"projects/{project.get_macro_name()}/docs", + ), + "mux_address": project.mux_address, + "pins": [ + { + "pin_index": str(i), + "ui": project.info.pinout.ui[i], + "uo": project.info.pinout.uo[i], + "uio": project.info.pinout.uio[i], + } + for i in range(8) + ], + } ) - yaml_data["mux_address"] = project.mux_address logging.info(f"building datasheet for {project}") @@ -103,7 +124,7 @@ class Docs: # now build the doc & print it try: - doc = doc_template.format(**yaml_data) + doc = chevron.render(doc_template, yaml_data) fh.write(doc) fh.write("\n\\clearpage\n") except IndexError: