Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Unfortunate HTML output template placeholder #377

Closed
kvid opened this issue Jun 5, 2024 · 4 comments · Fixed by #380
Closed

[feature] Unfortunate HTML output template placeholder #377

kvid opened this issue Jun 5, 2024 · 4 comments · Fixed by #380

Comments

@kvid
Copy link
Collaborator

kvid commented Jun 5, 2024

HTML output templates with placeholders for generated text is a new feature introduced in v0.4. All placeholders are named <!-- %something% -->, except one placeholder called "sheetsize_default" only.

  1. Why is it called sheetsize_default and not sheetsize or template_sheetsize? The replacement text is fetched from metadata.template.sheetsize.
  2. Why is it not called <!-- %template_sheetsize% --> to be consistent with the other placeholders?
  3. I guess the quote characters was needed to include in the search term to avoid false hits, and therefore re-inserted around the fetched value to keep the correct HTML syntax. This seems like a hack for this placeholder only, and would not be needed if using my suggestion in point 2 above. Then <!-- %template_sheetsize% --> could be placed within the quote characters in the template, but the quote characters need not be replaced, and special treatment of this placeholder is no longer needed. The code would be cleaner, and a documentation description would be easier to understand because all placeholders are treated equally.

I suggest replacing https://github.com/wireviz/WireViz/blob/v0.4/src/wireviz/wv_html.py#L104-L106 with a simple entry

        "<!-- %template_sheetsize% -->": metadata.get("template", {}).get("sheetsize", ""),

inserted together with the others at https://github.com/wireviz/WireViz/blob/v0.4/src/wireviz/wv_html.py#L88
and then update the placeholder to <!-- %template_sheetsize% --> in templates/din-6771.html

@martinrieder
Copy link
Contributor

martinrieder commented Jun 6, 2024

I propose to use the default placeholder pattern that is used in Jinja. It would allow using this as a templating engine that is much more powerful than the simple replacements that we are currently using:
Jinja Template Designer Documentation

Note that Jinja could also be used to generate the GV files from templates, though I would consider that a major change that is to be discussed separately.

@kvid
Copy link
Collaborator Author

kvid commented Jun 7, 2024

@formatc1702 - Is my original issue here trivial, or might there be bad side-effects?

The suggestion by @martinrieder is also valid, but that must be handled later, in a separate issue.

@formatc1702
Copy link
Collaborator

formatc1702 commented Jun 11, 2024

TL;DR: it's debug legacy and can be changed.

The initial design of the technical drawing templates happened quite a while ago but I seem to recall the following reason:

Using sheetsize_default without any surrounding special characters allowed viewing the din-6771.html template file itself in the browser with no issues, while working on its layout and design. Placeholders using the HTML comment syntax <!-- --> simply show up as blanks, but using this syntax within the div's class attribute causes issues, thus sheetsize_default was chosen so it would resolve to a valid CSS class.

kvid added a commit that referenced this issue Jun 14, 2024
Fixes #377 (makes HTML output template placeholders more consistent)
kvid added a commit that referenced this issue Jun 17, 2024
Fixes #377 (makes HTML output template placeholders more consistent)
kvid added a commit that referenced this issue Jun 17, 2024
Fixes #377 (makes HTML output template placeholders more consistent)
formatc1702 pushed a commit that referenced this issue Jun 25, 2024
Fixes #377 (makes HTML output template placeholders more consistent)
@kvid
Copy link
Collaborator Author

kvid commented Jul 13, 2024

Closed after releasing v0.4.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants