Closed nihlaeth closed 7 years ago
This would make code like this possible:
field = div(class_="default")(b("Hello"), i("there"))
if i_like_this_user:
field.class_ = "beautiful"
for child in field:
child.attributes["class"] = "green"
It's a bit of a silly example, but I hope you get my drift.
The idea about conversion needs a bit of work, because this way you could still define both class
and `class`. Maybe there should be a check at render time that throws an exception if an attribute is defined twice.
Hi @nihlaeth . Sorry for the delayed reply.
- do _ conversion in attribute names before storing in
Tag.attributes
so you don't accidentally define things like data-target, id and class twice when working there directly
My preference would be documenting this behavior and leave as it is. I guess it is easier to understand the current behavior.
- make attributes accessible as properties (again doing the _ conversion thing)
I guess it is better to have only one way for accessing properties. They are available at Tag.attributes
. Zen of Python :)
- expose children via sequence methods on non-self-closing tags
Same as 2. Children are available at Tag.children
.
Thanks for considering it :)
I'm writing a toolset for working with pyhtml. Things like functions for easily creating complicated bootstrap forms and such. While working on this I got several ideas that would make working with pyhtml easier. But I don't want to start working on a pull request if you don't agree with the direction I'm thinking in. So here are the changes I'd like to make:
Tag.attributes
so you don't accidentally define things like data-target, id and class twice when working there directly