Skip to content

Commit

Permalink
feat(datasheet): use mustache for project_preview
Browse files Browse the repository at this point in the history
  • Loading branch information
htfab committed May 6, 2024
1 parent 643ed6e commit 508782b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
20 changes: 0 additions & 20 deletions docs/project_preview.md

This file was deleted.

15 changes: 15 additions & 0 deletions docs/project_preview.md.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# {{title}}

* Author: {{author}}
* Description: {{&description}}
* Language: {{language}}

{{&info}}

## Pinout

| # | Input | Output | Bidirectional |
|---------------|----------|----------|----------------|
{{#pins}}
| {{pin_index}} | {{&ui}} | {{&uo}} | {{&uio}} |
{{/pins}}
21 changes: 16 additions & 5 deletions project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import typing

import cairosvg # type: ignore
import chevron
import gdstk # type: ignore
import yaml
from git.repo import Repo
Expand Down Expand Up @@ -526,15 +527,25 @@ def check_docs(self):
# 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:
Expand All @@ -545,7 +556,7 @@ def create_pdf(self):

# 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:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 508782b

Please sign in to comment.