Files
ergogen-footprint-converter/src/ergogen_footprint_converter/converter.py
2024-04-27 22:10:24 +02:00

32 lines
926 B
Python

from kiutils.footprint import Footprint
class Converter:
footprint: Footprint
template: str
def __init__(self, footprint: Footprint):
self.footprint = footprint
self.template = open("res/template.js").read()
def convert(self) -> str:
main = self.footprint.to_sexpr()
# replace new footprint name with module to be consistent
main = main.replace("footprint", "module")
return self.replace_template(self.template, "", main, "", "")
@staticmethod
def replace_template(template: str, params: str, main: str, captions: str, pins: str) -> str:
replacements = {
"{% params %}": params,
"{% main %}": main,
"{% captions %}": captions,
"{% pins %}": pins
}
for key in replacements:
template = template.replace(key, replacements[key])
return template