Skip to content

Commit

Permalink
Build output string in one big expression
Browse files Browse the repository at this point in the history
Build output string in component_table_entry() as the similar strings
in generate_bom(). Repeating a couple of minor if-expressions is small
cost to obtain a more compact and readable main expression.
  • Loading branch information
kvid committed Jan 3, 2021
1 parent d6d0d2a commit d15eeb1
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/wireviz/wv_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,18 @@ def component_table_entry(
mpn: Optional[str] = None,
) -> str:
"""Return a diagram node table row string with an additional component."""
output = f'{qty}'
if unit:
output += f' {unit}'
output += f' x {type}'
# print an extra line with part and manufacturer information if provided
manufacturer_str = manufacturer_info_field(manufacturer, mpn)
if pn or manufacturer_str:
output += '<br/>'
if pn:
output += f'P/N: {pn}'
if manufacturer_str:
output += ', '
if manufacturer_str:
output += manufacturer_str
output = html_line_breaks(output)
output = (f'{qty}'
+ (f' {unit}' if unit else '')
+ f' x {type}'
+ ('<br/>' if pn or manufacturer_str else '')
+ (f'P/N: {pn}' if pn else '')
+ (', ' if pn and manufacturer_str else '')
+ (manufacturer_str or ''))
# format the above output as left aligned text in a single visible cell
# indent is set to two to match the indent in the generated html table
return f'''<table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>
<td align="left" balign="left">{output}</td>
<td align="left" balign="left">{html_line_breaks(output)}</td>
</tr></table>'''

def manufacturer_info_field(manufacturer: Optional[str], mpn: Optional[str]) -> Optional[str]:
Expand Down

0 comments on commit d15eeb1

Please sign in to comment.