Change Metadata to a dict as requested by the owner
And a few other changes requested in the same review. Co-authored-by: Daniel Rojas <github@danielrojas.net>
This commit is contained in:
parent
d5c69116ea
commit
15d7374399
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from typing import Optional, List, Tuple, Union
|
from typing import Dict, List, Optional, Tuple, Union
|
||||||
from dataclasses import dataclass, field, InitVar
|
from dataclasses import dataclass, field, InitVar
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -31,12 +31,10 @@ Wire = Union[int, PlainText] # Wire number or Literal['s'] for shield
|
|||||||
NoneOrMorePinIndices = Union[PinIndex, Tuple[PinIndex, ...], None] # None, one, or a tuple of zero-based pin indices
|
NoneOrMorePinIndices = Union[PinIndex, Tuple[PinIndex, ...], None] # None, one, or a tuple of zero-based pin indices
|
||||||
OneOrMoreWires = Union[Wire, Tuple[Wire, ...]] # One or a tuple of wires
|
OneOrMoreWires = Union[Wire, Tuple[Wire, ...]] # One or a tuple of wires
|
||||||
|
|
||||||
|
# Metadata can contain whatever is needed by the HTML generation/template.
|
||||||
@dataclass
|
MetadataKeys = PlainText # Literal['title', 'description', 'notes', ...]
|
||||||
class Metadata:
|
class Metadata(dict):
|
||||||
title: PlainText
|
pass
|
||||||
description: Optional[MultilineHypertext] = None
|
|
||||||
notes: Optional[MultilineHypertext] = None
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@ -35,11 +35,12 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
|
|||||||
|
|
||||||
yaml_data = yaml.safe_load(yaml_input)
|
yaml_data = yaml.safe_load(yaml_input)
|
||||||
|
|
||||||
# Assign default metadata.title here to avoid needing file_out in Metadata.__post_init__().
|
|
||||||
harness = Harness(
|
harness = Harness(
|
||||||
Metadata(**{'title': Path(file_out).stem, **yaml_data.get('metadata', {})}),
|
metadata = Metadata(**yaml_data.get('metadata', {})),
|
||||||
Options(**yaml_data.get('options', {})),
|
options = Options(**yaml_data.get('options', {})),
|
||||||
)
|
)
|
||||||
|
if 'title' not in harness.metadata:
|
||||||
|
harness.metadata['title'] = Path(file_out).stem
|
||||||
|
|
||||||
# add items
|
# add items
|
||||||
sections = ['connectors', 'cables', 'connections']
|
sections = ['connectors', 'cables', 'connections']
|
||||||
|
|||||||
@ -15,13 +15,14 @@ def generate_html_output(filename: Union[str, Path], bom_list: List[List[str]],
|
|||||||
file.write('<html lang="en"><head>\n')
|
file.write('<html lang="en"><head>\n')
|
||||||
file.write(' <meta charset="UTF-8">\n')
|
file.write(' <meta charset="UTF-8">\n')
|
||||||
file.write(f' <meta name="generator" content="{APP_NAME} {__version__} - {APP_URL}">\n')
|
file.write(f' <meta name="generator" content="{APP_NAME} {__version__} - {APP_URL}">\n')
|
||||||
file.write(f' <title>{metadata.title}</title>\n')
|
file.write(f' <title>{metadata["title"]}</title>\n')
|
||||||
file.write(f'</head><body style="font-family:{options.fontname};background-color:'
|
file.write(f'</head><body style="font-family:{options.fontname};background-color:'
|
||||||
f'{wv_colors.translate_color(options.bgcolor, "HEX")}">\n')
|
f'{wv_colors.translate_color(options.bgcolor, "HEX")}">\n')
|
||||||
|
|
||||||
file.write(f'<h1>{metadata.title}</h1>\n')
|
file.write(f'<h1>{metadata["title"]}</h1>\n')
|
||||||
if metadata.description:
|
description = metadata.get('description')
|
||||||
file.write(f'<p>{metadata.description}</p>\n')
|
if description:
|
||||||
|
file.write(f'<p>{description}</p>\n')
|
||||||
file.write('<h2>Diagram</h2>\n')
|
file.write('<h2>Diagram</h2>\n')
|
||||||
with open_file_read(f'{filename}.svg') as svg:
|
with open_file_read(f'{filename}.svg') as svg:
|
||||||
file.write(re.sub(
|
file.write(re.sub(
|
||||||
@ -47,7 +48,8 @@ def generate_html_output(filename: Union[str, Path], bom_list: List[List[str]],
|
|||||||
file.write(' </tr>\n')
|
file.write(' </tr>\n')
|
||||||
file.write('</table>\n')
|
file.write('</table>\n')
|
||||||
|
|
||||||
if metadata.notes:
|
notes = metadata.get('notes')
|
||||||
file.write(f'<h2>Notes</h2>\n<p>{metadata.notes}</p>\n')
|
if notes:
|
||||||
|
file.write(f'<h2>Notes</h2>\n<p>{notes}</p>\n')
|
||||||
|
|
||||||
file.write('</body></html>\n')
|
file.write('</body></html>\n')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user