Skip to content

Commit

Permalink
Rename "sheetsize_default" to <!-- %template_sheetsize% --> (#380)
Browse files Browse the repository at this point in the history
Fixes #377 (makes HTML output template placeholders more consistent)
  • Loading branch information
kvid committed Jun 17, 2024
1 parent 0aca93e commit c8307cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/wireviz/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Note that there must be one single space between `--` and `%` at both ends.
| `<!-- %{item}% -->` | String or numeric value of `metadata.{item}` |
| `<!-- %{item}_{i}% -->` | Category number `{i}` within dict value of `metadata.{item}` |
| `<!-- %{item}_{i}_{key}% -->` | Value of `metadata.{item}.{category}.{key}` |
| `<!-- %template_sheetsize% -->` | Value of `metadata.template.sheetsize` |

Note that `{item}`, `{category}` and `{key}` in the description above can be
any valid YAML key, and `{i}` is an integer representing the 1-based index of
Expand Down
2 changes: 1 addition & 1 deletion src/wireviz/templates/din-6771.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions src/wireviz/wv_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def generate_html_output(
metadata: Metadata,
options: Options,
):

# load HTML template
templatename = metadata.get("template", {}).get("name")
if templatename:
Expand Down Expand Up @@ -87,6 +86,9 @@ def svgdata() -> str:
"<!-- %bom_reversed% -->": bom_html_reversed,
"<!-- %sheet_current% -->": "1", # TODO: handle multi-page documents
"<!-- %sheet_total% -->": "1", # TODO: handle multi-page documents
"<!-- %template_sheetsize% -->": metadata.get("template", {}).get(
"sheetsize", ""
),
}

def replacement_if_used(key: str, func: Callable[[], str]) -> None:
Expand All @@ -112,11 +114,8 @@ def replacement_if_used(key: str, func: Callable[[], str]) -> None:
replacements[f"<!-- %{item}_{index+1}_{entry_key}% -->"] = (
html_line_breaks(str(entry_value))
)

replacements['"sheetsize_default"'] = '"{}"'.format(
metadata.get("template", {}).get("sheetsize", "")
)
# include quotes so no replacement happens within <style> definition
elif isinstance(entry, (str, int, float)):
pass # TODO?: replacements[f"<!-- %{item}_{category}% -->"] = html_line_breaks(str(entry))

# perform replacements
# regex replacement adapted from:
Expand Down

0 comments on commit c8307cc

Please sign in to comment.