Closed rmorshea closed 1 year ago
htmldom.py
includes some editorializing. Specifically, it disallows attribute name interpolation. My reasoning here is that if you truly need to interpolate the name of an HTML attribute, you could just as easily form the name in a dictionary, and then use attribute expansion:
attrs = {f"my{attr}": True}
html"<a {attrs} />"
At present, I'm unsure if JSX has come to the same decision.
Thanks for the feedback. I'll make those changes and see if I can break down the program in a reasonable way for the tutorial.
I've managed to simplify htmldom.py
even more. I realized that I could store all the expression values in a list and interleave them with the HTML as it was parsed. This removes the need for any hackery with string.Template
and will make things much easier to explain in the tutorial (which I started getting to the meat of).
Definitely agree. As you said, it would be better to introduce tag string examples first and then present a comparison with Jinja. Also, the intro "Applications in templating" section does not cleanly lead into the meat of the tutorial in the following "Writing an html tag" section. I'll work on follow-up edits. Thankfully I think nearly all the content is there, so making these improvements should be much quicker.
This includes an intro for html tags (up until I got distracted making
htmldom.py
).htmldom.py
implements a more complete version of thehtml
tag we discussed in person - it supports attribute expansion along with interpolation of tags and attributes and does so while still relying onhtml.parser
. For example, the following:Produces:
My hope was that if I could implement this more fully featured
html
tag usinghtml.parser
it would remain approachable while also being more compelling. However, having implemented it now, I'm unsure of how it will pan out given the added complexity.