feat(datasheet): use mustache for project_preview

This commit is contained in:
htfab
2024-05-06 23:21:17 +03:00
committed by Uri Shaked
parent d490f49edb
commit b38aad5bff
4 changed files with 32 additions and 25 deletions
-20
View File
@@ -1,20 +0,0 @@
# {title}
* Author: {author}
* Description: {description}
* Language: {language}
{info}
## Pinout
| # | Input | Output | Bidirectional |
|---|--------------|--------------|--------------------|
| 0 | {ui[0]} | {uo[0]} | {uio[0]} |
| 1 | {ui[1]} | {uo[1]} | {uio[1]} |
| 2 | {ui[2]} | {uo[2]} | {uio[2]} |
| 3 | {ui[3]} | {uo[3]} | {uio[3]} |
| 4 | {ui[4]} | {uo[4]} | {uio[4]} |
| 5 | {ui[5]} | {uo[5]} | {uio[5]} |
| 6 | {ui[6]} | {uo[6]} | {uio[6]} |
| 7 | {ui[7]} | {uo[7]} | {uio[7]} |
+15
View File
@@ -0,0 +1,15 @@
# {{title}}
* Author: {{author}}
* Description: {{&description}}
* Language: {{language}}
{{&info}}
## Pinout
| # | Input | Output | Bidirectional |
|---------------|----------|----------|----------------|
{{#pins}}
| {{pin_index}} | {{&ui}} | {{&uo}} | {{&uio}} |
{{/pins}}
+16 -5
View File
@@ -10,6 +10,7 @@ import subprocess
import typing
import cairosvg # type: ignore
import chevron
import gdstk # type: ignore
import yaml
from git.repo import Repo
@@ -526,15 +527,25 @@ class Project:
# use pandoc to create a single page PDF preview
def create_pdf(self):
template_args = copy.deepcopy(self.info.__dict__)
template_args["ui"] = self.info.pinout.ui
template_args["uo"] = self.info.pinout.uo
template_args["uio"] = self.info.pinout.uio
template_args.update(
{
"pins": [
{
"pin_index": str(i),
"ui": self.info.pinout.ui[i],
"uo": self.info.pinout.uo[i],
"uio": self.info.pinout.uio[i],
}
for i in range(8)
],
}
)
logging.info("Creating PDF")
script_dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(script_dir, "docs/project_header.md")) as fh:
doc_header = fh.read()
with open(os.path.join(script_dir, "docs/project_preview.md")) as fh:
with open(os.path.join(script_dir, "docs/project_preview.md.mustache")) as fh:
doc_template = fh.read()
info_md = os.path.join(self.local_dir, "docs/info.md")
with open(info_md) as fh:
@@ -545,7 +556,7 @@ class Project:
# now build the doc & print it
try:
doc = doc_template.format(**template_args)
doc = chevron.render(doc_template, template_args)
fh.write(doc)
fh.write("\n\\pagebreak\n")
except IndexError:
+1
View File
@@ -4,6 +4,7 @@ CairoSVG==2.7.0
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.1.0
chevron==0.14.0
click==8.1.3
cssselect2==0.7.0
defusedxml==0.7.1