Generating HTML always felt awkward for me in many languages. From PHP where you sprinkle PHP between HTML or HTML between PHP, to frameworks in various languages where you populate variables and HTML is magically generated.
Somewhere in between there are template languages.
"Dominate" uses Python itself as the template language - this means there never is that "disconnect" where you have to validate your output, neither is it that disconnect coming from generators, nor do you have to learn and use a separate template language. Dominate can look like this:
And regarding the kwargs I had this feeling first of oh no "what is this!?"
I have been programming Python since 2000 and I never used kwargs before. I knew they were there somewhere but I never bothered with them.
I was at first a bit annoyed, but I really wanted to add my own tags and discovered it was actually quite nice if I could intercept arguments in my own tags. You don't have to use kwargs to add your own tags, but you can make the tags more powerful and composable that way.
But kwargs are really only worth it to me if there is a strong component of, "write once, use many times" to it.
You don't have to use kwargs to add your own tags to Dominate, you can just return tuples of building stone tags if you want to.
Generating HTML always felt awkward for me in many languages. From PHP where you sprinkle PHP between HTML or HTML between PHP, to frameworks in various languages where you populate variables and HTML is magically generated.
Somewhere in between there are template languages.
"Dominate" uses Python itself as the template language - this means there never is that "disconnect" where you have to validate your output, neither is it that disconnect coming from generators, nor do you have to learn and use a separate template language. Dominate can look like this:
If the Python is valid, so is the HTML.For me it hit a sweet spot. Dominate uses kwargs. I discovered this and (a?)bused kwargs when I wanted to add some tags of my own.