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

Add formatting for HTML templates #985

Merged
merged 18 commits into from
Feb 8, 2024
Merged

Add formatting for HTML templates #985

merged 18 commits into from
Feb 8, 2024

Conversation

munnsmunns
Copy link
Collaborator

@munnsmunns munnsmunns commented Feb 6, 2024

Adds formatting for HTML templates via djHTML. Formatting is applied via a pre-commit, and can also be manually applied using make format-html.

We had to manually update an SVG element which was really long since the formatter allows a maximum length of 10,000 (see the header.html SVG):

import textwrap
long_attr = "..."
print("\n".join(textwrap.wrap(long_attr, 5000)))

HTML allows for line breaks within an attribute; the page appears to render fine on modern browsers.


When using pre-commit, if you try to commit and the validation fails, it will throw an exception and try to format the files properly, but not commit anything automatically. As an example, in this example, I had a badly formatted html template:

(venv) ► git commit -m "test"
DjHTML...................................................................Failed
- hook id: djhtml
- files were modified by this hook

reindented hawc/apps/animal/templates/animal/_animal_group_list_tbl.html
1 template has been reindented.

ruff.................................................(no files to check)Skipped
ruff-format..........................................(no files to check)Skipped

It fixes the issue, but leaves the changes unstaged, so I'll need to manually stage and then try to commit again.

@munnsmunns munnsmunns marked this pull request as ready for review February 6, 2024 13:45
Copy link
Owner

@shapiromatron shapiromatron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Would you mind adding an update to the development.md docs file to just give a quick description of how to install or run pre commit? I think you have to run an init command or something to get it linked with the git repo, is that right?

@shapiromatron
Copy link
Owner

@caseyhans @rabstejnek - please check this one out and give it a test drive, if we're all ok with how it works, I think we can merge!

Copy link
Owner

@shapiromatron shapiromatron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, excited to add this!

@shapiromatron shapiromatron merged commit 204c7a7 into main Feb 8, 2024
3 checks passed
@shapiromatron shapiromatron deleted the add-djhtml branch February 8, 2024 20:03
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 this pull request may close these issues.

4 participants